mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
89eed5d36e
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>
72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
#include "gpslistmodel.h"
|
|
#include "helpers.h"
|
|
|
|
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(g);
|
|
endInsertRows();
|
|
}
|
|
|
|
void GpsListModel::update()
|
|
{
|
|
QVector<gpsTracker> trackers = GpsLocation::instance()->currentGPSInfo();
|
|
beginResetModel();
|
|
m_gpsFixes = trackers;
|
|
endResetModel();
|
|
}
|
|
|
|
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 > = m_gpsFixes[index.row()];
|
|
|
|
if (role == GpsDateRole)
|
|
return get_short_dive_date_string(gt.when);
|
|
else if (role == GpsNameRole)
|
|
return gt.name;
|
|
else if (role == GpsLatitudeRole)
|
|
return QString::number(gt.latitude.udeg / 1000000.0, 'f', 6);
|
|
else if (role == GpsLongitudeRole)
|
|
return QString::number(gt.longitude.udeg / 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;
|
|
}
|
|
|