summaryrefslogtreecommitdiffstats
path: root/qt-models/maplocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-30 16:51:59 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-09-06 11:48:47 -0700
commitb39f2406c6a520f0b3743324744f3c55914adc52 (patch)
tree8cfadbb34be79cf9e75d2280b70fc1d887380f49 /qt-models/maplocationmodel.cpp
parentcabe70be8079a69e159d46525fc8b283d9ec7c2a (diff)
downloadsubsurface-b39f2406c6a520f0b3743324744f3c55914adc52.tar.gz
Map: don't fully reset model on selection change
When changing the selection the MapLocationModel was reset. This lead to crashes on Qt-5.9 which are due to QML accessing data that was freed during model reset. This putative Qt bug doesn't happen on newer Qt versions. At least Qt-5.12 is known to work. Instead of fighting the bug, let's simply not reset the model but send a dataChanged() for every element of the MapLocationModel. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/maplocationmodel.cpp')
-rw-r--r--qt-models/maplocationmodel.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 0fe86f596..ea7d4f098 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -150,6 +150,15 @@ static bool hasSelectedDive(const dive_site *ds)
[] (const dive *d) { return d->selected; });
}
+void MapLocationModel::selectionChanged()
+{
+ if (m_mapLocations.isEmpty())
+ return;
+ for(MapLocation *m: m_mapLocations)
+ m->m_selected = m_selectedDs.contains(m->divesite());
+ emit dataChanged(createIndex(0, 0), createIndex(m_mapLocations.size() - 1, 0));
+}
+
void MapLocationModel::reload(QObject *map)
{
beginResetModel();