From 4467477389cf0d6de8e3797b1941c07162896907 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 12 Sep 2020 23:38:45 +0200 Subject: models: update DiveComputerModel when core data is reset To implement undo-semantics, we want a longer-lived dive-computer-model (currently, it is regenerated when the dialog is opened). Therefore, it must be reloaded when the core data is reset. Do this like for other models: listen to the dataReset() signal of DiveListNotifier. Signed-off-by: Berthold Stoeger --- qt-models/divecomputermodel.cpp | 10 ++++++++++ qt-models/divecomputermodel.h | 1 + qt-models/gpslistmodel.cpp | 1 - 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'qt-models') diff --git a/qt-models/divecomputermodel.cpp b/qt-models/divecomputermodel.cpp index 356e24ef8..c51e19279 100644 --- a/qt-models/divecomputermodel.cpp +++ b/qt-models/divecomputermodel.cpp @@ -2,11 +2,21 @@ #include "qt-models/divecomputermodel.h" #include "core/dive.h" #include "core/divelist.h" +#include "core/subsurface-qt/divelistnotifier.h" DiveComputerModel::DiveComputerModel(QObject *parent) : CleanerTableModel(parent), dcs(device_table.devices) { + connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &DiveComputerModel::update); setHeaderDataStrings(QStringList() << "" << tr("Model") << tr("Device ID") << tr("Nickname")); + update(); +} + +void DiveComputerModel::update() +{ + beginResetModel(); + dcs = device_table.devices; + endResetModel(); } QVariant DiveComputerModel::data(const QModelIndex &index, int role) const diff --git a/qt-models/divecomputermodel.h b/qt-models/divecomputermodel.h index 7f3d4171f..17f145f78 100644 --- a/qt-models/divecomputermodel.h +++ b/qt-models/divecomputermodel.h @@ -25,6 +25,7 @@ public: public slots: void remove(const QModelIndex &index); + void update(); private: std::vector dcs; diff --git a/qt-models/gpslistmodel.cpp b/qt-models/gpslistmodel.cpp index c463c3ed2..5fa7d1081 100644 --- a/qt-models/gpslistmodel.cpp +++ b/qt-models/gpslistmodel.cpp @@ -67,4 +67,3 @@ GpsListModel *GpsListModel::instance() static GpsListModel self; return &self; } - -- cgit v1.2.3-70-g09d2