Struct FilterData

The idea is that this struct will have all the needed data
that will be passed to the filter model. Everything that happens
on the filterwidget will fill out this struct, then forward it
to the model, that in turn will activate the filter hiding
some of the dives that matches on your divelist.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2018-12-06 20:07:47 +01:00 committed by Dirk Hohndel
parent 89413c5f07
commit 81bb6086c0
4 changed files with 63 additions and 5 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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();
}

View file

@ -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