mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
filter: introduce people- and tags-filtering in the mobile UI
Add a combo-box where the user can switch between "fulltext", "people" and "tags" filtering. Connect the combobox to the already existing filter-code. Dirk: make combo-box smaller by using a smaller font and restricting the width. Setting both maximum and preferred widths gives more consistent results. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
c1e33aac21
commit
e0766aa4bd
5 changed files with 36 additions and 10 deletions
|
@ -444,6 +444,21 @@ Kirigami.ScrollablePage {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.leftMargin: Kirigami.Units.gridUnit / 2
|
anchors.leftMargin: Kirigami.Units.gridUnit / 2
|
||||||
anchors.rightMargin: 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 {
|
Controls.TextField {
|
||||||
id: sitefilter
|
id: sitefilter
|
||||||
z: 10
|
z: 10
|
||||||
|
@ -452,7 +467,7 @@ Kirigami.ScrollablePage {
|
||||||
text: ""
|
text: ""
|
||||||
placeholderText: "Full text search"
|
placeholderText: "Full text search"
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
manager.setFilter(text)
|
manager.setFilter(text, sitefilterMode.currentIndex)
|
||||||
}
|
}
|
||||||
onEnabledChanged: {
|
onEnabledChanged: {
|
||||||
// reset the filter when it gets toggled
|
// reset the filter when it gets toggled
|
||||||
|
@ -539,7 +554,7 @@ Kirigami.ScrollablePage {
|
||||||
text: qsTr("Filter dives")
|
text: qsTr("Filter dives")
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
rootItem.filterToggle = !rootItem.filterToggle
|
rootItem.filterToggle = !rootItem.filterToggle
|
||||||
manager.setFilter("")
|
manager.setFilter("", 0)
|
||||||
numShownText = diveModel.shown()
|
numShownText = diveModel.shown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2094,13 +2094,20 @@ void QMLManager::showDownloadPage(QString deviceString)
|
||||||
emit pluggedInDeviceNameChanged();
|
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
|
// show that we are doing something, then do something in another thread in order not to block the UI
|
||||||
QMetaObject::invokeMethod(qmlWindow, "showBusyAndDisconnectModel");
|
QMetaObject::invokeMethod(qmlWindow, "showBusyAndDisconnectModel");
|
||||||
QtConcurrent::run(QThreadPool::globalInstance(),
|
QtConcurrent::run(QThreadPool::globalInstance(),
|
||||||
[this,filterText]{
|
[this,filterText,mode]{
|
||||||
DiveListSortModel::instance()->setFilter(filterText);
|
DiveListSortModel::instance()->setFilter(filterText, mode);
|
||||||
CollapsedDiveListSortModel::instance()->updateFilterState();
|
CollapsedDiveListSortModel::instance()->updateFilterState();
|
||||||
QMetaObject::invokeMethod(qmlWindow, "hideBusyAndConnectModel");
|
QMetaObject::invokeMethod(qmlWindow, "hideBusyAndConnectModel");
|
||||||
});
|
});
|
||||||
|
|
|
@ -104,7 +104,7 @@ public:
|
||||||
Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText);
|
Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText);
|
||||||
Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr);
|
Q_INVOKABLE int getConnectionIndex(const QString &deviceSubstr);
|
||||||
Q_INVOKABLE void setGitLocalOnly(const bool &value);
|
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();
|
static QMLManager *instance();
|
||||||
Q_INVOKABLE void registerError(QString error);
|
Q_INVOKABLE void registerError(QString error);
|
||||||
|
|
|
@ -207,13 +207,16 @@ void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||||
updateFilterState();
|
updateFilterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListSortModel::setFilter(QString f)
|
void DiveListSortModel::setFilter(QString f, FilterData::Mode mode)
|
||||||
{
|
{
|
||||||
f = f.trimmed();
|
f = f.trimmed();
|
||||||
FilterData data;
|
FilterData data;
|
||||||
if (!f.isEmpty()) {
|
if (!f.isEmpty()) {
|
||||||
data.mode = FilterData::Mode::FULLTEXT;
|
data.mode = mode;
|
||||||
data.fullText = f;
|
if (mode == FilterData::Mode::FULLTEXT)
|
||||||
|
data.fullText = f;
|
||||||
|
else
|
||||||
|
data.tags = f.split(",", QString::SkipEmptyParts);
|
||||||
}
|
}
|
||||||
DiveFilter::instance()->setFilter(data);
|
DiveFilter::instance()->setFilter(data);
|
||||||
CollapsedDiveListSortModel::instance()->updateFilterState();
|
CollapsedDiveListSortModel::instance()->updateFilterState();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "core/divefilter.h"
|
||||||
#include "core/subsurface-qt/diveobjecthelper.h"
|
#include "core/subsurface-qt/diveobjecthelper.h"
|
||||||
|
|
||||||
class CollapsedDiveListSortModel : public QSortFilterProxyModel
|
class CollapsedDiveListSortModel : public QSortFilterProxyModel
|
||||||
|
@ -48,7 +49,7 @@ public:
|
||||||
void updateFilterState();
|
void updateFilterState();
|
||||||
public slots:
|
public slots:
|
||||||
int getIdxForId(int id);
|
int getIdxForId(int id);
|
||||||
void setFilter(QString f);
|
void setFilter(QString f, FilterData::Mode mode);
|
||||||
void resetFilter();
|
void resetFilter();
|
||||||
int shown();
|
int shown();
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue