添加了测量界面,并完成功能

This commit is contained in:
hm
2022-06-10 17:21:23 +08:00
parent b0944d3561
commit 13eed26865
19 changed files with 1090 additions and 878 deletions
+2
View File
@@ -207,6 +207,7 @@ void PureProjection::FromCartesianTGeodetic(const double &X, const double &Y, co
}
double PureProjection::courseBetweenLatLng(PointLatLng const & p1, PointLatLng const & p2)
{
double lon1 = p1.Lng() * (M_PI / 180);
double lat1 = p1.Lat() * (M_PI / 180);
double lon2 = p2.Lng() * (M_PI / 180);
@@ -230,6 +231,7 @@ double PureProjection::DistanceBetweenLatLng(PointLatLng const & p1, PointLatLng
double d = R * c;
return d;
}
void PureProjection::offSetFromLatLngs(PointLatLng p1, PointLatLng p2, double &distance, double &bearing)
+31 -1
View File
@@ -107,6 +107,33 @@ void MeasureLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
font.setFamily("黑体");//非衬线
painter->setFont(font);
painter->drawText(line().p2().x(),line().p2().y() - 5,QString("%1km %2°").arg(QString::number(distance * 0.001,'f',3)).arg(QString::number(bearing * 57.3,'f',1)));
painter->save();
painter->setOpacity(0.8);
painter->setPen(Qt::NoPen);
painter->setBrush(QColor("#FFFFFF"));
painter->drawEllipse(line().p1(),5,5);
painter->drawEllipse(line().p2(),5,5);
painter->restore();
//画字
painter->save();
painter->setOpacity(1);
font.setWeight(QFont::ExtraBold);
font.setFamily("Arial");//非衬线
font.setPixelSize(8);
painter->setFont(font);
myPen.setWidth(1);
myPen.setColor(QColor("#000000"));
painter->setPen(myPen);
painter->drawText(QRect(line().p1().x() - 20,line().p1().y()-5,40,10),Qt::AlignCenter,QString::number(1));
painter->drawText(QRect(line().p2().x() - 20,line().p2().y()-5,40,10),Qt::AlignCenter,QString::number(2));
painter->restore();
}
@@ -152,6 +179,8 @@ void MeasureLine::setFrom(internals::PointLatLng p)
my_map->Projection()->offSetFromLatLngs(source,destination,distance,bearing);
emit Lineinfo(distance,bearing);
refreshLocations();
update();
@@ -164,8 +193,9 @@ void MeasureLine::setTo(internals::PointLatLng p)
my_map->Projection()->offSetFromLatLngs(source,destination,distance,bearing);
refreshLocations();
emit Lineinfo(distance,bearing);
refreshLocations();
update();
}
+4
View File
@@ -85,6 +85,10 @@ private:
double bearing;
signals:
void Lineinfo(qreal dis,qreal bearing);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
public slots:
+52 -20
View File
@@ -171,6 +171,12 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
measureline->hide();
connect(measureline,SIGNAL(Lineinfo(qreal,qreal)),
this,SIGNAL(Lineinfo(qreal,qreal)));
NoOperationTimer = new QTimer(this);
connect(NoOperationTimer,SIGNAL(timeout()),
this,SLOT(NOPTimeout()));
@@ -223,6 +229,9 @@ void OPMapWidget::UAVTip_clicked(bool flag)
void OPMapWidget::ruler_clicked(void)
{
emit setrulerClicked();
if(isMeasure)
{
isMeasure = false;
@@ -279,20 +288,6 @@ void OPMapWidget::ruler_clicked(void)
void OPMapWidget::table_clicked(void)
{
emit settableClicked();
/*
if(missiontable)
{
if(missiontable->isHidden())
{
missiontable->show();
}
else
{
missiontable->hide();
}
}
*/
}
@@ -704,12 +699,14 @@ void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
QPointF p = event->pos();
p = map->mapFromParent(p);
point_end = map->FromLocalToLatLng(p.x(), p.y());
//measurenumber = 1;
emit mousePosition(point_end.Lat(),point_end.Lng());
if(measureline)
{
if(measurenumber == 2)//取了第一个点后
{
emit MeasurePosition(measurenumber,point_end.Lat(),point_end.Lng());
measureline->setTo(point_end);
}
}
@@ -765,19 +762,24 @@ void OPMapWidget::mousePressEvent(QMouseEvent *event)
QPointF p = event->pos();
p = map->mapFromParent(p);
point_begin = map->FromLocalToLatLng(p.x(), p.y());
emit MeasurePosition(measurenumber,point_begin.Lat(),point_begin.Lng());
measurenumber ++;
if(measureline)
{
measureline->setFrom(point_begin);
}
}
else
{
QPointF p = event->pos();
p = map->mapFromParent(p);
point_end = map->FromLocalToLatLng(p.x(), p.y());
emit MeasurePosition(measurenumber,point_end.Lat(),point_end.Lng());
measurenumber = 1;
if(measureline)
@@ -814,14 +816,19 @@ void OPMapWidget::mouseReleaseEvent(QMouseEvent *event)
emit MouseReleaseEvent(event);
if(event->button() == Qt::RightButton)
/*
if(isMeasure)
{
if(isMeasure)
if(event->button() == Qt::RightButton)
{
ruler_clicked();
}
}
*/
}
void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
@@ -902,7 +909,32 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
emit MouseDoubleClickEvent(event);
}
void OPMapWidget::MeasureValueChanged(int num,qreal value)
{
if(measureline)
{
switch (num) {
case 1:
point_begin.SetLat(value);
measureline->setFrom(point_begin);
break;
case 2:
point_begin.SetLng(value);
measureline->setFrom(point_begin);
break;
case 3:
point_end.SetLat(value);
measureline->setTo(point_end);
break;
case 4:
point_end.SetLng(value);
measureline->setTo(point_end);
break;
default:
break;
}
}
}
////////////////WAYPOINT////////////////////////
+13
View File
@@ -543,6 +543,7 @@ signals:
void ripfinished();
void settableClicked(void);
void setrulerClicked(void);
void showMessage(const QString &message,int TimeOut = 0);
@@ -680,6 +681,13 @@ signals:
void clearTable();
void mousePosition(qreal lat,qreal lng);
void MeasurePosition(int num,qreal lat,qreal lng);
void Lineinfo(qreal dis,qreal bearing);
public slots:
void getAllPoints(int group);
@@ -796,6 +804,11 @@ public slots:
void userRipMap(bool start,qreal lat_l,qreal lng_l,qreal lat_r,qreal lng_r,qint8 zoom);
void MeasureValueChanged(int num,qreal value);
};
}
#endif // OPMAPWIDGET_H
-98
View File
@@ -1,98 +0,0 @@
#include "ruledialog.h"
#include "ui_ruledialog.h"
#include "qmessagebox.h"
RuleDialog::RuleDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::RuleDialog)
{
ui->setupUi(this);
setWindowFlags(Qt::WindowStaysOnTopHint);
setUrlFactory = new core::UrlFactory;
CurrentPoint = 1;
}
RuleDialog::~RuleDialog()
{
delete ui;
}
double RuleDialog::GetDiatance(internals::PointLatLng P1,internals::PointLatLng P2)
{
double EarthRadiusKm = 6378.137;
double dLat1InRad = P1.Lat() * (M_PI / 180);
double dLong1InRad = P1.Lng() * (M_PI / 180);
double dLat2InRad = P2.Lat() * (M_PI / 180);
double dLong2InRad = P2.Lng() * (M_PI / 180);
double dLongitude = dLong2InRad - dLong1InRad;
double dLatitude = dLat2InRad - dLat1InRad;
double a = pow(sin(dLatitude / 2), 2) + cos(dLat1InRad) * cos(dLat2InRad) * pow(sin(dLongitude / 2), 2);
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
double dDistance = EarthRadiusKm * c;
return dDistance;
}
double RuleDialog::GetHeading(internals::PointLatLng P1,internals::PointLatLng P2)
{
double temp;
double mLat = P2.Lat() - P1.Lat();
double mLon = (P2.Lng() - P1.Lng())* cos(((P2.Lat() + P1.Lat())/2)* 0.0174532925);
temp = 90.0 + atan2(-mLat, mLon) * 57.2957795;
if(temp < 0)temp += 360.0;
return temp;
}
void RuleDialog::RulePoint(internals::PointLatLng LatLng)
{
switch(CurrentPoint) {
case 1:{
Point1.SetLat(LatLng.Lat());
Point1.SetLng(LatLng.Lng());
ui->FirstPointLatitude->setText(QString::number(LatLng.Lat(),'f',8));
ui->FirstPointLongitude->setText(QString::number(LatLng.Lng(),'f',8));
CurrentPoint = 2;
} break;
case 2:{
Point2.SetLat(LatLng.Lat());
Point2.SetLng(LatLng.Lng());
ui->SecondPointLatitude->setText(QString::number(LatLng.Lat(),'f',8));
ui->SecondPointLongitude->setText(QString::number(LatLng.Lng(),'f',8));
} break;
default: LatLng = LatLng;
break;
}
}
void RuleDialog::ShowMousePos(internals::PointLatLng LatLng)
{
ui->MouseLatitude->setText(QString::number(LatLng.Lat(),'f',8));
ui->MouseLongitude->setText(QString::number(LatLng.Lng(),'f',8));
}
void RuleDialog::on_SelectFirstPointButton_clicked()
{
CurrentPoint = 1;
emit GetPoint(1);
}
void RuleDialog::on_SelectSecondPointButton_clicked()
{
CurrentPoint = 2;
emit GetPoint(2);
}
void RuleDialog::on_ConformButton_clicked()
{
double Distance;
Distance = GetDiatance(Point1,Point2);
ui->TwoPointDistance->setText(QString::number(Distance,'f',6) + "km");
double Heading;
Heading = GetHeading(Point1,Point2);
ui->TwoPointAngle->setText(QString::number(Heading,'f',2) + "°");
CurrentPoint = 1;//获取结束后从新选择第一点
}
-62
View File
@@ -1,62 +0,0 @@
#ifndef RULEDIALOG_H
#define RULEDIALOG_H
#include <QDialog>
#include "urlfactory.h"
#include "opmapwidget.h"
#include "qmessagebox.h"
namespace Ui {
class RuleDialog;
}
#ifdef QtopmapWidget
#include <mapwidgetglobal.h>
class OPMAPWIDGETSHARED_EXPORT RuleDialog : public QDialog {
#else
class RuleDialog : public QDialog
{
#endif
Q_OBJECT
public:
enum WindowsId{ ID = 5 };
explicit RuleDialog(QWidget *parent = 0);
~RuleDialog();
signals:
void isWindowClose(char);
void GetPoint(quint8);
private slots:
double GetDiatance(internals::PointLatLng P1,internals::PointLatLng P2);
double GetHeading(internals::PointLatLng P1,internals::PointLatLng P2);
void RulePoint(internals::PointLatLng LatLng);
void ShowMousePos(internals::PointLatLng LatLng);
void on_SelectFirstPointButton_clicked();
void on_SelectSecondPointButton_clicked();
void on_ConformButton_clicked();
private:
Ui::RuleDialog *ui;
core::UrlFactory *setUrlFactory;
internals::PointLatLng Point1;
internals::PointLatLng Point2;
quint8 CurrentPoint;
QMessageBox *Box1;
};
#endif // RULEDIALOG_H
-302
View File
@@ -1,302 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RuleDialog</class>
<widget class="QDialog" name="RuleDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>279</width>
<height>210</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>210</height>
</size>
</property>
<property name="windowTitle">
<string>测量</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>鼠标点位置</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="MouseLatitude">
<property name="font">
<font>
<family>微软雅黑</family>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="MouseLongitude">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>第一点坐标</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="FirstPointLatitude">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="FirstPointLongitude">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>两点距离</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="TwoPointDistance">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(0, 0, 255);</string>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="SelectFirstPointButton">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>选取第一点</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="SelectSecondPointButton">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>选取第二点</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ConformButton">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>第二点坐标</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="SecondPointLatitude">
<property name="font">
<font>
<family>微软雅黑</family>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="SecondPointLongitude">
<property name="font">
<font>
<family>微软雅黑</family>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>一点指向二点与正北夹角</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="TwoPointAngle">
<property name="font">
<font>
<family>微软雅黑</family>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>