diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-01-25 22:11:30 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-26 08:05:39 -0800 |
commit | a455b32e0241ac6928293005ede8e2d79220533d (patch) | |
tree | 3c0a76d8da25a763e48455536d35dc1658624d35 | |
parent | c210bfc0e0205067c4f4274afc7975486e35252a (diff) | |
download | subsurface-a455b32e0241ac6928293005ede8e2d79220533d.tar.gz |
Filter: implement reset filter
Move initialization to a separate function and connect that to the
reset button.
Two points of note:
1) Reseting the text-fields causes signals. Thus, signals have to
be ignored during reset. Do this with a new flag.
2) To make reset of the from-date work, the from-date has to be
initialized to a distinct value. Setting a default-constructed
QDateTime leaves the widget unchanged.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | desktop-widgets/filterwidget2.cpp | 51 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.h | 2 | ||||
-rw-r--r-- | qt-models/filtermodels.h | 4 |
3 files changed, 41 insertions, 16 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 028f774f1..ccc996f3c 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -5,7 +5,7 @@ #include <QDoubleSpinBox> -FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent) +FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent), ignoreSignal(false) { ui.setupUi(this); @@ -17,17 +17,6 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent) ui.minWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp); ui.maxWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp); - ui.minRating->setCurrentStars(data.minRating); - ui.maxRating->setCurrentStars(data.maxRating); - ui.minVisibility->setCurrentStars(data.minVisibility); - ui.maxVisibility->setCurrentStars(data.maxVisibility); - ui.minAirTemp->setValue(data.minAirTemp); - ui.maxAirTemp->setValue(data.maxAirTemp); - ui.minWaterTemp->setValue(data.minWaterTemp); - ui.maxWaterTemp->setValue(data.maxWaterTemp); - ui.planned->setChecked(data.logged); - ui.planned->setChecked(data.planned); - // TODO: unhide this when we discover how to search for equipment. ui.equipment->hide(); ui.labelEquipment->hide(); @@ -38,12 +27,13 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent) ui.toDate->setDisplayFormat(prefs.date_format); ui.toTime->setDisplayFormat(prefs.time_format); - ui.toDate->setDate(data.toDate.date()); - ui.toTime->setTime(data.toTime); // Initialize temperature fields to display correct unit. temperatureChanged(); + connect(ui.clear, &QToolButton::clicked, + this, &FilterWidget2::clearFilter); + connect(ui.maxRating, &StarWidget::valueChanged, this, &FilterWidget2::updateFilter); @@ -100,6 +90,36 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent) // Update counts if dives were added / removed connect(MultiFilterSortModel::instance(), &MultiFilterSortModel::countsChanged, this, &FilterWidget2::countsChanged); + + // Reset all fields. + clearFilter(); +} + +void FilterWidget2::clearFilter() +{ + ignoreSignal = true; // Prevent signals to force filter recalculation + filterData = FilterData(); + ui.minRating->setCurrentStars(filterData.minRating); + ui.maxRating->setCurrentStars(filterData.maxRating); + ui.minVisibility->setCurrentStars(filterData.minVisibility); + ui.maxVisibility->setCurrentStars(filterData.maxVisibility); + ui.minAirTemp->setValue(filterData.minAirTemp); + ui.maxAirTemp->setValue(filterData.maxAirTemp); + ui.minWaterTemp->setValue(filterData.minWaterTemp); + ui.maxWaterTemp->setValue(filterData.maxWaterTemp); + ui.planned->setChecked(filterData.logged); + ui.planned->setChecked(filterData.planned); + ui.people->clear(); + ui.location->clear(); + ui.equipment->clear(); + ui.tags->clear(); + ui.fromDate->setDate(filterData.fromDate.date()); + ui.fromTime->setTime(filterData.fromTime); + ui.toDate->setDate(filterData.toDate.date()); + ui.toTime->setTime(filterData.toTime); + ignoreSignal = false; + + filterDataChanged(filterData); } void FilterWidget2::temperatureChanged() @@ -113,6 +133,9 @@ void FilterWidget2::temperatureChanged() void FilterWidget2::updateFilter() { + if (ignoreSignal) + return; + filterData.validFilter = true; filterData.minVisibility = ui.minVisibility->currentStars(); filterData.maxVisibility = ui.maxVisibility->currentStars(); diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index 23d08dd2a..2988fac67 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -28,10 +28,12 @@ public slots: void updatePlanned(int value); void updateLogged(int value); private slots: + void clearFilter(); void temperatureChanged(); void countsChanged(); private: + bool ignoreSignal; Ui::FilterWidget2 ui; void filterDataChanged(const FilterData &data); FilterData filterData; diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index faaae8c2f..7ef50df92 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -27,8 +27,8 @@ struct FilterData { double maxWaterTemp = 200; double minAirTemp = -50; double maxAirTemp = 200; - QDateTime fromDate; - QTime fromTime; + QDateTime fromDate = QDateTime(QDate(1980,1,1)); + QTime fromTime = QTime(0,0); QDateTime toDate = QDateTime::currentDateTime(); QTime toTime = QTime::currentTime(); QStringList tags; |