diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2021-01-01 12:55:47 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-01-02 12:47:15 -0800 |
commit | 5048a695aa1085a7eb03263b95a466e28ff40ab0 (patch) | |
tree | 0e3e25bba85e87af6a8fb60977ab02d1064021ee /core | |
parent | 53b572f98791146e1755a7bbb5f22f2e521eea8f (diff) | |
download | subsurface-5048a695aa1085a7eb03263b95a466e28ff40ab0.tar.gz |
mobile: turn GpsLocation into a regular singleton construct
Simply move the initialization of the logging function into its own method and
call that in the QMLManager constructor.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/gpslocation.cpp | 21 | ||||
-rw-r--r-- | core/gpslocation.h | 5 |
2 files changed, 9 insertions, 17 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index fd598683f..1da12fe5b 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -15,17 +15,12 @@ #include <QApplication> #include <QTimer> -GpsLocation *GpsLocation::m_Instance = NULL; - -GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) : - QObject(parent), +GpsLocation::GpsLocation() : m_GpsSource(0), + showMessageCB(0), waitingForPosition(false), haveSource(UNKNOWN) { - Q_ASSERT_X(m_Instance == NULL, "GpsLocation", "GpsLocation recreated"); - m_Instance = this; - showMessageCB = showMsgCB; // create a QSettings object that's separate from the main application settings geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, QStringLiteral("org.subsurfacedivelog"), QStringLiteral("subsurfacelocation"), this); @@ -39,19 +34,17 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) : GpsLocation *GpsLocation::instance() { - Q_ASSERT(m_Instance != NULL); - - return m_Instance; + static GpsLocation self; + return &self; } -bool GpsLocation::hasInstance() +GpsLocation::~GpsLocation() { - return m_Instance != NULL; } -GpsLocation::~GpsLocation() +void GpsLocation::setLogCallBack(void (*showMsgCB)(const char *)) { - m_Instance = NULL; + showMessageCB = showMsgCB; } void GpsLocation::setGpsTimeThreshold(int seconds) diff --git a/core/gpslocation.h b/core/gpslocation.h index d376c5ec7..ea3373d3b 100644 --- a/core/gpslocation.h +++ b/core/gpslocation.h @@ -29,14 +29,14 @@ struct DiveAndLocation { class GpsLocation : public QObject { Q_OBJECT public: - GpsLocation(void (*showMsgCB)(const char *msg), QObject *parent); + GpsLocation(); ~GpsLocation(); static GpsLocation *instance(); - static bool hasInstance(); std::vector<DiveAndLocation> getLocations(); int getGpsNum() const; bool hasLocationsSource(); QString currentPosition(); + void setLogCallBack(void (*showMsgCB)(const char *msg)); QMap<qint64, gpsTracker> currentGPSInfo() const; @@ -49,7 +49,6 @@ private: QNetworkReply *reply; QString userAgent; void (*showMessageCB)(const char *msg); - static GpsLocation *m_Instance; bool waitingForPosition; QMap<qint64, gpsTracker> m_trackers; QList<gpsTracker> m_deletedTrackers; |