Commit a0c4d463 authored by Camilo higuita's avatar Camilo higuita

polish contactsmodle interface

parent 4f275ffe
...@@ -144,7 +144,7 @@ Maui.ApplicationWindow ...@@ -144,7 +144,7 @@ Maui.ApplicationWindow
ContactsView ContactsView
{ {
id: _favsView id: _favsView
list.sqlquery : "select * from contacts where fav = 1" list.query : "fav=1"
// listView.model: KPeople.PersonsModel { // listView.model: KPeople.PersonsModel {
// id: contactsModel // id: contactsModel
......
...@@ -14,7 +14,11 @@ ...@@ -14,7 +14,11 @@
ContactsModel::ContactsModel(QObject *parent) : BaseList(parent) ContactsModel::ContactsModel(QObject *parent) : BaseList(parent)
{ {
this->syncer = new Synchroniser(this); 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); // connect(this, &ContactsModel::queryChanged, this, &ContactsModel::setList);
// this->getList(); // this->getList();
} }
...@@ -32,13 +36,7 @@ void ContactsModel::setQuery(const QString &query) ...@@ -32,13 +36,7 @@ void ContactsModel::setQuery(const QString &query)
this->query = query; this->query = query;
qDebug()<< "setting query"<< this->query; qDebug()<< "setting query"<< this->query;
if(this->list.isEmpty()) this->filter();
this->getList();
if(this->query.isEmpty())
this->setList();
else
this->filter();
emit this->queryChanged(); emit this->queryChanged();
} }
...@@ -48,26 +46,6 @@ QString ContactsModel::getQuery() const ...@@ -48,26 +46,6 @@ QString ContactsModel::getQuery() const
return this->query; 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) void ContactsModel::setSortBy(const SORTBY &sort)
{ {
...@@ -248,17 +226,41 @@ bool ContactsModel::remove(const int &index) ...@@ -248,17 +226,41 @@ bool ContactsModel::remove(const int &index)
void ContactsModel::filter() void ContactsModel::filter()
{ {
if(list.isEmpty())
return;
if(this->query.isEmpty())
{
this->setList();
return;
}
FMH::MODEL_LIST res; 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)) for(const auto data : item)
res << item; {
if(data.contains(this->query, Qt::CaseInsensitive) && !res.contains(item))
res << item;
}
} }
} }
emit this->preListChanged();
emit this->preListChanged();
this->list = res; this->list = res;
emit this->postListChanged(); emit this->postListChanged();
......
...@@ -10,7 +10,6 @@ class ContactsModel : public BaseList ...@@ -10,7 +10,6 @@ class ContactsModel : public BaseList
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged) 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) Q_PROPERTY(ContactsModel::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public: public:
...@@ -37,11 +36,8 @@ public: ...@@ -37,11 +36,8 @@ public:
FMH::MODEL_LIST items() const override; FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const; QString getQuery() const;
void setQuery(const QString &query);
void setSQLQuery(const QString &query);
QString getSQLQuery() const;
void setSortBy(const ContactsModel::SORTBY &sort); void setSortBy(const ContactsModel::SORTBY &sort);
ContactsModel::SORTBY getSortBy() const; ContactsModel::SORTBY getSortBy() const;
...@@ -54,8 +50,7 @@ private: ...@@ -54,8 +50,7 @@ private:
void getList(const QString &query = "select * from contacts"); void getList(const QString &query = "select * from contacts");
void filter(); void filter();
QString query = "undefined"; QString query;
QString SQLQuery = "";
ContactsModel::SORTBY sort = ContactsModel::SORTBY::N; ContactsModel::SORTBY sort = ContactsModel::SORTBY::N;
signals: signals:
......
...@@ -63,7 +63,7 @@ Maui.Page ...@@ -63,7 +63,7 @@ Maui.Page
anchors.centerIn: parent anchors.centerIn: parent
width: isWide ? control.width * 0.8 : control.width * 0.95 width: isWide ? control.width * 0.8 : control.width * 0.95
// height: rowHeight // height: rowHeight
placeholderText: listView.count placeholderText: qsTr("Search %1 contacts... ".arg(listView.count))
onAccepted: list.query = text onAccepted: list.query = text
onCleared: list.reset() onCleared: list.reset()
colorScheme.backgroundColor: "#4f5160" 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