mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Dive site: replace UUID by pointer in mobile code
Replace UUIDs by pointers to dive-site in mobile code. In both cases, the value is transported via a QVariant. The function getCoordinatesForUUID(), which was only used from mobile, can be replaced by a getCoordinatesFor() function taking a variant supposed to contain a dive-site pointer. Likewise, the variant of the centerOnDiveSite function is now supposed to wrap a pointer-to-divesite. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									872d56de01
								
							
						
					
					
						commit
						75b5d61522
					
				
					 7 changed files with 19 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -127,9 +127,9 @@ QString DiveObjectHelper::gps_decimal() const
 | 
			
		|||
	return val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariant DiveObjectHelper::dive_site_uuid() const
 | 
			
		||||
QVariant DiveObjectHelper::dive_site() const
 | 
			
		||||
{
 | 
			
		||||
	return QVariant::fromValue(m_dive->dive_site_uuid);
 | 
			
		||||
	return QVariant::fromValue((void *)get_dive_site_by_uuid(m_dive->dive_site_uuid));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString DiveObjectHelper::duration() const
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ class DiveObjectHelper : public QObject {
 | 
			
		|||
	Q_PROPERTY(QString location READ location CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QString gps READ gps CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QString gps_decimal READ gps_decimal CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QVariant dive_site_uuid READ dive_site_uuid CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QVariant dive_site READ dive_site CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QString duration READ duration CONSTANT)
 | 
			
		||||
	Q_PROPERTY(bool noDive READ noDive CONSTANT)
 | 
			
		||||
	Q_PROPERTY(QString depth READ depth CONSTANT)
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +65,7 @@ public:
 | 
			
		|||
	QString location() const;
 | 
			
		||||
	QString gps() const;
 | 
			
		||||
	QString gps_decimal() const;
 | 
			
		||||
	QVariant dive_site_uuid() const;
 | 
			
		||||
	QVariant dive_site() const;
 | 
			
		||||
	QString duration() const;
 | 
			
		||||
	bool noDive() const;
 | 
			
		||||
	QString depth() const;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,19 +22,17 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
 | 
			
		|||
	        this, SLOT(selectedLocationChanged(MapLocation *)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QGeoCoordinate MapWidgetHelper::getCoordinatesForUUID(QVariant dive_site_uuid)
 | 
			
		||||
QGeoCoordinate MapWidgetHelper::getCoordinates(QVariant dive_site)
 | 
			
		||||
{
 | 
			
		||||
	const uint32_t uuid = qvariant_cast<uint32_t>(dive_site_uuid);
 | 
			
		||||
	struct dive_site *ds = get_dive_site_by_uuid(uuid);
 | 
			
		||||
	struct dive_site *ds = (struct dive_site *)dive_site.value<uintptr_t>();
 | 
			
		||||
	if (!ds || !dive_site_has_gps_location(ds))
 | 
			
		||||
		return QGeoCoordinate(0.0, 0.0);
 | 
			
		||||
	return QGeoCoordinate(ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MapWidgetHelper::centerOnDiveSiteUUID(QVariant dive_site_uuid)
 | 
			
		||||
void MapWidgetHelper::centerOnDiveSite(QVariant dive_site)
 | 
			
		||||
{
 | 
			
		||||
	const uint32_t uuid = qvariant_cast<uint32_t>(dive_site_uuid);
 | 
			
		||||
	struct dive_site *ds = get_dive_site_by_uuid(uuid);
 | 
			
		||||
	struct dive_site *ds = (struct dive_site *)dive_site.value<uintptr_t>();
 | 
			
		||||
	if (ds)
 | 
			
		||||
		centerOnDiveSite(ds);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,8 +29,8 @@ public:
 | 
			
		|||
 | 
			
		||||
	void centerOnDiveSite(struct dive_site *);
 | 
			
		||||
	void centerOnSelectedDiveSite();
 | 
			
		||||
	Q_INVOKABLE QGeoCoordinate getCoordinatesForUUID(QVariant dive_site_uuid);
 | 
			
		||||
	Q_INVOKABLE void centerOnDiveSiteUUID(QVariant dive_site_uuid);
 | 
			
		||||
	Q_INVOKABLE QGeoCoordinate getCoordinates(QVariant dive_site);
 | 
			
		||||
	Q_INVOKABLE void centerOnDiveSite(QVariant dive_site);
 | 
			
		||||
	Q_INVOKABLE void reloadMapLocations();
 | 
			
		||||
	Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional);
 | 
			
		||||
	Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,7 +180,7 @@ Kirigami.Page {
 | 
			
		|||
		}
 | 
			
		||||
		onTriggered: {
 | 
			
		||||
			showMap()
 | 
			
		||||
			mapPage.centerOnDiveSiteUUID(currentItem.modelData.dive.dive_site_uuid)
 | 
			
		||||
			mapPage.centerOnDiveSite(currentItem.modelData.dive.dive_site)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,7 +52,7 @@ Item {
 | 
			
		|||
				enabled: dive.gps_decimal !== ""
 | 
			
		||||
				onClicked: {
 | 
			
		||||
					showMap()
 | 
			
		||||
					mapPage.centerOnDiveSiteUUID(dive.dive_site_uuid)
 | 
			
		||||
					mapPage.centerOnDiveSite(dive.dive_site)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +63,7 @@ Item {
 | 
			
		|||
			text: qsTr("Map it")
 | 
			
		||||
			onClicked: {
 | 
			
		||||
				showMap()
 | 
			
		||||
				mapPage.centerOnDiveSiteUUID(dive.dive_site_uuid)
 | 
			
		||||
				mapPage.centerOnDiveSite(dive.dive_site)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		Row {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,19 +40,19 @@ Kirigami.Page {
 | 
			
		|||
		mapWidget.mapHelper.reloadMapLocations()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function centerOnDiveSiteUUID(uuid) {
 | 
			
		||||
		if (!uuid) {
 | 
			
		||||
			console.warn("main.qml: centerOnDiveSiteUUI(): uuid is undefined!")
 | 
			
		||||
	function centerOnDiveSite(ds) {
 | 
			
		||||
		if (!ds) {
 | 
			
		||||
			console.warn("main.qml: centerOnDiveSite(): dive site is undefined!")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		// on firstRun, hard pan/center the map to the desired location so that
 | 
			
		||||
		// we don't start at an arbitrary location such as [0,0] or London.
 | 
			
		||||
		if (firstRun) {
 | 
			
		||||
			var coord = mapWidget.mapHelper.getCoordinatesForUUID(uuid)
 | 
			
		||||
			var coord = mapWidget.mapHelper.getCoordinates(ds)
 | 
			
		||||
			centerOnLocationHard(coord.latitude, coord.longitude)
 | 
			
		||||
			firstRun = false
 | 
			
		||||
		} // continue here as centerOnDiveSiteUUID() also does marker selection.
 | 
			
		||||
		mapWidget.mapHelper.centerOnDiveSiteUUID(uuid)
 | 
			
		||||
		} // continue here as centerOnDiveSite() also does marker selection.
 | 
			
		||||
		mapWidget.mapHelper.centerOnDiveSite(ds)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function centerOnLocation(lat, lon) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue