From 22fb6071f7a56fca7dfb456b16e88b70a7c9ac91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 10 Dec 2020 22:02:09 +0100 Subject: [PATCH] Refactoring --- src/GUI/mapitem.cpp | 8 +++++++- src/GUI/mapitem.h | 4 +++- src/GUI/mapview.cpp | 11 +++-------- src/GUI/mapview.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/GUI/mapitem.cpp b/src/GUI/mapitem.cpp index 343b3d24..c921641d 100644 --- a/src/GUI/mapitem.cpp +++ b/src/GUI/mapitem.cpp @@ -2,6 +2,7 @@ #include #include #include "map/map.h" +#include "mapaction.h" #include "popup.h" #include "tooltip.h" #include "mapitem.h" @@ -19,14 +20,19 @@ QString MapItem::info() const return tt.toString(); } -MapItem::MapItem(Map *src, Map *map, GraphicsItem *parent) +MapItem::MapItem(MapAction *action, Map *map, GraphicsItem *parent) : PlaneItem(parent) { + Map *src = action->data().value(); + Q_ASSERT(map->isReady()); + _name = src->name(); _fileName = src->path(); _bounds = RectC(src->xy2ll(src->bounds().topLeft()), src->xy2ll(src->bounds().bottomRight())); + connect(this, SIGNAL(triggered()), action, SLOT(trigger())); + _map = map; _digitalZoom = 0; diff --git a/src/GUI/mapitem.h b/src/GUI/mapitem.h index 3f3edbbe..d78039f0 100644 --- a/src/GUI/mapitem.h +++ b/src/GUI/mapitem.h @@ -3,12 +3,14 @@ #include "planeitem.h" +class MapAction; + class MapItem : public QObject, public PlaneItem { Q_OBJECT public: - MapItem(Map *src, Map *map, GraphicsItem *parent = 0); + MapItem(MapAction *action, Map *map, GraphicsItem *parent = 0); QPainterPath shape() const {return _painterPath;} QRectF boundingRect() const {return _painterPath.boundingRect();} diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index dc72951a..955191e8 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -222,7 +222,7 @@ void MapView::addWaypoints(const QVector &waypoints) } } -MapItem *MapView::addMap(Map *map) +MapItem *MapView::addMap(MapAction *map) { MapItem *mi = new MapItem(map, _map); mi->setColor(_palette.nextColor()); @@ -276,13 +276,8 @@ void MapView::loadMaps(const QList &maps) { int zoom = _map->zoom(); - for (int i = 0; i < maps.size(); i++) { - MapAction *a = maps.at(i); - Map *map = a->data().value(); - Q_ASSERT(map->isReady()); - MapItem *mi = addMap(map); - connect(mi, SIGNAL(triggered()), a, SLOT(trigger())); - } + for (int i = 0; i < maps.size(); i++) + addMap(maps.at(i)); if (fitMapZoom() != zoom) rescale(); diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index 045c89c0..77204dbd 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -111,7 +111,7 @@ private: PathItem *addTrack(const Track &track); PathItem *addRoute(const Route &route); - MapItem *addMap(Map *map); + MapItem *addMap(MapAction *map); void addArea(const Area &area); void addWaypoints(const QVector &waypoints); void addPOI(const QList &waypoints);