修改航点,添加属性,修改显示
This commit is contained in:
+11
-7
@@ -93,12 +93,13 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(nav,SIGNAL(SizeChanged(QResizeEvent*)),
|
||||
this,SLOT(resizeEvent(QResizeEvent*)));
|
||||
|
||||
// connect(nav,&QNavigationWidget::SizeChanged,
|
||||
// this,&MainWindow::resizeEvent);
|
||||
|
||||
|
||||
copk = new Cockpit(this);
|
||||
|
||||
connect(copk,SIGNAL(SizeChanged(QResizeEvent*)),
|
||||
this,SLOT(resizeEvent(QResizeEvent*)));
|
||||
|
||||
copk->setGeometry(this->width() - copk->width(),0,300,340);
|
||||
copk->show();
|
||||
|
||||
|
||||
//在quick load 之前注册即可
|
||||
@@ -179,6 +180,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
copk->setGeometry(this->width() - copk->width(),0,copk->width(),copk->height());
|
||||
quick->setGeometry(this->width() - quick->width(),copk->height(),quick->width(),this->height() - copk->height());
|
||||
|
||||
qDebug() << "resize";
|
||||
|
||||
update();
|
||||
|
||||
@@ -345,20 +347,22 @@ void MainWindow::subui(QString arg)//子界面管理
|
||||
|
||||
void MainWindow::onTabIndexChanged(const int &index)//界面选择管理
|
||||
{
|
||||
if((index == 0)||(index == 1))//隐藏
|
||||
if((index == 0)||(index == 1)) map->show();
|
||||
else map->hide();
|
||||
|
||||
if((index == 0))//隐藏
|
||||
{
|
||||
map->show();
|
||||
copk->show();
|
||||
quick->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
map->hide();
|
||||
copk->hide();
|
||||
quick->hide();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(index == 2) linkui->show();
|
||||
else linkui->hide();
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ Cockpit::Cockpit(QWidget *parent): QWidget(parent)
|
||||
|
||||
UpdateTimer->start(50);//50Hz
|
||||
|
||||
|
||||
}
|
||||
|
||||
Cockpit::~Cockpit()
|
||||
@@ -116,6 +117,29 @@ void Cockpit::wheelEvent(QWheelEvent *e)
|
||||
//update();
|
||||
}
|
||||
|
||||
void Cockpit::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
emit SizeChanged(event);
|
||||
}
|
||||
|
||||
void Cockpit::hideEvent(QHideEvent *event)
|
||||
{
|
||||
LastSize = this->size();
|
||||
this->resize(0,LastSize.height());
|
||||
|
||||
QResizeEvent *e;
|
||||
resizeEvent(e);
|
||||
}
|
||||
|
||||
void Cockpit::showEvent(QShowEvent *event)
|
||||
{
|
||||
this->resize(LastSize);
|
||||
QResizeEvent *e;
|
||||
resizeEvent(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Cockpit::setPitch(double Pitch)
|
||||
{
|
||||
if(isnan(Pitch))
|
||||
|
||||
@@ -113,6 +113,8 @@ typedef struct{
|
||||
Q_SIGNALS:
|
||||
void errorSignal(int);
|
||||
|
||||
void SizeChanged(QResizeEvent *);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setPitch(qreal Pitch);
|
||||
void setRoll(qreal Roll);
|
||||
@@ -133,7 +135,10 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
void hideEvent(QHideEvent *);
|
||||
void showEvent(QShowEvent *);
|
||||
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
@@ -159,6 +164,7 @@ private slots:
|
||||
|
||||
private:
|
||||
|
||||
QSize LastSize;
|
||||
|
||||
QTimer *UpdateTimer = nullptr;
|
||||
|
||||
|
||||
@@ -51,12 +51,13 @@ MAVLinkInspector::MAVLinkInspector(const QString& title, QAction* action,QWidget
|
||||
}
|
||||
|
||||
|
||||
void MAVLinkInspector::_vehicleAdded(quint32 id)
|
||||
void MAVLinkInspector::_vehicleAdded(quint32 m_sysid,quint32 m_compid)
|
||||
{
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(id), id);
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(m_sysid), m_sysid);
|
||||
ui->componentComboBox->addItem(tr("Component %1").arg(m_compid), m_compid);
|
||||
|
||||
// Add a tree for a new UAS
|
||||
addUAStoTree(id);
|
||||
addUAStoTree(m_sysid);
|
||||
}
|
||||
|
||||
void MAVLinkInspector::selectDropDownMenuSystem(int dropdownid)
|
||||
@@ -274,9 +275,9 @@ void MAVLinkInspector::refreshView()
|
||||
}
|
||||
}
|
||||
|
||||
void MAVLinkInspector::addUAStoTree(int sysId)
|
||||
void MAVLinkInspector::addUAStoTree(int m_sysid)
|
||||
{
|
||||
if(!uasTreeWidgetItems.contains(sysId))
|
||||
if(!uasTreeWidgetItems.contains(m_sysid))
|
||||
{
|
||||
// Add the UAS to the main tree after it has been created
|
||||
//Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->getVehicleById(sysId);
|
||||
@@ -284,12 +285,12 @@ void MAVLinkInspector::addUAStoTree(int sysId)
|
||||
{
|
||||
//UASInterface* uas = vehicle->uas();
|
||||
QStringList idstring;
|
||||
idstring << QString("Vehicle %1").arg(sysId);//uas->getUASID());
|
||||
idstring << QString("Vehicle %1").arg(m_sysid);//uas->getUASID());
|
||||
QTreeWidgetItem* uasWidget = new QTreeWidgetItem(idstring);
|
||||
uasWidget->setFirstColumnSpanned(true);
|
||||
uasTreeWidgetItems.insert(sysId,uasWidget);
|
||||
uasTreeWidgetItems.insert(m_sysid,uasWidget);
|
||||
ui->treeWidget->addTopLevelItem(uasWidget);
|
||||
uasMsgTreeItems.insert(sysId,new QMap<int, QTreeWidgetItem*>());
|
||||
uasMsgTreeItems.insert(m_sysid,new QMap<int, QTreeWidgetItem*>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ protected:
|
||||
/** @brief Rebuild the list of components */
|
||||
void rebuildComponentList();
|
||||
/* @brief Create a new tree for a new UAS */
|
||||
void addUAStoTree(int sysId);
|
||||
void addUAStoTree(int m_sysid);
|
||||
|
||||
static const unsigned int updateInterval; ///< The update interval of the refresh function
|
||||
static const float updateHzLowpass; ///< The low-pass filter value for the frequency of each message
|
||||
|
||||
private slots:
|
||||
void _vehicleAdded(quint32 id);
|
||||
void _vehicleAdded(quint32 m_sysid, quint32 m_compid);
|
||||
|
||||
private:
|
||||
Ui::MAVLinkInspector *ui;
|
||||
|
||||
@@ -61,47 +61,30 @@ void ParameterInspector::resizeEvent(QResizeEvent * event)
|
||||
|
||||
|
||||
//添加一个设备,
|
||||
void ParameterInspector::addVehicles(uint16_t id)
|
||||
void ParameterInspector::addVehicles(uint16_t sysid,uint16_t compid)
|
||||
{
|
||||
if(!vehicles.keys().contains(id))
|
||||
if(!vehicles.keys().contains(sysid))
|
||||
{
|
||||
//如果还没有这个设备,就添加一个
|
||||
QMap<int, mavlink_param_value_t> param;
|
||||
vehicles.insert(id,param);
|
||||
vehicles.insert(sysid,param);
|
||||
|
||||
//同时检查combox有没有,没有就添加
|
||||
if(ui->systemComboBox->findText(tr("Vehicle %1").arg(id)) == (-1))
|
||||
if(ui->systemComboBox->findText(tr("Vehicle %1").arg(sysid)) == (-1))
|
||||
{
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(id), id);
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(sysid), sysid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
foreach (QTreeWidgetItem* item, uasTopLevelItems)
|
||||
|
||||
//同时检查combox有没有,没有就添加
|
||||
if(ui->componentComboBox->findText(tr("Comp %1").arg(compid)) == (-1))
|
||||
{
|
||||
if(item->data(0,Qt::DisplayRole).toInt() == id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTreeWidgetItem* ite;
|
||||
|
||||
ite->setData(0,Qt::DisplayRole,tr("Vehicle %1").arg(id));
|
||||
|
||||
uasTopLevelItems.insert(id,ite);
|
||||
ui->componentComboBox->addItem(tr("Comp %1").arg(compid), compid);
|
||||
}
|
||||
|
||||
|
||||
qDebug() << item->data(0,Qt::DisplayRole);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// ui->treeWidget->addTopLevelItems(uasTopLevelItems);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -366,6 +349,7 @@ void ParameterInspector::on_ReadButton_clicked()
|
||||
uint8_t m_type = 0;
|
||||
|
||||
m_sysid = ui->systemComboBox->currentData().toInt();
|
||||
m_compid = ui->componentComboBox->currentData().toInt();
|
||||
|
||||
emit ReadCmd(m_sysid,m_compid,m_type);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void addVehicles(uint16_t id);
|
||||
void addVehicles(uint16_t sysid, uint16_t compid);
|
||||
|
||||
void appendParameter(mavlink_message_t msg);
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ void MavLinkNode::Mavlinkparse(quint32 src,QByteArray datagram)
|
||||
void MavLinkNode::MAVLinkRcv_Handler(mavlink_message_t msg)
|
||||
{
|
||||
//用于给参数添加设备,便于读取
|
||||
Parameter->paramInspect->addVehicles(msg.sysid);
|
||||
Parameter->paramInspect->addVehicles(msg.sysid,msg.compid);
|
||||
|
||||
|
||||
switch (msg.msgid) {
|
||||
|
||||
@@ -276,7 +276,7 @@ void ParameterProcess::ReadStateMachine(void)//一整列
|
||||
}
|
||||
}
|
||||
|
||||
//写航线状态机
|
||||
//写状态机
|
||||
void ParameterProcess::WriteStateMachine(void)
|
||||
{
|
||||
static uint8_t step = 0;
|
||||
|
||||
@@ -66,6 +66,18 @@ FORMS += \
|
||||
|
||||
INCLUDEPATH += $$PWD/../../thirdpart/include
|
||||
|
||||
#添加mavlink目录
|
||||
INCLUDEPATH += $$PWD/../../mavlink \
|
||||
$$PWD/../../mavlink/ardupilotmega \
|
||||
$$PWD/../../mavlink/common \
|
||||
$$PWD/../../mavlink/icarous \
|
||||
$$PWD/../../mavlink/uAvionix \
|
||||
$$PWD/../../mavlink/XYK \
|
||||
$$PWD/../../mavlink/message_definitions
|
||||
|
||||
|
||||
|
||||
|
||||
LIBS += -L$$PWD/../../thirdpart/lib -lcore
|
||||
LIBS += -L$$PWD/../../thirdpart/lib -linternals
|
||||
|
||||
|
||||
@@ -252,17 +252,6 @@ void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
void OPMapWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mousePressEvent(event);
|
||||
|
||||
QPointF p = event->pos();
|
||||
|
||||
p = map->mapFromParent(p);
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
|
||||
LatLng = map->FromLocalToLatLng(p.x(), p.y());
|
||||
|
||||
qDebug() << "OPMapWidget" << QString::number(LatLng.Lat(),'f',8) << QString::number(LatLng.Lng(),'f',8);
|
||||
|
||||
emit MousePressEvent(event);
|
||||
}
|
||||
|
||||
@@ -275,6 +264,25 @@ void OPMapWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseDoubleClickEvent(event);
|
||||
|
||||
QPointF p = event->pos();
|
||||
|
||||
p = map->mapFromParent(p);
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
|
||||
LatLng = map->FromLocalToLatLng(p.x(), p.y());
|
||||
|
||||
qDebug() << "OPMapWidget" << QString::number(LatLng.Lat(),'f',8) << QString::number(LatLng.Lng(),'f',8);
|
||||
|
||||
|
||||
WPCreate(LatLng,0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
emit MouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,12 @@
|
||||
#include "waypointline.h"
|
||||
#include "waypointcircle.h"
|
||||
#include "waypointitem.h"
|
||||
|
||||
|
||||
|
||||
#include "mavlink.h"
|
||||
|
||||
|
||||
namespace mapcontrol {
|
||||
|
||||
#ifdef QtopmapWidget
|
||||
|
||||
@@ -29,161 +29,29 @@
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
namespace mapcontrol {
|
||||
WayPointItem::WayPointItem(const internals::PointLatLng &coord, int const & altitude, MapGraphicItem *map, wptype type) : coord(coord), reached(false), description(""), shownumber(true), isDragging(false), altitude(altitude), map(map), myType(type)
|
||||
WayPointItem::WayPointItem(double const &lat, double const &lng, float const &alt, MapGraphicItem *map) : isDragging(true), map(map)
|
||||
{
|
||||
text = 0;
|
||||
numberI = 0;
|
||||
isMagic = false;
|
||||
picture.load(QString::fromUtf8(":/markers/images/marker.png"));
|
||||
number = WayPointItem::snumber;
|
||||
++WayPointItem::snumber;
|
||||
|
||||
parpertys.command = MAV_CMD::MAV_CMD_NAV_WAYPOINT;//默认为航点
|
||||
parpertys.x = lat;
|
||||
parpertys.y = lng;
|
||||
parpertys.z = alt;
|
||||
|
||||
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
|
||||
RefreshPos();
|
||||
myHome = NULL;
|
||||
QList<QGraphicsItem *> list = map->childItems();
|
||||
foreach(QGraphicsItem * obj, list) {
|
||||
HomeItem *h = qgraphicsitem_cast <HomeItem *>(obj);
|
||||
|
||||
if (h) {
|
||||
myHome = h;
|
||||
}
|
||||
}
|
||||
|
||||
if (myHome) {
|
||||
map->Projection()->offSetFromLatLngs(myHome->Coord(), coord, relativeCoord.distance, relativeCoord.bearing);
|
||||
relativeCoord.altitudeRelative = Altitude() - myHome->Altitude();
|
||||
connect(myHome, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(onHomePositionChanged(internals::PointLatLng, float)));
|
||||
}
|
||||
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)
|
||||
{
|
||||
relativeCoord.bearing = 0;
|
||||
relativeCoord.distance = 0;
|
||||
relativeCoord.altitudeRelative = 0;
|
||||
myType = relative;
|
||||
if (magicwaypoint) {
|
||||
isMagic = true;
|
||||
picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png"));
|
||||
number = -1;
|
||||
} else {
|
||||
isMagic = false;
|
||||
number = WayPointItem::snumber;
|
||||
++WayPointItem::snumber;
|
||||
}
|
||||
text = 0;
|
||||
numberI = 0;
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
RefreshPos();
|
||||
myHome = NULL;
|
||||
QList<QGraphicsItem *> list = map->childItems();
|
||||
foreach(QGraphicsItem * obj, list) {
|
||||
HomeItem *h = qgraphicsitem_cast <HomeItem *>(obj);
|
||||
|
||||
if (h) {
|
||||
myHome = h;
|
||||
}
|
||||
}
|
||||
|
||||
if (myHome) {
|
||||
coord = map->Projection()->translate(myHome->Coord(), relativeCoord.distance, relativeCoord.bearing);
|
||||
SetAltitude(myHome->Altitude() + relativeCoord.altitudeRelative);
|
||||
connect(myHome, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(onHomePositionChanged(internals::PointLatLng, float)));
|
||||
}
|
||||
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)
|
||||
{
|
||||
text = 0;
|
||||
numberI = 0;
|
||||
isMagic = false;
|
||||
picture.load(QString::fromUtf8(":/markers/images/marker.png"));
|
||||
number = WayPointItem::snumber;
|
||||
++WayPointItem::snumber;
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
RefreshPos();
|
||||
myHome = NULL;
|
||||
QList<QGraphicsItem *> list = map->childItems();
|
||||
foreach(QGraphicsItem * obj, list) {
|
||||
HomeItem *h = qgraphicsitem_cast <HomeItem *>(obj);
|
||||
|
||||
if (h) {
|
||||
myHome = h;
|
||||
}
|
||||
}
|
||||
if (myHome) {
|
||||
map->Projection()->offSetFromLatLngs(myHome->Coord(), coord, relativeCoord.distance, relativeCoord.bearing);
|
||||
relativeCoord.altitudeRelative = Altitude() - myHome->Altitude();
|
||||
connect(myHome, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(onHomePositionChanged(internals::PointLatLng, float)));
|
||||
}
|
||||
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)
|
||||
{
|
||||
myHome = NULL;
|
||||
QList<QGraphicsItem *> list = map->childItems();
|
||||
foreach(QGraphicsItem * obj, list) {
|
||||
HomeItem *h = qgraphicsitem_cast <HomeItem *>(obj);
|
||||
|
||||
if (h) {
|
||||
myHome = h;
|
||||
}
|
||||
}
|
||||
if (myHome) {
|
||||
connect(myHome, SIGNAL(homePositionChanged(internals::PointLatLng, float)), this, SLOT(onHomePositionChanged(internals::PointLatLng, float)));
|
||||
coord = map->Projection()->translate(myHome->Coord(), relativeCoord.distance, relativeCoord.bearing);
|
||||
SetAltitude(myHome->Altitude() + relativeCoord.altitudeRelative);
|
||||
}
|
||||
myType = relative;
|
||||
text = 0;
|
||||
numberI = 0;
|
||||
isMagic = false;
|
||||
picture.load(QString::fromUtf8(":/markers/images/marker.png"));
|
||||
number = WayPointItem::snumber;
|
||||
++WayPointItem::snumber;
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
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)
|
||||
{
|
||||
myType = type;
|
||||
emit WPValuesChanged(this);
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
this->update();
|
||||
}
|
||||
|
||||
QRectF WayPointItem::boundingRect() const
|
||||
{
|
||||
@@ -209,16 +77,6 @@ void WayPointItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
text = new QGraphicsSimpleTextItem(this);
|
||||
textBG = new QGraphicsRectItem(this);
|
||||
|
||||
textBG->setBrush(Qt::white);
|
||||
|
||||
text->setPen(QPen(Qt::black));
|
||||
text->setPos(10, -picture.height());
|
||||
textBG->setPos(10, -picture.height());
|
||||
text->setZValue(3);
|
||||
RefreshToolTip();
|
||||
isDragging = true;
|
||||
}
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
@@ -226,18 +84,7 @@ void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (text) {
|
||||
delete text;
|
||||
text = NULL;
|
||||
}
|
||||
if (textBG) {
|
||||
delete textBG;
|
||||
textBG = NULL;
|
||||
}
|
||||
|
||||
isDragging = false;
|
||||
RefreshToolTip();
|
||||
|
||||
|
||||
emit manualCoordChange(this);
|
||||
emit localPositionChanged(this->pos(), this);
|
||||
@@ -252,13 +99,6 @@ void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (isDragging) {
|
||||
coord = map->FromLocalToLatLng(this->pos().x(), this->pos().y());
|
||||
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
|
||||
if (myHome) {
|
||||
map->Projection()->offSetFromLatLngs(myHome->Coord(), coord, relativeCoord.distance, relativeCoord.bearing);
|
||||
}
|
||||
QString relativeCoord_str =QString::number(relativeCoord.distance) + "m " + QString::number(relativeCoord.bearing * 180 / M_PI) + "deg";
|
||||
text->setText(coord_str + "\n" + relativeCoord_str);
|
||||
textBG->setRect(text->boundingRect());
|
||||
emit localPositionChanged(this->pos(), this);
|
||||
emit WPValuesChanged(this);
|
||||
}
|
||||
@@ -266,14 +106,6 @@ void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
}
|
||||
void WayPointItem::SetAltitude(const float &value)
|
||||
{
|
||||
if (altitude == value) {
|
||||
return;
|
||||
}
|
||||
altitude = value;
|
||||
if (myHome) {
|
||||
relativeCoord.altitudeRelative = altitude - myHome->Altitude();
|
||||
}
|
||||
RefreshToolTip();
|
||||
emit WPValuesChanged(this);
|
||||
this->update();
|
||||
}
|
||||
@@ -285,10 +117,7 @@ void WayPointItem::setRelativeCoord(distBearingAltitude value)
|
||||
return;
|
||||
}
|
||||
relativeCoord = value;
|
||||
if (myHome) {
|
||||
SetCoord(map->Projection()->translate(myHome->Coord(), relativeCoord.distance, relativeCoord.bearing));
|
||||
SetAltitude(myHome->Altitude() + relativeCoord.altitudeRelative);
|
||||
}
|
||||
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
emit WPValuesChanged(this);
|
||||
@@ -302,12 +131,7 @@ void WayPointItem::SetCoord(const internals::PointLatLng &value)
|
||||
}
|
||||
coord = value;
|
||||
distBearingAltitude back = relativeCoord;
|
||||
if (myHome) {
|
||||
map->Projection()->offSetFromLatLngs(myHome->Coord(), Coord(), back.distance, back.bearing);
|
||||
}
|
||||
if (qAbs(back.bearing - relativeCoord.bearing) > 0.01 || qAbs(back.distance - relativeCoord.distance) > 0.1) {
|
||||
relativeCoord = back;
|
||||
}
|
||||
|
||||
emit WPValuesChanged(this);
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
@@ -315,10 +139,10 @@ void WayPointItem::SetCoord(const internals::PointLatLng &value)
|
||||
}
|
||||
void WayPointItem::SetDescription(const QString &value)
|
||||
{
|
||||
if (description == value) {
|
||||
return;
|
||||
}
|
||||
description = value;
|
||||
//if (description == value) {
|
||||
// return;
|
||||
// }
|
||||
//description = value;
|
||||
RefreshToolTip();
|
||||
emit WPValuesChanged(this);
|
||||
this->update();
|
||||
@@ -328,9 +152,6 @@ void WayPointItem::SetNumber(const int &value)
|
||||
int oldnumber = number;
|
||||
|
||||
number = value;
|
||||
RefreshToolTip();
|
||||
numberI->setText(QString::number(numberAdjusted()));
|
||||
numberIBG->setRect(numberI->boundingRect().adjusted(-2, 0, 1, 0));
|
||||
this->update();
|
||||
emit WPNumberChanged(oldnumber, value, this);
|
||||
}
|
||||
@@ -356,21 +177,6 @@ void WayPointItem::SetReached(const bool &value)
|
||||
void WayPointItem::SetShowNumber(const bool &value)
|
||||
{
|
||||
shownumber = value;
|
||||
if ((numberI == 0) && value) {
|
||||
numberI = new QGraphicsSimpleTextItem(this);
|
||||
numberIBG = new QGraphicsRectItem(this);
|
||||
numberIBG->setBrush(Qt::white);
|
||||
numberIBG->setOpacity(0.5);
|
||||
numberI->setZValue(3);
|
||||
numberI->setPen(QPen(Qt::blue));
|
||||
numberI->setPos(0, -13 - picture.height());
|
||||
numberIBG->setPos(0, -13 - picture.height());
|
||||
numberI->setText(QString::number(numberAdjusted()));
|
||||
numberIBG->setRect(numberI->boundingRect().adjusted(-2, 0, 1, 0));
|
||||
} else if (!value && numberI) {
|
||||
delete numberI;
|
||||
delete numberIBG;
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
void WayPointItem::WPDeleted(const int &onumber, WayPointItem *waypoint)
|
||||
@@ -396,20 +202,7 @@ void WayPointItem::WPInserted(const int &onumber, WayPointItem *waypoint)
|
||||
|
||||
void WayPointItem::onHomePositionChanged(internals::PointLatLng homepos, float homeAltitude)
|
||||
{
|
||||
if (myType == relative) {
|
||||
coord = map->Projection()->translate(homepos, relativeCoord.distance, relativeCoord.bearing);
|
||||
SetAltitude(relativeCoord.altitudeRelative + homeAltitude);
|
||||
emit WPValuesChanged(this);
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
this->update();
|
||||
} else {
|
||||
if (myHome) {
|
||||
map->Projection()->offSetFromLatLngs(myHome->Coord(), coord, relativeCoord.distance, relativeCoord.bearing);
|
||||
relativeCoord.altitudeRelative = Altitude() - homeAltitude;
|
||||
}
|
||||
emit WPValuesChanged(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WayPointItem::WPRenumbered(const int &oldnumber, const int &newnumber, WayPointItem *waypoint)
|
||||
@@ -450,25 +243,12 @@ void WayPointItem::setOpacitySlot(qreal opacity)
|
||||
}
|
||||
void WayPointItem::RefreshToolTip()
|
||||
{
|
||||
QString type_str;
|
||||
|
||||
if (myType == relative) {
|
||||
type_str = "Relative";
|
||||
} else {
|
||||
type_str = "Absolute";
|
||||
}
|
||||
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
|
||||
QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distance) + " Bearing:" + QString::number(relativeCoord.bearing * 180 / M_PI);
|
||||
QString relativeAltitude_str = QString::number(relativeCoord.altitudeRelative);
|
||||
if (Number() != -1) {
|
||||
setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nRelative altitude:%6\nAltitude:%7\nType:%8\n%9").arg(QString::number(numberAdjusted())).arg(description).arg(coord_str).arg(relativeCoord_str).arg(relativeAltitude_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString));
|
||||
} else {
|
||||
setToolTip(QString("Magic WayPoint\nCoordinate:%1\nFrom Home:%2\nAltitude:%3\nType:%4\n%5").arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString));
|
||||
}
|
||||
}
|
||||
|
||||
void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag, bool enabled)
|
||||
{
|
||||
/*
|
||||
if (isMagic) {
|
||||
QGraphicsItem::setFlag(flag, enabled);
|
||||
return;
|
||||
@@ -479,6 +259,7 @@ void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag, bool enabled)
|
||||
picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
QGraphicsItem::setFlag(flag, enabled);
|
||||
}
|
||||
|
||||
@@ -490,27 +271,6 @@ int WayPointItem::snumber = 0;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
float param1;
|
||||
float param2;
|
||||
float param3;
|
||||
float param4;
|
||||
int32_t x; PARAM5 / local: x position in meters * 1e4, global: latitude in degrees * 10^7*
|
||||
int32_t y; PARAM6 / y position: local: x position in meters * 1e4, global: longitude in degrees *10^7
|
||||
float z; PARAM7 / z position: global: altitude in meters (relative or absolute, depending on frame.
|
||||
uint16_t seq; Waypoint ID (sequence number). Starts at zero. Increases monotonically for each waypoint, no gaps in the sequence (0,1,2,3,4)
|
||||
uint16_t command; /*< The scheduled action for the waypoint.
|
||||
uint8_t target_system; /*< System ID*
|
||||
uint8_t target_component; /*< Component ID*
|
||||
uint8_t frame; /*< The coordinate system of the waypoint.
|
||||
uint8_t current; /*< false:0, true:1
|
||||
uint8_t autocontinue; /*< Autocontinue to next waypoint
|
||||
uint8_t mission_type; /*< Mission type.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+48
-168
@@ -70,67 +70,46 @@ class OPMAPWIDGETSHARED_EXPORT WayPointItem : public QObject, public QGraphicsIt
|
||||
#else
|
||||
class WayPointItem : public QObject, public QGraphicsItem {
|
||||
#endif
|
||||
|
||||
Q_OBJECT Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
enum { Type = UserType + 1 };
|
||||
enum wptype { absolute, relative };
|
||||
/**
|
||||
* @brief Constructer
|
||||
*
|
||||
* @param coord coordinates in LatLng of the Waypoint
|
||||
* @param altitude altitude of the WayPoint
|
||||
* @param map pointer to map to use
|
||||
* @return
|
||||
*/
|
||||
WayPointItem(internals::PointLatLng const & coord, int const & altitude, MapGraphicItem *map, wptype type = absolute);
|
||||
WayPointItem(MapGraphicItem *map, bool magicwaypoint);
|
||||
/**
|
||||
* @brief Constructer
|
||||
*
|
||||
* @param coord coordinates in LatLng of the WayPoint
|
||||
* @param altitude altitude of the WayPoint
|
||||
* @param description description fo the WayPoint
|
||||
* @param map pointer to map to use
|
||||
* @return
|
||||
*/
|
||||
WayPointItem(internals::PointLatLng const & coord, int const & altitude, QString const & description, MapGraphicItem *map, wptype type = absolute);
|
||||
WayPointItem(distBearingAltitude const & relativeCoord, QString const & description, MapGraphicItem *map);
|
||||
|
||||
/**
|
||||
* @brief Returns the WayPoint description
|
||||
*
|
||||
* @return QString
|
||||
*/
|
||||
QString Description()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* @brief Sets the WayPoint description
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
void SetDescription(QString const & value);
|
||||
/**
|
||||
* @brief Returns true if WayPoint is Reached
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
//一个航点的属性
|
||||
typedef struct {
|
||||
float param1;
|
||||
float param2;
|
||||
float param3;
|
||||
float param4;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
float z;
|
||||
|
||||
uint16_t seq;
|
||||
uint16_t group;//多组航线
|
||||
|
||||
uint16_t command;
|
||||
uint8_t target_system;
|
||||
uint8_t target_component;
|
||||
uint8_t frame;
|
||||
uint8_t current;
|
||||
uint8_t autocontinue;
|
||||
uint8_t mission_type;
|
||||
}_property;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
WayPointItem(const double &lat, const double &lng, const float &alt, MapGraphicItem *map);
|
||||
|
||||
|
||||
|
||||
|
||||
bool Reached()
|
||||
{
|
||||
return reached;
|
||||
}
|
||||
/**
|
||||
* @brief Sets if WayPoint is Reached
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
|
||||
void SetReached(bool const & value);
|
||||
/**
|
||||
* @brief Returns the WayPoint number
|
||||
*
|
||||
*/
|
||||
|
||||
int Number()
|
||||
{
|
||||
return number;
|
||||
@@ -139,54 +118,25 @@ public:
|
||||
{
|
||||
return number + 1;
|
||||
}
|
||||
/**
|
||||
* @brief Sets WayPoint number
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
|
||||
void SetNumber(int const & value);
|
||||
/**
|
||||
* @brief Returns WayPoint LatLng coordinate
|
||||
*
|
||||
*/
|
||||
|
||||
internals::PointLatLng Coord()
|
||||
{
|
||||
return coord;
|
||||
return 0;//coord;
|
||||
}
|
||||
/**
|
||||
* @brief Sets WayPoint LatLng coordinate
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
|
||||
void SetCoord(internals::PointLatLng const & value);
|
||||
/**
|
||||
* @brief Used if WayPoint number is to be drawn on screen
|
||||
*
|
||||
*/
|
||||
|
||||
bool ShowNumber()
|
||||
{
|
||||
return shownumber;
|
||||
}
|
||||
/**
|
||||
* @brief Used to set if WayPoint number is to be drawn on screen
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
|
||||
void SetShowNumber(bool const & value);
|
||||
/**
|
||||
* @brief Returns the WayPoint altitude
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
float Altitude()
|
||||
{
|
||||
return altitude;
|
||||
}
|
||||
/**
|
||||
* @brief Sets the WayPoint Altitude
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void SetAltitude(const float &value);
|
||||
void setRelativeCoord(distBearingAltitude value);
|
||||
distBearingAltitude getRelativeCoord()
|
||||
@@ -197,113 +147,43 @@ public:
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
void RefreshToolTip();
|
||||
QPixmap picture;
|
||||
QString customString()
|
||||
{
|
||||
return myCustomString;
|
||||
}
|
||||
void setCustomString(QString arg)
|
||||
{
|
||||
myCustomString = arg;
|
||||
}
|
||||
void setFlag(GraphicsItemFlag flag, bool enabled);
|
||||
~WayPointItem();
|
||||
|
||||
static int snumber;
|
||||
void setWPType(wptype type);
|
||||
wptype WPType()
|
||||
{
|
||||
return myType;
|
||||
}
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
private:
|
||||
internals::PointLatLng coord; // coordinates of this WayPoint
|
||||
|
||||
typedef struct {
|
||||
float altitude;//相对海拔
|
||||
float velocity;//当前点速度
|
||||
float radiu;//半径
|
||||
qint8 action;//动作
|
||||
}_waypoint;
|
||||
|
||||
|
||||
|
||||
_property parpertys;
|
||||
|
||||
distBearingAltitude relativeCoord;
|
||||
bool reached;
|
||||
QString description;
|
||||
bool shownumber;
|
||||
bool isDragging;
|
||||
float altitude;
|
||||
MapGraphicItem *map;
|
||||
int number;
|
||||
bool isMagic;
|
||||
|
||||
QGraphicsSimpleTextItem *text;
|
||||
QGraphicsRectItem *textBG;
|
||||
QGraphicsSimpleTextItem *numberI;
|
||||
QGraphicsRectItem *numberIBG;
|
||||
|
||||
QTransform transf;
|
||||
HomeItem *myHome;
|
||||
wptype myType;
|
||||
QString myCustomString;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Called when a WayPoint is deleted
|
||||
*
|
||||
* @param number number of the WayPoint that was deleted
|
||||
*/
|
||||
void WPDeleted(int const & number, WayPointItem *waypoint);
|
||||
/**
|
||||
* @brief Called when a WayPoint is renumbered
|
||||
*
|
||||
* @param oldnumber the old WayPoint number
|
||||
* @param newnumber the new WayPoint number
|
||||
* @param waypoint a pointer to the WayPoint renumbered
|
||||
*/
|
||||
void WPRenumbered(int const & oldnumber, int const & newnumber, WayPointItem *waypoint);
|
||||
/**
|
||||
* @brief Called when a WayPoint is inserted
|
||||
*
|
||||
* @param number the number of the WayPoint
|
||||
* @param waypoint a pointer to the WayPoint inserted
|
||||
*/
|
||||
void WPInserted(int const & number, WayPointItem *waypoint);
|
||||
|
||||
void WPDeleted(int const & number, WayPointItem *waypoint);
|
||||
void WPRenumbered(int const & oldnumber, int const & newnumber, WayPointItem *waypoint);
|
||||
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 Value changes
|
||||
*
|
||||
*/
|
||||
void WPChanged(int Number,double Lat,double Lng);
|
||||
|
||||
|
||||
/**
|
||||
* @brief fires when this WayPoint number changes (not fired if due to a auto-renumbering)
|
||||
*
|
||||
* @param oldnumber this WayPoint old number
|
||||
* @param newnumber this WayPoint new number
|
||||
* @param waypoint a pointer to this WayPoint
|
||||
*/
|
||||
void WPNumberChanged(int const & oldnumber, int const & newnumber, WayPointItem *waypoint);
|
||||
|
||||
/**
|
||||
* @brief Fired when the description, altitude or coordinates change
|
||||
*
|
||||
* @param waypoint a pointer to this WayPoint
|
||||
*/
|
||||
|
||||
void WPValuesChanged(WayPointItem *waypoint);
|
||||
void waypointdoubleclick(WayPointItem *waypoint);
|
||||
void localPositionChanged(QPointF point, WayPointItem *waypoint);
|
||||
|
||||
Reference in New Issue
Block a user