mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 22:35:27 +00:00
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 <neolit123@gmail.com>
This commit is contained in:
parent
621dd53a43
commit
3624d30354
2 changed files with 21 additions and 0 deletions
|
@ -1,4 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QGeoCoordinate>
|
||||
#include <QDebug>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue