mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
c210bfc0e0
commit
a455b32e02
3 changed files with 41 additions and 16 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue