diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-06-28 15:24:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-29 16:13:03 -0700 |
commit | f9721fce4b12faee87398d23fd2f8b4d1b9a0309 (patch) | |
tree | 0ca37231d70028eb2fdaf615a812af8c9983b1cf /core | |
parent | 631be569fe5b277c4c1729019305e06b02cec611 (diff) | |
download | subsurface-f9721fce4b12faee87398d23fd2f8b4d1b9a0309.tar.gz |
filter: implement importing of filter presets
When importing a divelog, import filter presets. If there are
equal names, import only if the presets differ. In that case,
disambiguate the name. This made things a bit more complicated,
as comparison of filter presets had to be implemented.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divefilter.cpp | 6 | ||||
-rw-r--r-- | core/divefilter.h | 1 | ||||
-rw-r--r-- | core/filterconstraint.cpp | 16 | ||||
-rw-r--r-- | core/filterconstraint.h | 1 | ||||
-rw-r--r-- | core/filterpreset.cpp | 3 | ||||
-rw-r--r-- | core/fulltext.cpp | 1 |
6 files changed, 26 insertions, 2 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp index 9f54f5cca..23d023b9d 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -22,6 +22,12 @@ static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) } } +bool FilterData::operator==(const FilterData &f2) const +{ + return fullText.originalQuery == f2.fullText.originalQuery && + fulltextStringMode == f2.fulltextStringMode && + constraints == f2.constraints; +} bool FilterData::validFilter() const { diff --git a/core/divefilter.h b/core/divefilter.h index 3ebb049ef..d8d28ab04 100644 --- a/core/divefilter.h +++ b/core/divefilter.h @@ -32,6 +32,7 @@ struct FilterData { StringFilterMode fulltextStringMode = StringFilterMode::STARTSWITH; std::vector<filter_constraint> constraints; bool validFilter() const; + bool operator==(const FilterData &) const; }; class DiveFilter { diff --git a/core/filterconstraint.cpp b/core/filterconstraint.cpp index 4bddc7b53..fb8b49e8c 100644 --- a/core/filterconstraint.cpp +++ b/core/filterconstraint.cpp @@ -602,6 +602,22 @@ filter_constraint &filter_constraint::operator=(const filter_constraint &c) return *this; } +bool filter_constraint::operator==(const filter_constraint &f2) const +{ + if (type != f2.type || string_mode != f2.string_mode || range_mode != f2.range_mode || negate != f2.negate) + return false; + if (filter_constraint_is_timestamp(type)) + return data.timestamp_range.from == f2.data.timestamp_range.from && + data.timestamp_range.to == f2.data.timestamp_range.to; + else if (filter_constraint_is_string(type)) + return *data.string_list == *(f2.data.string_list); + else if (filter_constraint_is_multiple_choice(type)) + return data.multiple_choice == f2.data.multiple_choice; + else + return data.numerical_range.from == f2.data.numerical_range.from && + data.numerical_range.to == f2.data.numerical_range.to; +} + filter_constraint::~filter_constraint() { if (filter_constraint_is_string(type)) diff --git a/core/filterconstraint.h b/core/filterconstraint.h index d6596d09d..b3bd72354 100644 --- a/core/filterconstraint.h +++ b/core/filterconstraint.h @@ -86,6 +86,7 @@ struct filter_constraint { filter_constraint(const filter_constraint &); filter_constraint &operator=(const filter_constraint &); ~filter_constraint(); + bool operator==(const filter_constraint &f2) const; #endif }; diff --git a/core/filterpreset.cpp b/core/filterpreset.cpp index b21306502..fa48a9fd2 100644 --- a/core/filterpreset.cpp +++ b/core/filterpreset.cpp @@ -133,8 +133,9 @@ FilterData filter_preset_get(int preset) return filter_preset_table[preset].data; } -int filter_preset_add(const QString &name, const FilterData &d) +int filter_preset_add(const QString &nameIn, const FilterData &d) { + QString name = get_unique_preset_name(nameIn, filter_preset_table); return filter_preset_add_to_table(name, d, filter_preset_table); } diff --git a/core/fulltext.cpp b/core/fulltext.cpp index 38afb0798..acebc36ba 100644 --- a/core/fulltext.cpp +++ b/core/fulltext.cpp @@ -18,7 +18,6 @@ struct full_text_cache { class FullText { std::map<QString, std::vector<dive *>> words; // Dives that belong to each word public: - void populate(); // Rebuild from current dive_table void registerDive(struct dive *d); // Note: can be called repeatedly void unregisterDive(struct dive *d); // Note: can be called repeatedly |