diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-01-27 11:27:41 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-01-27 11:32:40 -0800 |
commit | 6f953d51de0796bd584938d759b32eeffb849463 (patch) | |
tree | 21d4578f12991ff94f24770c1e89d6a0f9864132 | |
parent | 9342dedb265ed314e1657e82aef407176f7d1e04 (diff) | |
download | subsurface-6f953d51de0796bd584938d759b32eeffb849463.tar.gz |
QML UI: correctly notify of model change
This may seem weird, but it seems to work to make sure that the model
actually is correctly updated when updating a dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-models/divelistmodel.cpp | 19 | ||||
-rw-r--r-- | qt-models/divelistmodel.h | 2 |
2 files changed, 19 insertions, 2 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index e6514064f..6e0804743 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -16,12 +16,27 @@ void DiveListModel::addDive(dive *d) endInsertRows(); } +void DiveListModel::insertDive(int i, DiveObjectHelper *newDive) +{ + beginInsertRows(QModelIndex(), i, i); + m_dives.insert(i, newDive); + endInsertRows(); +} + +void DiveListModel::removeDive(int i) +{ + beginRemoveRows(QModelIndex(), i, i); + m_dives.removeAt(i); + endRemoveRows(); +} + void DiveListModel::updateDive(dive *d) { for (int i = 0; i < m_dives.count(); i++) { if (m_dives.at(i)->id() == d->id) { DiveObjectHelper *newDive = new DiveObjectHelper(d); - m_dives.replace(i, newDive); + removeDive(i); + insertDive(i, newDive); break; } } @@ -88,4 +103,4 @@ DiveListModel *DiveListModel::instance() DiveObjectHelper* DiveListModel::at(int i){ return m_dives.at(i); -}
\ No newline at end of file +} diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index 5265cd1b0..adc298515 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -20,6 +20,8 @@ public: static DiveListModel *instance(); DiveListModel(QObject *parent = 0); void addDive(dive *d); + void insertDive(int i, DiveObjectHelper *newDive); + void removeDive(int i); void updateDive(dive *d); void clear(); int rowCount(const QModelIndex &parent = QModelIndex()) const; |