aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-11 21:36:51 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-11-11 22:44:58 +0100
commite434b5aa4066990a1dbf67670e09b650d87be753 (patch)
tree68d759ef056be49a6220130af98bd6a64e7d5388
parenta474264cc87d10b36287bd800efc46a35a97eb78 (diff)
downloadsubsurface-e434b5aa4066990a1dbf67670e09b650d87be753.tar.gz
Cleanup: introduce DiveTripModelBase::IS_TRIP_ROLE
To test whether an entry is a trip, we passed a pointer to the trip through a QVariant and tested that for null-ity. Passing pointers through QVariants has given us myriads of problems in QML, therefore introduce a bool IS_TRIP_ROLE Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/divelistview.cpp3
-rw-r--r--qt-models/divetripmodel.cpp2
-rw-r--r--qt-models/divetripmodel.h1
-rw-r--r--qt-models/filtermodels.cpp3
4 files changed, 5 insertions, 4 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 409b22e38..c012b9832 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -348,8 +348,7 @@ void DiveListView::clearTripSelection()
// we want to make sure no trips are selected
Q_FOREACH (const QModelIndex &index, selectionModel()->selectedRows()) {
- dive_trip_t *trip = index.data(DiveTripModelBase::TRIP_ROLE).value<dive_trip *>();
- if (!trip)
+ if (!index.data(DiveTripModelBase::IS_TRIP_ROLE).toBool())
continue;
selectionModel()->select(index, QItemSelectionModel::Deselect);
}
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index ada648762..4e8478a33 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -723,6 +723,8 @@ QVariant DiveTripModelTree::data(const QModelIndex &index, int role) const
return defaultModelFont();
dive_or_trip entry = tripOrDive(index);
+ if (role == IS_TRIP_ROLE)
+ return !!entry.trip;
if (entry.trip)
return tripData(entry.trip, index.column(), role);
else if (entry.dive)
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index e0eefb1f0..dc0d4b299 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -49,6 +49,7 @@ public:
enum ExtraRoles {
STAR_ROLE = Qt::UserRole + 1,
+ IS_TRIP_ROLE,
DIVE_ROLE,
TRIP_ROLE,
DIVE_IDX,
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 0226e1220..27bb33856 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -228,8 +228,7 @@ void MultiFilterSortModel::myInvalidate()
for (int i = 0; i < m->rowCount(QModelIndex()); ++i) {
QModelIndex idx = m->index(i, 0, QModelIndex());
- dive_trip *trip = m->data(idx, DiveTripModelBase::TRIP_ROLE).value<dive_trip *>();
- if (trip) {
+ if (m->data(idx, DiveTripModelBase::IS_TRIP_ROLE).toBool()) {
// This is a trip -> loop over all dives and see if any is selected
bool showTrip = false;