From 8a33c04894d6830885d7f47140962d5fdafd648f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 15 Nov 2019 20:59:13 +0100 Subject: [PATCH] Cleanup: use DiveTripModelBase::clear() to reset the log Introduce a DiveTripModelBase::clear() function that cleanly clears all dive data inside a beginResetModel()/endResetModel() pair. Thus, the UI will be cleanly reset and we can remove explicit calls to - graphics->setEmptyState() - mainTab->clearTabs() - mainTab->clearTabs() - diveList->reload() from MainWindow::closeCurrentFile(). Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 6 +----- qt-models/divetripmodel.cpp | 7 +++++++ qt-models/divetripmodel.h | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 632917733..7b3120ca4 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -657,12 +657,8 @@ void MainWindow::closeCurrentFile() { /* free the dives and trips */ clear_git_id(); - clear_dive_file_data(); + DiveTripModelBase::instance()->clear(); setCurrentFile(nullptr); - graphics->setEmptyState(); - mainTab->clearTabs(); - mainTab->updateDiveInfo(); - diveList->reload(); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); MapWidget::instance()->reload(); LocationInformationModel::instance()->update(); diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index d8166d2eb..5fedd432f 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -372,6 +372,13 @@ void DiveTripModelBase::resetModel(DiveTripModelBase::Layout layout) currentModel.reset(new DiveTripModelList); } +void DiveTripModelBase::clear() +{ + beginResetModel(); + clear_dive_file_data(); + endResetModel(); +} + DiveTripModelBase::DiveTripModelBase(QObject *parent) : QAbstractItemModel(parent) { } diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h index dc0d4b299..6b3f26fd7 100644 --- a/qt-models/divetripmodel.h +++ b/qt-models/divetripmodel.h @@ -70,6 +70,9 @@ public: // by instance(). static void resetModel(Layout layout); + // Clear all dives + void clear(); + Qt::ItemFlags flags(const QModelIndex &index) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;