diff options
Diffstat (limited to 'qt-models/mobilelistmodel.cpp')
-rw-r--r-- | qt-models/mobilelistmodel.cpp | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/qt-models/mobilelistmodel.cpp b/qt-models/mobilelistmodel.cpp index e679c72c6..3312a2d97 100644 --- a/qt-models/mobilelistmodel.cpp +++ b/qt-models/mobilelistmodel.cpp @@ -2,23 +2,11 @@ #include "mobilelistmodel.h" #include "core/divelist.h" // for shown_dives -MobileListModel::MobileListModel(DiveTripModelBase *sourceIn) : - source(sourceIn), - expandedRow(-1) +MobileListModelBase::MobileListModelBase(DiveTripModelBase *sourceIn) : source(sourceIn) { - connect(source, &DiveTripModelBase::modelAboutToBeReset, this, &MobileListModel::beginResetModel); - connect(source, &DiveTripModelBase::modelReset, this, &MobileListModel::endResetModel); - connect(source, &DiveTripModelBase::rowsAboutToBeRemoved, this, &MobileListModel::prepareRemove); - connect(source, &DiveTripModelBase::rowsRemoved, this, &MobileListModel::doneRemove); - connect(source, &DiveTripModelBase::rowsAboutToBeInserted, this, &MobileListModel::prepareInsert); - connect(source, &DiveTripModelBase::rowsInserted, this, &MobileListModel::doneInsert); - connect(source, &DiveTripModelBase::rowsAboutToBeMoved, this, &MobileListModel::prepareMove); - connect(source, &DiveTripModelBase::rowsMoved, this, &MobileListModel::doneMove); - connect(source, &DiveTripModelBase::dataChanged, this, &MobileListModel::changed); - connect(&diveListNotifier, &DiveListNotifier::numShownChanged, this, &MobileListModel::shownChanged); } -QHash<int, QByteArray> MobileListModel::roleNames() const +QHash<int, QByteArray> MobileListModelBase::roleNames() const { QHash<int, QByteArray> roles; roles[DiveTripModelBase::IS_TRIP_ROLE] = "isTrip"; @@ -66,6 +54,40 @@ int MobileListModel::shown() const return shown_dives; } +int MobileListModelBase::columnCount(const QModelIndex &parent) const +{ + return source->columnCount(parent); +} + +QModelIndex MobileListModelBase::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + return createIndex(row, column); +} + +QModelIndex MobileListModelBase::parent(const QModelIndex &index) const +{ + // These are flat models - there is no parent + return QModelIndex(); +} + +MobileListModel::MobileListModel(DiveTripModelBase *source) : MobileListModelBase(source), + expandedRow(-1) +{ + connect(source, &DiveTripModelBase::modelAboutToBeReset, this, &MobileListModel::beginResetModel); + connect(source, &DiveTripModelBase::modelReset, this, &MobileListModel::endResetModel); + connect(source, &DiveTripModelBase::rowsAboutToBeRemoved, this, &MobileListModel::prepareRemove); + connect(source, &DiveTripModelBase::rowsRemoved, this, &MobileListModel::doneRemove); + connect(source, &DiveTripModelBase::rowsAboutToBeInserted, this, &MobileListModel::prepareInsert); + connect(source, &DiveTripModelBase::rowsInserted, this, &MobileListModel::doneInsert); + connect(source, &DiveTripModelBase::rowsAboutToBeMoved, this, &MobileListModel::prepareMove); + connect(source, &DiveTripModelBase::rowsMoved, this, &MobileListModel::doneMove); + connect(source, &DiveTripModelBase::dataChanged, this, &MobileListModel::changed); + connect(&diveListNotifier, &DiveListNotifier::numShownChanged, this, &MobileListModel::shownChanged); +} + // We want to show the newest dives first. Therefore, we have to invert // the indexes with respect to the source model. To avoid mental gymnastics // in the rest of the code, we do this right before sending to the @@ -201,20 +223,6 @@ QModelIndex MobileListModel::mapToSource(const QModelIndex &idx) const return sourceIndex(row - expandedRow - 1, col, expandedRow); } -QModelIndex MobileListModel::index(int row, int column, const QModelIndex &parent) const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - return createIndex(row, column); -} - -QModelIndex MobileListModel::parent(const QModelIndex &index) const -{ - // This is a flat model - there is no parent - return QModelIndex(); -} - int MobileListModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) @@ -222,11 +230,6 @@ int MobileListModel::rowCount(const QModelIndex &parent) const return source->rowCount() + numSubItems(); } -int MobileListModel::columnCount(const QModelIndex &parent) const -{ - return source->columnCount(parent); -} - QVariant MobileListModel::data(const QModelIndex &index, int role) const { if (role == IsTopLevelRole) @@ -270,7 +273,6 @@ void MobileListModel::prepareRemove(const QModelIndex &parent, int first, int la beginRemoveRows(QModelIndex(), range.first, range.last); } - void MobileListModel::updateRowAfterRemove(const IndexRange &range, int &row) { if (row < 0) @@ -534,6 +536,7 @@ MobileModels *MobileModels::instance() MobileModels::MobileModels() : lm(&source) { + reset(); } MobileListModel *MobileModels::listModel() |