From 0026aa395599489c09be3b7892b96923c670b7cf Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 14 Aug 2019 18:09:17 +0200 Subject: Mobile: replace clear()/addAllDives() pairs by reload() The clear()/addAllDives() pair was bogus as the former didn't clear the model (this is not possible anymore - the model represents the core dive list) and the latter readded all dives again. Replace this by a reload() function. Signed-off-by: Berthold Stoeger --- qt-models/divelistmodel.cpp | 25 +++---------------------- qt-models/divelistmodel.h | 4 ++-- 2 files changed, 5 insertions(+), 24 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 79a901282..ef384f4cd 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -71,10 +71,10 @@ int DiveListSortModel::getIdxForId(int id) return -1; } -void DiveListSortModel::clear() +void DiveListSortModel::reload() { DiveListModel *mySourceModel = qobject_cast(sourceModel()); - mySourceModel->clear(); + mySourceModel->reload(); } // In QML, section headings can only be strings. To identify dives that @@ -136,25 +136,6 @@ DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent) m_instance = this; } -void DiveListModel::addDive(const QList &listOfDives) -{ - if (listOfDives.isEmpty()) - return; - beginInsertRows(QModelIndex(), rowCount(), rowCount() + listOfDives.count() - 1); - endInsertRows(); -} - -void DiveListModel::addAllDives() -{ - QListlistOfDives; - int i; - struct dive *d; - for_each_dive (i, d) - listOfDives.append(d); - addDive(listOfDives); - -} - void DiveListModel::insertDive(int i, DiveObjectHelper *) { beginInsertRows(QModelIndex(), i, i); @@ -185,7 +166,7 @@ void DiveListModel::updateDive(int i, dive *d) insertDive(i, nullptr); // TODO: DiveObjectHelper not needed anymore - remove second argument } -void DiveListModel::clear() +void DiveListModel::reload() { beginResetModel(); endResetModel(); diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index 622cd30f3..e08479a21 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -13,7 +13,7 @@ class DiveListSortModel : public QSortFilterProxyModel public: DiveListSortModel(QObject *parent = 0); void setSourceModel(QAbstractItemModel *sourceModel); - Q_INVOKABLE void clear(); + Q_INVOKABLE void reload(); Q_INVOKABLE QVariant tripIdToObject(const QString &s); Q_INVOKABLE QString tripTitle(const QVariant &trip); Q_INVOKABLE QString tripShortDate(const QVariant &trip); @@ -54,7 +54,7 @@ public: void removeDive(int i); void removeDiveById(int id); void updateDive(int i, dive *d); - void clear(); + void reload(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int getDiveIdx(int id) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -- cgit v1.2.3-70-g09d2