mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Untangle Library Linkage
with the adittion of gpslistmodel/location, the libraries qt-models had a direct dependency on subsurface-core, and subsurface-core had a direct dependency on qt-models, this is bad. Moving a bit of code around I'v managed to clean this out, and also to clear a bit of uneeded code (GpsTracker and gpsTracker where basically the same thing.) Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
7b155774c5
commit
89eed5d36e
7 changed files with 36 additions and 86 deletions
|
@ -225,8 +225,6 @@ if(${SUBSURFACE_TARGET_EXECUTABLE} MATCHES "MobileExecutable")
|
||||||
set(MOBILE_SRC
|
set(MOBILE_SRC
|
||||||
qt-mobile/qmlmanager.cpp
|
qt-mobile/qmlmanager.cpp
|
||||||
qt-mobile/qmlprofile.cpp
|
qt-mobile/qmlprofile.cpp
|
||||||
qt-models/divelistmodel.cpp
|
|
||||||
qt-models/gpslistmodel.cpp
|
|
||||||
subsurface-mobile-main.cpp
|
subsurface-mobile-main.cpp
|
||||||
subsurface-mobile-helper.cpp
|
subsurface-mobile-helper.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
#include "qt-models/divelistmodel.h"
|
#include "qt-models/divelistmodel.h"
|
||||||
|
#include <gpslistmodel.h>
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
#include "pref.h"
|
#include "pref.h"
|
||||||
#include "qthelper.h"
|
#include "qthelper.h"
|
||||||
|
@ -511,18 +512,20 @@ void QMLManager::sendGpsData()
|
||||||
void QMLManager::downloadGpsData()
|
void QMLManager::downloadGpsData()
|
||||||
{
|
{
|
||||||
locationProvider->downloadFromServer();
|
locationProvider->downloadFromServer();
|
||||||
locationProvider->updateModel();
|
populateGpsData();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::populateGpsData()
|
void QMLManager::populateGpsData()
|
||||||
{
|
{
|
||||||
locationProvider->updateModel();
|
if (GpsListModel::instance())
|
||||||
|
GpsListModel::instance()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLManager::clearGpsData()
|
void QMLManager::clearGpsData()
|
||||||
{
|
{
|
||||||
locationProvider->clearGpsData();
|
locationProvider->clearGpsData();
|
||||||
locationProvider->updateModel();
|
populateGpsData();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLManager::logText() const
|
QString QMLManager::logText() const
|
||||||
|
|
|
@ -20,6 +20,8 @@ set(SUBSURFACE_MODELS_LIB_SRCS
|
||||||
divelocationmodel.cpp
|
divelocationmodel.cpp
|
||||||
divesitepicturesmodel.cpp
|
divesitepicturesmodel.cpp
|
||||||
ssrfsortfilterproxymodel.cpp
|
ssrfsortfilterproxymodel.cpp
|
||||||
|
divelistmodel.cpp
|
||||||
|
gpslistmodel.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS})
|
source_group("Subsurface Models" FILES ${SUBSURFACE_MODELS})
|
||||||
|
|
|
@ -1,38 +1,6 @@
|
||||||
#include "gpslistmodel.h"
|
#include "gpslistmodel.h"
|
||||||
#include "helpers.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::m_instance = NULL;
|
||||||
|
|
||||||
GpsListModel::GpsListModel(QObject *parent) : QAbstractListModel(parent)
|
GpsListModel::GpsListModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
|
@ -40,13 +8,21 @@ GpsListModel::GpsListModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpsListModel::addGpsFix(gpsTracker *g)
|
void GpsListModel::addGpsFix(gpsTracker g)
|
||||||
{
|
{
|
||||||
beginInsertColumns(QModelIndex(), rowCount(), rowCount());
|
beginInsertColumns(QModelIndex(), rowCount(), rowCount());
|
||||||
m_gpsFixes.append(GpsTracker(g));
|
m_gpsFixes.append(g);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GpsListModel::update()
|
||||||
|
{
|
||||||
|
QVector<gpsTracker> trackers = GpsLocation::instance()->currentGPSInfo();
|
||||||
|
beginResetModel();
|
||||||
|
m_gpsFixes = trackers;
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
void GpsListModel::clear()
|
void GpsListModel::clear()
|
||||||
{
|
{
|
||||||
if (m_gpsFixes.count()) {
|
if (m_gpsFixes.count()) {
|
||||||
|
@ -66,16 +42,16 @@ QVariant GpsListModel::data(const QModelIndex &index, int role) const
|
||||||
if (index.row() < 0 || index.row() > m_gpsFixes.count())
|
if (index.row() < 0 || index.row() > m_gpsFixes.count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const GpsTracker > = m_gpsFixes[index.row()];
|
const gpsTracker > = m_gpsFixes[index.row()];
|
||||||
|
|
||||||
if (role == GpsDateRole)
|
if (role == GpsDateRole)
|
||||||
return get_short_dive_date_string(gt.when());
|
return get_short_dive_date_string(gt.when);
|
||||||
else if (role == GpsNameRole)
|
else if (role == GpsNameRole)
|
||||||
return QString(gt.name());
|
return gt.name;
|
||||||
else if (role == GpsLatitudeRole)
|
else if (role == GpsLatitudeRole)
|
||||||
return QString::number(gt.latitude() / 1000000.0, 'f', 6);
|
return QString::number(gt.latitude.udeg / 1000000.0, 'f', 6);
|
||||||
else if (role == GpsLongitudeRole)
|
else if (role == GpsLongitudeRole)
|
||||||
return QString::number(gt.longitude() / 1000000.0, 'f', 6);
|
return QString::number(gt.longitude.udeg / 1000000.0, 'f', 6);
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,30 +5,6 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QAbstractListModel>
|
#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
|
class GpsListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -43,14 +19,14 @@ public:
|
||||||
|
|
||||||
static GpsListModel *instance();
|
static GpsListModel *instance();
|
||||||
GpsListModel(QObject *parent = 0);
|
GpsListModel(QObject *parent = 0);
|
||||||
void addGpsFix(struct gpsTracker *g);
|
void addGpsFix(gpsTracker g);
|
||||||
void clear();
|
void clear();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
|
void update();
|
||||||
private:
|
private:
|
||||||
QList<GpsTracker> m_gpsFixes;
|
QVector<gpsTracker> m_gpsFixes;
|
||||||
static GpsListModel *m_instance;
|
static GpsListModel *m_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -327,33 +327,29 @@ void GpsLocation::applyLocations()
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SUBSURFACE_MOBILE
|
QVector< gpsTracker > GpsLocation::currentGPSInfo() const
|
||||||
void GpsLocation::updateModel()
|
|
||||||
{
|
{
|
||||||
GpsListModel *gpsListModel = GpsListModel::instance();
|
QVector<gpsTracker> trackers;
|
||||||
if (!gpsListModel) {
|
|
||||||
qDebug() << "no gpsListModel";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int cnt = geoSettings->value("count", 0).toInt();
|
int cnt = geoSettings->value("count", 0).toInt();
|
||||||
if (cnt == 0) {
|
if (cnt == 0) {
|
||||||
qDebug() << "no gps fixes";
|
qDebug() << "no gps fixes";
|
||||||
gpsListModel->clear();
|
return trackers;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a table with the GPS information
|
// create a table with the GPS information
|
||||||
|
trackers.reserve(cnt);
|
||||||
|
|
||||||
struct gpsTracker gt;
|
struct gpsTracker gt;
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; i++) {
|
||||||
gt.latitude.udeg = geoSettings->value(QString("gpsFix%1_lat").arg(i)).toInt();
|
gt.latitude.udeg = geoSettings->value(QString("gpsFix%1_lat").arg(i)).toInt();
|
||||||
gt.longitude.udeg = geoSettings->value(QString("gpsFix%1_lon").arg(i)).toInt();
|
gt.longitude.udeg = geoSettings->value(QString("gpsFix%1_lon").arg(i)).toInt();
|
||||||
gt.when = geoSettings->value(QString("gpsFix%1_time").arg(i)).toULongLong();
|
gt.when = geoSettings->value(QString("gpsFix%1_time").arg(i)).toULongLong();
|
||||||
gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString();
|
gt.name = geoSettings->value(QString("gpsFix%1_name").arg(i)).toString();
|
||||||
gpsListModel->addGpsFix(>);
|
trackers.append(gt);
|
||||||
}
|
}
|
||||||
qDebug() << "added" << cnt << "gps fixes to model";
|
return trackers;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void GpsLocation::clearGpsData()
|
void GpsLocation::clearGpsData()
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
bool hasLocationsSource();
|
bool hasLocationsSource();
|
||||||
QString currentPosition();
|
QString currentPosition();
|
||||||
|
|
||||||
|
QVector<gpsTracker> currentGPSInfo() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGeoPositionInfo lastPos;
|
QGeoPositionInfo lastPos;
|
||||||
QGeoPositionInfoSource *getGpsSource();
|
QGeoPositionInfoSource *getGpsSource();
|
||||||
|
@ -49,9 +51,6 @@ public slots:
|
||||||
void downloadFromServer();
|
void downloadFromServer();
|
||||||
void postError(QNetworkReply::NetworkError error);
|
void postError(QNetworkReply::NetworkError error);
|
||||||
void getUseridError(QNetworkReply::NetworkError error);
|
void getUseridError(QNetworkReply::NetworkError error);
|
||||||
#ifdef SUBSURFACE_MOBILE
|
|
||||||
void updateModel();
|
|
||||||
#endif
|
|
||||||
void clearGpsData();
|
void clearGpsData();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue