This commit is contained in:
2020-07-02 17:53:47 +08:00
parent 882e35e99d
commit cc0f38307a
6 changed files with 128 additions and 37 deletions
+42 -31
View File
@@ -5,8 +5,8 @@ namespace mapcontrol {
AltitudeItem::AltitudeItem(MapGraphicItem *map, QColor background) : myMap(map), myColor(background)
{
this->setFlag(QGraphicsItem::ItemIsMovable, false);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
@@ -16,9 +16,9 @@ AltitudeItem::AltitudeItem(MapGraphicItem *map, QColor background) : myMap(map),
this->setZValue(4);
Elevation = 300;
Elevation = 0;
Altitude = 100;
Altitude = 0;
@@ -51,42 +51,33 @@ void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
if(Altitude >= Elevation)
{
//画海拔
ePen.setColor(QColor("#5CACEE"));
ePen.setColor(QColor("#32CD32"));
painter->setPen(ePen);
painter->setBrush(QColor("#5CACEE"));
painter->setBrush(QColor("#32CD32"));
painter->drawRect(1,
this->boundingRect().height() *(1 - (Altitude - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
(this->boundingRect().height() - this->boundingRect().width()) *(1 - (Altitude - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
this->boundingRect().width() - 2,
this->boundingRect().height() * (Altitude - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min));
//画地形高度
ePen.setColor(QColor("#8B5A2B"));
ePen.setColor(QColor("#B8860B"));
painter->setPen(ePen);
painter->setBrush(QColor("#8B5A2B"));
painter->setBrush(QColor("#B8860B"));
painter->drawRect(1,
this->boundingRect().height() *(1 - (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
(this->boundingRect().height() - this->boundingRect().width()) *(1 - (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
this->boundingRect().width() - 2,
this->boundingRect().height() * (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min));
}
else
{
//画地形高度
ePen.setColor(QColor("#8B5A2B"));
ePen.setColor(QColor("#EE4000"));
painter->setPen(ePen);
painter->setBrush(QColor("#8B5A2B"));
painter->setBrush(QColor("#EE4000"));
painter->drawRect(1,
this->boundingRect().height() *(1 - (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
(this->boundingRect().height() - this->boundingRect().width()) *(1 - (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
this->boundingRect().width() - 2,
this->boundingRect().height() * (Elevation - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min));
//画海拔
ePen.setColor(QColor("#5CACEE"));
painter->setPen(ePen);
painter->setBrush(QColor("#5CACEE"));
painter->drawRect(1,
this->boundingRect().height() *(1 - (Altitude - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min)),
this->boundingRect().width() - 2,
this->boundingRect().height() * (Altitude - AltitudeItem::min) / (AltitudeItem::max - AltitudeItem::min));
}
@@ -136,6 +127,9 @@ void AltitudeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
qDebug() << "mousePressEvent";
if (event->button() == Qt::LeftButton) {
isDragging = true;
pos_old = event->scenePos();
}
@@ -149,7 +143,7 @@ void AltitudeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
qDebug() << "mouseReleaseEvent";
if (event->button() == Qt::LeftButton) {
isDragging = false;
}
QGraphicsItem::mouseReleaseEvent(event);
@@ -162,15 +156,34 @@ void AltitudeItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
}
void AltitudeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
//qDebug() << event;
if (isDragging) {
//this->setPos(event->pos());
/*
qreal x_diff = pos_old.x() - event->scenePos().x();
qreal y_diff = pos_old.y() - event->scenePos().y();
qDebug() << pos_old.x() << x_diff;
foreach(QGraphicsItem * i, myMap->childItems()) {
AltitudeItem *w = qgraphicsitem_cast<AltitudeItem *>(i);
if (w) {
w->setPos(event->scenePos().x(),w->pos().y());
}
}
*/
}
QGraphicsItem::mouseMoveEvent(event);
//QGraphicsItem::mouseMoveEvent(event);
}
void AltitudeItem::setNumber(int value)
{
number = value;
update();
}
@@ -180,7 +193,6 @@ void AltitudeItem::setElevation(float value)
{
Elevation = value;
if(value > AltitudeItem::max)
{
AltitudeItem::max = value;
@@ -191,14 +203,13 @@ void AltitudeItem::setElevation(float value)
AltitudeItem::min = value;
}
update();
}
void AltitudeItem::setAltitude(float value)
{
Altitude = value;
if(value > max)
{
max = value;
@@ -208,11 +219,11 @@ void AltitudeItem::setAltitude(float value)
{
min = value;
}
//检查当前所有的点的最大最小值
update();
}
float AltitudeItem::max = 500;
float AltitudeItem::max = 1;
float AltitudeItem::min = 0;
}
+9 -3
View File
@@ -13,8 +13,7 @@
namespace mapcontrol {
class WayPointItem;
class OPMapWidget;
//class OPMapWidget;
#ifdef QtopmapWidget
#include <mapwidgetglobal.h>
@@ -37,7 +36,10 @@ public:
myColor = color;
}
int Number(void)
{
return number;
}
static float max;
static float min;
@@ -57,6 +59,10 @@ private:
int number;
QPointF pos_old;
protected:
+61 -3
View File
@@ -835,12 +835,19 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
connect(item, SIGNAL(localPositionChanged(QPointF, WayPointItem *)), this, SLOT(WPLocalChanged(QPointF, WayPointItem *)), Qt::DirectConnection);
connect(item,SIGNAL(SetCurrent(int)),
this,SIGNAL(setCurrent(int)), Qt::DirectConnection);
connect(item,SIGNAL(ElevationChanged(int,double)),
this,SLOT(ElevationChanged(int,double)), Qt::DirectConnection);
connect(item,SIGNAL(AltitudeChanged(int,double)),
this,SLOT(AltitudeChanged(int,double)), Qt::DirectConnection);
//生成后立即选中,并且把信息发给ui界面
setSelectedWP(item);
item->emitWPProperty();
@@ -1370,4 +1377,55 @@ void OPMapWidget::setMapTypes(QVariant value)
this->SetMapType(Helper::MapTypeFromString(value.toString()));
}
void OPMapWidget::ElevationChanged(int seq,double value)
{
foreach(QGraphicsItem * i, map->childItems()) {
AltitudeItem *w = qgraphicsitem_cast<AltitudeItem *>(i);
if (w)
{
if(w->Number() == seq)
{
w->setElevation(value);
break;
}
}
}
}
void OPMapWidget::AltitudeChanged(int seq,double value)
{
foreach(QGraphicsItem * i, map->childItems()) {
AltitudeItem *w = qgraphicsitem_cast<AltitudeItem *>(i);
if (w)
{
if(w->Number() == seq)
{
w->setAltitude(value);
break;
}
}
}
}
}
+6
View File
@@ -572,6 +572,12 @@ public slots:
void setMapTypes(QVariant value);
void ElevationChanged(int seq,double value);
void AltitudeChanged(int seq,double value);
void receivedPoint(float param1,float param2,float param3,float param4,
int32_t x,int32_t y,float z,
uint16_t seq,
+8
View File
@@ -664,6 +664,8 @@ void WayPointItem::setWPProperty(float param1,float param2,float param3,float pa
ElevationTrig();
emit AltitudeChanged(this->Number(),property.z);
}
}
@@ -726,6 +728,8 @@ void WayPointItem::SetDefault(double lat,double lng,float alt,uint16_t seq)
ElevationTrig();
emit AltitudeChanged(this->Number(),property.z);
//...
}
@@ -762,6 +766,9 @@ void WayPointItem::SetLng(double value)
void WayPointItem::SetAlt(float value)
{
property.z = value;
emit AltitudeChanged(this->Number(),property.z);
}
void WayPointItem::SetSeq(uint16_t value)
@@ -851,6 +858,7 @@ void WayPointItem::ElevationUpdate(QNetworkReply *reply)
qDebug() << "Seq:" << this->Number() << "Elevation" << Elevation;
emit ElevationChanged(this->Number(),Elevation);
}
isElevationLock = false;
+2
View File
@@ -376,6 +376,8 @@ signals:
void aboutToBeDeleted(WayPointItem *);
void ElevationChanged(int seq,double value);
void AltitudeChanged(int seq,double value);
friend class propertyui;