Commit a0c4d463 authored by Camilo higuita's avatar Camilo higuita

polish contactsmodle interface

parent 4f275ffe
......@@ -144,7 +144,7 @@ Maui.ApplicationWindow
ContactsView
{
id: _favsView
list.sqlquery : "select * from contacts where fav = 1"
list.query : "fav=1"
// listView.model: KPeople.PersonsModel {
// id: contactsModel
......
......@@ -14,7 +14,11 @@
ContactsModel::ContactsModel(QObject *parent) : BaseList(parent)
{
this->syncer = new Synchroniser(this);
connect(syncer, &Synchroniser::contactsReady, this, &ContactsModel::setList);
connect(syncer, &Synchroniser::contactsReady, [this]()
{
this->setList();
this->filter();
});
// connect(this, &ContactsModel::queryChanged, this, &ContactsModel::setList);
// this->getList();
}
......@@ -32,13 +36,7 @@ void ContactsModel::setQuery(const QString &query)
this->query = query;
qDebug()<< "setting query"<< this->query;
if(this->list.isEmpty())
this->getList();
if(this->query.isEmpty())
this->setList();
else
this->filter();
this->filter();
emit this->queryChanged();
}
......@@ -48,26 +46,6 @@ QString ContactsModel::getQuery() const
return this->query;
}
void ContactsModel::setSQLQuery(const QString &query)
{
if(this->SQLQuery == query)
return;
this->SQLQuery = query;
qDebug()<< "setting query"<< this->SQLQuery;
emit this->preListChanged();
this->getList(this->SQLQuery);
this->sortList();
emit this->postListChanged();
emit this->SQLQueryChanged();
}
QString ContactsModel::getSQLQuery() const
{
return this->SQLQuery;
}
void ContactsModel::setSortBy(const SORTBY &sort)
{
......@@ -248,17 +226,41 @@ bool ContactsModel::remove(const int &index)
void ContactsModel::filter()
{
if(list.isEmpty())
return;
if(this->query.isEmpty())
{
this->setList();
return;
}
FMH::MODEL_LIST res;
for(const auto item : this->list)
if(this->query.contains("="))
{
auto q = this->query.split("=", QString::SkipEmptyParts);
if(q.size() == 2)
{
for(const auto item : this->list)
{
if(item[FMH::MODEL_NAME_KEY[q.first().trimmed()]] == q.last().trimmed())
res << item;
}
}
}else
{
for(const auto data : item)
for(const auto item : this->list)
{
if(data.contains(this->query, Qt::CaseInsensitive) && !res.contains(item))
res << item;
for(const auto data : item)
{
if(data.contains(this->query, Qt::CaseInsensitive) && !res.contains(item))
res << item;
}
}
}
emit this->preListChanged();
emit this->preListChanged();
this->list = res;
emit this->postListChanged();
......
......@@ -10,7 +10,6 @@ class ContactsModel : public BaseList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged)
Q_PROPERTY(QString sqlquery READ getSQLQuery WRITE setSQLQuery NOTIFY SQLQueryChanged)
Q_PROPERTY(ContactsModel::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
......@@ -37,11 +36,8 @@ public:
FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const;
void setSQLQuery(const QString &query);
QString getSQLQuery() const;
void setQuery(const QString &query);
void setSortBy(const ContactsModel::SORTBY &sort);
ContactsModel::SORTBY getSortBy() const;
......@@ -54,8 +50,7 @@ private:
void getList(const QString &query = "select * from contacts");
void filter();
QString query = "undefined";
QString SQLQuery = "";
QString query;
ContactsModel::SORTBY sort = ContactsModel::SORTBY::N;
signals:
......
......@@ -63,7 +63,7 @@ Maui.Page
anchors.centerIn: parent
width: isWide ? control.width * 0.8 : control.width * 0.95
// height: rowHeight
placeholderText: listView.count
placeholderText: qsTr("Search %1 contacts... ".arg(listView.count))
onAccepted: list.query = text
onCleared: list.reset()
colorScheme.backgroundColor: "#4f5160"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment