mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
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>
This commit is contained in:
parent
6fb841887d
commit
d421660f91
2 changed files with 63 additions and 7 deletions
|
@ -171,6 +171,10 @@ Item {
|
|||
mapAnimationZoomOut.stop()
|
||||
}
|
||||
|
||||
function centerOnRectangle(topLeft, bottomRight, center) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
function deselectMapLocation() {
|
||||
animateMapZoomOut()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue