添加指令可以修改参数

This commit is contained in:
hm
2021-07-03 12:14:31 +08:00
parent 5f5795ab2d
commit 3553a97f9f
3 changed files with 127 additions and 139 deletions
+108 -131
View File
@@ -10,8 +10,6 @@ CommandUI::CommandUI(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
this->setAcceptDrops(true);
m_parent = parent; m_parent = parent;
//检测文件夹,如果不存在,那么就新建一个,这里存着所有的qml文件 //检测文件夹,如果不存在,那么就新建一个,这里存着所有的qml文件
QDir *Dir = new QDir; QDir *Dir = new QDir;
@@ -43,17 +41,6 @@ CommandUI::CommandUI(QWidget *parent) :
connect(DoubleClickTimer,SIGNAL(timeout()), connect(DoubleClickTimer,SIGNAL(timeout()),
this,SLOT(DoubleClickTimeout())); this,SLOT(DoubleClickTimeout()));
ui->comboBox_seq->hide();
ui->label_seq->hide();
ui->pushButton_setSeq->hide();
ui->comboBox_uav->hide();
ui->label_uav->hide();
ui->pushButton_setUAV->hide();
} }
CommandUI::~CommandUI() CommandUI::~CommandUI()
@@ -61,30 +48,11 @@ CommandUI::~CommandUI()
delete ui; delete ui;
} }
void CommandUI::wheelEvent(QWheelEvent *event) void CommandUI::wheelEvent(QWheelEvent *e)
{ {
int max = ui->tabWidget_Command->count();
int current = ui->tabWidget_Command->currentIndex();
if(event->delta() < 0)
{
if(current < (max - 1))
{
current++;
ui->tabWidget_Command->setCurrentIndex(current);
}
}
else if(event->delta() > 0)
{
if(current > 0)
{
current--;
ui->tabWidget_Command->setCurrentIndex(current);
}
}
} }
void CommandUI::keyPressEvent(QKeyEvent *event) //键盘按下事件 void CommandUI::keyPressEvent(QKeyEvent *event) //键盘按下事件
{ {
switch(event->key()) switch(event->key())
@@ -97,35 +65,6 @@ void CommandUI::keyPressEvent(QKeyEvent *event) //键盘按下事件
} }
} }
void CommandUI::dragEnterEvent(QDragEnterEvent *event)
{
if(!event->mimeData()->urls()[0].fileName().right(5).compare(tr(".json")))
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}
void CommandUI::dropEvent(QDropEvent *event)
{
const QMimeData *qm = event->mimeData();
QString fileName = qm->urls()[0].toLocalFile();
if(fileName.right(5) == ".json")
{
setCommandFile(fileName);
}
}
void CommandUI::mousePressEvent(QMouseEvent *event) void CommandUI::mousePressEvent(QMouseEvent *event)
{ {
@@ -199,6 +138,7 @@ void CommandUI::updateUI(void)
CommandButton *btn = new CommandButton(ui->tabWidget_Command->widget(info.toObject().find(_PageJsonKey).value().toInt())); CommandButton *btn = new CommandButton(ui->tabWidget_Command->widget(info.toObject().find(_PageJsonKey).value().toInt()));
btn->setParameters(binfo.toObject().find(_rowJsonKey).value().toVariant(), btn->setParameters(binfo.toObject().find(_rowJsonKey).value().toVariant(),
binfo.toObject().find(_colunmJsonKey).value().toVariant(), binfo.toObject().find(_colunmJsonKey).value().toVariant(),
binfo.toObject().find(_noticeJsonKey).value().toVariant(), binfo.toObject().find(_noticeJsonKey).value().toVariant(),
@@ -214,6 +154,8 @@ void CommandUI::updateUI(void)
binfo.toObject().find(_param6JsonKey).value().toVariant(), binfo.toObject().find(_param6JsonKey).value().toVariant(),
binfo.toObject().find(_param7JsonKey).value().toVariant()); binfo.toObject().find(_param7JsonKey).value().toVariant());
btn->show(); btn->show();
btn->raise(); btn->raise();
@@ -455,18 +397,6 @@ void CommandUI::setSecondValue(QVariant value)
m_param7 = value; m_param7 = value;
} }
qDebug() << tr("clicked") << m_name
<< m_param1.toDouble()
<< m_param2.toDouble()
<< m_param3.toDouble()
<< m_param4.toDouble()
<< m_param5.toDouble()
<< m_param6.toDouble()
<< m_param7.toDouble()
<< m_command
<< m_confirm;
emit cmd_long(m_param1.toDouble(), emit cmd_long(m_param1.toDouble(),
m_param2.toDouble(), m_param2.toDouble(),
m_param3.toDouble(), m_param3.toDouble(),
@@ -478,8 +408,35 @@ void CommandUI::setSecondValue(QVariant value)
} }
void CommandUI::setParamValue(QVariant value)
{
emit showMessage(tr("无人机 %1 %2 %3 %4")
.arg(QString::number(m_currentSys))
.arg(m_name)
.arg(m_param1.toString())
.arg(value.toString()));
//找到要编辑的,然后把数字赋值过去
/*
bool flag = false;
m_param3.toDouble(&flag);
if(!flag)
{
m_param3 = value;
}
*/
m_param3 = value;
emit WriteParam(m_currentSys,1,m_param1,m_param2,m_param3);
}
void CommandUI::on_commandClicked() void CommandUI::on_commandClicked()
{ {
//找到消息的发送者 //找到消息的发送者
CommandButton *btn = qobject_cast<CommandButton *>(sender()); CommandButton *btn = qobject_cast<CommandButton *>(sender());
@@ -497,44 +454,37 @@ void CommandUI::on_commandClicked()
m_param7 = btn->Param7(); m_param7 = btn->Param7();
uint32_t dialogValue = btn->Dialog().toInt(); int32_t dialogValue = btn->Dialog().toInt();
if(dialogValue != 0)
switch (dialogValue) {
case -1://param
{ {
if(dialogValue == 1)
{
//根据这个comfirm 确定要输入的参数
Confirm *confirmor = new Confirm(this);
confirmor->setGeometry(0,0,this->width(),this->height());
//设置警告界面
confirmor->setNotice(btn->Notice().toString());
connect(confirmor,SIGNAL(confirmValue(QVariant)),
this,SLOT(setSecondConfirm(QVariant)));
confirmor->show();
}
else if(dialogValue == 2)
{
//value 确定要输入的参数 //value 确定要输入的参数
Inputter *inputter = new Inputter(this); Inputter *inputter = new Inputter(this);
inputter->setGeometry(0,0,this->width(),this->height()); inputter->setGeometry(0,0,this->width(),this->height());
//设置警告界面 //设置警告界面
inputter->setLabel(btn->Notice()); QString str;
str.append(tr("set parameter \n"));
str.append(m_param1.toString());
str.append(" ");
str.append(m_param2.toString());
str.append("\n");
str.append(btn->Notice().toString());
inputter->setLabel(str);
connect(inputter,SIGNAL(confirmValue(QVariant)), connect(inputter,SIGNAL(confirmValue(QVariant)),
this,SLOT(setSecondValue(QVariant))); this,SLOT(setParamValue(QVariant)));
inputter->show(); inputter->show();
}
//qDebug() << "Notice:" << btn->Notice();
} }break;
else case 0:{
{
btn->setProperty("state",state::failure); btn->setProperty("state",state::failure);
btn->style()->unpolish(btn); btn->style()->unpolish(btn);
btn->style()->polish(btn); btn->style()->polish(btn);
@@ -547,18 +497,48 @@ void CommandUI::on_commandClicked()
m_param6.toDouble(), m_param6.toDouble(),
m_param7.toDouble(), m_param7.toDouble(),
m_command,m_confirm); m_command,m_confirm);
} }break;
case 1:{
//根据这个comfirm 确定要输入的参数
Confirm *confirmor = new Confirm(this);
confirmor->setGeometry(0,0,this->width(),this->height());
qDebug() << tr("clicked") << btn->text() //设置警告界面
<< m_param1 confirmor->setNotice(btn->Notice().toString());
<< m_param2
<< m_param3 connect(confirmor,SIGNAL(confirmValue(QVariant)),
<< m_param4 this,SLOT(setSecondConfirm(QVariant)));
<< m_param5
<< m_param6 confirmor->show();
<< m_param7 }break;
<< m_command case 2:{
<< m_confirm; //value 确定要输入的参数
Inputter *inputter = new Inputter(this);
inputter->setGeometry(0,0,this->width(),this->height());
//设置警告界面
inputter->setLabel(btn->Notice());
connect(inputter,SIGNAL(confirmValue(QVariant)),
this,SLOT(setSecondValue(QVariant)));
inputter->show();
}break;
default:{
btn->setProperty("state",state::failure);
btn->style()->unpolish(btn);
btn->style()->polish(btn);
emit cmd_long(m_param1.toDouble(),
m_param2.toDouble(),
m_param3.toDouble(),
m_param4.toDouble(),
m_param5.toDouble(),
m_param6.toDouble(),
m_param7.toDouble(),
m_command,m_confirm);
}break;
}
} }
@@ -596,7 +576,14 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result)
{ {
isFundSender = true; isFundSender = true;
if(flag)
{
btn->setProperty("state",state::success);
}
else
{
btn->setProperty("state",state::failure);
}
switch (result) { switch (result) {
@@ -628,14 +615,6 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result)
break; break;
} }
if(flag)
{
btn->setProperty("state",state::success);
}
else
{
btn->setProperty("state",state::failure);
}
btn->style()->unpolish(btn); btn->style()->unpolish(btn);
btn->style()->polish(btn); btn->style()->polish(btn);
@@ -657,18 +636,9 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result)
{ {
if(string.size() > 0) if(string.size() > 0)
{ {
QVariant flag; QTextToSpeech *tts = new QTextToSpeech();
Config *cfg = new Config(); tts->say(string);
tts->deleteLater();
cfg->getTTS(&flag);
if(flag.toBool())
{
QTextToSpeech *tts = new QTextToSpeech();
tts->say(string);
tts->deleteLater();
}
emit showMessage(string); emit showMessage(string);
} }
@@ -723,6 +693,13 @@ void CommandUI::addVehicles(int sysid, int compid)
} }
void CommandUI::CurrentUAV(int id,int comp)
{
m_currentSys = id;
m_currentComp = comp;
}
void CommandUI::setPointCount(QList<int> nums) void CommandUI::setPointCount(QList<int> nums)
{ {
ui->comboBox_seq->clear(); ui->comboBox_seq->clear();
+13 -8
View File
@@ -38,9 +38,7 @@
#include "Config/Config.h" #include "Config/Config.h"
#include "QDragEnterEvent"
#include "QDropEvent"
#include "QMimeData"
#include "QMessageBox" #include "QMessageBox"
namespace Ui { namespace Ui {
@@ -63,14 +61,11 @@ public:
~CommandUI(); ~CommandUI();
protected: protected:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *e);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void loadCommandJson(const QString& jsonFilename); void loadCommandJson(const QString& jsonFilename);
public slots: public slots:
@@ -85,6 +80,9 @@ public slots:
void setCurrent(QVariant value); void setCurrent(QVariant value);
void setPointCount(QList<int> nums); void setPointCount(QList<int> nums);
void CurrentUAV(int id, int comp);
signals: signals:
void Accepted(bool flag,uint16_t command,uint8_t result); void Accepted(bool flag,uint16_t command,uint8_t result);
@@ -96,6 +94,8 @@ signals:
void cmd_long( float param1,float param2,float param3,float param4,float param5,float param6,float param7,uint16_t command,uint8_t confirmation); void cmd_long( float param1,float param2,float param3,float param4,float param5,float param6,float param7,uint16_t command,uint8_t confirmation);
void WriteParam(uint8_t m_sysid, uint8_t m_compid ,QVariant id,QVariant type,QVariant value);
/* /*
void searchallPoint(void); void searchallPoint(void);
void searchallUav(void); void searchallUav(void);
@@ -110,7 +110,7 @@ private slots:
void setSecondConfirm(QVariant value); void setSecondConfirm(QVariant value);
void setSecondValue(QVariant value); void setSecondValue(QVariant value);
void setParamValue(QVariant value);
@@ -140,6 +140,7 @@ private:
const char* _rowJsonKey = "row"; const char* _rowJsonKey = "row";
const char* _colunmJsonKey = "column"; const char* _colunmJsonKey = "column";
const char* _typeJsonKey = "Type";
const char* _noticeJsonKey = "Notice"; const char* _noticeJsonKey = "Notice";
const char* _param1JsonKey = "param1"; const char* _param1JsonKey = "param1";
const char* _param2JsonKey = "param2"; const char* _param2JsonKey = "param2";
@@ -172,6 +173,7 @@ private:
QString m_name = 0; QString m_name = 0;
QVariant m_Type = 0;//0 cmd 1 param
QVariant m_param1 = 0; QVariant m_param1 = 0;
QVariant m_param2 = 0; QVariant m_param2 = 0;
QVariant m_param3 = 0; QVariant m_param3 = 0;
@@ -186,6 +188,9 @@ private:
int m_currentSeq = 0; int m_currentSeq = 0;
int m_currentSys = 1;
int m_currentComp = 1;
}; };
#endif // COMMANDUI_H #endif // COMMANDUI_H
+6
View File
@@ -255,6 +255,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(map,SIGNAL(PointNumber(QList<int>)), connect(map,SIGNAL(PointNumber(QList<int>)),
commandUI,SLOT(setPointCount(QList<int>))); commandUI,SLOT(setPointCount(QList<int>)));
connect(map,SIGNAL(uav_selected(int,int)),
commandUI,SLOT(CurrentUAV(int,int)),Qt::DirectConnection);
/* /*
connect(map,&mapcontrol::OPMapWidget::PointNumber, connect(map,&mapcontrol::OPMapWidget::PointNumber,
commandUI,&CommandUI::setPointCount,Qt::DirectConnection); commandUI,&CommandUI::setPointCount,Qt::DirectConnection);
@@ -372,6 +375,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(dlink->mavlinknode->Commander,SIGNAL(commandAccepted(bool,uint16_t,uint8_t)), connect(dlink->mavlinknode->Commander,SIGNAL(commandAccepted(bool,uint16_t,uint8_t)),
commandUI,SLOT(commandAccepted(bool,uint16_t,uint8_t)),Qt::DirectConnection); commandUI,SLOT(commandAccepted(bool,uint16_t,uint8_t)),Qt::DirectConnection);
connect(commandUI,SIGNAL(WriteParam(uint8_t,uint8_t,QVariant,QVariant,QVariant)),
dlink->mavlinknode->Parameter,SLOT(WriteCmd2(uint8_t,uint8_t,QVariant,QVariant,QVariant)),Qt::DirectConnection);
//check ----- dlink //check ----- dlink
connect(checkUI,SIGNAL(cmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)), connect(checkUI,SIGNAL(cmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),
dlink->mavlinknode->Commander,SLOT(WriteCmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),Qt::DirectConnection); dlink->mavlinknode->Commander,SLOT(WriteCmd_long(float,float,float,float,float,float,float,uint16_t,uint8_t)),Qt::DirectConnection);