summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/divelistview.cpp11
-rw-r--r--qt-models/divetripmodel.cpp14
-rw-r--r--qt-models/divetripmodel.h3
3 files changed, 22 insertions, 6 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 4354fdb26..b81b16557 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -86,8 +86,11 @@ void DiveListView::resetModel()
MultiFilterSortModel::instance()->resetModel(currentLayout);
// If the model was reset, we have to reconnect the signals and tell
// the filter model to update its source model.
- connect(DiveTripModelBase::instance(), &DiveTripModelBase::selectionChanged, this, &DiveListView::diveSelectionChanged);
- connect(DiveTripModelBase::instance(), &DiveTripModelBase::currentDiveChanged, this, &DiveListView::currentDiveChanged);
+ DiveTripModelBase *m = DiveTripModelBase::instance();
+ connect(m, &DiveTripModelBase::selectionChanged, this, &DiveListView::diveSelectionChanged);
+ connect(m, &DiveTripModelBase::currentDiveChanged, this, &DiveListView::currentDiveChanged);
+ // Get the initial selection
+ m->initSelection();
}
void DiveListView::calculateInitialColumnWidth(int col)
@@ -519,10 +522,6 @@ void DiveListView::reload()
{
resetModel();
- if (amount_selected && current_dive != NULL)
- selectDive(get_divenr(current_dive), true);
- else
- select_newest_visible_dive();
if (selectedIndexes().count()) {
QModelIndex curr = selectedIndexes().first();
curr = curr.parent().isValid() ? curr.parent() : curr;
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 04af9c47f..ee0620c5e 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -3,6 +3,7 @@
#include "core/divefilter.h"
#include "core/gettextfromc.h"
#include "core/metrics.h"
+#include "core/selection.h"
#include "core/trip.h"
#include "core/qthelper.h"
#include "core/divesite.h"
@@ -372,6 +373,19 @@ void DiveTripModelBase::resetModel(DiveTripModelBase::Layout layout)
currentModel.reset(new DiveTripModelList);
}
+// After resetting the model, the higher up model or view may call this
+// function to get informed on the current selection.
+// TODO: Currently, this reads and resets the selection. Make this more
+// efficient by maintaining a list of selected dives.
+void DiveTripModelBase::initSelection()
+{
+ std::vector<dive *> dives = getDiveSelection();
+ if (!dives.empty())
+ setSelection(dives, current_dive);
+ else
+ select_newest_visible_dive();
+}
+
void DiveTripModelBase::clear()
{
beginResetModel();
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index 8756ba217..4f5b55f02 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -72,6 +72,9 @@ public:
// by instance().
static void resetModel(Layout layout);
+ // Call after having set the model to be informed of the current selection.
+ void initSelection();
+
// Clear all dives
void clear();