diff options
-rw-r--r-- | mobile-widgets/qml/DiveList.qml | 19 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 13 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 2 | ||||
-rw-r--r-- | qt-models/divelistmodel.cpp | 9 | ||||
-rw-r--r-- | qt-models/divelistmodel.h | 3 |
5 files changed, 36 insertions, 10 deletions
diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index 60d2f5ea1..3017de8e6 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -444,6 +444,21 @@ Kirigami.ScrollablePage { anchors.right: parent.right anchors.leftMargin: Kirigami.Units.gridUnit / 2 anchors.rightMargin: Kirigami.Units.gridUnit / 2 + TemplateComboBox { + id: sitefilterMode + editable: false + model: ListModel { + ListElement {text: qsTr("Fulltext")} + ListElement {text: qsTr("People")} + ListElement {text: qsTr("Tags")} + } + font.pointSize: subsurfaceTheme.smallPointSize + Layout.preferredWidth: parent.width * 0.2 + Layout.maximumWidth: parent.width * 0.3 + onActivated: { + manager.setFilter(sitefilter.text, currentIndex) + } + } Controls.TextField { id: sitefilter z: 10 @@ -452,7 +467,7 @@ Kirigami.ScrollablePage { text: "" placeholderText: "Full text search" onAccepted: { - manager.setFilter(text) + manager.setFilter(text, sitefilterMode.currentIndex) } onEnabledChanged: { // reset the filter when it gets toggled @@ -539,7 +554,7 @@ Kirigami.ScrollablePage { text: qsTr("Filter dives") onTriggered: { rootItem.filterToggle = !rootItem.filterToggle - manager.setFilter("") + manager.setFilter("", 0) numShownText = diveModel.shown() } } diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index a877818cb..5896428b8 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -2094,13 +2094,20 @@ void QMLManager::showDownloadPage(QString deviceString) emit pluggedInDeviceNameChanged(); } -void QMLManager::setFilter(const QString filterText) +void QMLManager::setFilter(const QString filterText, int index) { + FilterData::Mode mode; + switch(index) { + default: + case 0: mode = FilterData::Mode::FULLTEXT; break; + case 1: mode = FilterData::Mode::PEOPLE; break; + case 2: mode = FilterData::Mode::TAGS; break; + } // show that we are doing something, then do something in another thread in order not to block the UI QMetaObject::invokeMethod(qmlWindow, "showBusyAndDisconnectModel"); QtConcurrent::run(QThreadPool::globalInstance(), - [this,filterText]{ - DiveListSortModel::instance()->setFilter(filterText); + [this,filterText,mode]{ + DiveListSortModel::instance()->setFilter(filterText, mode); CollapsedDiveListSortModel::instance()->updateFilterState(); QMetaObject::invokeMethod(qmlWindow, "hideBusyAndConnectModel"); }); diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index c3124c21c..466413dd3 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -104,7 +104,7 @@ public: Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText); Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr); Q_INVOKABLE void setGitLocalOnly(const bool &value); - Q_INVOKABLE void setFilter(const QString filterText); + Q_INVOKABLE void setFilter(const QString filterText, int mode); static QMLManager *instance(); Q_INVOKABLE void registerError(QString error); diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 05f163505..d1ae4093d 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -207,13 +207,16 @@ void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel) updateFilterState(); } -void DiveListSortModel::setFilter(QString f) +void DiveListSortModel::setFilter(QString f, FilterData::Mode mode) { f = f.trimmed(); FilterData data; if (!f.isEmpty()) { - data.mode = FilterData::Mode::FULLTEXT; - data.fullText = f; + data.mode = mode; + if (mode == FilterData::Mode::FULLTEXT) + data.fullText = f; + else + data.tags = f.split(",", QString::SkipEmptyParts); } DiveFilter::instance()->setFilter(data); CollapsedDiveListSortModel::instance()->updateFilterState(); diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index f09003b5f..b051605ae 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -5,6 +5,7 @@ #include <QAbstractListModel> #include <QSortFilterProxyModel> +#include "core/divefilter.h" #include "core/subsurface-qt/diveobjecthelper.h" class CollapsedDiveListSortModel : public QSortFilterProxyModel @@ -48,7 +49,7 @@ public: void updateFilterState(); public slots: int getIdxForId(int id); - void setFilter(QString f); + void setFilter(QString f, FilterData::Mode mode); void resetFilter(); int shown(); protected: |