diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-12-11 10:55:45 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-10 09:25:57 -0700 |
commit | 71b378aa82296c76c504c8f6b7f765601c7ae821 (patch) | |
tree | 642d0207caaff6d00768368e54c7e44fc08f5cd5 /qt-models/mobilelistmodel.h | |
parent | 7e1ac2167bb531b54974c182f131af8b14c401b1 (diff) | |
download | subsurface-71b378aa82296c76c504c8f6b7f765601c7ae821.tar.gz |
mobile/divelist: derive MobileListModel from a base model
In analogy to the DiveTripModel split, derive MobileListModel from a base
model that exports the roles, etc. This will allow us to create a second model,
which nevertheless possesses the same roles and all that without too much code
duplication.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/mobilelistmodel.h')
-rw-r--r-- | qt-models/mobilelistmodel.h | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/qt-models/mobilelistmodel.h b/qt-models/mobilelistmodel.h index f5242a3c9..f5214d9bd 100644 --- a/qt-models/mobilelistmodel.h +++ b/qt-models/mobilelistmodel.h @@ -1,10 +1,21 @@ // SPDX-License-Identifier: GPL-2.0 +// This header files declares two linear models used by the mobile UI. +// +// MobileListModel presents a list of trips and optionally the dives of +// one expanded trip. It is used for quick navigation through trips. +// +// MobileDiveListModel gives a linearized view of all dives, sorted by +// trip. Even if there is temporal overlap of trips, all dives of +// a trip are listed in a contiguous block. This model is used for +// swiping through dives. #ifndef MOBILELISTMODEL_H #define MOBILELISTMODEL_H #include "divetripmodel.h" -class MobileListModel : public QAbstractItemModel { +// This is the base class of the mobile-list model. All it does +// is exporting the various dive fields as roles. +class MobileListModelBase : public QAbstractItemModel { Q_OBJECT public: enum Roles { @@ -44,6 +55,19 @@ public: FirstGasRole, SelectedRole, }; + QHash<int, QByteArray> roleNames() const override; +protected: + DiveTripModelBase *source; + MobileListModelBase(DiveTripModelBase *source); +private: + int columnCount(const QModelIndex &parent) const override; + QModelIndex index(int row, int column, const QModelIndex &parent) const override; + QModelIndex parent(const QModelIndex &index) const override; +}; + +class MobileListModel : public MobileListModelBase { + Q_OBJECT +public: MobileListModel(DiveTripModelBase *source); void expand(int row); void unexpand(); @@ -71,14 +95,9 @@ private: 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); |