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-18 23:50:07 +00:00
|
|
|
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
|
|
|
this, SLOT(selectedLocationChanged(MapLocation *)));
|
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-17 20:13:31 +00:00
|
|
|
QVariant coord = QVariant::fromValue(QGeoCoordinate(latitude, longitude));
|
|
|
|
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, coord));
|
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-18 23:02:43 +00:00
|
|
|
locationList.append(new MapLocation(ds->uuid, 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
|
|
|
}
|
2017-07-18 23:50:07 +00:00
|
|
|
|
|
|
|
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
|
|
|
{
|
|
|
|
qDebug() << location;
|
|
|
|
}
|