2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-06-09 19:20:44 +00:00
|
|
|
#ifndef DIVELISTMODEL_H
|
|
|
|
#define DIVELISTMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2016-01-29 02:23:14 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-01-07 18:01:24 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/subsurface-qt/DiveObjectHelper.h"
|
2015-06-09 19:20:44 +00:00
|
|
|
|
2019-11-06 05:54:03 +00:00
|
|
|
class CollapsedDiveListSortModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static CollapsedDiveListSortModel *instance();
|
|
|
|
void setSourceModel(QAbstractItemModel *sourceModel);
|
|
|
|
Q_INVOKABLE QString tripTitle(const QString &trip);
|
|
|
|
Q_INVOKABLE QString tripShortDate(const QString &trip);
|
|
|
|
Q_INVOKABLE void setActiveTrip(const QString &trip);
|
|
|
|
Q_INVOKABLE QString activeTrip() const;
|
|
|
|
// super subtle optimization alert - in order to reduce the number of model accesses from QML,
|
|
|
|
// the two states where we show the dive in question have odd numbers
|
|
|
|
enum CollapsedState {
|
|
|
|
DontShow = 0,
|
|
|
|
ShowDive = 1,
|
|
|
|
ShowTrip = 2,
|
|
|
|
ShowDiveAndTrip = 3
|
|
|
|
};
|
|
|
|
void updateFilterState();
|
|
|
|
void updateSelectionState();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CollapsedDiveListSortModel();
|
|
|
|
bool isExpanded(struct dive_trip *dt) const;
|
|
|
|
QString m_activeTrip;
|
|
|
|
};
|
|
|
|
|
2016-01-29 02:23:14 +00:00
|
|
|
class DiveListSortModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-09-28 21:31:40 +00:00
|
|
|
static DiveListSortModel *instance();
|
2018-10-22 13:00:53 +00:00
|
|
|
void setSourceModel(QAbstractItemModel *sourceModel);
|
2019-11-06 05:54:03 +00:00
|
|
|
QString getFilterString() const;
|
2019-08-14 16:09:17 +00:00
|
|
|
Q_INVOKABLE void reload();
|
2019-11-06 05:54:03 +00:00
|
|
|
QString filterString;
|
|
|
|
void updateFilterState();
|
2016-01-29 02:23:14 +00:00
|
|
|
public slots:
|
|
|
|
int getIdxForId(int id);
|
2018-02-04 15:46:03 +00:00
|
|
|
void setFilter(QString f);
|
|
|
|
void resetFilter();
|
2018-10-17 10:28:53 +00:00
|
|
|
int shown();
|
2018-10-22 13:00:53 +00:00
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
private:
|
2019-09-29 08:44:27 +00:00
|
|
|
DiveListSortModel();
|
2016-01-29 02:23:14 +00:00
|
|
|
};
|
|
|
|
|
2019-10-20 02:12:50 +00:00
|
|
|
QString formatSac(const dive *d);
|
|
|
|
QString formatNotes(const dive *d);
|
|
|
|
QString format_gps_decimal(const dive *d);
|
|
|
|
QStringList formatGetCylinder(const dive *d);
|
|
|
|
QStringList getStartPressure(const dive *d);
|
|
|
|
QStringList getEndPressure(const dive *d);
|
|
|
|
QStringList getFirstGas(const dive *d);
|
2019-10-20 11:37:51 +00:00
|
|
|
QStringList getFullCylinderList();
|
2019-10-20 02:12:50 +00:00
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
class DiveListModel : public QAbstractListModel
|
2015-06-09 19:20:44 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum DiveListRoles {
|
2019-10-20 11:37:51 +00:00
|
|
|
DiveDateRole = Qt::UserRole + 1,
|
2019-08-14 21:53:28 +00:00
|
|
|
TripIdRole,
|
2019-08-14 22:03:15 +00:00
|
|
|
TripNrDivesRole,
|
2019-08-14 22:15:30 +00:00
|
|
|
DateTimeRole,
|
2019-08-14 22:18:25 +00:00
|
|
|
IdRole,
|
|
|
|
NumberRole,
|
2019-08-14 22:23:25 +00:00
|
|
|
LocationRole,
|
2019-10-20 02:12:50 +00:00
|
|
|
DepthRole,
|
|
|
|
DurationRole,
|
2019-08-14 22:30:56 +00:00
|
|
|
DepthDurationRole,
|
2019-10-20 02:12:50 +00:00
|
|
|
RatingRole,
|
|
|
|
VizRole,
|
|
|
|
SuitRole,
|
|
|
|
AirTempRole,
|
|
|
|
WaterTempRole,
|
|
|
|
SacRole,
|
|
|
|
SumWeightRole,
|
|
|
|
DiveMasterRole,
|
|
|
|
BuddyRole,
|
|
|
|
NotesRole,
|
|
|
|
GpsDecimalRole,
|
|
|
|
GpsRole,
|
|
|
|
NoDiveRole,
|
|
|
|
DiveSiteRole,
|
|
|
|
CylinderRole,
|
2019-10-20 11:37:51 +00:00
|
|
|
GetCylinderRole,
|
|
|
|
CylinderListRole,
|
2019-10-20 02:12:50 +00:00
|
|
|
SingleWeightRole,
|
|
|
|
StartPressureRole,
|
|
|
|
EndPressureRole,
|
|
|
|
FirstGasRole,
|
2019-11-06 05:54:03 +00:00
|
|
|
CollapsedRole,
|
|
|
|
SelectedRole,
|
2015-06-09 19:20:44 +00:00
|
|
|
};
|
|
|
|
|
2019-09-27 23:26:54 +00:00
|
|
|
static DiveListModel *instance();
|
2019-04-01 20:15:19 +00:00
|
|
|
void addDive(const QList<dive *> &listOfDives);
|
2016-04-06 04:17:37 +00:00
|
|
|
void addAllDives();
|
2019-08-13 15:22:15 +00:00
|
|
|
void insertDive(int i);
|
2016-01-27 19:27:41 +00:00
|
|
|
void removeDive(int i);
|
2016-01-29 14:25:13 +00:00
|
|
|
void removeDiveById(int id);
|
2016-01-27 19:50:04 +00:00
|
|
|
void updateDive(int i, dive *d);
|
2019-09-26 11:47:49 +00:00
|
|
|
void reload(); // Only call after clearing the model!
|
2019-08-13 19:11:08 +00:00
|
|
|
struct dive *getDive(int i);
|
2015-06-09 19:20:44 +00:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
2016-03-02 12:41:36 +00:00
|
|
|
int getDiveIdx(int id) const;
|
2019-08-13 19:31:53 +00:00
|
|
|
QModelIndex getDiveQIdx(int id);
|
2015-06-09 19:20:44 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
QHash<int, QByteArray> roleNames() const;
|
2015-12-27 05:37:18 +00:00
|
|
|
QString startAddDive();
|
2018-01-07 15:08:25 +00:00
|
|
|
void resetInternalData();
|
2019-09-26 11:37:44 +00:00
|
|
|
void clear(); // Clear all dives in core
|
2019-08-13 06:19:04 +00:00
|
|
|
Q_INVOKABLE DiveObjectHelper at(int i);
|
2019-09-29 08:44:27 +00:00
|
|
|
private:
|
|
|
|
DiveListModel();
|
2015-06-09 19:20:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DIVELISTMODEL_H
|