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:
Lubomir I. Ivanov 2017-07-21 17:31:58 +03:00 committed by Dirk Hohndel
parent 621dd53a43
commit 3624d30354
2 changed files with 21 additions and 0 deletions

View file

@ -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;
}

View file

@ -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