diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-11 21:16:48 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-09 12:41:11 -0700 |
commit | 35b33b8c6a86b6add120aaa1c65f37d21f6a53a8 (patch) | |
tree | 01e88c4b9dec612f354d8a151f4c6cc0c6fcea80 /qt-models/mobilelistmodel.h | |
parent | 90f8c1138e3869803bf363be6da117db0248e179 (diff) | |
download | subsurface-35b33b8c6a86b6add120aaa1c65f37d21f6a53a8.tar.gz |
mobile/divelist: add first version of new MobileListModel proxy model
Create a model which represents all top-level items and, potentially, one
expanded trip as a flat list.
Pass down roles to the source model and let the source model handle that. We'll
have to do some ifdef-ery, but so be it.
Additionally, compile the base model on mobile as well.
This contains a couple of hacks to make things compile at all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/mobilelistmodel.h')
-rw-r--r-- | qt-models/mobilelistmodel.h | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/qt-models/mobilelistmodel.h b/qt-models/mobilelistmodel.h new file mode 100644 index 000000000..92a12960d --- /dev/null +++ b/qt-models/mobilelistmodel.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef MOBILELISTMODEL_H +#define MOBILELISTMODEL_H + +#include "divetripmodel.h" + +class MobileListModel : public QAbstractItemModel { + Q_OBJECT +public: + enum Roles { + IsTopLevelRole = DiveTripModelBase::LAST_ROLE + 1, + DiveDateRole, + TripIdRole, + TripNrDivesRole, + DateTimeRole, + IdRole, + NumberRole, + LocationRole, + DepthRole, + DurationRole, + DepthDurationRole, + RatingRole, + VizRole, + SuitRole, + AirTempRole, + WaterTempRole, + SacRole, + SumWeightRole, + DiveMasterRole, + BuddyRole, + NotesRole, + GpsDecimalRole, + GpsRole, + NoDiveRole, + DiveSiteRole, + CylinderRole, + GetCylinderRole, + CylinderListRole, + SingleWeightRole, + StartPressureRole, + EndPressureRole, + FirstGasRole, + SelectedRole, + }; + MobileListModel(DiveTripModelBase *source); + static MobileListModel *instance(); + void resetModel(); + void expand(int row); + void unexpand(); + void toggle(int row); + Q_PROPERTY(int shown READ shown NOTIFY shownChanged); +signals: + void shownChanged(); +private: + struct IndexRange { + bool visible; + int first, last; + }; + void connectSignals(); + std::vector<IndexRange> rangeStack; + QModelIndex sourceIndex(int row, int col, int parentRow = -1) const; + int numSubItems() const; + int mapRowFromSourceTopLevel(int row) const; + int mapRowFromSourceTopLevelForInsert(int row) const; + int mapRowFromSourceTrip(const QModelIndex &parent, int parentRow, int row) const; + int mapRowFromSource(const QModelIndex &parent, int row) const; + int invertRow(const QModelIndex &parent, int row) const; + IndexRange mapRangeFromSource(const QModelIndex &parent, int first, int last) const; + IndexRange mapRangeFromSourceForInsert(const QModelIndex &parent, int first, int last) const; + QModelIndex mapFromSource(const QModelIndex &idx) const; + QModelIndex mapToSource(const QModelIndex &idx) const; + static void updateRowAfterRemove(const IndexRange &range, int &row); + static void updateRowAfterMove(const IndexRange &range, const IndexRange &dest, int &row); + QVariant data(const QModelIndex &index, int role) const override; + QModelIndex index(int row, int column, const QModelIndex &parent) const override; + QModelIndex parent(const QModelIndex &index) const override; + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QHash<int, QByteArray> roleNames() const override; + int shown() const; + + DiveTripModelBase *source; + int expandedRow; +private slots: + void prepareRemove(const QModelIndex &parent, int first, int last); + void doneRemove(const QModelIndex &parent, int first, int last); + void prepareInsert(const QModelIndex &parent, int first, int last); + void doneInsert(const QModelIndex &parent, int first, int last); + void prepareMove(const QModelIndex &parent, int first, int last, const QModelIndex &dest, int destRow); + void doneMove(const QModelIndex &parent, int first, int last, const QModelIndex &dest, int destRow); + void changed(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); +}; + +#endif |