diff options
-rw-r--r-- | desktop-widgets/filterwidget2.cpp | 36 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.h | 4 | ||||
-rw-r--r-- | qt-models/filtermodels.cpp | 6 | ||||
-rw-r--r-- | qt-models/filtermodels.h | 24 |
4 files changed, 64 insertions, 6 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 9bf526a88..50cad019a 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -8,10 +8,17 @@ FilterWidget2::FilterWidget2(QWidget* parent) , ui(new Ui::FilterWidget2()) { ui->setupUi(this); - ui->minRating->setCurrentStars(0); - ui->maxRating->setCurrentStars(5); - ui->minVisibility->setCurrentStars(0); - ui->maxVisibility->setCurrentStars(5); + + 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); + ui->to->setDate(data.to.date()); connect(ui->maxRating, &StarWidget::valueChanged, this, &FilterWidget2::updateFilter); @@ -55,5 +62,24 @@ FilterWidget2::FilterWidget2(QWidget* parent) 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(); + + emit filterDataChanged(data); } diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index 70313c5d2..a9d976ec8 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -6,6 +6,7 @@ #include <memory> #include "ui_filterwidget2.h" +#include "qt-models/filtermodels.h" namespace Ui { class FilterWidget2; @@ -13,12 +14,13 @@ namespace Ui { class FilterWidget2 : public QWidget { Q_OBJECT + public: explicit FilterWidget2(QWidget *parent = 0); void updateFilter(); signals: - void filterUpdated(); + void filterDataChanged(const FilterData& data); private: std::unique_ptr<Ui::FilterWidget2> ui; diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 4063ba149..a6e80aa8f 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -711,3 +711,9 @@ bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2 // Hand sorting down to the source model. return model->lessThan(i1, i2); } + +void MultiFilterSortModel::filterDataChanged(const FilterData& data) +{ + filterData = data; + myInvalidate(); +} diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 8830e99c3..6956146e1 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -6,6 +6,8 @@ #include <QStringListModel> #include <QSortFilterProxyModel> +#include <QDateTime> + #include <stdint.h> #include <vector> @@ -13,6 +15,25 @@ struct dive; struct dive_trip; class DiveTripModel; +struct FilterData { + bool validFilter = false; + int minVisibility = 0; + int maxVisibility = 5; + int minRating = 0; + int maxRating = 5; + double minWaterTemp = 0; + double maxWaterTemp = 100; + double minAirTemp = 0; + double maxAirTemp = 100; + QDateTime from; + QDateTime to = QDateTime::currentDateTime(); + QStringList tags; + QStringList people; + QStringList location; + QStringList equipment; + bool invertFilter; +}; + class FilterModelBase : public QAbstractListModel { Q_OBJECT private: @@ -137,14 +158,17 @@ slots: void stopFilterDiveSite(); void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles); void setLayout(DiveTripModel::Layout layout); + void filterDataChanged(const FilterData& data); signals: void filterFinished(); + private: MultiFilterSortModel(QObject *parent = 0); QList<FilterModelBase *> models; struct dive_site *curr_dive_site; DiveTripModel *model; + FilterData filterData; }; #endif |