summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mobile-widgets/qmlmanager.cpp4
-rw-r--r--qt-models/divelistmodel.cpp8
-rw-r--r--qt-models/divelistmodel.h3
-rw-r--r--subsurface-helper.cpp4
4 files changed, 12 insertions, 7 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index fcb25e4a5..f6c182a55 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -825,7 +825,7 @@ void QMLManager::consumeFinishedLoad(timestamp_t currentDiveTimestamp)
process_loaded_dives();
DiveListModel::instance()->reload();
if (currentDiveTimestamp)
- setUpdateSelectedDive(dlSortModel->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
+ setUpdateSelectedDive(DiveListSortModel::instance()->getIdxForId(get_dive_id_closest_to(currentDiveTimestamp)));
appendTextToLog(QStringLiteral("%1 dives loaded").arg(dive_table.nr));
if (dive_table.nr == 0)
setStartPageText(tr("Cloud storage open successfully. No dives in dive list."));
@@ -2056,7 +2056,7 @@ void QMLManager::setFilter(const QString filterText)
QMetaObject::invokeMethod(qmlWindow, "showBusy");
QtConcurrent::run(QThreadPool::globalInstance(),
[=]{
- dlSortModel->setFilter(filterText);
+ DiveListSortModel::instance()->setFilter(filterText);
QMetaObject::invokeMethod(qmlWindow, "hideBusy");
});
}
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 6d94b09c9..d3c4e3ce2 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -6,7 +6,7 @@
#include "core/ssrf.h" // for LOG_STP
#include <QDateTime>
-DiveListSortModel::DiveListSortModel(QObject *parent) : QSortFilterProxyModel(parent)
+DiveListSortModel::DiveListSortModel()
{
setSourceModel(DiveListModel::instance());
setDynamicSortFilter(true);
@@ -16,6 +16,12 @@ DiveListSortModel::DiveListSortModel(QObject *parent) : QSortFilterProxyModel(pa
LOG_STP("run_ui diveListModel sorted");
}
+DiveListSortModel *DiveListSortModel::instance()
+{
+ static DiveListSortModel self;
+ return &self;
+}
+
void DiveListSortModel::updateFilterState()
{
if (filterString.isEmpty()) {
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 87c5bb254..e7fb5369c 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -11,7 +11,8 @@ class DiveListSortModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
- DiveListSortModel(QObject *parent = 0);
+ DiveListSortModel();
+ static DiveListSortModel *instance();
void setSourceModel(QAbstractItemModel *sourceModel);
Q_INVOKABLE void reload();
Q_INVOKABLE QString tripTitle(const QString &trip);
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp
index 26e58ece9..c389e2099 100644
--- a/subsurface-helper.cpp
+++ b/subsurface-helper.cpp
@@ -96,14 +96,13 @@ void run_ui()
qDebug() << "QML import path" << engine.importPathList();
#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
- DiveListSortModel *sortModel = new DiveListSortModel(0);
QSortFilterProxyModel *gpsSortModel = new QSortFilterProxyModel(nullptr);
gpsSortModel->setSourceModel(GpsListModel::instance());
gpsSortModel->setDynamicSortFilter(true);
gpsSortModel->setSortRole(GpsListModel::GpsWhenRole);
gpsSortModel->sort(0, Qt::DescendingOrder);
QQmlContext *ctxt = engine.rootContext();
- ctxt->setContextProperty("diveModel", sortModel);
+ ctxt->setContextProperty("diveModel", DiveListSortModel::instance());
ctxt->setContextProperty("gpsModel", gpsSortModel);
ctxt->setContextProperty("vendorList", vendorList);
set_non_bt_addresses();
@@ -135,7 +134,6 @@ void run_ui()
LOG_STP("run_ui show_computer_list");
manager->setDevicePixelRatio(qml_window->devicePixelRatio(), qml_window->screen());
- manager->dlSortModel = sortModel;
manager->qmlWindow = qqWindowObject;
manager->screenChanged(screen);
qDebug() << "qqwindow screen has ldpi/pdpi" << screen->logicalDotsPerInch() << screen->physicalDotsPerInch();