From 99d25403593e5f2d1800bb5ad685bc73488d92f6 Mon Sep 17 00:00:00 2001 From: LM Date: Mon, 11 Jul 2011 12:52:10 +0200 Subject: [PATCH] 2D map now fully operational --- .../src/mapwidget/mapgraphicitem.cpp | 18 ++++----------- .../src/mapwidget/mapgraphicitem.h | 5 +++++ .../src/mapwidget/opmapwidget.cpp | 6 ++--- .../src/mapwidget/waypointlineitem.cpp | 22 +++++++++++++++---- .../src/mapwidget/waypointlineitem.h | 4 ++++ src/ui/HDDisplay.cc | 2 ++ src/ui/HUD.cc | 3 +-- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp index 9575b890b..a54417613 100644 --- a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp @@ -92,13 +92,8 @@ namespace mapcontrol GPSItem* wwww=qgraphicsitem_cast(i); if(wwww) wwww->RefreshPos(); - QGraphicsItemGroup* wwwww=qgraphicsitem_cast(i); - if(wwwww) - foreach(QGraphicsItem* i, wwwww->childItems()) - { - WaypointLineItem* line = qgraphicsitem_cast(i); - if (line) line->RefreshPos(); - } + + emit mapChanged(); } } void MapGraphicItem::ChildPosRefresh() @@ -117,13 +112,8 @@ namespace mapcontrol GPSItem* wwww=qgraphicsitem_cast(i); if(wwww) wwww->RefreshPos(); - QGraphicsItemGroup* wwwww=qgraphicsitem_cast(i); - if(wwwww) - foreach(QGraphicsItem* i, wwwww->childItems()) - { - WaypointLineItem* line = qgraphicsitem_cast(i); - if (line) line->RefreshPos(); - } + + emit mapChanged(); } } void MapGraphicItem::ConstructLastImage(int const& zoomdiff) diff --git a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index da846d31a..96621d059 100644 --- a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -229,6 +229,11 @@ namespace mapcontrol * @param zoom */ void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi); + + /** + * @brief Fired when map changes in any visible way + */ + void mapChanged(); }; } #endif // MAPGRAPHICITEM_H diff --git a/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp b/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp index f8f44e45a..18258cb83 100644 --- a/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp @@ -94,8 +94,7 @@ namespace mapcontrol UAVItem* newUAV = new UAVItem(map,this); newUAV->setParentItem(map); UAVS.insert(id, newUAV); - QGraphicsItemGroup* waypointLine = new QGraphicsItemGroup(); - waypointLine->setParentItem(map); + QGraphicsItemGroup* waypointLine = new QGraphicsItemGroup(map); waypointLines.insert(id, waypointLine); return newUAV; } @@ -103,8 +102,7 @@ namespace mapcontrol void OPMapWidget::AddUAV(int id, UAVItem* uav) { uav->setParentItem(map); - QGraphicsItemGroup* waypointLine = new QGraphicsItemGroup(); - waypointLine->setParentItem(map); + QGraphicsItemGroup* waypointLine = new QGraphicsItemGroup(map); waypointLines.insert(id, waypointLine); UAVS.insert(id, uav); } diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp index 4e7605565..34811a9a5 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp @@ -17,6 +17,9 @@ WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor pen.setWidth(2); setPen(pen); + point1 = wp1->Coord(); + point2 = wp2->Coord(); + // Pixel coordinates of the local points core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); @@ -33,6 +36,7 @@ WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor connect(wp2, SIGNAL(destroyed()), this, SLOT(deleteLater())); // Map Zoom and move + connect(map, SIGNAL(mapChanged()), this, SLOT(updateWPValues())); } void WaypointLineItem::RefreshPos() @@ -45,10 +49,13 @@ void WaypointLineItem::RefreshPos() else { // Set new pixel coordinates based on new global coordinates - core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); - core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); - - setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y()); + //QTimer::singleShot(0, this, SLOT(updateWPValues())); + core::Point localPoint1 = map->FromLatLngToLocal(point1); + core::Point localPoint2 = map->FromLatLngToLocal(point2); + if (!localPoint1.IsEmpty() && !localPoint2.IsEmpty()) + { + setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y()); + } } } @@ -63,6 +70,8 @@ void WaypointLineItem::updateWPValues(WayPointItem* waypoint) else { // Set new pixel coordinates based on new global coordinates + point1 = wp1->Coord(); + point2 = wp2->Coord(); core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); @@ -70,6 +79,11 @@ void WaypointLineItem::updateWPValues(WayPointItem* waypoint) } } +void WaypointLineItem::updateWPValues() +{ + updateWPValues(NULL); +} + int WaypointLineItem::type()const { return Type; diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h index 807356ece..e57a91b6a 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.h @@ -23,6 +23,10 @@ public slots: void updateWPValues(WayPointItem* waypoint); /** * @brief Update waypoint values + */ + void updateWPValues(); + /** + * @brief Update waypoint values * */ void RefreshPos(); diff --git a/src/ui/HDDisplay.cc b/src/ui/HDDisplay.cc index 1fe81518d..8ee4b3c37 100644 --- a/src/ui/HDDisplay.cc +++ b/src/ui/HDDisplay.cc @@ -112,6 +112,8 @@ HDDisplay::HDDisplay(QStringList* plotList, QString title, QWidget *parent) : this->setMinimumHeight(125); this->setMinimumWidth(100); + scalingFactor = this->width()/vwidth; + // Refresh timer refreshTimer->setInterval(180); // connect(refreshTimer, SIGNAL(timeout()), this, SLOT(triggerUpdate())); diff --git a/src/ui/HUD.cc b/src/ui/HUD.cc index 51001fec5..82c68414a 100644 --- a/src/ui/HUD.cc +++ b/src/ui/HUD.cc @@ -147,6 +147,7 @@ HUD::HUD(int width, int height, QWidget* parent) setMinimumSize(80, 60); // Set preferred size setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + scalingFactor = this->width()/vwidth; // Fill with black background QImage fill = QImage(width, height, QImage::Format_Indexed8); @@ -196,8 +197,6 @@ HUD::HUD(int width, int height, QWidget* parent) createActions(); if (UASManager::instance()->getActiveUAS() != NULL) setActiveUAS(UASManager::instance()->getActiveUAS()); - - setVisible(false); } HUD::~HUD() -- 2.22.0