2018-10-13 09:52:08 +00:00
|
|
|
#include "desktop-widgets/filterwidget2.h"
|
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
2019-01-25 21:41:07 +00:00
|
|
|
#include "desktop-widgets/mainwindow.h"
|
2019-01-20 20:01:00 +00:00
|
|
|
#include "core/qthelper.h"
|
|
|
|
#include "core/settings/qPrefUnit.h"
|
2018-10-13 09:52:08 +00:00
|
|
|
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
|
2019-01-25 21:11:30 +00:00
|
|
|
FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent), ignoreSignal(false)
|
2018-10-13 09:52:08 +00:00
|
|
|
{
|
2019-01-17 22:01:57 +00:00
|
|
|
ui.setupUi(this);
|
2018-12-06 19:07:47 +00:00
|
|
|
|
|
|
|
FilterData data;
|
2019-01-20 20:15:46 +00:00
|
|
|
|
|
|
|
// Use default values to set minimum and maximum air and water temperature.
|
|
|
|
ui.minAirTemp->setRange(data.minAirTemp, data.maxAirTemp);
|
|
|
|
ui.maxAirTemp->setRange(data.minAirTemp, data.maxAirTemp);
|
|
|
|
ui.minWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp);
|
|
|
|
ui.maxWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp);
|
|
|
|
|
2018-11-16 14:23:39 +00:00
|
|
|
// TODO: unhide this when we discover how to search for equipment.
|
2019-01-17 22:01:57 +00:00
|
|
|
ui.equipment->hide();
|
2019-01-26 22:02:09 +00:00
|
|
|
ui.equipmentMode->hide();
|
2019-01-17 22:01:57 +00:00
|
|
|
ui.labelEquipment->hide();
|
2018-11-16 14:23:39 +00:00
|
|
|
|
2019-01-20 16:00:56 +00:00
|
|
|
ui.fromDate->setDisplayFormat(prefs.date_format);
|
|
|
|
ui.fromTime->setDisplayFormat(prefs.time_format);
|
|
|
|
|
|
|
|
ui.toDate->setDisplayFormat(prefs.date_format);
|
|
|
|
ui.toTime->setDisplayFormat(prefs.time_format);
|
2018-10-13 09:52:08 +00:00
|
|
|
|
2019-01-20 20:01:00 +00:00
|
|
|
// Initialize temperature fields to display correct unit.
|
|
|
|
temperatureChanged();
|
|
|
|
|
2019-01-25 21:11:30 +00:00
|
|
|
connect(ui.clear, &QToolButton::clicked,
|
|
|
|
this, &FilterWidget2::clearFilter);
|
|
|
|
|
2019-01-25 21:41:07 +00:00
|
|
|
connect(ui.close, &QToolButton::clicked,
|
|
|
|
this, &FilterWidget2::closeFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.maxRating, &StarWidget::valueChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.minRating, &StarWidget::valueChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.maxVisibility, &StarWidget::valueChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.minVisibility, &StarWidget::valueChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-26 22:02:09 +00:00
|
|
|
// We need these insane casts because Qt decided to function-overload some of their signals(!).
|
|
|
|
// QDoubleSpinBox::valueChanged() sends double and QString using the same signal name.
|
|
|
|
// QComboBox::currentIndexChanged() sends int and QString using the same signal name.
|
|
|
|
// Qt 5.7 provides a "convenient" helper that hides this, but only if compiling in C++14
|
|
|
|
// or higher. One can then write: "QOverload<double>(&QDoubleSpinBox::valueChanged)", etc.
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.maxAirTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.minAirTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.maxWaterTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.minWaterTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-20 16:00:56 +00:00
|
|
|
connect(ui.fromDate, &QDateTimeEdit::dateChanged,
|
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
|
|
|
connect(ui.fromTime, &QDateTimeEdit::timeChanged,
|
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
|
|
|
connect(ui.toDate, &QDateTimeEdit::dateChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-20 16:00:56 +00:00
|
|
|
connect(ui.toTime, &QDateTimeEdit::timeChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.tags, &QLineEdit::textChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-26 22:02:09 +00:00
|
|
|
connect(ui.tagsMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
2019-01-22 08:32:39 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.people, &QLineEdit::textChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-26 22:02:09 +00:00
|
|
|
connect(ui.peopleMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
2019-01-22 08:32:39 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.location, &QLineEdit::textChanged,
|
2018-10-13 09:52:08 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
2019-01-01 17:49:56 +00:00
|
|
|
|
2019-01-26 22:02:09 +00:00
|
|
|
connect(ui.locationMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
2019-01-22 08:32:39 +00:00
|
|
|
this, &FilterWidget2::updateFilter);
|
|
|
|
|
2019-01-22 08:38:57 +00:00
|
|
|
connect(ui.logged, &QCheckBox::stateChanged,
|
|
|
|
this, &FilterWidget2::updateLogged);
|
2019-01-01 17:49:56 +00:00
|
|
|
|
2019-01-22 08:38:57 +00:00
|
|
|
connect(ui.planned, &QCheckBox::stateChanged,
|
|
|
|
this, &FilterWidget2::updatePlanned);
|
2019-01-20 20:01:00 +00:00
|
|
|
|
|
|
|
// Update temperature fields if user changes temperature-units in preferences.
|
2019-01-22 08:38:57 +00:00
|
|
|
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged,
|
|
|
|
this, &FilterWidget2::temperatureChanged);
|
|
|
|
|
|
|
|
connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged,
|
|
|
|
this, &FilterWidget2::temperatureChanged);
|
2019-01-25 20:30:43 +00:00
|
|
|
|
|
|
|
// Update counts if dives were added / removed
|
|
|
|
connect(MultiFilterSortModel::instance(), &MultiFilterSortModel::countsChanged,
|
|
|
|
this, &FilterWidget2::countsChanged);
|
2019-01-25 21:11:30 +00:00
|
|
|
|
|
|
|
// 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);
|
2019-01-26 22:02:09 +00:00
|
|
|
ui.tagsMode->setCurrentIndex(filterData.tagsNegate ? 1 : 0);
|
|
|
|
ui.peopleMode->setCurrentIndex(filterData.peopleNegate ? 1 : 0);
|
|
|
|
ui.locationMode->setCurrentIndex(filterData.locationNegate ? 1 : 0);
|
|
|
|
ui.equipmentMode->setCurrentIndex(filterData.equipmentNegate ? 1 : 0);
|
|
|
|
|
2019-01-25 21:11:30 +00:00
|
|
|
ignoreSignal = false;
|
|
|
|
|
|
|
|
filterDataChanged(filterData);
|
2019-01-20 20:01:00 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 21:41:07 +00:00
|
|
|
void FilterWidget2::closeFilter()
|
|
|
|
{
|
|
|
|
MainWindow::instance()->setApplicationState("Default");
|
|
|
|
}
|
|
|
|
|
2019-01-20 20:01:00 +00:00
|
|
|
void FilterWidget2::temperatureChanged()
|
|
|
|
{
|
|
|
|
QString temp = get_temp_unit();
|
|
|
|
ui.minAirTemp->setSuffix(temp);
|
|
|
|
ui.maxAirTemp->setSuffix(temp);
|
|
|
|
ui.minWaterTemp->setSuffix(temp);
|
|
|
|
ui.maxWaterTemp->setSuffix(temp);
|
2018-10-13 09:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::updateFilter()
|
|
|
|
{
|
2019-01-25 21:11:30 +00:00
|
|
|
if (ignoreSignal)
|
|
|
|
return;
|
|
|
|
|
2018-12-16 19:43:01 +00:00
|
|
|
filterData.validFilter = true;
|
2019-01-17 22:01:57 +00:00
|
|
|
filterData.minVisibility = ui.minVisibility->currentStars();
|
|
|
|
filterData.maxVisibility = ui.maxVisibility->currentStars();
|
|
|
|
filterData.minRating = ui.minRating->currentStars();
|
|
|
|
filterData.maxRating = ui.maxRating->currentStars();
|
|
|
|
filterData.minWaterTemp = ui.minWaterTemp->value();
|
|
|
|
filterData.maxWaterTemp = ui.maxWaterTemp->value();
|
|
|
|
filterData.minAirTemp = ui.minAirTemp->value();
|
|
|
|
filterData.maxWaterTemp = ui.maxWaterTemp->value();
|
2019-01-20 16:00:56 +00:00
|
|
|
filterData.fromDate = ui.fromDate->dateTime();
|
|
|
|
filterData.fromTime = ui.fromTime->time();
|
|
|
|
filterData.toDate = ui.toDate->dateTime();
|
|
|
|
filterData.toTime = ui.toTime->time();
|
2019-01-17 22:01:57 +00:00
|
|
|
filterData.tags = ui.tags->text().split(",", QString::SkipEmptyParts);
|
|
|
|
filterData.people = ui.people->text().split(",", QString::SkipEmptyParts);
|
|
|
|
filterData.location = ui.location->text().split(",", QString::SkipEmptyParts);
|
|
|
|
filterData.equipment = ui.equipment->text().split(",", QString::SkipEmptyParts);
|
2019-01-26 22:02:09 +00:00
|
|
|
filterData.tagsNegate = ui.tagsMode->currentIndex() == 1;
|
|
|
|
filterData.peopleNegate = ui.peopleMode->currentIndex() == 1;
|
|
|
|
filterData.locationNegate = ui.locationMode->currentIndex() == 1;
|
|
|
|
filterData.equipmentNegate = ui.equipmentMode->currentIndex() == 1;
|
2019-01-17 22:01:57 +00:00
|
|
|
filterData.logged = ui.logged->isChecked();
|
|
|
|
filterData.planned = ui.planned->isChecked();
|
2018-12-06 19:07:47 +00:00
|
|
|
|
2018-12-16 19:43:01 +00:00
|
|
|
filterDataChanged(filterData);
|
2018-11-16 14:24:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-01 17:49:56 +00:00
|
|
|
void FilterWidget2::updateLogged(int value) {
|
|
|
|
if (value == Qt::Unchecked)
|
2019-01-17 22:01:57 +00:00
|
|
|
ui.planned->setChecked(true);
|
2019-01-01 17:49:56 +00:00
|
|
|
updateFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::updatePlanned(int value) {
|
|
|
|
if (value == Qt::Unchecked)
|
2019-01-17 22:01:57 +00:00
|
|
|
ui.logged->setChecked(true);
|
2019-01-01 17:49:56 +00:00
|
|
|
updateFilter();
|
|
|
|
}
|
|
|
|
|
2018-11-16 14:24:11 +00:00
|
|
|
void FilterWidget2::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
2018-12-16 19:33:37 +00:00
|
|
|
filterDataChanged(filterData);
|
2018-11-16 14:24:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::hideEvent(QHideEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::hideEvent(event);
|
2019-01-25 21:41:07 +00:00
|
|
|
clearFilter();
|
2018-12-16 19:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::filterDataChanged(const FilterData &data)
|
|
|
|
{
|
|
|
|
MultiFilterSortModel::instance()->filterDataChanged(data);
|
2019-01-25 20:30:43 +00:00
|
|
|
countsChanged();
|
|
|
|
}
|
2019-01-25 18:44:16 +00:00
|
|
|
|
2019-01-25 20:30:43 +00:00
|
|
|
void FilterWidget2::countsChanged()
|
|
|
|
{
|
2019-01-25 18:44:16 +00:00
|
|
|
ui.filterText->setText(tr("%L1/%L2 shown").arg(MultiFilterSortModel::instance()->divesDisplayed)
|
|
|
|
.arg(dive_table.nr));
|
2018-10-13 09:52:08 +00:00
|
|
|
}
|