1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Merge remote-tracking branch 'origin/thread/OP-1071_Map_Emergency_Line' into next

Conflicts:
	ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp
	ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp
This commit is contained in:
Philippe Renon 2015-01-31 15:35:07 +01:00
commit 5bc17d7b87
8 changed files with 66 additions and 41 deletions

View File

@ -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;
}

View File

@ -511,10 +511,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();

View File

@ -29,8 +29,8 @@
#include "homeitem.h"
namespace mapcontrol {
WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(map), myColor(color), myClockWise(clockwise)
WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(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,8 +40,8 @@ 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) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(map), myColor(color), myClockWise(clockwise)
WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool clockwise, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsEllipseItem(map),
my_center(center), my_radius(radius), my_map(map), QGraphicsEllipseItem(map), myColor(color), myClockWise(clockwise), dashed(dashed), width(width)
{
connect(radius, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(refreshLocations()));
connect(center, SIGNAL(localPositionChanged(QPointF)), this, SLOT(refreshLocations()));
@ -67,6 +67,14 @@ void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
p2 = QPointF(line.p1().x(), line.p1().y() - line.length());
QPen myPen = pen();
myPen.setColor(myColor);
if(width > 0) {
myPen.setWidth(width);
}
if(dashed){
QVector<qreal> dashes;
dashes << 4 << 8;
myPen.setDashPattern(dashes);
}
qreal arrowSize = 10;
painter->setPen(myPen);
QBrush brush = painter->brush();

View File

@ -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:

View File

@ -29,8 +29,8 @@
#include "homeitem.h"
namespace mapcontrol {
WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color) : QGraphicsLineItem(map),
source(from), destination(to), my_map(map), myColor(color)
WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsLineItem(map),
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) : QGraphicsLineItem(map),
source(from), destination(to), my_map(map), myColor(color)
WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsLineItem(map),
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<qreal> 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());

View File

@ -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:

View File

@ -103,39 +103,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;
@ -164,7 +164,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);

View File

@ -56,8 +56,8 @@ private slots:
void selectedWPChanged(QList<WayPointItem *>);
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();