From 7337ff386bf80fe9116c117e01abbb32651fd7db Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 26 Sep 2020 11:40:54 +0200 Subject: cleanup: rename FilterWidget2 to FilterWidget The name "FilterWidget2" is historical and has no meaning anymore, since the current version has little to nothing to do with the "second" version of the widget. Rename the class and source files accordingly. Signed-off-by: Berthold Stoeger --- desktop-widgets/CMakeLists.txt | 6 +- desktop-widgets/filterwidget.cpp | 266 ++++++++++++++++++++++++++++++++++++++ desktop-widgets/filterwidget.h | 58 +++++++++ desktop-widgets/filterwidget.ui | 256 ++++++++++++++++++++++++++++++++++++ desktop-widgets/filterwidget2.cpp | 266 -------------------------------------- desktop-widgets/filterwidget2.h | 59 --------- desktop-widgets/filterwidget2.ui | 256 ------------------------------------ desktop-widgets/mainwindow.cpp | 2 +- desktop-widgets/mainwindow.h | 4 +- 9 files changed, 586 insertions(+), 587 deletions(-) create mode 100644 desktop-widgets/filterwidget.cpp create mode 100644 desktop-widgets/filterwidget.h create mode 100644 desktop-widgets/filterwidget.ui delete mode 100644 desktop-widgets/filterwidget2.cpp delete mode 100644 desktop-widgets/filterwidget2.h delete mode 100644 desktop-widgets/filterwidget2.ui diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt index 4a3259318..5a1418d76 100644 --- a/desktop-widgets/CMakeLists.txt +++ b/desktop-widgets/CMakeLists.txt @@ -27,7 +27,7 @@ set (SUBSURFACE_UI diveplanner.ui diveshareexportdialog.ui downloadfromdivecomputer.ui - filterwidget2.ui + filterwidget.ui findmovedimagesdialog.ui importgps.ui listfilter.ui @@ -80,8 +80,8 @@ set(SUBSURFACE_INTERFACE downloadfromdivecomputer.h filterconstraintwidget.cpp filterconstraintwidget.h - filterwidget2.cpp - filterwidget2.h + filterwidget.cpp + filterwidget.h findmovedimagesdialog.cpp findmovedimagesdialog.h groupedlineedit.cpp diff --git a/desktop-widgets/filterwidget.cpp b/desktop-widgets/filterwidget.cpp new file mode 100644 index 000000000..96797bcea --- /dev/null +++ b/desktop-widgets/filterwidget.cpp @@ -0,0 +1,266 @@ +#include "desktop-widgets/filterwidget.h" +#include "desktop-widgets/filterconstraintwidget.h" +#include "desktop-widgets/simplewidgets.h" +#include "desktop-widgets/mainwindow.h" +#include "commands/command.h" +#include "core/qthelper.h" +#include "core/divelist.h" +#include "core/settings/qPrefUnit.h" +#include "qt-models/filterpresetmodel.h" + +FilterWidget::FilterWidget(QWidget* parent) : + QWidget(parent), + ignoreSignal(false), + presetModified(false) +{ + ui.setupUi(this); + + QMenu *newConstraintMenu = new QMenu(this); + QStringList constraintTypes = filter_constraint_type_list_translated(); + for (int i = 0; i < constraintTypes.size(); ++i) { + filter_constraint_type type = filter_constraint_type_from_index(i); + newConstraintMenu->addAction(constraintTypes[i], [this, type]() { addConstraint(type); }); + } + ui.addConstraintButton->setMenu(newConstraintMenu); + ui.addConstraintButton->setPopupMode(QToolButton::InstantPopup); + ui.constraintTable->setColumnStretch(4, 1); // The fifth column is were the actual constraint resides - stretch that. + + ui.loadSetButton->setPopupMode(QToolButton::InstantPopup); + + ui.presetTable->setModel(FilterPresetModel::instance()); + ui.presetTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.presetTable->setSelectionMode(QAbstractItemView::SingleSelection); + + connect(ui.clear, &QToolButton::clicked, this, &FilterWidget::clearFilter); + connect(ui.close, &QToolButton::clicked, this, &FilterWidget::closeFilter); + connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget::filterChanged); + connect(ui.fulltextStringMode, QOverload::of(&QComboBox::currentIndexChanged), this, &FilterWidget::filterChanged); + connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget::presetClicked); + connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget::presetSelected); + + connect(&constraintModel, &FilterConstraintModel::rowsInserted, this, &FilterWidget::constraintAdded); + connect(&constraintModel, &FilterConstraintModel::rowsRemoved, this, &FilterWidget::constraintRemoved); + connect(&constraintModel, &FilterConstraintModel::dataChanged, this, &FilterWidget::constraintChanged); + connect(&constraintModel, &FilterConstraintModel::modelReset, this, &FilterWidget::constraintsReset); + + // QDataWidgetMapper might be the more civilized way to keep the menus up to data. + // For now, let's be blunt and fully reload the context menu if the presets list changes. + // This gives us more flexibility in populating the menus. + QAbstractItemModel *presetModel = FilterPresetModel::instance(); + connect(presetModel, &QAbstractItemModel::rowsInserted, this, &FilterWidget::updatePresetMenu); + connect(presetModel, &QAbstractItemModel::rowsRemoved, this, &FilterWidget::updatePresetMenu); + connect(presetModel, &QAbstractItemModel::dataChanged, this, &FilterWidget::updatePresetMenu); + connect(presetModel, &QAbstractItemModel::modelReset, this, &FilterWidget::updatePresetMenu); + + clearFilter(); + updatePresetMenu(); +} + +FilterWidget::~FilterWidget() +{ +} + +void FilterWidget::updatePresetMenu() +{ + loadFilterPresetMenu.reset(new QMenu); + QAbstractItemModel *model = FilterPresetModel::instance(); + int count = model->rowCount(QModelIndex()); + if (count == 0) { + ui.loadSetButton->setEnabled(false); + return; + } + ui.loadSetButton->setEnabled(true); + for (int i = 0; i < count; ++i) { + QModelIndex idx = model->index(i, FilterPresetModel::NAME); + QString name = model->data(idx, Qt::DisplayRole).value(); + loadFilterPresetMenu->addAction(name, [this,i,model]() { selectPreset(i); }); + } + ui.loadSetButton->setMenu(loadFilterPresetMenu.get()); +} + +void FilterWidget::selectPreset(int i) +{ + QAbstractItemModel *model = FilterPresetModel::instance(); + QItemSelectionModel *selectionModel = ui.presetTable->selectionModel(); + QModelIndex idx = model->index(i, 0); + selectionModel->reset(); + selectionModel->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); +} + +void FilterWidget::loadPreset(int index) +{ + ignoreSignal = true; // When reloading the filter UI, we get numerous constraintChanged signals. Ignore them. + FilterData filter = filter_preset_get(index); + setFilterData(filter); + ignoreSignal = false; + presetModified = false; + updateFilter(); +} + +void FilterWidget::constraintAdded(const QModelIndex &parent, int first, int last) +{ + if (parent.isValid() || last < first) + return; // We only support one level + constraintWidgets.reserve(constraintWidgets.size() + 1 + last - first); + for (int i = last + 1; i < (int)constraintWidgets.size(); ++i) + constraintWidgets[i]->moveToRow(i); + for (int i = first; i <= last; ++i) { + QModelIndex idx = constraintModel.index(i, 0); + constraintWidgets.emplace(constraintWidgets.begin() + i, new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable)); + } + filterChanged(); +} + +void FilterWidget::constraintRemoved(const QModelIndex &parent, int first, int last) +{ + if (parent.isValid() || last < first) + return; // We only support one level + constraintWidgets.erase(constraintWidgets.begin() + first, constraintWidgets.begin() + last + 1); + for (int i = first; i < (int)constraintWidgets.size(); ++i) + constraintWidgets[i]->moveToRow(i); + filterChanged(); +} + +void FilterWidget::presetClicked(const QModelIndex &index) +{ + if (!index.isValid()) + return; + + if (index.column() == FilterPresetModel::REMOVE) + Command::removeFilterPreset(index.row()); +} + +void FilterWidget::presetSelected(const QItemSelection &selected, const QItemSelection &) +{ + if (selected.indexes().isEmpty()) + return clearFilter(); + const QModelIndex index = selected.indexes()[0]; + if (!index.isValid()) + return clearFilter(); + loadPreset(index.row()); +} + +void FilterWidget::constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) +{ + // Note: this may appear strange, but we don't update the widget if we get + // 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. + filterChanged(); +} + +void FilterWidget::constraintsReset() +{ + constraintWidgets.clear(); + int count = constraintModel.rowCount(QModelIndex()); + for (int i = 0; i < count; ++i) { + QModelIndex idx = constraintModel.index(i, 0); + constraintWidgets.emplace_back(new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable)); + } + updateFilter(); +} + +void FilterWidget::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. + ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH); + ui.fullText->clear(); + ui.presetTable->clearSelection(); + ignoreSignal = false; + constraintModel.reload({}); // Causes a filter reload +} + +void FilterWidget::closeFilter() +{ + MainWindow::instance()->setApplicationState(ApplicationState::Default); +} + +FilterData FilterWidget::createFilterData() const +{ + FilterData filterData; + filterData.fulltextStringMode = (StringFilterMode)ui.fulltextStringMode->currentIndex(); + filterData.fullText = ui.fullText->text(); + filterData.constraints = constraintModel.getConstraints(); + return filterData; +} + +void FilterWidget::setFilterData(const FilterData &filterData) +{ + ui.fulltextStringMode->setCurrentIndex((int)filterData.fulltextStringMode); + ui.fullText->setText(filterData.fullText.originalQuery); + constraintModel.reload(filterData.constraints); +} + +void FilterWidget::filterChanged() +{ + presetModified = true; + updateFilter(); +} + +void FilterWidget::updateFilter() +{ + if (ignoreSignal) + return; + + FilterData filterData = createFilterData(); + DiveFilter::instance()->setFilter(filterData); + updatePresetLabel(); +} + +int FilterWidget::selectedPreset() const +{ + QModelIndexList selection = ui.presetTable->selectionModel()->selectedRows(); + return selection.size() >= 1 ? selection[0].row() : -1; +} + +void FilterWidget::updatePresetLabel() +{ + int presetId = selectedPreset(); + QString text; + if (presetId >= 0) { + text = filter_preset_name_qstring(presetId); + if (presetModified) + text += " (" + tr("modified") + ")"; + } + ui.currentSet->setText(text); +} + +void FilterWidget::on_addSetButton_clicked() +{ + // If there is a selected item, suggest that to the user. + // Thus, if the user selects an item and modify the filter, + // they can simply overwrite the preset. + int presetId = selectedPreset(); + QString selectedPreset = presetId >= 0 ? filter_preset_name_qstring(presetId) : QString(); + + AddFilterPresetDialog dialog(selectedPreset, this); + QString name = dialog.doit(); + if (name.isEmpty()) + return; + int idx = filter_preset_id(name); + if (idx >= 0) + Command::editFilterPreset(idx, createFilterData()); + else + Command::createFilterPreset(name, createFilterData()); + presetModified = false; + updatePresetLabel(); +} + +void FilterWidget::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + ui.fullText->setFocus(); + updateFilter(); +} + +void FilterWidget::hideEvent(QHideEvent *event) +{ + QWidget::hideEvent(event); +} + +void FilterWidget::addConstraint(filter_constraint_type type) +{ + constraintModel.addConstraint(type); +} diff --git a/desktop-widgets/filterwidget.h b/desktop-widgets/filterwidget.h new file mode 100644 index 000000000..9a9777c08 --- /dev/null +++ b/desktop-widgets/filterwidget.h @@ -0,0 +1,58 @@ +#ifndef FILTERWIDGET_H +#define FILTERWIDGET_H + +#include +#include + +#include "ui_filterwidget.h" +#include "core/divefilter.h" +#include "qt-models/filterconstraintmodel.h" + +class FilterConstraintWidget; +class QMenu; +class QHideEvent; +class QShowEvent; + +class FilterWidget : public QWidget { + Q_OBJECT + +public: + explicit FilterWidget(QWidget *parent = 0); + ~FilterWidget(); + +protected: + void hideEvent(QHideEvent *event) override; + void showEvent(QShowEvent *event) override; + +private slots: + void clearFilter(); + void closeFilter(); + 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 &roles); + void constraintsReset(); + void updatePresetMenu(); + void presetClicked(const QModelIndex &index); + void presetSelected(const QItemSelection &selected, const QItemSelection &); + void on_addSetButton_clicked(); + +private: + bool ignoreSignal; + bool presetModified; + Ui::FilterWidget ui; + FilterConstraintModel constraintModel; + void addConstraint(filter_constraint_type type); + std::vector> constraintWidgets; + FilterData createFilterData() const; + void updateFilter(); + void setFilterData(const FilterData &filterData); + void loadPreset(int index); + void selectPreset(int i); + void clearFilterData(); + std::unique_ptr loadFilterPresetMenu; + int selectedPreset() const; // returns -1 of no preset is selected + void updatePresetLabel(); +}; + +#endif diff --git a/desktop-widgets/filterwidget.ui b/desktop-widgets/filterwidget.ui new file mode 100644 index 000000000..71f293821 --- /dev/null +++ b/desktop-widgets/filterwidget.ui @@ -0,0 +1,256 @@ + + + FilterWidget + + + + 0 + 0 + 510 + 349 + + + + + 0 + 0 + + + + Form + + + + + + 0 + + + + Filter + + + QFrame::NoFrame + + + QFrame::Plain + + + true + + + + + 0 + 0 + 486 + 487 + + + + + + + + + + true + + + + Filter + + + + + + + + + + 0 + 0 + + + + Add constraint + + + + + + + Qt::Horizontal + + + + + + + Current set: + + + + + + + + + + + + + + + 0 + 0 + + + + Save set + + + + + + + + 0 + 0 + + + + Load set + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Reset + + + + :edit-clear-icon:edit-clear-icon + + + Qt::ToolButtonTextBesideIcon + + + + + + + + 0 + 0 + + + + Close + + + + :filter-close:filter-close + + + Qt::ToolButtonTextBesideIcon + + + + + + + + + Fulltext + + + + 0 + 0 + + + + + + + + + + + 0 + 0 + + + + + Substring + + + + + Starts with + + + + + Full word + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Filter sets + + + + + + + + fulltextStringMode + fullText + clear + close + + + + diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp deleted file mode 100644 index 4fe056078..000000000 --- a/desktop-widgets/filterwidget2.cpp +++ /dev/null @@ -1,266 +0,0 @@ -#include "desktop-widgets/filterwidget2.h" -#include "desktop-widgets/filterconstraintwidget.h" -#include "desktop-widgets/simplewidgets.h" -#include "desktop-widgets/mainwindow.h" -#include "commands/command.h" -#include "core/qthelper.h" -#include "core/divelist.h" -#include "core/settings/qPrefUnit.h" -#include "qt-models/filterpresetmodel.h" - -FilterWidget2::FilterWidget2(QWidget* parent) : - QWidget(parent), - ignoreSignal(false), - presetModified(false) -{ - ui.setupUi(this); - - QMenu *newConstraintMenu = new QMenu(this); - QStringList constraintTypes = filter_constraint_type_list_translated(); - for (int i = 0; i < constraintTypes.size(); ++i) { - filter_constraint_type type = filter_constraint_type_from_index(i); - newConstraintMenu->addAction(constraintTypes[i], [this, type]() { addConstraint(type); }); - } - ui.addConstraintButton->setMenu(newConstraintMenu); - ui.addConstraintButton->setPopupMode(QToolButton::InstantPopup); - ui.constraintTable->setColumnStretch(4, 1); // The fifth column is were the actual constraint resides - stretch that. - - ui.loadSetButton->setPopupMode(QToolButton::InstantPopup); - - ui.presetTable->setModel(FilterPresetModel::instance()); - ui.presetTable->setSelectionBehavior(QAbstractItemView::SelectRows); - ui.presetTable->setSelectionMode(QAbstractItemView::SingleSelection); - - connect(ui.clear, &QToolButton::clicked, this, &FilterWidget2::clearFilter); - connect(ui.close, &QToolButton::clicked, this, &FilterWidget2::closeFilter); - connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::filterChanged); - connect(ui.fulltextStringMode, QOverload::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::filterChanged); - connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget2::presetClicked); - connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget2::presetSelected); - - connect(&constraintModel, &FilterConstraintModel::rowsInserted, this, &FilterWidget2::constraintAdded); - connect(&constraintModel, &FilterConstraintModel::rowsRemoved, this, &FilterWidget2::constraintRemoved); - connect(&constraintModel, &FilterConstraintModel::dataChanged, this, &FilterWidget2::constraintChanged); - connect(&constraintModel, &FilterConstraintModel::modelReset, this, &FilterWidget2::constraintsReset); - - // QDataWidgetMapper might be the more civilized way to keep the menus up to data. - // For now, let's be blunt and fully reload the context menu if the presets list changes. - // This gives us more flexibility in populating the menus. - QAbstractItemModel *presetModel = FilterPresetModel::instance(); - connect(presetModel, &QAbstractItemModel::rowsInserted, this, &FilterWidget2::updatePresetMenu); - connect(presetModel, &QAbstractItemModel::rowsRemoved, this, &FilterWidget2::updatePresetMenu); - connect(presetModel, &QAbstractItemModel::dataChanged, this, &FilterWidget2::updatePresetMenu); - connect(presetModel, &QAbstractItemModel::modelReset, this, &FilterWidget2::updatePresetMenu); - - clearFilter(); - updatePresetMenu(); -} - -FilterWidget2::~FilterWidget2() -{ -} - -void FilterWidget2::updatePresetMenu() -{ - loadFilterPresetMenu.reset(new QMenu); - QAbstractItemModel *model = FilterPresetModel::instance(); - int count = model->rowCount(QModelIndex()); - if (count == 0) { - ui.loadSetButton->setEnabled(false); - return; - } - ui.loadSetButton->setEnabled(true); - for (int i = 0; i < count; ++i) { - QModelIndex idx = model->index(i, FilterPresetModel::NAME); - QString name = model->data(idx, Qt::DisplayRole).value(); - loadFilterPresetMenu->addAction(name, [this,i,model]() { selectPreset(i); }); - } - ui.loadSetButton->setMenu(loadFilterPresetMenu.get()); -} - -void FilterWidget2::selectPreset(int i) -{ - QAbstractItemModel *model = FilterPresetModel::instance(); - QItemSelectionModel *selectionModel = ui.presetTable->selectionModel(); - QModelIndex idx = model->index(i, 0); - selectionModel->reset(); - selectionModel->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); -} - -void FilterWidget2::loadPreset(int index) -{ - ignoreSignal = true; // When reloading the filter UI, we get numerous constraintChanged signals. Ignore them. - FilterData filter = filter_preset_get(index); - setFilterData(filter); - ignoreSignal = false; - presetModified = false; - updateFilter(); -} - -void FilterWidget2::constraintAdded(const QModelIndex &parent, int first, int last) -{ - if (parent.isValid() || last < first) - return; // We only support one level - constraintWidgets.reserve(constraintWidgets.size() + 1 + last - first); - for (int i = last + 1; i < (int)constraintWidgets.size(); ++i) - constraintWidgets[i]->moveToRow(i); - for (int i = first; i <= last; ++i) { - QModelIndex idx = constraintModel.index(i, 0); - constraintWidgets.emplace(constraintWidgets.begin() + i, new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable)); - } - filterChanged(); -} - -void FilterWidget2::constraintRemoved(const QModelIndex &parent, int first, int last) -{ - if (parent.isValid() || last < first) - return; // We only support one level - constraintWidgets.erase(constraintWidgets.begin() + first, constraintWidgets.begin() + last + 1); - for (int i = first; i < (int)constraintWidgets.size(); ++i) - constraintWidgets[i]->moveToRow(i); - filterChanged(); -} - -void FilterWidget2::presetClicked(const QModelIndex &index) -{ - if (!index.isValid()) - return; - - if (index.column() == FilterPresetModel::REMOVE) - Command::removeFilterPreset(index.row()); -} - -void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &) -{ - if (selected.indexes().isEmpty()) - return clearFilter(); - const QModelIndex index = selected.indexes()[0]; - if (!index.isValid()) - return clearFilter(); - loadPreset(index.row()); -} - -void FilterWidget2::constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) -{ - // Note: this may appear strange, but we don't update the widget if we get - // 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. - filterChanged(); -} - -void FilterWidget2::constraintsReset() -{ - constraintWidgets.clear(); - int count = constraintModel.rowCount(QModelIndex()); - for (int i = 0; i < count; ++i) { - QModelIndex idx = constraintModel.index(i, 0); - constraintWidgets.emplace_back(new FilterConstraintWidget(&constraintModel, idx, ui.constraintTable)); - } - updateFilter(); -} - -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. - ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH); - ui.fullText->clear(); - ui.presetTable->clearSelection(); - ignoreSignal = false; - constraintModel.reload({}); // Causes a filter reload -} - -void FilterWidget2::closeFilter() -{ - MainWindow::instance()->setApplicationState(ApplicationState::Default); -} - -FilterData FilterWidget2::createFilterData() const -{ - FilterData filterData; - filterData.fulltextStringMode = (StringFilterMode)ui.fulltextStringMode->currentIndex(); - filterData.fullText = ui.fullText->text(); - filterData.constraints = constraintModel.getConstraints(); - return filterData; -} - -void FilterWidget2::setFilterData(const FilterData &filterData) -{ - ui.fulltextStringMode->setCurrentIndex((int)filterData.fulltextStringMode); - ui.fullText->setText(filterData.fullText.originalQuery); - constraintModel.reload(filterData.constraints); -} - -void FilterWidget2::filterChanged() -{ - presetModified = true; - updateFilter(); -} - -void FilterWidget2::updateFilter() -{ - if (ignoreSignal) - return; - - FilterData filterData = createFilterData(); - DiveFilter::instance()->setFilter(filterData); - updatePresetLabel(); -} - -int FilterWidget2::selectedPreset() const -{ - QModelIndexList selection = ui.presetTable->selectionModel()->selectedRows(); - return selection.size() >= 1 ? selection[0].row() : -1; -} - -void FilterWidget2::updatePresetLabel() -{ - int presetId = selectedPreset(); - QString text; - if (presetId >= 0) { - text = filter_preset_name_qstring(presetId); - if (presetModified) - text += " (" + tr("modified") + ")"; - } - ui.currentSet->setText(text); -} - -void FilterWidget2::on_addSetButton_clicked() -{ - // If there is a selected item, suggest that to the user. - // Thus, if the user selects an item and modify the filter, - // they can simply overwrite the preset. - int presetId = selectedPreset(); - QString selectedPreset = presetId >= 0 ? filter_preset_name_qstring(presetId) : QString(); - - AddFilterPresetDialog dialog(selectedPreset, this); - QString name = dialog.doit(); - if (name.isEmpty()) - return; - int idx = filter_preset_id(name); - if (idx >= 0) - Command::editFilterPreset(idx, createFilterData()); - else - Command::createFilterPreset(name, createFilterData()); - presetModified = false; - updatePresetLabel(); -} - -void FilterWidget2::showEvent(QShowEvent *event) -{ - QWidget::showEvent(event); - ui.fullText->setFocus(); - updateFilter(); -} - -void FilterWidget2::hideEvent(QHideEvent *event) -{ - QWidget::hideEvent(event); -} - -void FilterWidget2::addConstraint(filter_constraint_type type) -{ - constraintModel.addConstraint(type); -} diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h deleted file mode 100644 index 33404d5fc..000000000 --- a/desktop-widgets/filterwidget2.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef FILTERWIDGET_2_H -#define FILTERWIDGET_2_H - - -#include -#include - -#include "ui_filterwidget2.h" -#include "core/divefilter.h" -#include "qt-models/filterconstraintmodel.h" - -class FilterConstraintWidget; -class QMenu; -class QHideEvent; -class QShowEvent; - -class FilterWidget2 : public QWidget { - Q_OBJECT - -public: - explicit FilterWidget2(QWidget *parent = 0); - ~FilterWidget2(); - -protected: - void hideEvent(QHideEvent *event) override; - void showEvent(QShowEvent *event) override; - -private slots: - void clearFilter(); - void closeFilter(); - 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 &roles); - void constraintsReset(); - void updatePresetMenu(); - void presetClicked(const QModelIndex &index); - void presetSelected(const QItemSelection &selected, const QItemSelection &); - void on_addSetButton_clicked(); - -private: - bool ignoreSignal; - bool presetModified; - Ui::FilterWidget2 ui; - FilterConstraintModel constraintModel; - void addConstraint(filter_constraint_type type); - std::vector> constraintWidgets; - FilterData createFilterData() const; - void updateFilter(); - void setFilterData(const FilterData &filterData); - void loadPreset(int index); - void selectPreset(int i); - void clearFilterData(); - std::unique_ptr loadFilterPresetMenu; - int selectedPreset() const; // returns -1 of no preset is selected - void updatePresetLabel(); -}; - -#endif diff --git a/desktop-widgets/filterwidget2.ui b/desktop-widgets/filterwidget2.ui deleted file mode 100644 index 5fa0fc505..000000000 --- a/desktop-widgets/filterwidget2.ui +++ /dev/null @@ -1,256 +0,0 @@ - - - FilterWidget2 - - - - 0 - 0 - 510 - 349 - - - - - 0 - 0 - - - - Form - - - - - - 0 - - - - Filter - - - QFrame::NoFrame - - - QFrame::Plain - - - true - - - - - 0 - 0 - 486 - 487 - - - - - - - - - - true - - - - Filter - - - - - - - - - - 0 - 0 - - - - Add constraint - - - - - - - Qt::Horizontal - - - - - - - Current set: - - - - - - - - - - - - - - - 0 - 0 - - - - Save set - - - - - - - - 0 - 0 - - - - Load set - - - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - Reset - - - - :edit-clear-icon:edit-clear-icon - - - Qt::ToolButtonTextBesideIcon - - - - - - - - 0 - 0 - - - - Close - - - - :filter-close:filter-close - - - Qt::ToolButtonTextBesideIcon - - - - - - - - - Fulltext - - - - 0 - 0 - - - - - - - - - - - 0 - 0 - - - - - Substring - - - - - Starts with - - - - - Full word - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Filter sets - - - - - - - - fulltextStringMode - fullText - clear - close - - - - diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 91395d077..4e801aae3 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -182,7 +182,7 @@ MainWindow::MainWindow() : QMainWindow(), registerApplicationState(ApplicationState::EditDiveSite, { { diveSiteEdit, FLAG_NONE }, { profileContainer, FLAG_DISABLED }, { diveList, FLAG_DISABLED }, { mapWidget, FLAG_NONE } }); registerApplicationState(ApplicationState::FilterDive, { { mainTab.get(), FLAG_NONE }, { profileContainer, FLAG_NONE }, - { diveList, FLAG_NONE }, { &filterWidget2, FLAG_NONE } }); + { diveList, FLAG_NONE }, { &filterWidget, FLAG_NONE } }); setApplicationState(ApplicationState::Default); setWindowIcon(QIcon(":subsurface-icon")); diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index ccf6baf22..d7a8acf08 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -18,7 +18,7 @@ #include "ui_mainwindow.h" #include "ui_plannerDetails.h" #include "desktop-widgets/notificationwidget.h" -#include "desktop-widgets/filterwidget2.h" +#include "desktop-widgets/filterwidget.h" #include "core/applicationstate.h" #include "core/gpslocation.h" #include "core/dive.h" @@ -174,7 +174,7 @@ slots: private: Ui::MainWindow ui; - FilterWidget2 filterWidget2; + FilterWidget filterWidget; QAction *actionNextDive; QAction *actionPreviousDive; QAction *undoAction; -- cgit v1.2.3-70-g09d2