summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/filterwidget2.cpp
blob: d120ffe4d19618cbad76946bf7c5c4c9b54df3e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "desktop-widgets/filterwidget2.h"
#include "desktop-widgets/simplewidgets.h"

#include <QDoubleSpinBox>

FilterWidget2::FilterWidget2(QWidget* parent)
: QWidget(parent)
, ui(new Ui::FilterWidget2())
{
	ui->setupUi(this);

	FilterData data;
	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);

	// TODO: unhide this when we discover how to search for equipment.
	ui->equipment->hide();
	ui->labelEquipment->hide();
	ui->invertFilter->hide();

	ui->to->setDate(data.to.date());

	connect(ui->maxRating, &StarWidget::valueChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->minRating, &StarWidget::valueChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->maxVisibility, &StarWidget::valueChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->minVisibility, &StarWidget::valueChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->maxAirTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
		this, &FilterWidget2::updateFilter);

	connect(ui->minAirTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
		this, &FilterWidget2::updateFilter);

	connect(ui->maxWaterTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
		this, &FilterWidget2::updateFilter);

	connect(ui->minWaterTemp, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
		this, &FilterWidget2::updateFilter);

	connect(ui->from, &QDateTimeEdit::dateTimeChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->to, &QDateTimeEdit::dateTimeChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->tags, &QLineEdit::textChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->people, &QLineEdit::textChanged,
		this, &FilterWidget2::updateFilter);

	connect(ui->location, &QLineEdit::textChanged,
		this, &FilterWidget2::updateFilter);
}

void FilterWidget2::updateFilter()
{
	FilterData data;

	data.validFilter = true;
	data.minVisibility = ui->minVisibility->currentStars();
	data.maxVisibility = ui->maxVisibility->currentStars();
	data.minRating = ui->minRating->currentStars();
	data.maxRating = ui->maxRating->currentStars();
	data.minWaterTemp = ui->minWaterTemp->value();
	data.maxWaterTemp = ui->maxWaterTemp->value();
	data.minAirTemp = ui->minAirTemp->value();
	data.maxWaterTemp = ui->maxWaterTemp->value();
	data.from = ui->from->dateTime();
	data.to = ui->to->dateTime();
	data.tags = ui->tags->text().split(",", QString::SkipEmptyParts);
	data.people = ui->people->text().split(",", QString::SkipEmptyParts);
	data.location = ui->location->text().split(",", QString::SkipEmptyParts);
	data.equipment = ui->equipment->text().split(",", QString::SkipEmptyParts);
	data.invertFilter = ui->invertFilter->isChecked();

	filterData = data;
	emit filterDataChanged(data);
}

void FilterWidget2::showEvent(QShowEvent *event)
{
	QWidget::showEvent(event);
	emit filterDataChanged(filterData);
}

void FilterWidget2::hideEvent(QHideEvent *event)
{
	QWidget::hideEvent(event);
	FilterData data;
	emit filterDataChanged(data);
}