From e7dafe36aabfe45a4a0b8d6b8056fa9e4d03aaf4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 9 Dec 2019 15:22:02 +0100 Subject: [PATCH] Dive list: clear dive data via the filter model The UI talks to the filter model. Therefore route clearing of data through that model instead of accessing the source model directly. This will allow us to remove the DiveTripModel::instance() function and makes control flow less "jumpy". Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 3 ++- qt-models/filtermodels.cpp | 5 +++++ qt-models/filtermodels.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index b8baac371..3a92656ad 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -69,6 +69,7 @@ #include "qt-models/cylindermodel.h" #include "qt-models/divepicturemodel.h" #include "qt-models/diveplannermodel.h" +#include "qt-models/filtermodels.h" #include "qt-models/tankinfomodel.h" #include "qt-models/weightsysteminfomodel.h" #include "qt-models/yearlystatisticsmodel.h" @@ -650,7 +651,7 @@ void MainWindow::closeCurrentFile() { /* free the dives and trips */ clear_git_id(); - DiveTripModelBase::instance()->clear(); + MultiFilterSortModel::instance()->clear(); setCurrentFile(nullptr); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); MapWidget::instance()->reload(); diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index dcb7e69ad..463276e13 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -32,6 +32,11 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout) m->initSelection(); } +void MultiFilterSortModel::clear() +{ + DiveTripModelBase::instance()->clear(); +} + // Translate selection into local indexes and re-emit signal void MultiFilterSortModel::selectionChangedSlot(const QVector &indexes) { diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 6677c713d..fef39e0d5 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -14,6 +14,7 @@ public: bool lessThan(const QModelIndex &, const QModelIndex &) const override; void resetModel(DiveTripModelBase::Layout layout); + void clear(); signals: void selectionChanged(const QVector &indexes); void currentDiveChanged(QModelIndex index);