2017-04-27 20:25:32 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-06-09 22:20:44 +03:00
|
|
|
#ifndef DIVELISTMODEL_H
|
|
|
|
#define DIVELISTMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2016-01-28 18:23:14 -08:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-01-07 16:01:24 -02:00
|
|
|
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/subsurface-qt/DiveObjectHelper.h"
|
2015-06-09 22:20:44 +03:00
|
|
|
|
2016-01-28 18:23:14 -08:00
|
|
|
class DiveListSortModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DiveListSortModel(QObject *parent = 0);
|
2018-10-22 14:00:53 +01:00
|
|
|
void setSourceModel(QAbstractItemModel *sourceModel);
|
2017-05-28 11:48:30 -07:00
|
|
|
Q_INVOKABLE void addAllDives();
|
|
|
|
Q_INVOKABLE void clear();
|
2018-11-22 22:10:38 +01:00
|
|
|
Q_INVOKABLE QVariant tripIdToObject(const QString &s);
|
|
|
|
Q_INVOKABLE QString tripTitle(const QVariant &trip);
|
|
|
|
Q_INVOKABLE QString tripShortDate(const QVariant &trip);
|
2016-01-28 18:23:14 -08:00
|
|
|
public slots:
|
|
|
|
int getDiveId(int idx);
|
|
|
|
int getIdxForId(int id);
|
2018-02-04 16:46:03 +01:00
|
|
|
void setFilter(QString f);
|
|
|
|
void resetFilter();
|
2018-10-17 06:28:53 -04:00
|
|
|
int shown();
|
2018-10-22 14:00:53 +01:00
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
private:
|
|
|
|
QString filterString;
|
|
|
|
void updateFilterState();
|
2016-01-28 18:23:14 -08:00
|
|
|
};
|
|
|
|
|
2015-06-09 22:20:44 +03:00
|
|
|
class DiveListModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum DiveListRoles {
|
2016-01-07 16:01:24 -02:00
|
|
|
DiveRole = Qt::UserRole + 1,
|
2018-02-04 16:46:03 +01:00
|
|
|
DiveDateRole,
|
2018-10-19 21:16:50 -04:00
|
|
|
FullTextRole,
|
|
|
|
FullTextNoNotesRole
|
2015-06-09 22:20:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static DiveListModel *instance();
|
|
|
|
DiveListModel(QObject *parent = 0);
|
2016-04-05 21:17:37 -07:00
|
|
|
void addDive(QList<dive *> listOfDives);
|
|
|
|
void addAllDives();
|
2016-01-27 11:27:41 -08:00
|
|
|
void insertDive(int i, DiveObjectHelper *newDive);
|
|
|
|
void removeDive(int i);
|
2016-01-29 06:25:13 -08:00
|
|
|
void removeDiveById(int id);
|
2016-01-27 11:50:04 -08:00
|
|
|
void updateDive(int i, dive *d);
|
2015-11-30 10:09:46 -08:00
|
|
|
void clear();
|
2015-06-09 22:20:44 +03:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
2016-01-28 18:23:14 -08:00
|
|
|
int getDiveId(int idx) const;
|
2016-03-02 04:41:36 -08:00
|
|
|
int getDiveIdx(int id) const;
|
2015-06-09 22:20:44 +03:00
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
QHash<int, QByteArray> roleNames() const;
|
2015-12-26 21:37:18 -08:00
|
|
|
QString startAddDive();
|
2018-01-07 16:08:25 +01:00
|
|
|
void resetInternalData();
|
2016-01-07 16:01:24 -02:00
|
|
|
Q_INVOKABLE DiveObjectHelper* at(int i);
|
2015-06-09 22:20:44 +03:00
|
|
|
private:
|
2016-01-07 16:01:24 -02:00
|
|
|
QList<DiveObjectHelper*> m_dives;
|
2015-06-09 22:20:44 +03:00
|
|
|
static DiveListModel *m_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DIVELISTMODEL_H
|