aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-02-14 13:10:24 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-01 10:21:44 -0800
commit41aae1aebe1aea4db58d61a171f7ecd76b6282d7 (patch)
tree7997fef36ae33f3627f6e33d609509396effc166
parent34549c4cc308ecd740c0913ff3f6e2461caa7404 (diff)
downloadsubsurface-41aae1aebe1aea4db58d61a171f7ecd76b6282d7.tar.gz
filter: move StringMode out of FilterData
The FilterData struct has the enum StringMode, which describes how strings are searched (substring, startswith, exact). To make it more generally accessible, remove it from the class. Since it is an "enum class", the values don't pollute the global namespace anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/divefilter.cpp20
-rw-r--r--core/divefilter.h23
-rw-r--r--desktop-widgets/filterwidget2.cpp12
3 files changed, 28 insertions, 27 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp
index 7f47e45ac..1372f5a0f 100644
--- a/core/divefilter.cpp
+++ b/core/divefilter.cpp
@@ -73,16 +73,16 @@ namespace {
// Check whether either all, any or none of the items of the first list is
// in the second list as a super string.
// The mode is controlled by the second argument
- bool check(const QStringList &items, const QStringList &list, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool check(const QStringList &items, const QStringList &list, FilterData::Mode mode, StringFilterMode stringMode)
{
bool negate = mode == FilterData::Mode::NONE_OF;
bool any_of = mode == FilterData::Mode::ANY_OF;
StrCheck strchk =
- stringMode == FilterData::StringMode::SUBSTRING ?
+ stringMode == StringFilterMode::SUBSTRING ?
[](const QString &s1, const QString &s2) { return s1.contains(s2, Qt::CaseInsensitive); } :
- stringMode == FilterData::StringMode::STARTSWITH ?
+ stringMode == StringFilterMode::STARTSWITH ?
[](const QString &s1, const QString &s2) { return s1.startsWith(s2, Qt::CaseInsensitive); } :
- /* FilterData::StringMode::EXACT */
+ /* StringFilterMode::EXACT */
[](const QString &s1, const QString &s2) { return s1.compare(s2, Qt::CaseInsensitive) == 0; };
auto fun = [&list, negate, strchk](const QString &item)
{ return listContainsSuperstring(list, item, strchk) != negate; };
@@ -90,7 +90,7 @@ namespace {
: std::all_of(items.begin(), items.end(), fun);
}
- bool hasTags(const QStringList &tags, const struct dive *d, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool hasTags(const QStringList &tags, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)
{
if (tags.isEmpty())
return true;
@@ -99,7 +99,7 @@ namespace {
return check(tags, dive_tags, mode, stringMode);
}
- bool hasPersons(const QStringList &people, const struct dive *d, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool hasPersons(const QStringList &people, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)
{
if (people.isEmpty())
return true;
@@ -108,7 +108,7 @@ namespace {
return check(people, dive_people, mode, stringMode);
}
- bool hasLocations(const QStringList &locations, const struct dive *d, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool hasLocations(const QStringList &locations, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)
{
if (locations.isEmpty())
return true;
@@ -123,12 +123,12 @@ namespace {
}
// TODO: Finish this implementation.
- bool hasEquipment(const QStringList &, const struct dive *, FilterData::Mode, FilterData::StringMode)
+ bool hasEquipment(const QStringList &, const struct dive *, FilterData::Mode, StringFilterMode)
{
return true;
}
- bool hasSuits(const QStringList &suits, const struct dive *d, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool hasSuits(const QStringList &suits, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)
{
if (suits.isEmpty())
return true;
@@ -138,7 +138,7 @@ namespace {
return check(suits, diveSuits, mode, stringMode);
}
- bool hasNotes(const QStringList &dnotes, const struct dive *d, FilterData::Mode mode, FilterData::StringMode stringMode)
+ bool hasNotes(const QStringList &dnotes, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)
{
if (dnotes.isEmpty())
return true;
diff --git a/core/divefilter.h b/core/divefilter.h
index aa166d022..129fe0888 100644
--- a/core/divefilter.h
+++ b/core/divefilter.h
@@ -13,6 +13,12 @@ struct ShownChange {
bool currentChanged;
};
+enum class StringFilterMode {
+ SUBSTRING = 0,
+ STARTSWITH = 1,
+ EXACT = 2
+};
+
// The dive filter for mobile is currently much simpler than for desktop.
// Therefore, for now we have two completely separate implementations.
// This should be unified in the future.
@@ -43,11 +49,6 @@ struct FilterData {
ANY_OF = 1,
NONE_OF = 2
};
- enum class StringMode {
- SUBSTRING = 0,
- STARTSWITH = 1,
- EXACT = 2
- };
bool validFilter = false;
int minVisibility = 0;
@@ -77,12 +78,12 @@ struct FilterData {
Mode dnotesMode = Mode::ALL_OF;
Mode suitMode = Mode::ANY_OF;
Mode equipmentMode = Mode::ALL_OF;
- StringMode tagsStringMode = StringMode::SUBSTRING;
- StringMode peopleStringMode = StringMode::SUBSTRING;
- StringMode locationStringMode = StringMode::SUBSTRING;
- StringMode dnotesStringMode = StringMode::SUBSTRING;
- StringMode suitStringMode = StringMode::SUBSTRING;
- StringMode equipmentStringMode = StringMode::SUBSTRING;
+ StringFilterMode tagsStringMode = StringFilterMode::SUBSTRING;
+ StringFilterMode peopleStringMode = StringFilterMode::SUBSTRING;
+ StringFilterMode locationStringMode = StringFilterMode::SUBSTRING;
+ StringFilterMode dnotesStringMode = StringFilterMode::SUBSTRING;
+ StringFilterMode suitStringMode = StringFilterMode::SUBSTRING;
+ StringFilterMode equipmentStringMode = StringFilterMode::SUBSTRING;
bool logged = true;
bool planned = true;
};
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp
index 2df96062f..534cb4594 100644
--- a/desktop-widgets/filterwidget2.cpp
+++ b/desktop-widgets/filterwidget2.cpp
@@ -226,12 +226,12 @@ void FilterWidget2::updateFilter()
filterData.suitMode = (FilterData::Mode)ui.suitMode->currentIndex();
filterData.dnotesMode = (FilterData::Mode)ui.dnotesMode->currentIndex();
filterData.equipmentMode = (FilterData::Mode)ui.equipmentMode->currentIndex();
- filterData.tagsStringMode = (FilterData::StringMode)ui.tagsStringMode->currentIndex();
- filterData.peopleStringMode = (FilterData::StringMode)ui.peopleStringMode->currentIndex();
- filterData.locationStringMode = (FilterData::StringMode)ui.locationStringMode->currentIndex();
- filterData.suitStringMode = (FilterData::StringMode)ui.suitStringMode->currentIndex();
- filterData.dnotesStringMode = (FilterData::StringMode)ui.dnotesStringMode->currentIndex();
- filterData.equipmentStringMode = (FilterData::StringMode)ui.equipmentStringMode->currentIndex();
+ filterData.tagsStringMode = (StringFilterMode)ui.tagsStringMode->currentIndex();
+ filterData.peopleStringMode = (StringFilterMode)ui.peopleStringMode->currentIndex();
+ filterData.locationStringMode = (StringFilterMode)ui.locationStringMode->currentIndex();
+ filterData.suitStringMode = (StringFilterMode)ui.suitStringMode->currentIndex();
+ filterData.dnotesStringMode = (StringFilterMode)ui.dnotesStringMode->currentIndex();
+ filterData.equipmentStringMode = (StringFilterMode)ui.equipmentStringMode->currentIndex();
filterData.logged = ui.logged->isChecked();
filterData.planned = ui.planned->isChecked();