mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
fb6210a99a
To reset the core data structures, the mobile and desktop UIs were calling into the dive-list models, which then reset the core data structures, themselves and the unrelated locationinformation model. The UI code then reset various other things, such as the TankInformation model or the map. . This was unsatisfying from a control-flow perspective, as the models should display the core data, not act on it. Moreover, this meant lots of intricate intermodule-dependencies. Thus, straighten up the control flow: give the C core the possibility to send a "all data reset" event. And do that in those functions that reset the core data structures. Let each module react to this event by itself. This removes inter-module dependencies. For example, the MainWindow now doesn't have to reset the TankInfoModel or the MapWidget. Then, to reset the core data structures, let the UI code simply directly call the respective core functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "qt-models/gpslistmodel.h"
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
|
#include "core/qthelper.h"
|
|
#include <QVector>
|
|
|
|
GpsListModel::GpsListModel()
|
|
{
|
|
connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &GpsListModel::update);
|
|
}
|
|
|
|
void GpsListModel::update()
|
|
{
|
|
QVector<gpsTracker> trackers = QVector<gpsTracker>::fromList(GpsLocation::instance()->currentGPSInfo().values());
|
|
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&) 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 == GpsWhenRole)
|
|
return gt.when;
|
|
else if (role == GpsNameRole)
|
|
return gt.name;
|
|
else if (role == GpsLatitudeRole)
|
|
return QString::number(gt.location.lat.udeg / 1000000.0, 'f', 6);
|
|
else if (role == GpsLongitudeRole)
|
|
return QString::number(gt.location.lon.udeg / 1000000.0, 'f', 6);
|
|
return QVariant();
|
|
}
|
|
|
|
QHash<int, QByteArray> GpsListModel::roleNames() const
|
|
{
|
|
QHash<int, QByteArray> roles;
|
|
roles[GpsDateRole] = "date";
|
|
roles[GpsWhenRole] = "when";
|
|
roles[GpsNameRole] = "name";
|
|
roles[GpsLatitudeRole] = "latitude";
|
|
roles[GpsLongitudeRole] = "longitude";
|
|
return roles;
|
|
}
|
|
|
|
GpsListModel *GpsListModel::instance()
|
|
{
|
|
static GpsListModel self;
|
|
return &self;
|
|
}
|
|
|