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>
This commit is contained in:
Berthold Stoeger 2020-06-28 15:24:19 +02:00 committed by Dirk Hohndel
parent 631be569fe
commit f9721fce4b
14 changed files with 81 additions and 13 deletions

View file

@ -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
{

View file

@ -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 {

View file

@ -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))

View file

@ -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
};

View file

@ -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);
}

View file

@ -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