mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
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:
parent
89413c5f07
commit
81bb6086c0
4 changed files with 63 additions and 5 deletions
|
@ -8,10 +8,17 @@ FilterWidget2::FilterWidget2(QWidget* parent)
|
||||||
, ui(new Ui::FilterWidget2())
|
, ui(new Ui::FilterWidget2())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->minRating->setCurrentStars(0);
|
|
||||||
ui->maxRating->setCurrentStars(5);
|
FilterData data;
|
||||||
ui->minVisibility->setCurrentStars(0);
|
ui->minRating->setCurrentStars(data.minRating);
|
||||||
ui->maxVisibility->setCurrentStars(5);
|
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,
|
connect(ui->maxRating, &StarWidget::valueChanged,
|
||||||
this, &FilterWidget2::updateFilter);
|
this, &FilterWidget2::updateFilter);
|
||||||
|
@ -55,5 +62,24 @@ FilterWidget2::FilterWidget2(QWidget* parent)
|
||||||
|
|
||||||
void 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();
|
||||||
|
|
||||||
|
emit filterDataChanged(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "ui_filterwidget2.h"
|
#include "ui_filterwidget2.h"
|
||||||
|
#include "qt-models/filtermodels.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FilterWidget2;
|
class FilterWidget2;
|
||||||
|
@ -13,12 +14,13 @@ namespace Ui {
|
||||||
|
|
||||||
class FilterWidget2 : public QWidget {
|
class FilterWidget2 : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FilterWidget2(QWidget *parent = 0);
|
explicit FilterWidget2(QWidget *parent = 0);
|
||||||
void updateFilter();
|
void updateFilter();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filterUpdated();
|
void filterDataChanged(const FilterData& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::FilterWidget2> ui;
|
std::unique_ptr<Ui::FilterWidget2> ui;
|
||||||
|
|
|
@ -711,3 +711,9 @@ bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2
|
||||||
// Hand sorting down to the source model.
|
// Hand sorting down to the source model.
|
||||||
return model->lessThan(i1, i2);
|
return model->lessThan(i1, i2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MultiFilterSortModel::filterDataChanged(const FilterData& data)
|
||||||
|
{
|
||||||
|
filterData = data;
|
||||||
|
myInvalidate();
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -13,6 +15,25 @@ struct dive;
|
||||||
struct dive_trip;
|
struct dive_trip;
|
||||||
class DiveTripModel;
|
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 {
|
class FilterModelBase : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
@ -137,14 +158,17 @@ slots:
|
||||||
void stopFilterDiveSite();
|
void stopFilterDiveSite();
|
||||||
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
||||||
void setLayout(DiveTripModel::Layout layout);
|
void setLayout(DiveTripModel::Layout layout);
|
||||||
|
void filterDataChanged(const FilterData& data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filterFinished();
|
void filterFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MultiFilterSortModel(QObject *parent = 0);
|
MultiFilterSortModel(QObject *parent = 0);
|
||||||
QList<FilterModelBase *> models;
|
QList<FilterModelBase *> models;
|
||||||
struct dive_site *curr_dive_site;
|
struct dive_site *curr_dive_site;
|
||||||
DiveTripModel *model;
|
DiveTripModel *model;
|
||||||
|
FilterData filterData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue