summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--qt-models/gpslistmodel.cpp96
-rw-r--r--qt-models/gpslistmodel.h57
-rw-r--r--subsurface-core/gpslocation.cpp7
-rw-r--r--subsurface-core/gpslocation.h7
5 files changed, 162 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f4d90d2a..18101e087 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -226,6 +226,7 @@ if(${SUBSURFACE_TARGET_EXECUTABLE} MATCHES "MobileExecutable")
qt-mobile/qmlmanager.cpp
qt-mobile/qmlprofile.cpp
qt-models/divelistmodel.cpp
+ qt-models/gpslistmodel.cpp
subsurface-mobile-main.cpp
subsurface-mobile-helper.cpp
)
diff --git a/qt-models/gpslistmodel.cpp b/qt-models/gpslistmodel.cpp
new file mode 100644
index 000000000..6bd1cfdf0
--- /dev/null
+++ b/qt-models/gpslistmodel.cpp
@@ -0,0 +1,96 @@
+#include "gpslistmodel.h"
+#include "helpers.h"
+
+GpsTracker::GpsTracker()
+{
+ m_latitude = 0;
+ m_longitude = 0;
+ m_when = 0;
+ m_name = QString();
+}
+
+GpsTracker::~GpsTracker()
+{
+}
+
+uint64_t GpsTracker::when() const
+{
+ return m_when;
+}
+
+int32_t GpsTracker::latitude() const
+{
+ return m_latitude;
+}
+
+int32_t GpsTracker::longitude() const
+{
+ return m_longitude;
+}
+
+QString GpsTracker::name() const
+{
+ return m_name;
+}
+
+GpsListModel *GpsListModel::m_instance = NULL;
+
+GpsListModel::GpsListModel(QObject *parent) : QAbstractListModel(parent)
+{
+ m_instance = this;
+}
+
+void GpsListModel::addGpsFix(gpsTracker *g)
+{
+ beginInsertColumns(QModelIndex(), rowCount(), rowCount());
+ m_gpsFixes.append(GpsTracker(g));
+ endInsertRows();
+}
+
+void GpsListModel::clear()
+{
+ if (m_gpsFixes.count()) {
+ beginRemoveRows(QModelIndex(), 0, m_gpsFixes.count() - 1);
+ m_gpsFixes.clear();
+ endRemoveRows();
+ }
+}
+
+int GpsListModel::rowCount(const QModelIndex &parent) const
+{
+ return m_gpsFixes.count();
+}
+
+QVariant GpsListModel::data(const QModelIndex &index, int role) const
+{
+ if (index.row() < 0 || index.row() > m_gpsFixes.count())
+ return QVariant();
+
+ const GpsTracker &gt = m_gpsFixes[index.row()];
+
+ if (role == GpsDateRole)
+ return get_short_dive_date_string(gt.when());
+ else if (role == GpsNameRole)
+ return QString(gt.name());
+ else if (role == GpsLatitudeRole)
+ return QString::number(gt.latitude() / 1000000.0, 'f', 6);
+ else if (role == GpsLongitudeRole)
+ return QString::number(gt.longitude() / 1000000.0, 'f', 6);
+ return QVariant();
+}
+
+QHash<int, QByteArray> GpsListModel::roleNames() const
+{
+ QHash<int, QByteArray> roles;
+ roles[GpsDateRole] = "when";
+ roles[GpsNameRole] = "name";
+ roles[GpsLatitudeRole] = "latitude";
+ roles[GpsLongitudeRole] = "longitude";
+ return roles;
+}
+
+GpsListModel *GpsListModel::instance()
+{
+ return m_instance;
+}
+
diff --git a/qt-models/gpslistmodel.h b/qt-models/gpslistmodel.h
new file mode 100644
index 000000000..35a5a03c4
--- /dev/null
+++ b/qt-models/gpslistmodel.h
@@ -0,0 +1,57 @@
+#ifndef GPSLISTMODEL_H
+#define GPSLISTMODEL_H
+
+#include "gpslocation.h"
+#include <QObject>
+#include <QAbstractListModel>
+
+class GpsTracker
+{
+private:
+ quint64 m_when;
+ qint32 m_latitude;
+ qint32 m_longitude;
+ QString m_name;
+
+public:
+ GpsTracker(struct gpsTracker *gt)
+ {
+ m_when = gt->when;
+ m_latitude = gt->latitude.udeg;
+ m_longitude = gt->longitude.udeg;
+ m_name = gt->name;
+ }
+ GpsTracker();
+ ~GpsTracker();
+ uint64_t when() const;
+ int32_t latitude() const;
+ int32_t longitude() const;
+ QString name() const;
+};
+
+class GpsListModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+
+ enum GpsListRoles {
+ GpsDateRole = Qt::UserRole + 1,
+ GpsNameRole,
+ GpsLatitudeRole,
+ GpsLongitudeRole
+ };
+
+ static GpsListModel *instance();
+ GpsListModel(QObject *parent = 0);
+ void addGpsFix(struct gpsTracker *g);
+ void clear();
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QHash<int, QByteArray> roleNames() const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+private:
+ QList<GpsTracker> m_gpsFixes;
+ static GpsListModel *m_instance;
+};
+
+#endif // GPSLISTMODEL_H
diff --git a/subsurface-core/gpslocation.cpp b/subsurface-core/gpslocation.cpp
index 9019f59c7..6106dd358 100644
--- a/subsurface-core/gpslocation.cpp
+++ b/subsurface-core/gpslocation.cpp
@@ -1,4 +1,5 @@
#include "gpslocation.h"
+#include "gpslistmodel.h"
#include "pref.h"
#include "dive.h"
#include "helpers.h"
@@ -195,12 +196,6 @@ int GpsLocation::getGpsNum() const
return geoSettings->value("count", 0).toInt();
}
-struct gpsTracker {
- degrees_t latitude;
- degrees_t longitude;
- time_t when;
-};
-
static void copy_gps_location(struct gpsTracker *gps, struct dive *d)
{
struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
diff --git a/subsurface-core/gpslocation.h b/subsurface-core/gpslocation.h
index 94706f611..d595c877e 100644
--- a/subsurface-core/gpslocation.h
+++ b/subsurface-core/gpslocation.h
@@ -9,6 +9,13 @@
#include <QSettings>
#include <QNetworkReply>
+struct gpsTracker {
+ degrees_t latitude;
+ degrees_t longitude;
+ time_t when;
+ QString name;
+};
+
class GpsLocation : QObject
{
Q_OBJECT