From f56b4b8a9bcc9bb823786c43bc213ab727923b2a Mon Sep 17 00:00:00 2001 From: PT_Dreamer Date: Sat, 18 Aug 2012 18:07:39 +0100 Subject: [PATCH] GCS/MapLib - Switched to a signal slot aproach on several functions which need to be propagated. --- .../opmapcontrol/src/mapwidget/gpsitem.cpp | 7 +++ .../libs/opmapcontrol/src/mapwidget/gpsitem.h | 4 +- .../opmapcontrol/src/mapwidget/homeitem.cpp | 7 +++ .../opmapcontrol/src/mapwidget/homeitem.h | 4 +- .../src/mapwidget/mapgraphicitem.cpp | 61 ++----------------- .../src/mapwidget/mapgraphicitem.h | 4 +- .../opmapcontrol/src/mapwidget/uavitem.cpp | 9 +++ .../libs/opmapcontrol/src/mapwidget/uavitem.h | 4 +- .../src/mapwidget/waypointcircle.cpp | 7 +++ .../src/mapwidget/waypointcircle.h | 1 + .../src/mapwidget/waypointitem.cpp | 13 ++++ .../opmapcontrol/src/mapwidget/waypointitem.h | 3 +- .../src/mapwidget/waypointline.cpp | 7 +++ .../opmapcontrol/src/mapwidget/waypointline.h | 1 + 14 files changed, 69 insertions(+), 63 deletions(-) diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp index 48afa7fbd..862498444 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp @@ -45,6 +45,8 @@ namespace mapcontrol mapfollowtype=UAVMapFollowType::None; trailtype=UAVTrailType::ByDistance; timer.start(); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } GPSItem::~GPSItem() { @@ -139,6 +141,11 @@ namespace mapcontrol } } + + void GPSItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); + } void GPSItem::SetTrailType(const UAVTrailType::Types &value) { trailtype=value; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h index 64931ea7f..5ab04b431 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h @@ -103,7 +103,6 @@ namespace mapcontrol void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); QRectF boundingRect() const; /** * @brief Sets the trail time to be used if TrailType is ByTimeElapsed @@ -218,7 +217,8 @@ namespace mapcontrol // QRectF rect; public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); void UAVLeftSafetyBouble(internals::PointLatLng const& position); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp index 93a4aa113..58572f231 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp @@ -40,6 +40,8 @@ namespace mapcontrol coord=internals::PointLatLng(50,50); RefreshToolTip(); setCacheMode(QGraphicsItem::DeviceCoordinateCache); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } void HomeItem::RefreshToolTip() @@ -92,6 +94,11 @@ namespace mapcontrol } + void HomeItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); + } + void HomeItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->button()==Qt::LeftButton) diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h index c3bdd4f3f..50cb48b53 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h @@ -47,7 +47,6 @@ namespace mapcontrol QWidget *widget); QRectF boundingRect() const; int type() const; - void RefreshPos(); bool ShowSafeArea()const{return showsafearea;} void SetShowSafeArea(bool const& value){showsafearea=value;} int SafeArea()const{return safearea;} @@ -76,7 +75,8 @@ namespace mapcontrol void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: void homePositionChanged(internals::PointLatLng coord,float); void homedoubleclick(HomeItem* waypoint); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp index a0289bfdf..9c627e8c2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp @@ -42,8 +42,8 @@ namespace mapcontrol this->SetZoom(2); this->setFlag(ItemIsFocusable); connect(core,SIGNAL(OnNeedInvalidation()),this,SLOT(Core_OnNeedInvalidation())); - connect(core,SIGNAL(OnMapDrag()),this,SLOT(ChildPosRefresh())); - connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(ChildPosRefresh())); + connect(core,SIGNAL(OnMapDrag()),this,SLOT(childPosRefresh())); + connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(childPosRefresh())); setCacheMode(QGraphicsItem::ItemCoordinateCache); //resize(); @@ -82,64 +82,15 @@ namespace mapcontrol void MapGraphicItem::Core_OnNeedInvalidation() { this->update(); - foreach(QGraphicsItem* i,this->childItems()) - { - WayPointItem* w=qgraphicsitem_cast(i); - if(w) - w->RefreshPos(); - UAVItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->RefreshPos(); - HomeItem* www=qgraphicsitem_cast(i); - if(www) - www->RefreshPos(); - GPSItem* wwww=qgraphicsitem_cast(i); - if(wwww) - wwww->RefreshPos(); - } + emit childRefreshPosition(); } - void MapGraphicItem::ChildPosRefresh() + void MapGraphicItem::childPosRefresh() { - foreach(QGraphicsItem* i,this->childItems()) - { - WayPointItem* w=qgraphicsitem_cast(i); - if(w) - w->RefreshPos(); - UAVItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->RefreshPos(); - HomeItem* www=qgraphicsitem_cast(i); - if(www) - www->RefreshPos(); - GPSItem* wwww=qgraphicsitem_cast(i); - if(wwww) - wwww->RefreshPos(); - } + emit childRefreshPosition(); } void MapGraphicItem::setOverlayOpacity(qreal value) { - foreach(QGraphicsItem* i,this->childItems()) - { - WayPointItem* w=qgraphicsitem_cast(i); - if(w) - w->setOpacity(value); - UAVItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->setOpacity(value); - HomeItem* www=qgraphicsitem_cast(i); - if(www) - www->setOpacity(value); - GPSItem* wwww=qgraphicsitem_cast(i); - if(wwww) - wwww->setOpacity(value); - WayPointLine* wwwww=qgraphicsitem_cast(i); - if(wwwww) - wwwww->setOpacity(value); - WayPointCircle* wwwwww=qgraphicsitem_cast(i); - if(wwwwww) - wwwwww->setOpacity(value); - - } + emit childSetOpacity(value); } void MapGraphicItem::ConstructLastImage(int const& zoomdiff) { diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index 1d3ce17f3..06786e222 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -200,7 +200,7 @@ namespace mapcontrol void SetMapType(MapType::Types const& value){core->SetMapType(value);} private slots: void Core_OnNeedInvalidation(); - void ChildPosRefresh(); + void childPosRefresh(); public slots: /** * @brief To be called when the scene size changes @@ -216,6 +216,8 @@ namespace mapcontrol */ void wpdoubleclicked(WayPointItem * wp); void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi); + void childRefreshPosition(); + void childSetOpacity(qreal value); }; } #endif // MAPGRAPHICITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp index b1ee0d1e2..5b07f3c6e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp @@ -50,6 +50,9 @@ namespace mapcontrol mapfollowtype=UAVMapFollowType::None; trailtype=UAVTrailType::ByDistance; timer.start(); + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } UAVItem::~UAVItem() { @@ -233,6 +236,7 @@ namespace mapcontrol //Last thing to do: set bound rectangle as function of largest object + prepareGeometryChange(); boundingRectSize=groundspeed_mps_filt*ringTime*4*meters2pixels+20; //Largest object is currently the biggest ring + a little bit of margin for the text } @@ -401,6 +405,11 @@ namespace mapcontrol } } + + void UAVItem::setOpacitySlot(qreal opacity) + { + this->setOpacity(opacity); + } void UAVItem::SetTrailType(const UAVTrailType::Types &value) { trailtype=value; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h index 155f61581..ef3ade80e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h @@ -128,7 +128,6 @@ namespace mapcontrol void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); QRectF boundingRect() const; /** * @brief Sets the trail time to be used if TrailType is ByTimeElapsed @@ -253,7 +252,8 @@ namespace mapcontrol bool showJustChanged; public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); void UAVLeftSafetyBouble(internals::PointLatLng const& position); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp index c6dfac384..5fc785369 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp @@ -38,6 +38,7 @@ WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius,bool c connect(center,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); connect(radius,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); refreshLocations(); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } @@ -48,6 +49,7 @@ WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool cloc connect(center,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations())); connect(center,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); refreshLocations(); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } int WayPointCircle::type() const @@ -106,4 +108,9 @@ void WayPointCircle::waypointdeleted() this->deleteLater(); } +void WayPointCircle::setOpacitySlot(qreal opacity) +{ + setOpacity(opacity); +} + } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h index 1c89fb798..4be7b0898 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h @@ -62,6 +62,7 @@ protected: public slots: void refreshLocations(); void waypointdeleted(); + void setOpacitySlot(qreal opacity); }; } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp index 8c7491fe5..1582d03ab 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp @@ -60,6 +60,8 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu } connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(false),description(""),shownumber(true),isDragging(false),altitude(0),map(map) @@ -105,6 +107,8 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals } connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map,wptype type):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map),myType(type) { @@ -136,6 +140,8 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals } connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } WayPointItem::WayPointItem(const distBearingAltitude &relativeCoordenate, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoordenate),reached(false),description(description),shownumber(true),isDragging(false),map(map) @@ -169,6 +175,8 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals RefreshPos(); connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } void WayPointItem::setWPType(wptype type) @@ -455,6 +463,11 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals this->setPos(point.X(),point.Y()); emit localPositionChanged(this->pos(),this); } + + void WayPointItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); + } void WayPointItem::RefreshToolTip() { QString type_str; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h index df5f3b5e9..452eef81e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h @@ -156,7 +156,6 @@ public: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); void RefreshToolTip(); QPixmap picture; QString customString(){return myCustomString;} @@ -217,6 +216,8 @@ public slots: void WPInserted(int const& number,WayPointItem* waypoint); void onHomePositionChanged(internals::PointLatLng,float altitude); + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: /** * @brief fires when this WayPoint number changes (not fired if due to a auto-renumbering) diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp index 7ba3072db..a31c93cbb 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp @@ -44,6 +44,7 @@ WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem this->setZValue(9); else if(myColor==Qt::red) this->setZValue(8); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color):source(from), @@ -59,6 +60,7 @@ WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map this->setZValue(9); else if(myColor==Qt::red) this->setZValue(8); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } int WayPointLine::type() const { @@ -112,4 +114,9 @@ void WayPointLine::waypointdeleted() this->deleteLater(); } +void WayPointLine::setOpacitySlot(qreal opacity) +{ + setOpacity(opacity); +} + } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h index 6d8985f77..5b7a40f85 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h @@ -60,6 +60,7 @@ protected: public slots: void refreshLocations(); void waypointdeleted(); + void setOpacitySlot(qreal opacity); }; } #endif // WAYPOINTLINE_H