summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-24 17:11:29 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit22fe0c14e885161ae9a18a00b71283a77679d06c (patch)
treeca8c6bff95de31442b72a400d2c4a26190cc4606
parent9afea37e15db29f59048d1bc2553838943ca1b62 (diff)
downloadsubsurface-22fe0c14e885161ae9a18a00b71283a77679d06c.tar.gz
Dive sites: add fulltext filter
In the dive site tab, add a fulltext filter. The UI is only a mock up. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp5
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h1
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.ui17
-rw-r--r--qt-models/divelocationmodel.cpp16
-rw-r--r--qt-models/divelocationmodel.h2
5 files changed, 34 insertions, 7 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp
index dc0b6be67..816835dd3 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp
@@ -74,3 +74,8 @@ void TabDiveSite::on_purgeUnused_clicked()
{
Command::purgeUnusedDiveSites();
}
+
+void TabDiveSite::on_filterText_textChanged(const QString &text)
+{
+ model.setFilter(text);
+}
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.h b/desktop-widgets/tab-widgets/TabDiveSite.h
index b9c07ed69..1fdaeb989 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.h
+++ b/desktop-widgets/tab-widgets/TabDiveSite.h
@@ -17,6 +17,7 @@ private slots:
void diveSiteAdded(struct dive_site *, int idx);
void diveSiteChanged(struct dive_site *ds, int field);
void on_purgeUnused_clicked();
+ void on_filterText_textChanged(const QString &text);
private:
Ui::TabDiveSite ui;
DiveSiteSortedModel model;
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.ui b/desktop-widgets/tab-widgets/TabDiveSite.ui
index b536f101a..0d53b3510 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.ui
+++ b/desktop-widgets/tab-widgets/TabDiveSite.ui
@@ -15,11 +15,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QToolButton" name="purgeUnused">
- <property name="text">
- <string>Purge unused dive sites</string>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="layout">
+ <item>
+ <widget class="QToolButton" name="purgeUnused">
+ <property name="text">
+ <string>Purge unused dive sites</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="filterText"/>
+ </item>
+ </layout>
</item>
<item>
<widget class="TableView" name="diveSites" native="true"/>
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index fbeab7be8..538f27e16 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -178,8 +178,14 @@ void LocationInformationModel::diveSiteDivesChanged(struct dive_site *ds)
bool DiveSiteSortedModel::filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const
{
- // TODO: filtering
- return true;
+ if (fullText.isEmpty())
+ return true;
+
+ if (sourceRow < 0 || sourceRow > dive_site_table.nr)
+ return false;
+ struct dive_site *ds = dive_site_table.dive_sites[sourceRow];
+ QString text = QString(ds->name) + QString(ds->description) + QString(ds->notes);
+ return text.contains(fullText, Qt::CaseInsensitive);
}
bool DiveSiteSortedModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
@@ -272,6 +278,12 @@ void DiveSiteSortedModel::remove(const QModelIndex &index)
}
#endif // SUBSURFACE_MOBILE
+void DiveSiteSortedModel::setFilter(const QString &text)
+{
+ fullText = text.trimmed();
+ invalidateFilter();
+}
+
GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance()
{
static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel();
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 9f1c4468b..ca74ad791 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -44,6 +44,7 @@ private:
struct dive_site *getDiveSite(const QModelIndex &idx);
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
+ QString fullText;
#ifndef SUBSURFACE_MOBILE
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
public slots:
@@ -52,6 +53,7 @@ public slots:
public:
DiveSiteSortedModel();
QStringList allSiteNames() const;
+ void setFilter(const QString &text);
};
// To access only divesites at the given GPS coordinates with the exception of a given dive site