Compare commits
3 Commits
master
...
cleanupGps
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eb246f921 | ||
|
|
cb9a337965 | ||
|
|
257698aff4 |
@ -15,17 +15,12 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
GpsLocation *GpsLocation::m_Instance = NULL;
|
GpsLocation::GpsLocation() :
|
||||||
|
|
||||||
GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_GpsSource(0),
|
m_GpsSource(0),
|
||||||
|
showMessageCB(0),
|
||||||
waitingForPosition(false),
|
waitingForPosition(false),
|
||||||
haveSource(UNKNOWN)
|
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
|
// create a QSettings object that's separate from the main application settings
|
||||||
geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
|
geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
|
||||||
QStringLiteral("org.subsurfacedivelog"), QStringLiteral("subsurfacelocation"), this);
|
QStringLiteral("org.subsurfacedivelog"), QStringLiteral("subsurfacelocation"), this);
|
||||||
@ -39,19 +34,17 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent) :
|
|||||||
|
|
||||||
GpsLocation *GpsLocation::instance()
|
GpsLocation *GpsLocation::instance()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_Instance != NULL);
|
static GpsLocation self;
|
||||||
|
return &self;
|
||||||
return m_Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GpsLocation::hasInstance()
|
|
||||||
{
|
|
||||||
return m_Instance != NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GpsLocation::~GpsLocation()
|
GpsLocation::~GpsLocation()
|
||||||
{
|
{
|
||||||
m_Instance = NULL;
|
}
|
||||||
|
|
||||||
|
void GpsLocation::setLogCallBack(void (*showMsgCB)(const char *))
|
||||||
|
{
|
||||||
|
showMessageCB = showMsgCB;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsLocation::setGpsTimeThreshold(int seconds)
|
void GpsLocation::setGpsTimeThreshold(int seconds)
|
||||||
|
|||||||
@ -29,14 +29,14 @@ struct DiveAndLocation {
|
|||||||
class GpsLocation : public QObject {
|
class GpsLocation : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GpsLocation(void (*showMsgCB)(const char *msg), QObject *parent);
|
GpsLocation();
|
||||||
~GpsLocation();
|
~GpsLocation();
|
||||||
static GpsLocation *instance();
|
static GpsLocation *instance();
|
||||||
static bool hasInstance();
|
|
||||||
std::vector<DiveAndLocation> getLocations();
|
std::vector<DiveAndLocation> getLocations();
|
||||||
int getGpsNum() const;
|
int getGpsNum() const;
|
||||||
bool hasLocationsSource();
|
bool hasLocationsSource();
|
||||||
QString currentPosition();
|
QString currentPosition();
|
||||||
|
void setLogCallBack(void (*showMsgCB)(const char *msg));
|
||||||
|
|
||||||
QMap<qint64, gpsTracker> currentGPSInfo() const;
|
QMap<qint64, gpsTracker> currentGPSInfo() const;
|
||||||
|
|
||||||
@ -49,7 +49,6 @@ private:
|
|||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
QString userAgent;
|
QString userAgent;
|
||||||
void (*showMessageCB)(const char *msg);
|
void (*showMessageCB)(const char *msg);
|
||||||
static GpsLocation *m_Instance;
|
|
||||||
bool waitingForPosition;
|
bool waitingForPosition;
|
||||||
QMap<qint64, gpsTracker> m_trackers;
|
QMap<qint64, gpsTracker> m_trackers;
|
||||||
QList<gpsTracker> m_deletedTrackers;
|
QList<gpsTracker> m_deletedTrackers;
|
||||||
|
|||||||
@ -209,7 +209,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
|||||||
m_instance = this;
|
m_instance = this;
|
||||||
m_lastDevicePixelRatio = qApp->devicePixelRatio();
|
m_lastDevicePixelRatio = qApp->devicePixelRatio();
|
||||||
timer.start();
|
timer.start();
|
||||||
connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
|
|
||||||
|
|
||||||
// make upload signals available in QML
|
// make upload signals available in QML
|
||||||
// Remark: signal - signal connect
|
// Remark: signal - signal connect
|
||||||
@ -290,11 +289,11 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
|||||||
connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged,
|
connect(&btDiscovery->localBtDevice, &QBluetoothLocalDevice::hostModeStateChanged,
|
||||||
this, &QMLManager::btHostModeChange);
|
this, &QMLManager::btHostModeChange);
|
||||||
}
|
}
|
||||||
// create location manager service
|
// add log call back to the location manager service singleton
|
||||||
locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
|
GpsLocation::instance()->setLogCallBack(&appendTextToLogStandalone);
|
||||||
progress_callback = &progressCallback;
|
progress_callback = &progressCallback;
|
||||||
connect(locationProvider, SIGNAL(haveSourceChanged()), this, SLOT(hasLocationSourceChanged()));
|
connect(GpsLocation::instance(), &GpsLocation::haveSourceChanged, this, &QMLManager::hasLocationSourceChanged);
|
||||||
setLocationServiceAvailable(locationProvider->hasLocationsSource());
|
setLocationServiceAvailable(GpsLocation::instance()->hasLocationsSource());
|
||||||
set_git_update_cb(&gitProgressCB);
|
set_git_update_cb(&gitProgressCB);
|
||||||
|
|
||||||
// present dive site lists sorted by name
|
// present dive site lists sorted by name
|
||||||
@ -324,6 +323,9 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
|||||||
connect(Command::getUndoStack(), &QUndoStack::undoTextChanged, this, &QMLManager::undoTextChanged);
|
connect(Command::getUndoStack(), &QUndoStack::undoTextChanged, this, &QMLManager::undoTextChanged);
|
||||||
connect(Command::getUndoStack(), &QUndoStack::redoTextChanged, this, &QMLManager::redoTextChanged);
|
connect(Command::getUndoStack(), &QUndoStack::redoTextChanged, this, &QMLManager::redoTextChanged);
|
||||||
|
|
||||||
|
// now that everything is setup, connect the application changed signal
|
||||||
|
connect(qobject_cast<QApplication *>(QApplication::instance()), &QApplication::applicationStateChanged, this, &QMLManager::applicationStateChanged);
|
||||||
|
|
||||||
// we start out with clean data
|
// we start out with clean data
|
||||||
updateHaveLocalChanges(false);
|
updateHaveLocalChanges(false);
|
||||||
}
|
}
|
||||||
@ -1611,25 +1613,25 @@ int QMLManager::addDive()
|
|||||||
QString QMLManager::getCurrentPosition()
|
QString QMLManager::getCurrentPosition()
|
||||||
{
|
{
|
||||||
static bool hasLocationSource = false;
|
static bool hasLocationSource = false;
|
||||||
if (locationProvider->hasLocationsSource() != hasLocationSource) {
|
if (GpsLocation::instance()->hasLocationsSource() != hasLocationSource) {
|
||||||
hasLocationSource = !hasLocationSource;
|
hasLocationSource = !hasLocationSource;
|
||||||
setLocationServiceAvailable(hasLocationSource);
|
setLocationServiceAvailable(hasLocationSource);
|
||||||
}
|
}
|
||||||
if (!hasLocationSource)
|
if (!hasLocationSource)
|
||||||
return tr("Unknown GPS location");
|
return tr("Unknown GPS location");
|
||||||
|
|
||||||
QString positionResponse = locationProvider->currentPosition();
|
QString positionResponse = GpsLocation::instance()->currentPosition();
|
||||||
if (positionResponse == GPS_CURRENT_POS)
|
if (positionResponse == GPS_CURRENT_POS)
|
||||||
connect(locationProvider, &GpsLocation::acquiredPosition, this, &QMLManager::waitingForPositionChanged, Qt::UniqueConnection);
|
connect(GpsLocation::instance(), &GpsLocation::acquiredPosition, this, &QMLManager::waitingForPositionChanged, Qt::UniqueConnection);
|
||||||
else
|
else
|
||||||
disconnect(locationProvider, &GpsLocation::acquiredPosition, this, &QMLManager::waitingForPositionChanged);
|
disconnect(GpsLocation::instance(), &GpsLocation::acquiredPosition, this, &QMLManager::waitingForPositionChanged);
|
||||||
return positionResponse;
|
return positionResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::applyGpsData()
|
void QMLManager::applyGpsData()
|
||||||
{
|
{
|
||||||
appendTextToLog("Applying GPS fiexs");
|
appendTextToLog("Applying GPS fiexs");
|
||||||
std::vector<DiveAndLocation> fixes = locationProvider->getLocations();
|
std::vector<DiveAndLocation> fixes = GpsLocation::instance()->getLocations();
|
||||||
Command::applyGPSFixes(fixes);
|
Command::applyGPSFixes(fixes);
|
||||||
appendTextToLog(QString("Attached %1 GPS fixes").arg(fixes.size()));
|
appendTextToLog(QString("Attached %1 GPS fixes").arg(fixes.size()));
|
||||||
if (fixes.size())
|
if (fixes.size())
|
||||||
@ -1644,19 +1646,19 @@ void QMLManager::populateGpsData()
|
|||||||
|
|
||||||
void QMLManager::clearGpsData()
|
void QMLManager::clearGpsData()
|
||||||
{
|
{
|
||||||
locationProvider->clearGpsData();
|
GpsLocation::instance()->clearGpsData();
|
||||||
populateGpsData();
|
populateGpsData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::deleteGpsFix(quint64 when)
|
void QMLManager::deleteGpsFix(quint64 when)
|
||||||
{
|
{
|
||||||
locationProvider->deleteGpsFix(when);
|
GpsLocation::instance()->deleteGpsFix(when);
|
||||||
populateGpsData();
|
populateGpsData();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLManager::logText() const
|
QString QMLManager::logText() const
|
||||||
{
|
{
|
||||||
QString logText = m_logText + QString("\nNumer of GPS fixes: %1").arg(locationProvider->getGpsNum());
|
QString logText = m_logText + QString("\nNumer of GPS fixes: %1").arg(GpsLocation::instance()->getGpsNum());
|
||||||
return logText;
|
return logText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1674,7 +1676,7 @@ void QMLManager::appendTextToLog(const QString &newText)
|
|||||||
void QMLManager::setLocationServiceEnabled(bool locationServiceEnabled)
|
void QMLManager::setLocationServiceEnabled(bool locationServiceEnabled)
|
||||||
{
|
{
|
||||||
m_locationServiceEnabled = locationServiceEnabled;
|
m_locationServiceEnabled = locationServiceEnabled;
|
||||||
locationProvider->serviceEnable(m_locationServiceEnabled);
|
GpsLocation::instance()->serviceEnable(m_locationServiceEnabled);
|
||||||
emit locationServiceEnabledChanged();
|
emit locationServiceEnabledChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1687,7 +1689,7 @@ void QMLManager::setLocationServiceAvailable(bool locationServiceAvailable)
|
|||||||
|
|
||||||
void QMLManager::hasLocationSourceChanged()
|
void QMLManager::hasLocationSourceChanged()
|
||||||
{
|
{
|
||||||
setLocationServiceAvailable(locationProvider->hasLocationsSource());
|
setLocationServiceAvailable(GpsLocation::instance()->hasLocationsSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::setVerboseEnabled(bool verboseMode)
|
void QMLManager::setVerboseEnabled(bool verboseMode)
|
||||||
|
|||||||
@ -254,7 +254,6 @@ private:
|
|||||||
bool m_verboseEnabled;
|
bool m_verboseEnabled;
|
||||||
bool m_diveListProcessing;
|
bool m_diveListProcessing;
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
GpsLocation *locationProvider;
|
|
||||||
bool m_loadFromCloud;
|
bool m_loadFromCloud;
|
||||||
static QMLManager *m_instance;
|
static QMLManager *m_instance;
|
||||||
QString m_notificationText;
|
QString m_notificationText;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user