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)
|
|
|
|
{
|
2017-07-19 22:03:04 +00:00
|
|
|
if (!dive_site_has_gps_location(ds)) {
|
|
|
|
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
2017-07-16 21:06:05 +00:00
|
|
|
return;
|
2017-07-19 22:03:04 +00:00
|
|
|
}
|
2017-07-19 00:06:40 +00:00
|
|
|
MapLocation *location = m_mapLocationModel->getMapLocationForUuid(ds->uuid);
|
|
|
|
QMetaObject::invokeMethod(m_map, "centerOnMapLocation", Q_ARG(QVariant, QVariant::fromValue(location)));
|
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;
|
|
|
|
}
|