From 635d67ee7feed0ddc7a5e36d6a7f5c2ed1ee9ba1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 18 Nov 2019 18:44:17 +0100 Subject: Dive list: clear internal data when clearing model The DiveListModelBase::clear() implementation was flawed: It cleared the data in the core, but left the data in the model untouched. The code was relying on the fact that the caller would reset the model manually. Not a good idea. Therefore, clear the internal data to keep the model consistent at all times. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'qt-models/divetripmodel.cpp') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index d2e6a634d..bcdf14377 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -376,6 +376,7 @@ void DiveTripModelBase::clear() { beginResetModel(); clear_dive_file_data(); + clearData(); emit diveListNotifier.divesSelected({}, nullptr); // Inform profile, etc of changed selection endResetModel(); } @@ -607,6 +608,11 @@ int DiveTripModelTree::rowCount(const QModelIndex &parent) const return entry.d_or_t.trip ? entry.dives.size() : 0; } +void DiveTripModelList::clearData() +{ + items.clear(); +} + static const quintptr noParent = ~(quintptr)0; // This is the "internalId" marker for top-level item QModelIndex DiveTripModelTree::index(int row, int column, const QModelIndex &parent) const @@ -1238,6 +1244,11 @@ int DiveTripModelList::rowCount(const QModelIndex &parent) const return parent.isValid() ? 0 : items.size(); } +void DiveTripModelTree::clearData() +{ + items.clear(); +} + QModelIndex DiveTripModelList::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) -- cgit v1.2.3-70-g09d2