2017-07-16 23:04:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-07-15 23:51:08 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2017-07-17 15:02:37 +00:00
|
|
|
#include "qmlmapwidgethelper.h"
|
2017-07-16 21:06:05 +00:00
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/divesite.h"
|
2017-07-17 15:02:37 +00:00
|
|
|
#include "qt-models/maplocationmodel.h"
|
2017-07-16 21:06:05 +00:00
|
|
|
|
2017-07-15 23:51:08 +00:00
|
|
|
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
|
|
|
{
|
2017-07-17 15:02:37 +00:00
|
|
|
m_mapLocationModel = new MapLocationModel(this);
|
2017-07-15 23:51:08 +00:00
|
|
|
}
|
2017-07-16 21:06:05 +00:00
|
|
|
|
|
|
|
void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
|
|
|
|
{
|
|
|
|
if (!dive_site_has_gps_location(ds))
|
|
|
|
return;
|
|
|
|
|
|
|
|
qreal longitude = ds->longitude.udeg / 1000000.0;
|
|
|
|
qreal latitude = ds->latitude.udeg / 1000000.0;
|
2017-07-16 21:25:19 +00:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(m_map, "centerOnCoordinates",
|
|
|
|
Q_ARG(QVariant, latitude),
|
|
|
|
Q_ARG(QVariant, longitude));
|
2017-07-16 21:06:05 +00:00
|
|
|
}
|
2017-07-17 19:43:10 +00:00
|
|
|
|
|
|
|
void MapWidgetHelper::reloadMapLocations()
|
|
|
|
{
|
|
|
|
struct dive_site *ds;
|
|
|
|
int idx;
|
|
|
|
m_mapLocationModel->clear();
|
2017-07-17 20:04:00 +00:00
|
|
|
QVector<MapLocation *> locationList;
|
2017-07-17 19:43:10 +00:00
|
|
|
|
|
|
|
for_each_dive_site(idx, ds) {
|
|
|
|
if (!dive_site_has_gps_location(ds))
|
|
|
|
continue;
|
|
|
|
const qreal longitude = ds->longitude.udeg / 1000000.0;
|
|
|
|
const qreal latitude = ds->latitude.udeg / 1000000.0;
|
2017-07-17 19:59:14 +00:00
|
|
|
locationList.append(new MapLocation(QGeoCoordinate(latitude, longitude)));
|
2017-07-17 19:43:10 +00:00
|
|
|
}
|
2017-07-17 19:59:14 +00:00
|
|
|
m_mapLocationModel->addList(locationList);
|
2017-07-17 19:43:10 +00:00
|
|
|
}
|