From c1ae3a00059ce042e8b3ca60a82ae9b45b170d17 Mon Sep 17 00:00:00 2001 From: Fabien-B Date: Wed, 21 Feb 2024 16:47:43 +0100 Subject: [PATCH] [Map] Allows to show/hide MapItems. --- data/tile_sources.xml | 7 +++++++ src/widgets/map/map_items/aircraft_item.cpp | 9 +++++++++ src/widgets/map/map_items/aircraft_item.h | 1 + src/widgets/map/map_items/arrow_item.cpp | 4 ++++ src/widgets/map/map_items/arrow_item.h | 1 + src/widgets/map/map_items/circle_item.cpp | 8 ++++++++ src/widgets/map/map_items/circle_item.h | 2 ++ src/widgets/map/map_items/intruder_item.cpp | 5 +++++ src/widgets/map/map_items/intruder_item.h | 1 + src/widgets/map/map_items/map_item.cpp | 6 ++++-- src/widgets/map/map_items/map_item.h | 3 +++ src/widgets/map/map_items/quiver_item.cpp | 3 ++- src/widgets/map/map_items/quiver_item.h | 4 ++-- src/widgets/map/map_items/waypoint_item.cpp | 5 +++++ src/widgets/map/map_items/waypoint_item.h | 1 + 15 files changed, 55 insertions(+), 5 deletions(-) diff --git a/data/tile_sources.xml b/data/tile_sources.xml index e21e7bf1..3884bb01 100644 --- a/data/tile_sources.xml +++ b/data/tile_sources.xml @@ -1,4 +1,11 @@ + setVisible(visible); + graphics_text->setVisible(visible); + alarms->setVisible(visible); + for(auto &line: graphics_lines) { + line->setVisible(visible); + } +} + void AircraftItem::setForbidHighlight(bool fh) { graphics_aircraft->setForbidHighlight(fh); } diff --git a/src/widgets/map/map_items/aircraft_item.h b/src/widgets/map/map_items/aircraft_item.h index 829ef89e..1424cfe8 100644 --- a/src/widgets/map/map_items/aircraft_item.h +++ b/src/widgets/map/map_items/aircraft_item.h @@ -19,6 +19,7 @@ class AircraftItem : public MapItem virtual void setHighlighted(bool h); virtual void updateZValue(); + virtual void setVisible(bool visible); virtual void setForbidHighlight(bool fh); virtual void setEditable(bool ed){(void)ed;} virtual void removeFromScene(MapWidget* map); diff --git a/src/widgets/map/map_items/arrow_item.cpp b/src/widgets/map/map_items/arrow_item.cpp index 00a79751..aba5d7a3 100644 --- a/src/widgets/map/map_items/arrow_item.cpp +++ b/src/widgets/map/map_items/arrow_item.cpp @@ -43,6 +43,10 @@ void ArrowItem::updateZValue() { scene_item->setZValue(z_value); } +void ArrowItem::setVisible(bool visible) { + scene_item->setVisible(visible); +} + void ArrowItem::setForbidHighlight(bool fh) { (void)fh; } diff --git a/src/widgets/map/map_items/arrow_item.h b/src/widgets/map/map_items/arrow_item.h index 209f9ac0..49f64bec 100644 --- a/src/widgets/map/map_items/arrow_item.h +++ b/src/widgets/map/map_items/arrow_item.h @@ -15,6 +15,7 @@ class ArrowItem : public MapItem virtual void setHighlighted(bool h); virtual void updateZValue(); + virtual void setVisible(bool visible); virtual void setForbidHighlight(bool fh); virtual void setEditable(bool ed){(void)ed;} virtual void removeFromScene(MapWidget* map); diff --git a/src/widgets/map/map_items/circle_item.cpp b/src/widgets/map/map_items/circle_item.cpp index a0e72ec4..7d88d351 100644 --- a/src/widgets/map/map_items/circle_item.cpp +++ b/src/widgets/map/map_items/circle_item.cpp @@ -114,6 +114,14 @@ void CircleItem::updateZValue() { graphics_text->setZValue(z_value + 0.5); } +void CircleItem::setVisible(bool visible) { + circle->setVisible(visible); + graphics_text->setVisible(visible); + if(ownCenter()) { + center->setVisible(visible); + } +} + void CircleItem::updateGraphics(MapWidget* map, uint32_t update_event) { if(update_event & (UpdateEvent::ITEM_CHANGED | UpdateEvent::MAP_ZOOMED)) { double s = getScale(map->zoom(), map->scaleFactor()); diff --git a/src/widgets/map/map_items/circle_item.h b/src/widgets/map/map_items/circle_item.h index 8e6666ec..30e68374 100644 --- a/src/widgets/map/map_items/circle_item.h +++ b/src/widgets/map/map_items/circle_item.h @@ -16,6 +16,7 @@ class CircleItem : public MapItem WaypointItem* getCenter() { return center;} GraphicsCircle* getGraphicsCircle() {return circle;} void setOwnCenter(bool own) { if(own) {center->setParent(this);} } + bool ownCenter() {return center->parent() == this;} void setScalable(bool scalable) { circle->setIgnoreEvent(!scalable); } @@ -25,6 +26,7 @@ class CircleItem : public MapItem void setForbidHighlight(bool fh); virtual void setEditable(bool ed); virtual void updateZValue(); + virtual void setVisible(bool visible); virtual void updateGraphics(MapWidget* map, uint32_t update_event); virtual void removeFromScene(MapWidget* map); void setText(QString text); diff --git a/src/widgets/map/map_items/intruder_item.cpp b/src/widgets/map/map_items/intruder_item.cpp index ac09bced..04ecaf5e 100644 --- a/src/widgets/map/map_items/intruder_item.cpp +++ b/src/widgets/map/map_items/intruder_item.cpp @@ -76,3 +76,8 @@ void IntruderItem::updateZValue() { graphics_intruder->setZValue(z_value); graphics_text->setZValue(z_value); } + +void IntruderItem::setVisible(bool visible) { + graphics_intruder->setVisible(visible); + graphics_text->setVisible(visible); +} diff --git a/src/widgets/map/map_items/intruder_item.h b/src/widgets/map/map_items/intruder_item.h index 30029b24..938fda4b 100644 --- a/src/widgets/map/map_items/intruder_item.h +++ b/src/widgets/map/map_items/intruder_item.h @@ -16,6 +16,7 @@ class IntruderItem : public MapItem virtual void setForbidHighlight(bool fh) override; virtual void setEditable(bool ed) override; virtual void updateZValue() override; + virtual void setVisible(bool visible) override; void setPosition(Point2DLatLon pt); void setCourse(double c); diff --git a/src/widgets/map/map_items/map_item.cpp b/src/widgets/map/map_items/map_item.cpp index 38f01eb7..fb399161 100644 --- a/src/widgets/map/map_items/map_item.cpp +++ b/src/widgets/map/map_items/map_item.cpp @@ -11,7 +11,8 @@ MapItem::MapItem(QString ac_id, double neutral_scale_zoom, QObject *parent) : QObject(parent), ac_id(ac_id), zoom_factor(1), neutral_scale_zoom(neutral_scale_zoom), - z_value(0) + z_value(0), + visible(true) { auto color = AircraftManager::get()->getAircraft(ac_id)->getColor(); this->palette = PprzPalette(color); @@ -21,7 +22,8 @@ MapItem::MapItem(QString ac_id, PprzPalette palette, double neutral_scale_zoom, QObject(parent), ac_id(ac_id), palette(palette), zoom_factor(1), neutral_scale_zoom(neutral_scale_zoom), - z_value(0) + z_value(0), + visible(true) { } diff --git a/src/widgets/map/map_items/map_item.h b/src/widgets/map/map_items/map_item.h index 77ee5381..ab47da3b 100644 --- a/src/widgets/map/map_items/map_item.h +++ b/src/widgets/map/map_items/map_item.h @@ -47,6 +47,8 @@ class MapItem : public QObject double neutralScaleZoom() {return neutral_scale_zoom;} void setZoomFactor(double zf) {zoom_factor = zf;} virtual void updateZValue() = 0; + bool isVisible() {return visible;} + virtual void setVisible(bool visible) = 0; qreal zValue() {return z_value;} QString acId() {return ac_id;} void requestUpdate() {emit itemChanged();} @@ -75,6 +77,7 @@ class MapItem : public QObject double neutral_scale_zoom; qreal z_value; bool highlighted; + bool visible; qreal z_value_highlighted; qreal z_value_unhighlighted; diff --git a/src/widgets/map/map_items/quiver_item.cpp b/src/widgets/map/map_items/quiver_item.cpp index 7f7bae2d..3e2e4c65 100644 --- a/src/widgets/map/map_items/quiver_item.cpp +++ b/src/widgets/map/map_items/quiver_item.cpp @@ -1,3 +1,4 @@ +#include "quiver_item.h" #include "gcs_utils.h" #include "mapwidget.h" @@ -132,4 +133,4 @@ void QuiverItem::updateZValue() { // QPointF(-m_size * cos(angle), -m_size * sin(angle)) // }); // return arrow_poly; -// } \ No newline at end of file +// } diff --git a/src/widgets/map/map_items/quiver_item.h b/src/widgets/map/map_items/quiver_item.h index 9847dba2..9973e870 100644 --- a/src/widgets/map/map_items/quiver_item.h +++ b/src/widgets/map/map_items/quiver_item.h @@ -20,7 +20,7 @@ class QuiverItem : public MapItem virtual void updateZValue() override; virtual void setEditable(bool ed) override; - void setVisible(bool vis); + virtual void setVisible(bool vis); void addQuiver(Point2DLatLon pos, Point2DLatLon vpos); void removeQuivers(); @@ -33,4 +33,4 @@ class QuiverItem : public MapItem QList distance_l; }; -#endif // QUIVERITEM_H \ No newline at end of file +#endif // QUIVERITEM_H diff --git a/src/widgets/map/map_items/waypoint_item.cpp b/src/widgets/map/map_items/waypoint_item.cpp index e1c0a220..c62c12a4 100644 --- a/src/widgets/map/map_items/waypoint_item.cpp +++ b/src/widgets/map/map_items/waypoint_item.cpp @@ -119,6 +119,11 @@ void WaypointItem::updateZValue() { graphics_text->setZValue(z_value); } +void WaypointItem::setVisible(bool visible) { + point->setVisible(visible); + graphics_text->setVisible(visible); +} + void WaypointItem::updateGraphics(MapWidget* map, uint32_t update_event) { if(update_event & (UpdateEvent::ITEM_CHANGED | UpdateEvent::MAP_ZOOMED | UpdateEvent::MAP_ROTATED)) { QPointF scene_pos = scenePoint(Point2DLatLon(_waypoint), zoomLevel(map->zoom()), map->tileSize()); diff --git a/src/widgets/map/map_items/waypoint_item.h b/src/widgets/map/map_items/waypoint_item.h index 964c45ad..5f38a8d0 100644 --- a/src/widgets/map/map_items/waypoint_item.h +++ b/src/widgets/map/map_items/waypoint_item.h @@ -25,6 +25,7 @@ class WaypointItem : public MapItem virtual void addToMap(MapWidget* map); virtual void setHighlighted(bool h); virtual void updateZValue(); + virtual void setVisible(bool visible); virtual void setForbidHighlight(bool fh); virtual void setEditable(bool ed); virtual void removeFromScene(MapWidget* map);