summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-14 18:09:17 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-09-14 13:20:59 +0200
commit0026aa395599489c09be3b7892b96923c670b7cf (patch)
treedf1afd69466092143472ef5411d86cf141945e57
parent57b77c90b9dad6a114a13fe08b8ae7b986039de8 (diff)
downloadsubsurface-0026aa395599489c09be3b7892b96923c670b7cf.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--mobile-widgets/qml/DownloadFromDiveComputer.qml3
-rw-r--r--mobile-widgets/qmlmanager.cpp18
-rw-r--r--qt-models/divelistmodel.cpp25
-rw-r--r--qt-models/divelistmodel.h4
4 files changed, 12 insertions, 38 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml
index b80412673..a9cde6332 100644
--- a/mobile-widgets/qml/DownloadFromDiveComputer.qml
+++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml
@@ -390,8 +390,7 @@ Kirigami.Page {
manager.appendTextToLog("Save downloaded dives that were selected")
importModel.recordDives()
manager.saveChangesLocal()
- diveModel.clear()
- diveModel.addAllDives()
+ diveModel.reload()
pageStack.pop();
download.text = qsTr("Download")
divesDownloaded = false
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 8dcacf4cc..040c957e1 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -309,8 +309,7 @@ void QMLManager::openLocalThenRemote(QString url)
qPrefTechnicalDetails::set_show_ccr_sensors(git_prefs.show_ccr_sensors);
qPrefPartialPressureGas::set_po2(git_prefs.pp_graphs.po2);
process_loaded_dives();
- DiveListModel::instance()->clear();
- DiveListModel::instance()->addAllDives();
+ DiveListModel::instance()->reload();
appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr));
setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr));
}
@@ -529,7 +528,7 @@ void QMLManager::saveCloudCredentials()
getCloudURL(url);
manager()->clearAccessCache(); // remove any chached credentials
clear_git_id(); // invalidate our remembered GIT SHA
- DiveListModel::instance()->clear();
+ DiveListModel::instance()->reload();
GpsListModel::instance()->clear();
setStartPageText(tr("Attempting to open cloud storage with new credentials"));
// we therefore know that no one else is already accessing THIS git repo;
@@ -757,8 +756,7 @@ successful_exit:
if (noCloudToCloud) {
git_storage_update_progress(qPrintable(tr("Loading dives from local storage ('no cloud' mode)")));
mergeLocalRepo();
- DiveListModel::instance()->clear();
- DiveListModel::instance()->addAllDives();
+ DiveListModel::instance()->reload();
appendTextToLog(QStringLiteral("%1 dives loaded after importing nocloud local storage").arg(dive_table.nr));
noCloudToCloud = false;
mark_divelist_changed(true);
@@ -819,9 +817,8 @@ void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp)
prefs.show_ccr_setpoint = git_prefs.show_ccr_setpoint;
prefs.show_ccr_sensors = git_prefs.show_ccr_sensors;
prefs.pp_graphs.po2 = git_prefs.pp_graphs.po2;
- DiveListModel::instance()->clear();
process_loaded_dives();
- DiveListModel::instance()->addAllDives();
+ DiveListModel::instance()->reload();
if (currentDiveTimestamp)
setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
@@ -832,8 +829,7 @@ void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp)
void QMLManager::refreshDiveList()
{
- DiveListModel::instance()->clear();
- DiveListModel::instance()->addAllDives();
+ DiveListModel::instance()->reload();
}
void QMLManager::setupDivesite(struct dive *d, struct dive_site *ds, double lat, double lon, const char *locationtext)
@@ -1367,9 +1363,7 @@ bool QMLManager::undoDelete(int id)
add_dive_to_trip(deletedDive, trip);
}
record_dive(deletedDive);
- QList<dive *>diveAsList;
- diveAsList << deletedDive;
- DiveListModel::instance()->addDive(diveAsList);
+ DiveListModel::instance()->insertDive(get_idx_by_uniq_id(deletedDive->id), nullptr);
changesNeedSaving();
deletedDive = NULL;
deletedTrip = NULL;
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<DiveListModel *>(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<dive *> &listOfDives)
-{
- if (listOfDives.isEmpty())
- return;
- beginInsertRows(QModelIndex(), rowCount(), rowCount() + listOfDives.count() - 1);
- endInsertRows();
-}
-
-void DiveListModel::addAllDives()
-{
- QList<dive *>listOfDives;
- 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;