标尺添加
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 17 KiB |
@@ -52,7 +52,8 @@ SOURCES += $$PWD/mapgraphicitem.cpp \
|
||||
$$PWD/missiondialog.cpp \
|
||||
$$PWD/ruledialog.cpp \
|
||||
$$PWD/waypointbutton.cpp \
|
||||
$$PWD/waypointsetting.cpp
|
||||
$$PWD/waypointsetting.cpp \
|
||||
measureline.cpp
|
||||
|
||||
HEADERS += $$PWD/mapgraphicitem.h \
|
||||
$$PWD/opmapwidget.h \
|
||||
@@ -74,7 +75,8 @@ HEADERS += $$PWD/mapgraphicitem.h \
|
||||
$$PWD/missiondialog.h \
|
||||
$$PWD/ruledialog.h \
|
||||
$$PWD/waypointbutton.h \
|
||||
$$PWD/waypointsetting.h
|
||||
$$PWD/waypointsetting.h \
|
||||
measureline.h
|
||||
|
||||
RESOURCES += mapresources.qrc
|
||||
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file MeasureLine.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @brief A graphicsItem representing a line connecting 2 waypoints
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "measureline.h"
|
||||
#include <math.h>
|
||||
#include "homeitem.h"
|
||||
|
||||
namespace mapcontrol {
|
||||
MeasureLine::MeasureLine(internals::PointLatLng from, internals::PointLatLng to, MapGraphicItem *map, QColor color, bool dashed, int width) : QGraphicsLineItem(map),
|
||||
source(from), destination(to), my_map(map), myColor(color), dashed(dashed), lineWidth(width)
|
||||
{
|
||||
|
||||
|
||||
this->setLine(map->FromLatLngToLocal(from).X(), map->FromLatLngToLocal(from).Y(), map->FromLatLngToLocal(to).X(), map->FromLatLngToLocal(to).Y());
|
||||
/*
|
||||
connect(from, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
|
||||
connect(to, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(refreshLocations()));
|
||||
connect(from, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
|
||||
connect(to, SIGNAL(aboutToBeDeleted(WayPointItem *)), this, SLOT(waypointdeleted()));
|
||||
*/
|
||||
|
||||
this->setZValue(5);
|
||||
|
||||
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
|
||||
|
||||
isEdit = true;
|
||||
|
||||
}
|
||||
|
||||
int MeasureLine::type() const
|
||||
{
|
||||
// Enable the use of qgraphicsitem_cast with this item.
|
||||
return Type;
|
||||
}
|
||||
QPainterPath MeasureLine::shape() const
|
||||
{
|
||||
QPainterPath path = QGraphicsLineItem::shape();
|
||||
|
||||
path.addPolygon(arrowHead);
|
||||
return path;
|
||||
}
|
||||
void MeasureLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
QPen myPen = pen();
|
||||
|
||||
|
||||
if(isEdit == false)
|
||||
{
|
||||
myPen.setColor(myColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
myPen.setColor("#ffff00");
|
||||
}
|
||||
|
||||
painter->setPen(myPen);
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MeasureLine::setEdit(bool value)
|
||||
{
|
||||
isEdit = value;
|
||||
}
|
||||
|
||||
|
||||
void MeasureLine::refreshLocations()
|
||||
{
|
||||
|
||||
this->setLine(my_map->FromLatLngToLocal(source).X(), my_map->FromLatLngToLocal(source).Y(), my_map->FromLatLngToLocal(destination).X(), my_map->FromLatLngToLocal(destination).Y());
|
||||
update();
|
||||
}
|
||||
|
||||
void MeasureLine::waypointdeleted()
|
||||
{
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
void MeasureLine::WPLinedelete(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
Q_UNUSED(from)
|
||||
Q_UNUSED(to)
|
||||
|
||||
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void MeasureLine::setOpacitySlot(qreal opacity)
|
||||
{
|
||||
setOpacity(opacity);
|
||||
}
|
||||
|
||||
|
||||
void MeasureLine::setFrom(internals::PointLatLng p)
|
||||
{
|
||||
source.SetLat(p.Lat());
|
||||
source.SetLng(p.Lng());
|
||||
|
||||
my_map->Projection()->offSetFromLatLngs(source,destination,distance,bearing);
|
||||
|
||||
refreshLocations();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void MeasureLine::setTo(internals::PointLatLng p)
|
||||
{
|
||||
destination.SetLat(p.Lat());
|
||||
destination.SetLng(p.Lng());
|
||||
|
||||
my_map->Projection()->offSetFromLatLngs(source,destination,distance,bearing);
|
||||
|
||||
refreshLocations();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file waypointline.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @brief A graphicsItem representing a line connecting 2 waypoints
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef MEASURELINE_H
|
||||
#define MEASURELINE_H
|
||||
#include <QGraphicsItem>
|
||||
#include <QPainter>
|
||||
#include <QLabel>
|
||||
#include "pointlatlng.h"
|
||||
#include "mapgraphicitem.h"
|
||||
#include "waypointitem.h"
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
|
||||
namespace mapcontrol {
|
||||
|
||||
#ifdef QtopmapWidget
|
||||
#include <mapwidgetglobal.h>
|
||||
class OPMAPWIDGETSHARED_EXPORT MeasureLine : public QObject, public QGraphicsLineItem {
|
||||
#else
|
||||
class MeasureLine : public QObject, public QGraphicsLineItem {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Q_OBJECT Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
enum { Type = UserType + 8 };
|
||||
MeasureLine(internals::PointLatLng from, internals::PointLatLng to, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = -1);
|
||||
int type() const;
|
||||
QPainterPath shape() const;
|
||||
void setColor(const QColor &color)
|
||||
{
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
|
||||
void setEdit(bool value);
|
||||
|
||||
|
||||
bool Edit(void)
|
||||
{
|
||||
return isEdit;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
//QGraphicsItem *source;
|
||||
//QGraphicsItem *destination;
|
||||
|
||||
internals::PointLatLng source;
|
||||
internals::PointLatLng destination;
|
||||
|
||||
MapGraphicItem *my_map;
|
||||
QPolygonF arrowHead;
|
||||
QColor myColor;
|
||||
bool dashed;
|
||||
int lineWidth;
|
||||
|
||||
|
||||
double distance;
|
||||
double bearing;
|
||||
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
public slots:
|
||||
|
||||
|
||||
internals::PointLatLng LineFrom(void)
|
||||
{
|
||||
return this->source;
|
||||
}
|
||||
|
||||
internals::PointLatLng LineTo(void)
|
||||
{
|
||||
return this->destination;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WPLinedelete(WayPointItem *from, WayPointItem *to);
|
||||
void refreshLocations();
|
||||
void waypointdeleted();
|
||||
void setOpacitySlot(qreal opacity);
|
||||
|
||||
|
||||
void setFrom(internals::PointLatLng p);
|
||||
void setTo(internals::PointLatLng p);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
bool isEdit = false;
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
#endif // MeasureLine_H
|
||||
@@ -129,8 +129,10 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
connect(waypointsetting,SIGNAL(WPLoad(QString)),
|
||||
this,SLOT(WPLoad(QString)));
|
||||
|
||||
/*
|
||||
connect(this,SIGNAL(allPoint(QMap<int,int>)),
|
||||
waypointsetting,SLOT(setallPoint(QMap<int,int>)));
|
||||
*/
|
||||
|
||||
connect(waypointsetting,SIGNAL(searchall()),
|
||||
this,SLOT(WPsearchall()));
|
||||
@@ -148,6 +150,9 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
missiontable->hide();
|
||||
|
||||
|
||||
measureline = new MeasureLine(point_begin, point_end, map, QColor("#FFFF00"));
|
||||
mscene.addItem(measureline);
|
||||
measureline->hide();
|
||||
|
||||
//ruler = new RuleDialog();
|
||||
|
||||
@@ -199,7 +204,15 @@ void OPMapWidget::ruler_clicked(void)
|
||||
else
|
||||
{
|
||||
isMeasure = true;
|
||||
this->setCursor(QCursor(QPixmap(":/markers/images/ruler.png")));
|
||||
measurenumber = 1;//开始记录
|
||||
|
||||
if(measureline)
|
||||
{
|
||||
measureline->show();
|
||||
}
|
||||
|
||||
QPixmap pix(":/markers/images/ruler.png");
|
||||
this->setCursor(QCursor(pix.scaled(QSize(50,50), Qt::KeepAspectRatio)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,6 +574,27 @@ internals::PointLatLng OPMapWidget::currentMousePosition()
|
||||
void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
|
||||
if(altitudeitem)
|
||||
{
|
||||
if((event->pos().x() > altitudeitem->x())&&(event->pos().x() < (altitudeitem->boundingRect().width() + altitudeitem->x())) &&
|
||||
(event->pos().y() > altitudeitem->y())&&(event->pos().y() < (altitudeitem->boundingRect().height() + altitudeitem->y())))//在高度区域禁止生成航点
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//一个区域内禁止生成
|
||||
if(waypointsetting)
|
||||
{
|
||||
if((event->pos().x() > waypointsetting->x())&&(event->pos().x() < (waypointsetting->boundingRect().width() + waypointsetting->x())) &&
|
||||
(event->pos().y() > waypointsetting->y())&&(event->pos().y() < (waypointsetting->boundingRect().height() + waypointsetting->y())))//在按键区域禁止生成航点
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QPointF p = event->pos();
|
||||
|
||||
//qDebug() << "mouseMoveEvent";
|
||||
@@ -571,6 +605,23 @@ void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
isLNOP = false;
|
||||
|
||||
|
||||
if(isMeasure)
|
||||
{
|
||||
QPointF p = event->pos();
|
||||
p = map->mapFromParent(p);
|
||||
point_end = map->FromLocalToLatLng(p.x(), p.y());
|
||||
//measurenumber = 1;
|
||||
|
||||
if(measureline)
|
||||
{
|
||||
if(measurenumber == 2)//取了第一个点后
|
||||
{
|
||||
measureline->setTo(point_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit EmitCurrentMousePosition(currentmouseposition);
|
||||
}
|
||||
|
||||
@@ -579,7 +630,62 @@ void OPMapWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
|
||||
//qDebug() << "mousePressEvent";
|
||||
if(altitudeitem)
|
||||
{
|
||||
if((event->pos().x() > altitudeitem->x())&&(event->pos().x() < (altitudeitem->boundingRect().width() + altitudeitem->x())) &&
|
||||
(event->pos().y() > altitudeitem->y())&&(event->pos().y() < (altitudeitem->boundingRect().height() + altitudeitem->y())))//在高度区域禁止生成航点
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//一个区域内禁止生成
|
||||
if(waypointsetting)
|
||||
{
|
||||
if((event->pos().x() > waypointsetting->x())&&(event->pos().x() < (waypointsetting->boundingRect().width() + waypointsetting->x())) &&
|
||||
(event->pos().y() > waypointsetting->y())&&(event->pos().y() < (waypointsetting->boundingRect().height() + waypointsetting->y())))//在按键区域禁止生成航点
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
|
||||
if(isMeasure)
|
||||
{
|
||||
if(measurenumber == 1)
|
||||
{
|
||||
QPointF p = event->pos();
|
||||
p = map->mapFromParent(p);
|
||||
point_begin = map->FromLocalToLatLng(p.x(), p.y());
|
||||
measurenumber ++;
|
||||
|
||||
if(measureline)
|
||||
{
|
||||
measureline->setFrom(point_begin);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
QPointF p = event->pos();
|
||||
p = map->mapFromParent(p);
|
||||
point_end = map->FromLocalToLatLng(p.x(), p.y());
|
||||
measurenumber = 1;
|
||||
|
||||
if(measureline)
|
||||
{
|
||||
measureline->setTo(point_end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
isLNOP = false;
|
||||
|
||||
@@ -599,6 +705,12 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
|
||||
|
||||
if(isMeasure)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(altitudeitem)
|
||||
{
|
||||
if((event->pos().x() > altitudeitem->x())&&(event->pos().x() < (altitudeitem->boundingRect().width() + altitudeitem->x())) &&
|
||||
|
||||
@@ -59,6 +59,10 @@
|
||||
#include "missiondialog.h"
|
||||
#include "ruledialog.h"
|
||||
#include "QDialog"
|
||||
|
||||
#include "measureline.h"
|
||||
|
||||
|
||||
namespace mapcontrol {
|
||||
|
||||
#ifdef QtopmapWidget
|
||||
@@ -387,6 +391,9 @@ public:
|
||||
|
||||
WayPointSetting *waypointsetting;
|
||||
|
||||
|
||||
MeasureLine *measureline = nullptr;
|
||||
|
||||
//MissionDialog *missiontable;
|
||||
//RuleDialog *ruler;
|
||||
|
||||
@@ -486,6 +493,15 @@ private:
|
||||
|
||||
QTimer *NoOperationTimer = nullptr;
|
||||
|
||||
|
||||
|
||||
|
||||
internals::PointLatLng point_begin;
|
||||
internals::PointLatLng point_end;
|
||||
|
||||
int measurenumber = 1;
|
||||
|
||||
|
||||
private slots:
|
||||
void diagRefresh();
|
||||
// WayPointItem* item;//apagar
|
||||
|
||||
Reference in New Issue
Block a user