From e8dca2d0899f4f0ee63265ee06eab13f97c0caf5 Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Sat, 17 Aug 2013 23:05:02 +0200 Subject: [PATCH] OP-1071 Adds support for dashed lines and circles. Emergency lines were changed to be dashed and less wide. --- .../src/mapwidget/opmapwidget.cpp | 16 ++++----- .../opmapcontrol/src/mapwidget/opmapwidget.h | 8 ++--- .../src/mapwidget/waypointcircle.cpp | 6 ++-- .../src/mapwidget/waypointcircle.h | 6 ++-- .../src/mapwidget/waypointline.cpp | 33 +++++++++++++------ .../opmapcontrol/src/mapwidget/waypointline.h | 6 ++-- .../src/plugins/opmap/modelmapproxy.cpp | 18 +++++----- .../src/plugins/opmap/modelmapproxy.h | 4 +-- 8 files changed, 57 insertions(+), 40 deletions(-) diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp index f9ede780e..c931fe886 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp @@ -100,40 +100,40 @@ void OPMapWidget::SetUavPic(QString UAVPic) } } -WayPointLine *OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color) +WayPointLine *OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color, bool dashed, int width) { if (!from | !to) { return NULL; } - WayPointLine *ret = new WayPointLine(from, to, map, color); + WayPointLine *ret = new WayPointLine(from, to, map, color, dashed, width); ret->setOpacity(overlayOpacity); return ret; } -WayPointLine *OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to, QColor color) +WayPointLine *OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to, QColor color, bool dashed, int width) { if (!from | !to) { return NULL; } - WayPointLine *ret = new WayPointLine(from, to, map, color); + WayPointLine *ret = new WayPointLine(from, to, map, color, dashed, width); ret->setOpacity(overlayOpacity); return ret; } -WayPointCircle *OPMapWidget::WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise, QColor color) +WayPointCircle *OPMapWidget::WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise, QColor color, bool dashed, int width) { if (!center | !radius) { return NULL; } - WayPointCircle *ret = new WayPointCircle(center, radius, clockwise, map, color); + WayPointCircle *ret = new WayPointCircle(center, radius, clockwise, map, color, dashed, width); ret->setOpacity(overlayOpacity); return ret; } -WayPointCircle *OPMapWidget::WPCircleCreate(HomeItem *center, WayPointItem *radius, bool clockwise, QColor color) +WayPointCircle *OPMapWidget::WPCircleCreate(HomeItem *center, WayPointItem *radius, bool clockwise, QColor color, bool dashed, int width) { if (!center | !radius) { return NULL; } - WayPointCircle *ret = new WayPointCircle(center, radius, clockwise, map, color); + WayPointCircle *ret = new WayPointCircle(center, radius, clockwise, map, color, dashed, width); ret->setOpacity(overlayOpacity); return ret; } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h index f427a560c..67a473f85 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h @@ -510,10 +510,10 @@ public: } void SetShowDiagnostics(bool const & value); void SetUavPic(QString UAVPic); - WayPointLine *WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color); - WayPointLine *WPLineCreate(HomeItem *from, WayPointItem *to, QColor color); - WayPointCircle *WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise, QColor color); - WayPointCircle *WPCircleCreate(HomeItem *center, WayPointItem *radius, bool clockwise, QColor color); + WayPointLine *WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color, bool dashed = false, int width = -1); + WayPointLine *WPLineCreate(HomeItem *from, WayPointItem *to, QColor color, bool dashed = false, int width = -1); + WayPointCircle *WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise, QColor color, bool dashed = false, int width = -1); + WayPointCircle *WPCircleCreate(HomeItem *center, WayPointItem *radius, bool clockwise, QColor color, bool dashed = false, int width = -1); void deleteAllOverlays(); void WPSetVisibleAll(bool value); WayPointItem *magicWPCreate(); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp index 3748ab6d0..735a5538e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp @@ -29,8 +29,8 @@ #include "homeitem.h" namespace mapcontrol { -WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color) : my_center(center), - my_radius(radius), my_map(map), QGraphicsEllipseItem(map), myColor(color), myClockWise(clockwise) +WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : my_center(center), + my_radius(radius), my_map(map), QGraphicsEllipseItem(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width) { connect(center, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations())); connect(radius, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations())); @@ -40,7 +40,7 @@ WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal))); } -WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool clockwise, MapGraphicItem *map, QColor color) : my_center(center), +WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : my_center(center), my_radius(radius), my_map(map), QGraphicsEllipseItem(map), myColor(color), myClockWise(clockwise) { connect(radius, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(refreshLocations())); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h index ec6ac5a13..43bc99a8b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h @@ -40,8 +40,8 @@ class WayPointCircle : public QObject, public QGraphicsEllipseItem { Q_OBJECT Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 9 }; - WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color = Qt::green); - WayPointCircle(HomeItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color = Qt::green); + WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = -1); + WayPointCircle(HomeItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = -1); int type() const; void setColor(const QColor &color) { @@ -55,6 +55,8 @@ private: QColor myColor; bool myClockWise; QLineF line; + bool dashed; + int width; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); public slots: diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp index eb750a1e6..7a94afad6 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp @@ -29,8 +29,8 @@ #include "homeitem.h" namespace mapcontrol { -WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color) : source(from), - destination(to), my_map(map), QGraphicsLineItem(map), myColor(color) +WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color, bool dashed, int width) : source(from), + destination(to), my_map(map), QGraphicsLineItem(map), myColor(color), dashed(dashed), lineWidth(width) { this->setLine(to->pos().x(), to->pos().y(), from->pos().x(), from->pos().y()); connect(from, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations())); @@ -47,8 +47,8 @@ WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal))); } -WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color) : source(from), - destination(to), my_map(map), QGraphicsLineItem(map), myColor(color) +WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color, bool dashed, int width) : source(from), + destination(to), my_map(map), QGraphicsLineItem(map), myColor(color), dashed(dashed), lineWidth(width) { this->setLine(to->pos().x(), to->pos().y(), from->pos().x(), from->pos().y()); connect(from, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(refreshLocations())); @@ -98,12 +98,25 @@ void WayPointLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti arrowHead.clear(); arrowHead << line().pointAt(0.5) << arrowP1 << arrowP2; painter->drawPolygon(arrowHead); - if (myColor == Qt::red) { - myPen.setWidth(3); - } else if (myColor == Qt::yellow) { - myPen.setWidth(2); - } else if (myColor == Qt::green) { - myPen.setWidth(1); + + if(dashed) + { + QVector dashes; + dashes << 4 << 8; + myPen.setDashPattern(dashes); + } + + if(lineWidth == -1) { + if (myColor == Qt::red) { + myPen.setWidth(3); + } else if (myColor == Qt::yellow) { + myPen.setWidth(2); + } else if (myColor == Qt::green) { + myPen.setWidth(1); + } + } + else { + myPen.setWidth(lineWidth); } painter->setPen(myPen); painter->drawLine(line()); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h index cc1cc3b93..ed1ea81d2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h @@ -40,8 +40,8 @@ class WayPointLine : public QObject, public QGraphicsLineItem { Q_OBJECT Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 8 }; - WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color = Qt::green); - WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color = Qt::green); + WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = -1); + WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = -1); int type() const; QPainterPath shape() const; void setColor(const QColor &color) @@ -54,6 +54,8 @@ private: MapGraphicItem *my_map; QPolygonF arrowHead; QColor myColor; + bool dashed; + int lineWidth; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); public slots: diff --git a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp index 2dac1b0ac..ce3c44e86 100644 --- a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp @@ -108,39 +108,39 @@ modelMapProxy::overlayType modelMapProxy::overlayTranslate(int type) } } -void modelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to, modelMapProxy::overlayType type, QColor color) +void modelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to, modelMapProxy::overlayType type, QColor color, bool dashed, int width) { if (from == NULL || to == NULL || from == to) { return; } switch (type) { case OVERLAY_LINE: - myMap->WPLineCreate(from, to, color); + myMap->WPLineCreate(from, to, color, dashed, width); break; case OVERLAY_CIRCLE_RIGHT: - myMap->WPCircleCreate(to, from, true, color); + myMap->WPCircleCreate(to, from, true, color, dashed, width); break; case OVERLAY_CIRCLE_LEFT: - myMap->WPCircleCreate(to, from, false, color); + myMap->WPCircleCreate(to, from, false, color, dashed, width); break; default: break; } } -void modelMapProxy::createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type, QColor color) +void modelMapProxy::createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type, QColor color, bool dashed, int width) { if (from == NULL || to == NULL) { return; } switch (type) { case OVERLAY_LINE: - myMap->WPLineCreate(to, from, color); + myMap->WPLineCreate(to, from, color, dashed, width); break; case OVERLAY_CIRCLE_RIGHT: - myMap->WPCircleCreate(to, from, true, color); + myMap->WPCircleCreate(to, from, true, color, dashed, width); break; case OVERLAY_CIRCLE_LEFT: - myMap->WPCircleCreate(to, from, false, color); + myMap->WPCircleCreate(to, from, false, color, dashed, width); break; default: break; @@ -169,7 +169,7 @@ void modelMapProxy::refreshOverlays() wp_next_overlay = overlayTranslate(model->data(model->index(x + 1, flightDataModel::MODE)).toInt()); wp_jump_overlay = overlayTranslate(model->data(model->index(wp_jump, flightDataModel::MODE)).toInt()); wp_error_overlay = overlayTranslate(model->data(model->index(wp_error, flightDataModel::MODE)).toInt()); - createOverlay(wp_current, findWayPointNumber(wp_error), wp_error_overlay, Qt::red); + createOverlay(wp_current, findWayPointNumber(wp_error), wp_error_overlay, Qt::red, true, 1); switch (model->data(model->index(x, flightDataModel::COMMAND)).toInt()) { case MapDataDelegate::COMMAND_ONCONDITIONNEXTWAYPOINT: wp_next = findWayPointNumber(x + 1); diff --git a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h index 04269c9ba..0c169698a 100644 --- a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h +++ b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h @@ -56,8 +56,8 @@ private slots: void selectedWPChanged(QList); private: overlayType overlayTranslate(int type); - void createOverlay(WayPointItem *from, WayPointItem *to, overlayType type, QColor color); - void createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type, QColor color); + void createOverlay(WayPointItem *from, WayPointItem *to, overlayType type, QColor color, bool dashed = false, int width = -1); + void createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type, QColor color, bool dashed = false, int width = -1); OPMapWidget *myMap; flightDataModel *model; void refreshOverlays();