完成航点高程读取
This commit is contained in:
+2
-19
@@ -5,14 +5,6 @@
|
||||
#include "QHBoxLayout"
|
||||
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
@@ -216,19 +208,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
menuBarUI->showMessage(tr("存在bug,连接界面udp数字输入的.可以超过3个,不合理"));
|
||||
|
||||
|
||||
|
||||
|
||||
qDebug() << "main window start";
|
||||
|
||||
|
||||
|
||||
//实例化QNetworkAccessManager
|
||||
networkManager=new QNetworkAccessManager(this);
|
||||
//设置get请求数据完成时回调函数getData(QNetworkReply*)
|
||||
connect(networkManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(getData(QNetworkReply *)));
|
||||
|
||||
//创建请求对象
|
||||
QNetworkRequest request=QNetworkRequest(QUrl("https://api.airmap.com/elevation/v1/ele/?points=30,32"));
|
||||
//发送get请求
|
||||
networkManager->get(request);
|
||||
}
|
||||
|
||||
//对返回的数据进行处理
|
||||
|
||||
@@ -108,8 +108,6 @@ protected:
|
||||
|
||||
QTimer *updateTimer;
|
||||
|
||||
QNetworkAccessManager *networkManager = nullptr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ void Cache::CacheGeocoder(const QString &urlEnd, const QString &content)
|
||||
#ifdef DEBUG_CACHE
|
||||
qDebug() << "CacheGeocoder: Filename:" << filename;
|
||||
#endif // DEBUG_CACHE
|
||||
QFileInfo File(filename);;
|
||||
QFileInfo File(filename);
|
||||
QDir dir = File.absoluteDir();
|
||||
QString path = dir.absolutePath();
|
||||
#ifdef DEBUG_CACHE
|
||||
|
||||
@@ -78,11 +78,11 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
altitudeitem = new AltitudeItem(map,Qt::red);
|
||||
altitudeitem->setParentItem(map);
|
||||
setOverlayOpacity(overlayOpacity);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -828,6 +828,9 @@ 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);
|
||||
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
#include "homeitem.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
#include "QJsonArray"
|
||||
#include "QJsonDocument"
|
||||
#include "QJsonObject"
|
||||
#include "QJsonParseError"
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -297,6 +303,7 @@ void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
qDebug() << "PressEvent isEdit" <<isEdit;
|
||||
//qDebug() << this->parent();
|
||||
|
||||
|
||||
}
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
@@ -325,6 +332,7 @@ void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
emit WPChanged(this->Number(),Coord().Lat(),Coord().Lng());
|
||||
}
|
||||
|
||||
ElevationTrig();
|
||||
//发送航点的属性
|
||||
emit WPProperty(property.param1,property.param2,property.param3,property.param4,
|
||||
property.x,property.y,property.z,
|
||||
@@ -354,6 +362,7 @@ void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
if(isFollowPrevious == false)
|
||||
{
|
||||
|
||||
//ElevationTrig();
|
||||
emit localPositionChanged(this->pos(), this);
|
||||
emit WPValuesChanged(this);
|
||||
}
|
||||
@@ -566,7 +575,14 @@ void WayPointItem::RefreshPos()
|
||||
SetLng(coord.Lng());
|
||||
|
||||
this->setPos(point.X(), point.Y());
|
||||
|
||||
|
||||
//qDebug() << "RefreshPos";
|
||||
|
||||
emit localPositionChanged(this->pos(), this);
|
||||
|
||||
//ElevationUpdate();
|
||||
//ElevationTrig();
|
||||
}
|
||||
|
||||
void WayPointItem::setOpacitySlot(qreal opacity)
|
||||
@@ -646,6 +662,8 @@ void WayPointItem::setWPProperty(float param1,float param2,float param3,float pa
|
||||
|
||||
emit WPFollowPrevious(isFollowPrevious,this);
|
||||
|
||||
ElevationTrig();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,6 +724,8 @@ void WayPointItem::SetDefault(double lat,double lng,float alt,uint16_t seq)
|
||||
|
||||
emit WPFollowPrevious(isFollowPrevious,this);
|
||||
|
||||
ElevationTrig();
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
@@ -778,6 +798,74 @@ void WayPointItem::SetGroup(uint16_t value)
|
||||
}
|
||||
|
||||
|
||||
void WayPointItem::ElevationTrig(void)
|
||||
{
|
||||
if(isElevationLock)
|
||||
{
|
||||
isElevationRequest = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QNetworkAccessManager *networkManager = nullptr;
|
||||
networkManager=new QNetworkAccessManager;
|
||||
|
||||
double lat = this->Coord().Lat();
|
||||
double lng = this->Coord().Lng();
|
||||
|
||||
QString url = QString("https://api.airmap.com/elevation/v1/ele/?points=%1,%2").arg(lat).arg(lng);
|
||||
QNetworkRequest request = QNetworkRequest(QUrl(url));
|
||||
|
||||
connect(networkManager,SIGNAL(finished(QNetworkReply*)),
|
||||
this,SLOT(ElevationUpdate(QNetworkReply *)));
|
||||
|
||||
networkManager->get(request);
|
||||
isElevationLock = true;
|
||||
isElevationRequest = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WayPointItem::ElevationUpdate(QNetworkReply *reply)
|
||||
{
|
||||
QByteArray bytes = reply->readAll();
|
||||
|
||||
QJsonParseError jsonParseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError);
|
||||
if (jsonParseError.error != QJsonParseError::NoError) {
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
if(json.value("status").toString() == "success")
|
||||
{
|
||||
QJsonValue jsonValue = json.value("data");
|
||||
|
||||
if (!jsonValue.isArray()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray Array = jsonValue.toArray();
|
||||
|
||||
Elevation = Array.at(0).toInt();
|
||||
|
||||
qDebug() << "Seq:" << this->Number() << "Elevation" << Elevation;
|
||||
|
||||
}
|
||||
|
||||
isElevationLock = false;
|
||||
|
||||
//结束之后检查一下是不是又触发了,是的话再查一次
|
||||
if(isElevationRequest)
|
||||
{
|
||||
ElevationTrig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==============全局计数===================
|
||||
int WayPointItem::snumber = 0;
|
||||
}
|
||||
|
||||
@@ -255,7 +255,10 @@ public:
|
||||
}
|
||||
|
||||
|
||||
|
||||
double getElevation(void)
|
||||
{
|
||||
return Elevation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -291,6 +294,11 @@ private:
|
||||
wptype myType;
|
||||
QString myCustomString;
|
||||
|
||||
|
||||
double Elevation = 0;
|
||||
bool isElevationRequest = false;
|
||||
bool isElevationLock = false;
|
||||
|
||||
public slots:
|
||||
|
||||
//这个地方还需要好好思考
|
||||
@@ -336,9 +344,9 @@ public slots:
|
||||
uint8_t autocontinue,
|
||||
uint8_t mission_type);
|
||||
|
||||
void ElevationTrig(void);
|
||||
|
||||
|
||||
|
||||
void ElevationUpdate(QNetworkReply *reply);
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user