界面可以跟随改变,已经添加了设置函数

This commit is contained in:
2020-04-27 18:08:03 +08:00
parent 87a189eb3d
commit 8d3a756f92
5 changed files with 250 additions and 353 deletions
+49 -167
View File
@@ -2,7 +2,8 @@
#include "ui_propertyui.h"
#include "QtQmlDepends"
const char* propertyui::_categoryJsonKey = "category";
const char* propertyui::_decimalPlacesJsonKey = "decimalPlaces";
@@ -70,7 +71,17 @@ propertyui::propertyui(QWidget *parent) :
QWidget(parent),
ui(new Ui::propertyui)
{
ui->setupUi(this);
this->adjustSize();
//载入json
_loadMavCmdInfoJson(":/json/MavCmdInfoCommon.json", true);
//给combox添加items
@@ -112,13 +123,15 @@ propertyui::propertyui(QWidget *parent) :
this,SLOT(on_radioButton_clicked()));
}
//如果combox的index或者string改变,那么也要重新建立参数信息
void propertyui::on_comboBox_friendlyName_currentTextChanged(const QString &arg1)
{
rebuildUI(arg1);
@@ -211,11 +224,6 @@ void propertyui::rebuildUI(QString CMD)
//重新载入UI
ui->label_Descript->setText(description());
//隐藏altitude 的描述
ui->label_Alt_description->setHidden(true);
//根据showDetails设置显示
if(isShowDetails == true)
{
@@ -232,16 +240,10 @@ void propertyui::rebuildUI(QString CMD)
//清除所有
clearLayout(ui->frame_Param->layout());
for(QMap<int, MissionCmdParamInfo*>::const_iterator item = _paramInfoMap.begin();item != _paramInfoMap.end();item++)
{
MissionCmdParamInfo* i = item.value();
switch(i->param())
{
case 1:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
@@ -261,164 +263,40 @@ void propertyui::rebuildUI(QString CMD)
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}break;
case 2:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
case 3:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
case 4:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
case 5:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
case 6:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
case 7:
{
QLabel *Label = new QLabel();
Label->setText(i->label());
QLabel *Unit = new QLabel();
Unit->setText(i->units());
if(i->enumStrings().size() != 0)
{
QComboBox *combox = new QComboBox();
combox->addItems(i->enumStrings());
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(combox);
}
else
{
QLineEdit *param = new QLineEdit();
param->setText(QString::number(i->defaultValue(),'f',i->decimalPlaces()));
ui->frame_Param->layout()->addWidget(Label);
ui->frame_Param->layout()->addWidget(param);
//ui->frame_Param->layout()->addWidget(Unit);
}
}
break;
}
}
}
}
void propertyui::setWayPointProperty(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)
{
m_param1 = param1;
m_param2 = param2;
m_param3 = param3;
m_param4 = param4;
m_x = x;
m_y = y;
m_z = z;
m_seq = seq;
m_group = group;
m_command = command;
m_target_system = target_system;
m_target_component = target_component;
m_frame = frame;
m_current = current;
m_autocontinue = autocontinue;
m_mission_type = mission_type;
}
@@ -714,6 +592,10 @@ bool propertyui::loadJsonInfo(const QJsonObject& jsonObject, bool requireFullObj
}
// Read params
//先清除这个参数存储buff
_paramInfoMap.clear();
for (int i=1; i<=7; i++) {
QString paramKey = QString(_paramJsonKeyFormat).arg(i);
+58 -35
View File
@@ -8,7 +8,6 @@
#include "QJsonObject"
#include "QJsonParseError"
#include "QQuickWidget"
#include "QQuickView"
#include "QtQml"
@@ -16,17 +15,10 @@
#include "qqml.h"
#include "QQmlEngine"
#include "QDebug"
#include "mavlink.h"
#include "JsonHelper.h"
#include "QComboBox"
#include "QLineEdit"
#include "QLabel"
@@ -36,13 +28,13 @@
#include "QtQmlDepends"
#ifdef QtopmapWidget
#include <mapwidgetglobal.h>
namespace Ui {
class OPMAPWIDGETSHARED_EXPORT propertyui;
}
class OPMAPWIDGETSHARED_EXPORT MissionCmdParamInfo : public QObject {
#else
class MissionCmdParamInfo : public QObject {
@@ -152,13 +144,7 @@ public:
//#include "waypointitem.h"
#ifdef QtopmapWidget
@@ -183,15 +169,15 @@ public:
~propertyui();
Q_PROPERTY(QString category READ category CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(bool friendlyEdit READ friendlyEdit CONSTANT)
Q_PROPERTY(QString friendlyName READ friendlyName CONSTANT)
Q_PROPERTY(QString rawName READ rawName CONSTANT)
Q_PROPERTY(bool isStandaloneCoordinate READ isStandaloneCoordinate CONSTANT)
Q_PROPERTY(bool specifiesCoordinate READ specifiesCoordinate CONSTANT)
Q_PROPERTY(bool specifiesAltitudeOnly READ specifiesAltitudeOnly CONSTANT)
Q_PROPERTY(int command READ intCommand CONSTANT)
Q_PROPERTY(QString category READ category NOTIFY propertyChanged )
Q_PROPERTY(QString description READ description NOTIFY propertyChanged )
Q_PROPERTY(bool friendlyEdit READ friendlyEdit NOTIFY propertyChanged )
Q_PROPERTY(QString friendlyName READ friendlyName NOTIFY propertyChanged )
Q_PROPERTY(QString rawName READ rawName NOTIFY propertyChanged )
Q_PROPERTY(bool isStandaloneCoordinate READ isStandaloneCoordinate NOTIFY propertyChanged )
Q_PROPERTY(bool specifiesCoordinate READ specifiesCoordinate NOTIFY propertyChanged )
Q_PROPERTY(bool specifiesAltitudeOnly READ specifiesAltitudeOnly NOTIFY propertyChanged )
Q_PROPERTY(int command READ intCommand NOTIFY propertyChanged )
MAV_CMD command(void) const { return _command; }
int intCommand(void) const { return (int)_command; }
@@ -205,15 +191,33 @@ public:
bool specifiesCoordinate (void) const;
bool specifiesAltitudeOnly (void) const;
void _loadMavCmdInfoJson(const QString& jsonFilename, bool baseCommandList);
bool loadJsonInfo(const QJsonObject& jsonObject, bool requireFullObject, QString& errorString);
void setWayPointProperty(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);
public slots:
//void editProperty(QString pro);
Q_SIGNALS:
void propertyChanged(void);
private slots:
void on_comboBox_friendlyName_currentTextChanged(const QString &arg1);
@@ -284,7 +288,26 @@ private:
bool isShowDetails = false;
//QQuickWidget *property_quick = nullptr;
//因为无法使用其他类定义的东西,因此这里自己定义
float m_param1;
float m_param2;
float m_param3;
float m_param4;
int32_t m_x;
int32_t m_y;
float m_z;
uint16_t m_seq;
uint16_t m_group;
uint16_t m_command;
uint8_t m_target_system;
uint8_t m_target_component;
uint8_t m_frame;
uint8_t m_current;
uint8_t m_autocontinue;
uint8_t m_mission_type;
};
+99 -122
View File
@@ -6,33 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>231</width>
<height>452</height>
<width>223</width>
<height>308</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_Last">
<property name="text">
<string>Last</string>
<property name="leftMargin">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Next">
<property name="text">
<string>Next</string>
<property name="bottomMargin">
<number>1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<item row="8" column="0">
<widget class="QFrame" name="frame_Speed">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@@ -81,7 +69,35 @@
</layout>
</widget>
</item>
<item row="5" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_Descript">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_info">
<item>
<widget class="QLabel" name="label_Seq">
<property name="text">
<string>Seq</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_friendlyName"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_ShowAll">
<property name="text">
<string>Details</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QFrame" name="frame_Param">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@@ -90,15 +106,11 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="3" column="0">
<widget class="QLabel" name="label_Param4">
<property name="text">
<string>Param4</string>
</property>
</widget>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_Param1"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_Param4"/>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_Param2"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_Param2">
@@ -107,32 +119,6 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_Param1"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_Param5">
<property name="text">
<string>Lat/X</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_Param6"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit_Param3"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_Param7">
<property name="text">
<string>Alt/Z</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="lineEdit_Param7"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_Param1">
<property name="text">
@@ -140,38 +126,29 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="lineEdit_Param5"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_Param6">
<property name="text">
<string>Lng/Y</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_Param3">
<property name="text">
<string>Param3</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_Param2"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_Descript">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_Direc">
<item>
<widget class="QPushButton" name="pushButton_Last">
<property name="text">
<string>TextLabel</string>
<string>Last</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Next">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_Type">
<item row="0" column="0">
<widget class="QComboBox" name="comboBox_MAV_CMD"/>
</item>
@@ -180,7 +157,7 @@
</item>
</layout>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QFrame" name="frame_Alt">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@@ -188,7 +165,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>1</number>
</property>
@@ -201,7 +178,17 @@
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<property name="spacing">
<number>2</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_Alt_description">
<property name="text">
<string>height</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QRadioButton" name="radioButton_Relative">
@@ -232,40 +219,46 @@
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="lineEdit_Alt"/>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_Alt_description">
<property name="text">
<string>TextLabel</string>
<widget class="QLineEdit" name="lineEdit_Alt">
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<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>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_Seq">
<property name="text">
<string>Seq</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_friendlyName"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_ShowAll">
<property name="text">
<string>Details</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
@@ -286,21 +279,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>lineEdit_Param7</sender>
<signal>textChanged(QString)</signal>
<receiver>lineEdit_Alt</receiver>
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>60</x>
<y>437</y>
</hint>
<hint type="destinationlabel">
<x>23</x>
<y>241</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+7
View File
@@ -427,6 +427,9 @@ void WayPointItem::RefreshPos()
{
core::Point point = map->FromLatLngToLocal(coord);
SetLat(coord.Lat());
SetLng(coord.Lng());
this->setPos(point.X(), point.Y());
emit localPositionChanged(this->pos(), this);
}
@@ -464,8 +467,12 @@ void WayPointItem::SetDefault(double lat,double lng,float alt,uint16_t seq)
property.y = lng * 10e5;
property.z = alt;
property.seq = seq;
property.group = 0;
property.command = MAV_CMD::MAV_CMD_NAV_WAYPOINT;
property.frame = MAV_FRAME::MAV_FRAME_GLOBAL;
property.current = 0;
property.autocontinue = 0;
property.mission_type = 0;
//...
}
+8
View File
@@ -38,6 +38,9 @@
#include "mavlink.h"
#include "propertyui.h"
namespace mapcontrol {
struct distBearingAltitude {
double distance;
@@ -297,6 +300,11 @@ signals:
void localPositionChanged(QPointF point, WayPointItem *waypoint);
void manualCoordChange(WayPointItem *);
void aboutToBeDeleted(WayPointItem *);
friend class propertyui;
};
}
#endif // WAYPOINTITEM_H