diff options
author | 2019-09-27 16:26:54 -0700 | |
---|---|---|
committer | 2019-09-27 16:26:58 -0700 | |
commit | 9ae7040a91c3e3e0606d7abe085ef6da47efd6d2 (patch) | |
tree | de120b115df95fb96d945581aca41cd8c760263c /mobile-widgets | |
parent | 400b218f769320221567b7b66f39c33126a7d2e1 (diff) | |
download | subsurface-9ae7040a91c3e3e0606d7abe085ef6da47efd6d2.tar.gz |
Revert the singleton PR
It turns out that this isn't working the way it was intended to.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 10 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 5 | ||||
-rw-r--r-- | mobile-widgets/qmlprefs.cpp | 17 | ||||
-rw-r--r-- | mobile-widgets/qmlprefs.h | 8 |
4 files changed, 35 insertions, 5 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 62c167653..858f2c730 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -44,6 +44,7 @@ #include "core/settings/qPrefUnit.h" #include "core/trip.h" +QMLManager *QMLManager::m_instance = NULL; bool noCloudToCloud = false; #define RED_FONT QLatin1Literal("<font color=\"red\">") @@ -149,6 +150,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false), m_showNonDiveComputers(false) { LOG_STP("qmlmgr starting"); + m_instance = this; m_lastDevicePixelRatio = qApp->devicePixelRatio(); timer.start(); connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged); @@ -449,6 +451,12 @@ QMLManager::~QMLManager() if (appLogFileOpen) appLogFile.close(); #endif + m_instance = NULL; +} + +QMLManager *QMLManager::instance() +{ + return m_instance; } #define CLOUDURL QString(prefs.cloud_base_url) @@ -1556,7 +1564,7 @@ void QMLManager::applyGpsData() void QMLManager::populateGpsData() { if (GpsListModel::instance()) - GpsListModel::instance()->update(QVector<gpsTracker>::fromList(locationProvider->currentGPSInfo().values())); + GpsListModel::instance()->update(); } void QMLManager::clearGpsData() diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 963c563d7..e47119a71 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -13,14 +13,13 @@ #include "core/btdiscovery.h" #include "core/gpslocation.h" #include "core/downloadfromdcthread.h" -#include "core/singleton.h" #include "qt-models/divelistmodel.h" #include "qt-models/completionmodels.h" #include "qt-models/divelocationmodel.h" #define NOCLOUD_LOCALSTORAGE format_string("%s/cloudstorage/localrepo[master]", system_default_directory()) -class QMLManager : public QObject, public SillySingleton<QMLManager> { +class QMLManager : public QObject { Q_OBJECT Q_PROPERTY(QString logText READ logText WRITE setLogText NOTIFY logTextChanged) Q_PROPERTY(bool locationServiceEnabled MEMBER m_locationServiceEnabled WRITE setLocationServiceEnabled NOTIFY locationServiceEnabledChanged) @@ -90,6 +89,7 @@ public: Q_INVOKABLE void setGitLocalOnly(const bool &value); Q_INVOKABLE void setFilter(const QString filterText); + static QMLManager *instance(); Q_INVOKABLE void registerError(QString error); QString consumeError(); @@ -219,6 +219,7 @@ private: bool m_verboseEnabled; GpsLocation *locationProvider; bool m_loadFromCloud; + static QMLManager *m_instance; struct dive *deletedDive; struct dive_trip *deletedTrip; QString m_notificationText; diff --git a/mobile-widgets/qmlprefs.cpp b/mobile-widgets/qmlprefs.cpp index e415c0e5d..cf7b5ddbb 100644 --- a/mobile-widgets/qmlprefs.cpp +++ b/mobile-widgets/qmlprefs.cpp @@ -8,13 +8,30 @@ /*** Global and constructors ***/ +QMLPrefs *QMLPrefs::m_instance = NULL; + QMLPrefs::QMLPrefs() : m_credentialStatus(qPrefCloudStorage::CS_UNKNOWN), m_oldStatus(qPrefCloudStorage::CS_UNKNOWN), m_showPin(false) { + // This strange construct is needed because QMLEngine calls new and that + // cannot be overwritten + if (!m_instance) + m_instance = this; +} + +QMLPrefs::~QMLPrefs() +{ + m_instance = NULL; } +QMLPrefs *QMLPrefs::instance() +{ + return m_instance; +} + + /*** public functions ***/ const QString QMLPrefs::cloudPassword() const { diff --git a/mobile-widgets/qmlprefs.h b/mobile-widgets/qmlprefs.h index 70964608b..99819fd7c 100644 --- a/mobile-widgets/qmlprefs.h +++ b/mobile-widgets/qmlprefs.h @@ -5,9 +5,9 @@ #include <QObject> #include "core/settings/qPrefCloudStorage.h" #include "core/settings/qPrefDisplay.h" -#include "core/singleton.h" -class QMLPrefs : public QObject, public SillySingleton<QMLPrefs> { + +class QMLPrefs : public QObject { Q_OBJECT Q_PROPERTY(QString cloudPassword MEMBER m_cloudPassword @@ -35,6 +35,9 @@ class QMLPrefs : public QObject, public SillySingleton<QMLPrefs> { NOTIFY oldStatusChanged) public: QMLPrefs(); + ~QMLPrefs(); + + static QMLPrefs *instance(); const QString cloudPassword() const; void setCloudPassword(const QString &cloudPassword); @@ -63,6 +66,7 @@ private: QString m_cloudPin; QString m_cloudUserName; qPrefCloudStorage::cloud_status m_credentialStatus; + static QMLPrefs *m_instance; qPrefCloudStorage::cloud_status m_oldStatus; bool m_showPin; |