From 2f2e9da2cd18d0450fa791371922ba1844338bb6 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 30 Nov 2015 10:09:46 -0800 Subject: Clear the Dive model before repopulating it Otherwise we could get duplicate dives in the dive list. Signed-off-by: Dirk Hohndel --- qt-models/divelistmodel.cpp | 7 +++++++ qt-models/divelistmodel.h | 1 + 2 files changed, 8 insertions(+) (limited to 'qt-models') diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 7d49f5c01..18f270c15 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -15,6 +15,13 @@ void DiveListModel::addDive(dive *d) endInsertRows(); } +void DiveListModel::clear() +{ + beginRemoveRows(QModelIndex(), 0, m_dives.count() - 1); + m_dives.clear(); + endRemoveRows(); +} + int DiveListModel::rowCount(const QModelIndex &) const { return m_dives.count(); diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index 958a783e9..fbeb13486 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -35,6 +35,7 @@ public: static DiveListModel *instance(); DiveListModel(QObject *parent = 0); void addDive(dive *d); + void clear(); int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QHash roleNames() const; -- cgit v1.2.3-70-g09d2