subsurface/qt-models/filtermodels.h
Berthold Stoeger 6ec82a3c80 Dive list: remove global pointer to DiveTrip model
This part of the code had that horrible pattern, where reseting
the model would invalidate all pointers to the DiveTrip model.
Internalize these complexities in the MultiFilterSortModel.
All accesses are now performed via that proxy model.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10 18:45:30 -08:00

32 lines
981 B
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef FILTERMODELS_H
#define FILTERMODELS_H
#include "divetripmodel.h"
#include <QSortFilterProxyModel>
#include <memory>
// This proxy model sits on top of either a DiveTripList or DiveTripTree model
// and does filtering and/or sorting.
class MultiFilterSortModel : public QSortFilterProxyModel {
Q_OBJECT
public:
static MultiFilterSortModel *instance();
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &, const QModelIndex &) const override;
void resetModel(DiveTripModelBase::Layout layout);
void clear();
signals:
void selectionChanged(const QVector<QModelIndex> &indexes);
void currentDiveChanged(QModelIndex index);
private slots:
void selectionChangedSlot(const QVector<QModelIndex> &indexes);
void currentDiveChangedSlot(QModelIndex index);
private:
MultiFilterSortModel(QObject *parent = 0);
std::unique_ptr<DiveTripModelBase> model;
};
#endif