| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QClipboard>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:04:23 +03:00
										 |  |  | #include <QVector>
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "qmlmapwidgethelper.h"
 | 
					
						
							|  |  |  | #include "core/divesite.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-03 22:15:19 +02:00
										 |  |  | #include "core/qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-17 18:13:55 +01:00
										 |  |  | #include "core/divefilter.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | #include "qt-models/maplocationmodel.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-09 21:33:01 +02:00
										 |  |  | #include "qt-models/divelocationmodel.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-03 23:16:40 +02:00
										 |  |  | #ifndef SUBSURFACE_MOBILE
 | 
					
						
							| 
									
										
										
										
											2019-08-30 15:25:59 +02:00
										 |  |  | #include "desktop-widgets/mapwidget.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-03 23:16:40 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define SMALL_CIRCLE_RADIUS_PX            26.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_mapLocationModel = new MapLocationModel(this); | 
					
						
							| 
									
										
										
										
											2017-12-28 12:20:34 +01:00
										 |  |  | 	m_smallCircleRadius = SMALL_CIRCLE_RADIUS_PX; | 
					
						
							|  |  |  | 	m_map = nullptr; | 
					
						
							|  |  |  | 	m_editMode = false; | 
					
						
							| 
									
										
										
										
											2019-05-09 21:33:01 +02:00
										 |  |  | 	connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidgetHelper::diveSiteChanged); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-28 22:04:56 +01:00
										 |  |  | QGeoCoordinate MapWidgetHelper::getCoordinates(struct dive_site *ds) | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-01 22:46:07 +02:00
										 |  |  | 	if (!dive_site_has_gps_location(ds)) | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 		return QGeoCoordinate(0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 	return QGeoCoordinate(ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001); | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds) | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-01 22:46:07 +02:00
										 |  |  | 	if (!dive_site_has_gps_location(ds)) { | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | 		// dive site with no GPS
 | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | 		m_mapLocationModel->setSelected(ds); | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | 		QMetaObject::invokeMethod(m_map, "deselectMapLocation"); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		// dive site with GPS
 | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | 		m_mapLocationModel->setSelected(ds); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 		QGeoCoordinate dsCoord (ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001); | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | 		QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 17:38:54 +02:00
										 |  |  | void MapWidgetHelper::setSelected(const QVector<dive_site *> &divesites) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_mapLocationModel->setSelected(divesites); | 
					
						
							| 
									
										
										
										
											2022-09-03 23:00:03 +02:00
										 |  |  | 	m_mapLocationModel->selectionChanged(); | 
					
						
							|  |  |  | 	updateEditMode(); | 
					
						
							| 
									
										
										
										
											2019-08-30 17:38:54 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | void MapWidgetHelper::centerOnSelectedDiveSite() | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-05 12:59:47 +02:00
										 |  |  | 	QVector<struct dive_site *> selDS = m_mapLocationModel->selectedDs(); | 
					
						
							| 
									
										
										
										
											2017-08-07 02:04:23 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-08 21:16:40 +02:00
										 |  |  | 	if (selDS.isEmpty()) { | 
					
						
							|  |  |  | 		// no selected dives with GPS coordinates
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 		QMetaObject::invokeMethod(m_map, "deselectMapLocation"); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:26:28 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// find the most top-left and bottom-right dive sites on the map coordinate system.
 | 
					
						
							|  |  |  | 	qreal minLat = 0.0, minLon = 0.0, maxLat = 0.0, maxLon = 0.0; | 
					
						
							|  |  |  | 	int count = 0; | 
					
						
							|  |  |  | 	for(struct dive_site *dss: selDS) { | 
					
						
							|  |  |  | 		if (!has_location(&dss->location)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		qreal lat = dss->location.lat.udeg * 0.000001; | 
					
						
							|  |  |  | 		qreal lon = dss->location.lon.udeg * 0.000001; | 
					
						
							|  |  |  | 		if (++count == 1) { | 
					
						
							|  |  |  | 			minLat = maxLat = lat; | 
					
						
							|  |  |  | 			minLon = maxLon = lon; | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (lat < minLat) | 
					
						
							|  |  |  | 			minLat = lat; | 
					
						
							|  |  |  | 		else if (lat > maxLat) | 
					
						
							|  |  |  | 			maxLat = lat; | 
					
						
							|  |  |  | 		if (lon < minLon) | 
					
						
							|  |  |  | 			minLon = lon; | 
					
						
							|  |  |  | 		else if (lon > maxLon) | 
					
						
							|  |  |  | 			maxLon = lon; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Pass coordinates to QML, either as a point or as a rectangle.
 | 
					
						
							|  |  |  | 	// If we didn't find any coordinates, do nothing.
 | 
					
						
							|  |  |  | 	if (count == 1) { | 
					
						
							| 
									
										
										
										
											2019-05-02 21:44:05 +02:00
										 |  |  | 		QGeoCoordinate dsCoord (selDS[0]->location.lat.udeg * 0.000001, selDS[0]->location.lon.udeg * 0.000001); | 
					
						
							|  |  |  | 		QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord))); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:26:28 +02:00
										 |  |  | 	} else if (count > 1) { | 
					
						
							| 
									
										
										
										
											2017-08-07 02:04:23 +03:00
										 |  |  | 		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", | 
					
						
							| 
									
										
										
										
											2019-05-08 22:26:28 +02:00
										 |  |  | 					  Q_ARG(QVariant, QVariant::fromValue(coordTopLeft)), | 
					
						
							|  |  |  | 					  Q_ARG(QVariant, QVariant::fromValue(coordBottomRight)), | 
					
						
							|  |  |  | 					  Q_ARG(QVariant, QVariant::fromValue(coordCenter))); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 22:19:23 +02:00
										 |  |  | void MapWidgetHelper::updateEditMode() | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-03 23:16:40 +02:00
										 |  |  | #ifndef SUBSURFACE_MOBILE
 | 
					
						
							|  |  |  | 	// The filter being set to dive site is the signal that we are in dive site edit mode.
 | 
					
						
							|  |  |  | 	// This is the case when either the dive site edit tab or the dive site list tab are active.
 | 
					
						
							| 
									
										
										
										
											2019-08-30 22:19:23 +02:00
										 |  |  | 	bool old = m_editMode; | 
					
						
							| 
									
										
										
										
											2019-11-17 18:13:55 +01:00
										 |  |  | 	m_editMode = DiveFilter::instance()->diveSiteMode(); | 
					
						
							| 
									
										
										
										
											2019-08-30 22:19:23 +02:00
										 |  |  | 	if (old != m_editMode) | 
					
						
							|  |  |  | 		emit editModeChanged(); | 
					
						
							| 
									
										
										
										
											2019-05-03 23:16:40 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-08-30 22:19:23 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MapWidgetHelper::reloadMapLocations() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	updateEditMode(); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:15:01 +02:00
										 |  |  | 	m_mapLocationModel->reload(m_map); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in) | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int idx; | 
					
						
							|  |  |  | 	struct dive *dive; | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	QList<int> selectedDiveIds; | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!ds_in) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	MapLocation *location = m_mapLocationModel->getMapLocation(ds_in); | 
					
						
							|  |  |  | 	if (!location) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2019-09-01 00:18:15 +02:00
										 |  |  | 	QGeoCoordinate locationCoord = location->coordinate; | 
					
						
							| 
									
										
										
										
											2019-08-30 12:38:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	for_each_dive (idx, dive) { | 
					
						
							|  |  |  | 		struct dive_site *ds = get_dive_site_for_dive(dive); | 
					
						
							|  |  |  | 		if (!dive_site_has_gps_location(ds)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | #ifndef SUBSURFACE_MOBILE
 | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 		const qreal latitude = ds->location.lat.udeg * 0.000001; | 
					
						
							|  |  |  | 		const qreal longitude = ds->location.lon.udeg * 0.000001; | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 		QGeoCoordinate dsCoord(latitude, longitude); | 
					
						
							|  |  |  | 		if (locationCoord.distanceTo(dsCoord) < m_smallCircleRadius) | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 			selectedDiveIds.append(idx); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | #else // the mobile version doesn't support multi-dive selection
 | 
					
						
							| 
									
										
										
										
											2019-09-01 00:18:15 +02:00
										 |  |  | 		if (ds == location->divesite) | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 			selectedDiveIds.append(dive->id); // use id here instead of index
 | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	int last; // get latest dive chronologically
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	if (!selectedDiveIds.isEmpty()) { | 
					
						
							|  |  |  | 		 last = selectedDiveIds.last(); | 
					
						
							|  |  |  | 		 selectedDiveIds.clear(); | 
					
						
							|  |  |  | 		 selectedDiveIds.append(last); | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	emit selectedDivesChanged(selectedDiveIds); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 02:58:19 +03:00
										 |  |  | void MapWidgetHelper::selectVisibleLocations() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int idx; | 
					
						
							|  |  |  | 	struct dive *dive; | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	QList<int> selectedDiveIds; | 
					
						
							| 
									
										
										
										
											2017-08-07 02:58:19 +03:00
										 |  |  | 	for_each_dive (idx, dive) { | 
					
						
							|  |  |  | 		struct dive_site *ds = get_dive_site_for_dive(dive); | 
					
						
							|  |  |  | 		if (!dive_site_has_gps_location(ds)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 		const qreal latitude = ds->location.lat.udeg * 0.000001; | 
					
						
							|  |  |  | 		const qreal longitude = ds->location.lon.udeg * 0.000001; | 
					
						
							| 
									
										
										
										
											2017-08-09 00:36:33 +03:00
										 |  |  | 		QGeoCoordinate dsCoord(latitude, longitude); | 
					
						
							|  |  |  | 		QPointF point; | 
					
						
							|  |  |  | 		QMetaObject::invokeMethod(m_map, "fromCoordinate", Q_RETURN_ARG(QPointF, point), | 
					
						
							|  |  |  | 		                          Q_ARG(QGeoCoordinate, dsCoord)); | 
					
						
							| 
									
										
										
										
											2019-05-02 22:22:52 +02:00
										 |  |  | 		if (!qIsNaN(point.x())) | 
					
						
							| 
									
										
										
										
											2020-03-11 11:30:51 +01:00
										 |  |  | #ifndef SUBSURFACE_MOBILE // indices on desktop
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 			selectedDiveIds.append(idx); | 
					
						
							| 
									
										
										
										
											2017-08-07 02:58:19 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | #else // use id on mobile instead of index
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 			selectedDiveIds.append(dive->id); | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	int last; // get latest dive chronologically
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	if (!selectedDiveIds.isEmpty()) { | 
					
						
							|  |  |  | 		 last = selectedDiveIds.last(); | 
					
						
							|  |  |  | 		 selectedDiveIds.clear(); | 
					
						
							|  |  |  | 		 selectedDiveIds.append(last); | 
					
						
							| 
									
										
										
										
											2018-03-08 21:43:23 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-05-02 22:41:24 +02:00
										 |  |  | 	emit selectedDivesChanged(selectedDiveIds); | 
					
						
							| 
									
										
										
										
											2017-08-07 02:58:19 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Based on a 2D Map widget circle with center "coord" and radius SMALL_CIRCLE_RADIUS_PX, | 
					
						
							|  |  |  |  * obtain a "small circle" with radius m_smallCircleRadius in meters: | 
					
						
							|  |  |  |  *     https://en.wikipedia.org/wiki/Circle_of_a_sphere
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The idea behind this circle is to be able to select multiple nearby dives, when clicking on | 
					
						
							|  |  |  |  * the map. This code can be in QML, but it is in C++ instead for performance reasons. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This can be made faster with an exponential regression [a * exp(b * x)], with a pretty | 
					
						
							|  |  |  |  * decent R-squared, but it becomes bound to map provider zoom level mappings and the | 
					
						
							|  |  |  |  * SMALL_CIRCLE_RADIUS_PX value, which makes the code hard to maintain. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void MapWidgetHelper::calculateSmallCircleRadius(QGeoCoordinate coord) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QPointF point; | 
					
						
							|  |  |  | 	QMetaObject::invokeMethod(m_map, "fromCoordinate", Q_RETURN_ARG(QPointF, point), | 
					
						
							| 
									
										
										
										
											2017-09-17 00:25:22 +03:00
										 |  |  | 	                          Q_ARG(QGeoCoordinate, coord)); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	QPointF point2(point.x() + SMALL_CIRCLE_RADIUS_PX, point.y()); | 
					
						
							|  |  |  | 	QGeoCoordinate coord2; | 
					
						
							|  |  |  | 	QMetaObject::invokeMethod(m_map, "toCoordinate", Q_RETURN_ARG(QGeoCoordinate, coord2), | 
					
						
							| 
									
										
										
										
											2017-09-17 00:25:22 +03:00
										 |  |  | 	                          Q_ARG(QPointF, point2)); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	m_smallCircleRadius = coord2.distanceTo(coord); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | static location_t mk_location(QGeoCoordinate coord) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return create_location(coord.latitude(), coord.longitude()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool savep = prefs.coordinates_traditional; | 
					
						
							|  |  |  | 	prefs.coordinates_traditional = formatTraditional; | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 	location_t location = mk_location(coord); | 
					
						
							| 
									
										
										
										
											2019-03-25 09:05:47 +01:00
										 |  |  | 	QApplication::clipboard()->setText(printGPSCoords(&location), QClipboard::Clipboard); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	prefs.coordinates_traditional = savep; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 17:03:54 +02:00
										 |  |  | void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord) | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-26 17:03:54 +02:00
										 |  |  | 	MapLocation *loc = m_mapLocationModel->getMapLocation(ds); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | 	if (loc) | 
					
						
							| 
									
										
										
										
											2019-09-01 00:18:15 +02:00
										 |  |  | 		loc->coordinate = coord; | 
					
						
							| 
									
										
										
										
											2018-10-20 14:12:15 -04:00
										 |  |  | 	location_t location = mk_location(coord); | 
					
						
							| 
									
										
										
										
											2019-03-14 23:28:45 +01:00
										 |  |  | 	emit coordinatesChanged(ds, location); | 
					
						
							| 
									
										
										
										
											2017-07-28 22:01:33 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 21:33:01 +02:00
										 |  |  | void MapWidgetHelper::diveSiteChanged(struct dive_site *ds, int field) | 
					
						
							| 
									
										
										
										
											2017-11-09 18:43:21 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-09 21:33:01 +02:00
										 |  |  | 	centerOnDiveSite(ds); | 
					
						
							| 
									
										
										
										
											2017-11-09 18:43:21 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 15:25:59 +02:00
										 |  |  | bool MapWidgetHelper::editMode() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return m_editMode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-12 03:58:26 +03:00
										 |  |  | QString MapWidgetHelper::pluginObject() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-03-22 16:43:21 +01:00
										 |  |  | 	QString lang = getUiLanguage().replace('_', '-'); | 
					
						
							| 
									
										
										
										
											2019-05-09 21:43:18 +02:00
										 |  |  | 	QString cacheFolder = QString(system_default_directory()).append("/googlemaps").replace("\\", "/"); | 
					
						
							|  |  |  | 	return QStringLiteral("import QtQuick 2.0;" | 
					
						
							|  |  |  | 			      "import QtLocation 5.3;" | 
					
						
							|  |  |  | 			      "Plugin {" | 
					
						
							|  |  |  | 			      "    id: mapPlugin;" | 
					
						
							|  |  |  | 			      "    name: 'googlemaps';" | 
					
						
							|  |  |  | 			      "    PluginParameter { name: 'googlemaps.maps.language'; value: '%1' }" | 
					
						
							|  |  |  | 			      "    PluginParameter { name: 'googlemaps.cachefolder'; value: '%2' }" | 
					
						
							|  |  |  | 			      "    Component.onCompleted: {" | 
					
						
							|  |  |  | 			      "        if (availableServiceProviders.indexOf(name) === -1) {" | 
					
						
							|  |  |  | 			      "            console.warn('MapWidget.qml: cannot find a plugin named: ' + name);" | 
					
						
							|  |  |  | 			      "        }" | 
					
						
							|  |  |  | 			      "    }" | 
					
						
							|  |  |  | 			      "}").arg(lang, cacheFolder); | 
					
						
							| 
									
										
										
										
											2017-08-12 03:58:26 +03:00
										 |  |  | } |