mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:33:24 +00:00
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>
This commit is contained in:
parent
1ed61aeabf
commit
cd27e36b8f
2 changed files with 25 additions and 10 deletions
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
FilterWidget2::FilterWidget2(QWidget* parent) :
|
FilterWidget2::FilterWidget2(QWidget* parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ignoreSignal(false)
|
ignoreSignal(false),
|
||||||
|
presetModified(false)
|
||||||
{
|
{
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
|
|
||||||
|
@ -32,8 +33,8 @@ FilterWidget2::FilterWidget2(QWidget* parent) :
|
||||||
|
|
||||||
connect(ui.clear, &QToolButton::clicked, this, &FilterWidget2::clearFilter);
|
connect(ui.clear, &QToolButton::clicked, this, &FilterWidget2::clearFilter);
|
||||||
connect(ui.close, &QToolButton::clicked, this, &FilterWidget2::closeFilter);
|
connect(ui.close, &QToolButton::clicked, this, &FilterWidget2::closeFilter);
|
||||||
connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::updateFilter);
|
connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::filterChanged);
|
||||||
connect(ui.fulltextStringMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::updateFilter);
|
connect(ui.fulltextStringMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::filterChanged);
|
||||||
connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget2::presetClicked);
|
connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget2::presetClicked);
|
||||||
connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget2::presetSelected);
|
connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget2::presetSelected);
|
||||||
|
|
||||||
|
@ -90,6 +91,7 @@ void FilterWidget2::loadPreset(int index)
|
||||||
{
|
{
|
||||||
FilterData filter = filter_preset_get(index);
|
FilterData filter = filter_preset_get(index);
|
||||||
setFilterData(filter);
|
setFilterData(filter);
|
||||||
|
presetModified = false;
|
||||||
updateFilter();
|
updateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ void FilterWidget2::constraintAdded(const QModelIndex &parent, int first, int la
|
||||||
QModelIndex idx = constraintModel.index(i, 0);
|
QModelIndex idx = constraintModel.index(i, 0);
|
||||||
constraintWidgets.emplace(constraintWidgets.begin() + i, new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable));
|
constraintWidgets.emplace(constraintWidgets.begin() + i, new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable));
|
||||||
}
|
}
|
||||||
updateFilter();
|
filterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterWidget2::constraintRemoved(const QModelIndex &parent, int first, int last)
|
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);
|
constraintWidgets.erase(constraintWidgets.begin() + first, constraintWidgets.begin() + last + 1);
|
||||||
for (int i = first; i < (int)constraintWidgets.size(); ++i)
|
for (int i = first; i < (int)constraintWidgets.size(); ++i)
|
||||||
constraintWidgets[i]->moveToRow(i);
|
constraintWidgets[i]->moveToRow(i);
|
||||||
updateFilter();
|
filterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterWidget2::presetClicked(const QModelIndex &index)
|
void FilterWidget2::presetClicked(const QModelIndex &index)
|
||||||
|
@ -128,7 +130,6 @@ void FilterWidget2::presetClicked(const QModelIndex &index)
|
||||||
|
|
||||||
void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &)
|
void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &)
|
||||||
{
|
{
|
||||||
updatePresetLabel();
|
|
||||||
if (selected.indexes().isEmpty())
|
if (selected.indexes().isEmpty())
|
||||||
return clearFilter();
|
return clearFilter();
|
||||||
const QModelIndex index = selected.indexes()[0];
|
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
|
// 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
|
// is currently editing the constraint and we don't want to bother them by
|
||||||
// overwriting strings with canonicalized data.
|
// overwriting strings with canonicalized data.
|
||||||
updateFilter();
|
filterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterWidget2::constraintsReset()
|
void FilterWidget2::constraintsReset()
|
||||||
|
@ -160,8 +161,8 @@ void FilterWidget2::constraintsReset()
|
||||||
void FilterWidget2::clearFilter()
|
void FilterWidget2::clearFilter()
|
||||||
{
|
{
|
||||||
ignoreSignal = true; // Prevent signals to force filter recalculation (TODO: check if necessary)
|
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.
|
ui.presetTable->selectionModel()->reset(); // Note: we use reset(), because that doesn't emit signals.
|
||||||
updatePresetLabel();
|
|
||||||
ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH);
|
ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH);
|
||||||
ui.fullText->clear();
|
ui.fullText->clear();
|
||||||
ui.presetTable->clearSelection();
|
ui.presetTable->clearSelection();
|
||||||
|
@ -190,6 +191,12 @@ void FilterWidget2::setFilterData(const FilterData &filterData)
|
||||||
constraintModel.reload(filterData.constraints);
|
constraintModel.reload(filterData.constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilterWidget2::filterChanged()
|
||||||
|
{
|
||||||
|
presetModified = true;
|
||||||
|
updateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
void FilterWidget2::updateFilter()
|
void FilterWidget2::updateFilter()
|
||||||
{
|
{
|
||||||
if (ignoreSignal)
|
if (ignoreSignal)
|
||||||
|
@ -197,6 +204,7 @@ void FilterWidget2::updateFilter()
|
||||||
|
|
||||||
FilterData filterData = createFilterData();
|
FilterData filterData = createFilterData();
|
||||||
DiveFilter::instance()->setFilter(filterData);
|
DiveFilter::instance()->setFilter(filterData);
|
||||||
|
updatePresetLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
int FilterWidget2::selectedPreset() const
|
int FilterWidget2::selectedPreset() const
|
||||||
|
@ -209,8 +217,11 @@ void FilterWidget2::updatePresetLabel()
|
||||||
{
|
{
|
||||||
int presetId = selectedPreset();
|
int presetId = selectedPreset();
|
||||||
QString text;
|
QString text;
|
||||||
if (presetId >= 0)
|
if (presetId >= 0) {
|
||||||
text = filter_preset_name_qstring(presetId);
|
text = filter_preset_name_qstring(presetId);
|
||||||
|
if (presetModified)
|
||||||
|
text += " (" + tr("modified") + ")";
|
||||||
|
}
|
||||||
ui.currentSet->setText(text);
|
ui.currentSet->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +242,8 @@ void FilterWidget2::on_addSetButton_clicked()
|
||||||
Command::editFilterPreset(idx, createFilterData());
|
Command::editFilterPreset(idx, createFilterData());
|
||||||
else
|
else
|
||||||
Command::createFilterPreset(name, createFilterData());
|
Command::createFilterPreset(name, createFilterData());
|
||||||
|
presetModified = false;
|
||||||
|
updatePresetLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterWidget2::showEvent(QShowEvent *event)
|
void FilterWidget2::showEvent(QShowEvent *event)
|
||||||
|
|
|
@ -28,7 +28,7 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void clearFilter();
|
void clearFilter();
|
||||||
void closeFilter();
|
void closeFilter();
|
||||||
void updateFilter();
|
void filterChanged();
|
||||||
void constraintAdded(const QModelIndex &parent, int first, int last);
|
void constraintAdded(const QModelIndex &parent, int first, int last);
|
||||||
void constraintRemoved(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);
|
void constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||||
|
@ -40,11 +40,13 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ignoreSignal;
|
bool ignoreSignal;
|
||||||
|
bool presetModified;
|
||||||
Ui::FilterWidget2 ui;
|
Ui::FilterWidget2 ui;
|
||||||
FilterConstraintModel constraintModel;
|
FilterConstraintModel constraintModel;
|
||||||
void addConstraint(filter_constraint_type type);
|
void addConstraint(filter_constraint_type type);
|
||||||
std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets;
|
std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets;
|
||||||
FilterData createFilterData() const;
|
FilterData createFilterData() const;
|
||||||
|
void updateFilter();
|
||||||
void setFilterData(const FilterData &filterData);
|
void setFilterData(const FilterData &filterData);
|
||||||
void loadPreset(int index);
|
void loadPreset(int index);
|
||||||
void selectPreset(int i);
|
void selectPreset(int i);
|
||||||
|
|
Loading…
Add table
Reference in a new issue