From dde2049027a483b2e211747e6f18d560a88c28bf Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk@hohndel.org>
Date: Mon, 25 Jun 2018 16:39:56 +0800
Subject: [PATCH] QML UI: correctly update the model

In order to trigger the redraw of an edited dive we need to make sure
the model realizes that it has been updated. So far the only way to make
sure this happens reliably appears to be to remove the item and
re-insert it. Seems weird, but with this the bug of not redrawing the
profile after an edit appears fixed.

Fixes #1419

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
---
 qt-models/divelistmodel.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 23427002a..8dc119ad8 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -94,8 +94,10 @@ void DiveListModel::removeDiveById(int id)
 void DiveListModel::updateDive(int i, dive *d)
 {
 	DiveObjectHelper *newDive = new DiveObjectHelper(d);
-	m_dives.replace(i, newDive);
-	emit dataChanged(createIndex(i, 0), createIndex(i, 0));
+	// we need to make sure that QML knows that this dive has changed -
+	// the only reliable way I've found is to remove and re-insert it
+	removeDive(i);
+	insertDive(i, newDive);
 }
 
 void DiveListModel::clear()