summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-12-11 09:50:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-11 08:31:57 -0500
commit7e12ac262b35bcab05bc4a7e69d8572cba5b7ef1 (patch)
tree569e70caa590bee9057f33f5fcc669b40ef4d26d /qt-models/divetripmodel.cpp
parent37b24857ed6a95c7017e443adc88fa8c4dea0c1a (diff)
downloadsubsurface-7e12ac262b35bcab05bc4a7e69d8572cba5b7ef1.tar.gz
Dive list: implement DiveTripModelBase::reset()
On desktop, resetting the model is realized by generating a new model object. This is due to the fact that we have two different models (tree and list) and for switching between those, we have to create a new object. On mobile, currently there are no plans to support the list-mode. Therefore, there is no reason the recreate the object. Instead, implement a reset() function that reloads the core data. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.cpp')
-rw-r--r--qt-models/divetripmodel.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index b76683175..eea4fcdba 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -379,6 +379,15 @@ void DiveTripModelBase::clear()
endResetModel();
}
+void DiveTripModelBase::reset()
+{
+ beginResetModel();
+ clearData();
+ populate();
+ endResetModel();
+ initSelection();
+}
+
DiveTripModelBase::DiveTripModelBase(QObject *parent) : QAbstractItemModel(parent)
{
}
@@ -561,7 +570,11 @@ DiveTripModelTree::DiveTripModelTree(QObject *parent) : DiveTripModelBase(parent
connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &DiveTripModelTree::tripChanged);
connect(&diveListNotifier, &DiveListNotifier::filterReset, this, &DiveTripModelTree::filterReset);
- // Fill model
+ populate();
+}
+
+void DiveTripModelTree::populate()
+{
for (int i = 0; i < dive_table.nr ; ++i) {
dive *d = get_dive(i);
update_cylinder_related_info(d);
@@ -1286,6 +1299,11 @@ DiveTripModelList::DiveTripModelList(QObject *parent) : DiveTripModelBase(parent
connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &DiveTripModelList::divesSelected);
connect(&diveListNotifier, &DiveListNotifier::filterReset, this, &DiveTripModelList::filterReset);
+ populate();
+}
+
+void DiveTripModelList::populate()
+{
// Fill model
items.reserve(dive_table.nr);
for (int i = 0; i < dive_table.nr ; ++i)