diff options
Diffstat (limited to 'qt-models')
-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; |