Skip to content

Commit 9dc2765

Browse files
Fabien-BFabien-B
authored andcommitted
Copy coordinates from map.
Implement #28.
1 parent 8145934 commit 9dc2765

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/widgets/map/map2d.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ void Map2D::mouseMoveEvent(QMouseEvent *event) {
263263
if(event->buttons() & mouse_load_tiles_mask) {
264264
updateTiles();
265265
}
266+
267+
QPointF scenePos = mapToScene(event->pos());
268+
auto tp = tilePoint(scenePos, zoomLevel(zoom()), tileSize());
269+
Point2DPseudoMercator ppm(tp);
270+
mouse_coords = CoordinatesTransform::get()->pseudoMercator_to_WGS84(ppm);
266271
}
267272

268273
void Map2D::updateTiles() {

src/widgets/map/map2d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Map2D : public QGraphicsView
4040
double scaleFactor() {return pow(2, _zoom - zoomLevel(_zoom));}
4141
void setMouseLoadTileMask(int mask) {mouse_load_tiles_mask = mask;}
4242

43+
Point2DLatLon getMouseCoords() { return mouse_coords;}
44+
4345
signals:
4446
void backgroundChanged(QColor);
4547

@@ -79,6 +81,8 @@ private slots:
7981
QMap<QString, TileProvider*> tile_providers;
8082

8183
QColor m_color_background;
84+
85+
Point2DLatLon mouse_coords;
8286
};
8387

8488
#endif // MAP2D_H

src/widgets/map/mapwidget.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ MapWidget::MapWidget(QWidget *parent) : Map2D(parent),
109109

110110
// Context menu
111111
mapMenu = new QMenu("Map", pprzApp()->mainWindow());
112+
113+
auto copy_coordinates = mapMenu->addAction("Copy coordinates");
114+
connect(copy_coordinates, &QAction::triggered, this, [=](){
115+
auto mc = getMouseCoords();
116+
auto clipboard = QApplication::clipboard();
117+
auto mc_txt = QString("%1, %2").arg(mc.lat(), 0, 'f', 7).arg(mc.lon(), 0, 'f', 7);
118+
clipboard->setText(mc_txt);
119+
});
120+
112121
show_hidden_wp_action = mapMenu->addAction("Show hidden waypoints");
113122
show_hidden_wp_action->setCheckable(true);
114123
connect(show_hidden_wp_action, &QAction::toggled, [=](bool show) {

0 commit comments

Comments
 (0)