From 0c91d01eb26793e745138c4598cf15d9a21c0136 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 21 Mar 2017 12:11:49 +0100 Subject: Filtering for maillistmodel and peoplemodel Works surprisingly well and is very useful for testing. The searchbar in the maillistmodel is a temporary solution as the global searchbar has some usability issues. E.g. how do we reset the search? As an intermediate step we could just hide the searchbar and make it visible by clicking on the search button. --- components/mail/contents/ui/Mail.qml | 1 + components/package/contents/ui/MailListView.qml | 11 ++++++++++- components/package/contents/ui/People.qml | 5 ++++- framework/domain/maillistmodel.cpp | 11 +++++++++++ framework/domain/maillistmodel.h | 4 ++++ framework/domain/peoplemodel.cpp | 11 +++++++++++ framework/domain/peoplemodel.h | 4 ++++ 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/components/mail/contents/ui/Mail.qml b/components/mail/contents/ui/Mail.qml index 1ae4062d..c5078877 100644 --- a/components/mail/contents/ui/Mail.qml +++ b/components/mail/contents/ui/Mail.qml @@ -395,6 +395,7 @@ Controls2.ApplicationWindow { anchors.fill: parent Controls2.TextField { + id: searchField Layout.fillWidth: true placeholderText: "Search... is not available in this beta" } diff --git a/components/package/contents/ui/MailListView.qml b/components/package/contents/ui/MailListView.qml index 35fd4ec9..97c1a0d4 100644 --- a/components/package/contents/ui/MailListView.qml +++ b/components/package/contents/ui/MailListView.qml @@ -31,6 +31,7 @@ Item { property variant currentMail: null property bool isDraft : false property int currentIndex + property string filterString: searchBar.text; onParentFolderChanged: { currentMail = null @@ -88,10 +89,17 @@ Item { } } + TextField { + id: searchBar + anchors.top: toolbar.bottom + width: parent.width + placeholderText: qsTr("Filter...") + } + ListView { id: listView - anchors.top: toolbar.bottom + anchors.top: searchBar.bottom width: parent.width height: parent.height - toolbar.height @@ -120,6 +128,7 @@ Item { model: KubeFramework.MailListModel { parentFolder: root.parentFolder + filter: root.filterString } delegate: Item { diff --git a/components/package/contents/ui/People.qml b/components/package/contents/ui/People.qml index f280e45b..de8425df 100644 --- a/components/package/contents/ui/People.qml +++ b/components/package/contents/ui/People.qml @@ -55,6 +55,7 @@ Popup { } TextField { + id: searchBar anchors.centerIn: parent placeholderText: "Search..." @@ -122,7 +123,9 @@ Popup { Repeater { - model: KubeFramework.PeopleModel{} + model: KubeFramework.PeopleModel { + filter: searchBar.text + } delegate: Rectangle { id: delegateRoot diff --git a/framework/domain/maillistmodel.cpp b/framework/domain/maillistmodel.cpp index 11fb9f82..5a462021 100644 --- a/framework/domain/maillistmodel.cpp +++ b/framework/domain/maillistmodel.cpp @@ -27,6 +27,7 @@ MailListModel::MailListModel(QObject *parent) { setDynamicSortFilter(true); sort(0, Qt::DescendingOrder); + setFilterCaseSensitivity(Qt::CaseInsensitive); } MailListModel::~MailListModel() @@ -34,6 +35,16 @@ MailListModel::~MailListModel() } +void MailListModel::setFilter(const QString &filter) +{ + setFilterWildcard(filter); +} + +QString MailListModel::filter() const +{ + return {}; +} + QHash< int, QByteArray > MailListModel::roleNames() const { QHash roles; diff --git a/framework/domain/maillistmodel.h b/framework/domain/maillistmodel.h index 5526a991..316ff4c6 100644 --- a/framework/domain/maillistmodel.h +++ b/framework/domain/maillistmodel.h @@ -31,6 +31,7 @@ class MailListModel : public QSortFilterProxyModel Q_OBJECT Q_PROPERTY (QVariant parentFolder READ parentFolder WRITE setParentFolder) Q_PROPERTY (QVariant mail READ mail WRITE setMail) + Q_PROPERTY (QString filter READ filter WRITE setFilter) public: MailListModel(QObject *parent = Q_NULLPTR); @@ -70,6 +71,9 @@ public: void setMail(const QVariant &mail); QVariant mail() const; + void setFilter(const QString &mail); + QString filter() const; + private: void fetchMail(Sink::ApplicationDomain::Mail::Ptr mail); diff --git a/framework/domain/peoplemodel.cpp b/framework/domain/peoplemodel.cpp index d33c6703..ef2cc9a0 100644 --- a/framework/domain/peoplemodel.cpp +++ b/framework/domain/peoplemodel.cpp @@ -29,6 +29,7 @@ PeopleModel::PeopleModel(QObject *parent) setDynamicSortFilter(true); sort(0, Qt::DescendingOrder); + setFilterCaseSensitivity(Qt::CaseInsensitive); Sink::Query query; query.setFlags(Sink::Query::LiveQuery); query.request(); @@ -43,6 +44,16 @@ PeopleModel::~PeopleModel() } +void PeopleModel::setFilter(const QString &filter) +{ + setFilterWildcard(filter); +} + +QString PeopleModel::filter() const +{ + return {}; +} + QHash< int, QByteArray > PeopleModel::roleNames() const { static QHash roles = { diff --git a/framework/domain/peoplemodel.h b/framework/domain/peoplemodel.h index 1e9d2d01..a59e752c 100644 --- a/framework/domain/peoplemodel.h +++ b/framework/domain/peoplemodel.h @@ -34,6 +34,7 @@ class PeopleModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY (QVariant addressbook READ addressbook WRITE setAddressbook) + Q_PROPERTY (QString filter READ filter WRITE setFilter) public: PeopleModel(QObject *parent = Q_NULLPTR); @@ -60,6 +61,9 @@ public: void setAddressbook(const QVariant &parentFolder); QVariant addressbook() const; + void setFilter(const QString &mail); + QString filter() const; + private: QSharedPointer mModel; }; -- cgit v1.2.3