summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-08-07 02:04:23 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-08-07 00:51:21 -0700
commitd421660f91d56ac434860a1deff17eeeacbc7e26 (patch)
tree7df8fac4ec0ff3c780ff95be45a768df429d1816 /mobile-widgets
parent6fb841887dbba208d47498a1746da46d659d959b (diff)
downloadsubsurface-d421660f91d56ac434860a1deff17eeeacbc7e26.tar.gz
mapwidgethelper: support tracking of all selected dive sites
MapWidgetHelper::centerOnDiveSite() now checks if more than one dive sites are selected and finds the most top-left and bottom-right ones in the coordinate system to form a rectangle. It also supports the special cases where a selected dive site does not have coordinates or the case where only a single dive site with GPS coordinates are selected. TODO: implement mapwidget.qml::centerOnRectangle() This QML function will receive a QGeoCoordinate based rectangle which has to be centered in the viewport with animation. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'mobile-widgets')
-rw-r--r--mobile-widgets/qml/MapWidget.qml4
-rw-r--r--mobile-widgets/qmlmapwidgethelper.cpp66
2 files changed, 63 insertions, 7 deletions
diff --git a/mobile-widgets/qml/MapWidget.qml b/mobile-widgets/qml/MapWidget.qml
index f3853de74..42bc546ce 100644
--- a/mobile-widgets/qml/MapWidget.qml
+++ b/mobile-widgets/qml/MapWidget.qml
@@ -171,6 +171,10 @@ Item {
mapAnimationZoomOut.stop()
}
+ function centerOnRectangle(topLeft, bottomRight, center) {
+ // TODO
+ }
+
function deselectMapLocation() {
animateMapZoomOut()
}
diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp
index c439fb131..954a83ebf 100644
--- a/mobile-widgets/qmlmapwidgethelper.cpp
+++ b/mobile-widgets/qmlmapwidgethelper.cpp
@@ -3,6 +3,7 @@
#include <QClipboard>
#include <QGeoCoordinate>
#include <QDebug>
+#include <QVector>
#include "qmlmapwidgethelper.h"
#include "core/dive.h"
@@ -21,16 +22,67 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
{
- if (!dive_site_has_gps_location(ds)) {
+ int idx;
+ struct dive *dive;
+ QVector<struct dive_site *> selDS;
+ QVector<QGeoCoordinate> selGC;
+ QGeoCoordinate dsCoord;
+
+ for_each_dive (idx, dive) {
+ struct dive_site *dss = get_dive_site_for_dive(dive);
+ if (!dive_site_has_gps_location(dss) || !dive->selected)
+ continue;
+ // only store dive sites with GPS
+ selDS.append(dss);
+ selGC.append(QGeoCoordinate(dss->latitude.udeg * 0.000001,
+ dss->longitude.udeg * 0.000001));
+ }
+ if (!dive_site_has_gps_location(ds) && !selDS.size()) {
+ // only a single dive site with no GPS selected
m_mapLocationModel->setSelectedUuid(ds ? ds->uuid : 0, false);
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
- return;
+
+ } else if (selDS.size() == 1) {
+ // a single dive site with GPS selected
+ ds = selDS.at(0);
+ m_mapLocationModel->setSelectedUuid(ds->uuid, false);
+ dsCoord.setLatitude(ds->latitude.udeg * 0.000001);
+ dsCoord.setLongitude(ds->longitude.udeg * 0.000001);
+ QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
+ } else if (selDS.size() > 1) {
+ /* more than one dive sites with GPS selected.
+ * find the most top-left and bottom-right dive sites on the map coordinate system. */
+ ds = selDS.at(0);
+ m_mapLocationModel->setSelectedUuid(ds->uuid, false);
+ qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0;
+ bool start = true;
+ foreach(QGeoCoordinate gc, selGC) {
+ qreal lat = gc.latitude();
+ qreal lon = gc.longitude();
+ if (start) {
+ minLat = maxLat = lat;
+ minLon = maxLon = lon;
+ start = false;
+ continue;
+ }
+ if (lat < minLat)
+ minLat = lat;
+ else if (lat > maxLat)
+ maxLat = lat;
+ if (lon < minLon)
+ minLon = lon;
+ else if (lon > maxLon)
+ maxLon = lon;
+ }
+ // pass rectangle coordinates to QML
+ QGeoCoordinate coordTopLeft(minLat, minLon);
+ QGeoCoordinate coordBottomRight(maxLat, maxLon);
+ QGeoCoordinate coordCenter(minLat + (maxLat - minLat) * 0.5, minLon + (maxLon - minLon) * 0.5);
+ QMetaObject::invokeMethod(m_map, "centerOnRectangle",
+ Q_ARG(QVariant, QVariant::fromValue(coordTopLeft)),
+ Q_ARG(QVariant, QVariant::fromValue(coordBottomRight)),
+ Q_ARG(QVariant, QVariant::fromValue(coordCenter)));
}
- m_mapLocationModel->setSelectedUuid(ds->uuid, false);
- const qreal latitude = ds->latitude.udeg * 0.000001;
- const qreal longitude = ds->longitude.udeg * 0.000001;
- QGeoCoordinate dsCoord(latitude, longitude);
- QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
}
void MapWidgetHelper::reloadMapLocations()