subsurface/core/gpslocation.h

79 lines
1.8 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0
#ifndef GPSLOCATION_H
#define GPSLOCATION_H
#include "units.h"
#include <QObject>
#include <QGeoCoordinate>
#include <QGeoPositionInfoSource>
#include <QGeoPositionInfo>
#include <QSettings>
#include <QNetworkReply>
#include <QMap>
#define GPS_CURRENT_POS gettextFromC::tr("Waiting to aquire GPS location")
QML UI: rewrite the commitChanges function I couldn't figure out how to break this down into small, useful commits. Part of the problem is that I kept going while working on this and as you can see from looking at the commit, diff tries so hard to find small code fragments that moved around, that the diff overall becomes quite unreadable and it seemed impossible to recreate the sequence of steps after the fact. It all started with adding the parsing for the GPS coordinates. But while testing that code I found several issues with the rest of the function. Most importantly it seemed ridiculous that we carefully tried to match the texts that the DiveObjectHelper would create for the various fields, instead of just using the DiveObjectHelper to do just that. And once I had converted that I once again realized just how long and hard to understand that function was getting and decided to break out some of the more complex parts into their own helper functions. But of course all this didn't happen in this logical, structured, ordered way. Instead I did all of these things at the same time, testing, rearranging, etc. So in the end I went with one BIG commit that does all of this in one fell swoop. This adds four helper functions to deal with start time/date, duration, location and gps coordinates, and depth of the dive. To avoid mistakes when dealing with the GPS coordinates, there's another helper to encapsulate the creation of the dive site and we switched to a current GPS location. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-15 13:01:14 +00:00
struct gpsTracker {
location_t location;
qint64 when;
QString name;
int idx;
};
struct DiveAndLocation {
struct dive *d;
location_t location;
QString name;
};
class GpsLocation : public QObject {
Q_OBJECT
public:
GpsLocation();
~GpsLocation();
static GpsLocation *instance();
std::vector<DiveAndLocation> getLocations();
int getGpsNum() const;
bool hasLocationsSource();
QString currentPosition();
void setLogCallBack(void (*showMsgCB)(const char *msg));
QMap<qint64, gpsTracker> currentGPSInfo() const;
private:
QGeoPositionInfo lastPos;
QGeoPositionInfoSource *getGpsSource();
QGeoPositionInfoSource *m_GpsSource;
void status(QString msg);
QSettings *geoSettings;
QNetworkReply *reply;
QString userAgent;
void (*showMessageCB)(const char *msg);
bool waitingForPosition;
QMap<qint64, gpsTracker> m_trackers;
QList<gpsTracker> m_deletedTrackers;
void loadFromStorage();
void addFixToStorage(gpsTracker &gt);
void replaceFixToStorage(gpsTracker &gt);
void deleteFixFromStorage(gpsTracker &gt);
void deleteFixesFromServer();
enum { UNKNOWN, NOGPS, HAVEGPS } haveSource;
signals:
void haveSourceChanged();
void acquiredPosition();
public slots:
void serviceEnable(bool toggle);
void newPosition(QGeoPositionInfo pos);
void updateTimeout();
void positionSourceError(QGeoPositionInfoSource::Error error);
void setGpsTimeThreshold(int seconds);
#ifdef SUBSURFACE_MOBILE
void clearGpsData();
#endif
void deleteGpsFix(qint64 when);
};
#endif // GPSLOCATION_H