From 3624d30354e50521559d5290de61d04375d35473 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 21 Jul 2017 17:31:58 +0300 Subject: mapwidgethelper: add the method copyToClipboardCoordinates() This method uses the helper printGPSCoords() to format the coordinates of a location into either decimal or sexagesimal. The selection is handled by the boolean flag "formatTraditional" and the user preferences flag - prefs.coordinates_traditional. Signed-off-by: Lubomir I. Ivanov --- mobile-widgets/qmlmapwidgethelper.cpp | 17 +++++++++++++++++ mobile-widgets/qmlmapwidgethelper.h | 4 ++++ 2 files changed, 21 insertions(+) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmapwidgethelper.cpp b/mobile-widgets/qmlmapwidgethelper.cpp index 70d165983..1bc884ecf 100644 --- a/mobile-widgets/qmlmapwidgethelper.cpp +++ b/mobile-widgets/qmlmapwidgethelper.cpp @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include #include #include "qmlmapwidgethelper.h" @@ -44,3 +47,17 @@ void MapWidgetHelper::selectedLocationChanged(MapLocation *location) { qDebug() << location; } + +void MapWidgetHelper::copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional) +{ + bool savep = prefs.coordinates_traditional; + prefs.coordinates_traditional = formatTraditional; + + const int lat = llrint(1000000.0 * coord.latitude()); + const int lon = llrint(1000000.0 * coord.longitude()); + const char *coordinates = printGPSCoords(lat, lon); + QApplication::clipboard()->setText(QString(coordinates), QClipboard::Clipboard); + + free((void *)coordinates); + prefs.coordinates_traditional = savep; +} diff --git a/mobile-widgets/qmlmapwidgethelper.h b/mobile-widgets/qmlmapwidgethelper.h index 83f9df140..3a7f28eb0 100644 --- a/mobile-widgets/qmlmapwidgethelper.h +++ b/mobile-widgets/qmlmapwidgethelper.h @@ -4,6 +4,7 @@ #include +class QGeoCoordinate; class MapLocationModel; class MapLocation; struct dive_site; @@ -19,6 +20,7 @@ public: void centerOnDiveSite(struct dive_site *); void reloadMapLocations(); + Q_INVOKABLE void copyToClipboardCoordinates(QGeoCoordinate coord, bool formatTraditional); private: QObject *m_map; @@ -31,4 +33,6 @@ signals: void modelChanged(); }; +extern "C" const char *printGPSCoords(int lat, int lon); + #endif -- cgit v1.2.3-70-g09d2