mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Create GpsListModel in order to be able to display GPS fixes
This will allow us to visualize the GPS fixes that are currently stored in the QML UI. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
0f31102020
commit
a7f8a7574e
5 changed files with 162 additions and 6 deletions
96
qt-models/gpslistmodel.cpp
Normal file
96
qt-models/gpslistmodel.cpp
Normal file
|
@ -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 > = 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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue