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>
This commit is contained in:
Dirk Hohndel 2019-09-27 16:26:54 -07:00
parent 400b218f76
commit 9ae7040a91
15 changed files with 118 additions and 89 deletions

View file

@ -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()

View file

@ -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;

View file

@ -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
{

View file

@ -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;