2018-10-13 09:52:08 +00:00
|
|
|
#include "desktop-widgets/filterwidget2.h"
|
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
|
|
|
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent)
|
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-17 22:01:57 +00:00
|
|
|
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);
|
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();
|
|
|
|
ui.labelEquipment->hide();
|
|
|
|
ui.invertFilter->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);
|
|
|
|
ui.toDate->setDate(data.toDate.date());
|
|
|
|
ui.toTime->setTime(data.toTime);
|
2018-10-13 09:52:08 +00:00
|
|
|
|
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-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-17 22:01:57 +00:00
|
|
|
connect(ui.people, &QLineEdit::textChanged,
|
2018-10-13 09:52:08 +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-17 22:01:57 +00:00
|
|
|
connect(ui.logged, SIGNAL(stateChanged(int)), this, SLOT(updateLogged(int)));
|
2019-01-01 17:49:56 +00:00
|
|
|
|
2019-01-17 22:01:57 +00:00
|
|
|
connect(ui.planned, SIGNAL(stateChanged(int)), this, SLOT(updatePlanned(int)));
|
2018-10-13 09:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::updateFilter()
|
|
|
|
{
|
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);
|
|
|
|
filterData.invertFilter = ui.invertFilter->isChecked();
|
|
|
|
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);
|
|
|
|
FilterData data;
|
2018-12-16 19:33:37 +00:00
|
|
|
filterDataChanged(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterWidget2::filterDataChanged(const FilterData &data)
|
|
|
|
{
|
|
|
|
MultiFilterSortModel::instance()->filterDataChanged(data);
|
2018-10-13 09:52:08 +00:00
|
|
|
}
|