diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-09-12 10:29:03 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-29 16:13:03 -0700 |
commit | cd27e36b8f99eca4b2870e14644a68d14f5232ba (patch) | |
tree | 57592599e88cb4a0b60489e1a172ee500976e086 | |
parent | 1ed61aeabfd2e28dc60d60f5af2253dd8b8e235a (diff) | |
download | subsurface-cd27e36b8f99eca4b2870e14644a68d14f5232ba.tar.gz |
filter: add modified flag
When editing the filter, the modified flag is set and shown to the
user. After saving / loading / clearing the filter, the flag is
reset. This simulates (probably badly) a usual load/save interface.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/filterwidget2.cpp | 31 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.h | 4 |
2 files changed, 25 insertions, 10 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 80718c64e..e6eede7df 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -10,7 +10,8 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent), - ignoreSignal(false) + ignoreSignal(false), + presetModified(false) { ui.setupUi(this); @@ -32,8 +33,8 @@ FilterWidget2::FilterWidget2(QWidget* parent) : connect(ui.clear, &QToolButton::clicked, this, &FilterWidget2::clearFilter); connect(ui.close, &QToolButton::clicked, this, &FilterWidget2::closeFilter); - connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::updateFilter); - connect(ui.fulltextStringMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::updateFilter); + connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::filterChanged); + connect(ui.fulltextStringMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::filterChanged); connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget2::presetClicked); connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget2::presetSelected); @@ -90,6 +91,7 @@ void FilterWidget2::loadPreset(int index) { FilterData filter = filter_preset_get(index); setFilterData(filter); + presetModified = false; updateFilter(); } @@ -104,7 +106,7 @@ void FilterWidget2::constraintAdded(const QModelIndex &parent, int first, int la QModelIndex idx = constraintModel.index(i, 0); constraintWidgets.emplace(constraintWidgets.begin() + i, new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable)); } - updateFilter(); + filterChanged(); } void FilterWidget2::constraintRemoved(const QModelIndex &parent, int first, int last) @@ -114,7 +116,7 @@ void FilterWidget2::constraintRemoved(const QModelIndex &parent, int first, int constraintWidgets.erase(constraintWidgets.begin() + first, constraintWidgets.begin() + last + 1); for (int i = first; i < (int)constraintWidgets.size(); ++i) constraintWidgets[i]->moveToRow(i); - updateFilter(); + filterChanged(); } void FilterWidget2::presetClicked(const QModelIndex &index) @@ -128,7 +130,6 @@ void FilterWidget2::presetClicked(const QModelIndex &index) void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &) { - updatePresetLabel(); if (selected.indexes().isEmpty()) return clearFilter(); const QModelIndex index = selected.indexes()[0]; @@ -143,7 +144,7 @@ void FilterWidget2::constraintChanged(const QModelIndex &topLeft, const QModelIn // a constraint-changed signal from the model. The reason being that the user // is currently editing the constraint and we don't want to bother them by // overwriting strings with canonicalized data. - updateFilter(); + filterChanged(); } void FilterWidget2::constraintsReset() @@ -160,8 +161,8 @@ void FilterWidget2::constraintsReset() void FilterWidget2::clearFilter() { ignoreSignal = true; // Prevent signals to force filter recalculation (TODO: check if necessary) + presetModified = false; ui.presetTable->selectionModel()->reset(); // Note: we use reset(), because that doesn't emit signals. - updatePresetLabel(); ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH); ui.fullText->clear(); ui.presetTable->clearSelection(); @@ -190,6 +191,12 @@ void FilterWidget2::setFilterData(const FilterData &filterData) constraintModel.reload(filterData.constraints); } +void FilterWidget2::filterChanged() +{ + presetModified = true; + updateFilter(); +} + void FilterWidget2::updateFilter() { if (ignoreSignal) @@ -197,6 +204,7 @@ void FilterWidget2::updateFilter() FilterData filterData = createFilterData(); DiveFilter::instance()->setFilter(filterData); + updatePresetLabel(); } int FilterWidget2::selectedPreset() const @@ -209,8 +217,11 @@ void FilterWidget2::updatePresetLabel() { int presetId = selectedPreset(); QString text; - if (presetId >= 0) + if (presetId >= 0) { text = filter_preset_name_qstring(presetId); + if (presetModified) + text += " (" + tr("modified") + ")"; + } ui.currentSet->setText(text); } @@ -231,6 +242,8 @@ void FilterWidget2::on_addSetButton_clicked() Command::editFilterPreset(idx, createFilterData()); else Command::createFilterPreset(name, createFilterData()); + presetModified = false; + updatePresetLabel(); } void FilterWidget2::showEvent(QShowEvent *event) diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index 900cbdad7..33404d5fc 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -28,7 +28,7 @@ protected: private slots: void clearFilter(); void closeFilter(); - void updateFilter(); + void filterChanged(); void constraintAdded(const QModelIndex &parent, int first, int last); void constraintRemoved(const QModelIndex &parent, int first, int last); void constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); @@ -40,11 +40,13 @@ private slots: private: bool ignoreSignal; + bool presetModified; Ui::FilterWidget2 ui; FilterConstraintModel constraintModel; void addConstraint(filter_constraint_type type); std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets; FilterData createFilterData() const; + void updateFilter(); void setFilterData(const FilterData &filterData); void loadPreset(int index); void selectPreset(int i); |