|
@@ -1,73 +1,61 @@
|
|
|
#include "projectdialog.h"
|
|
|
-#include "ui_projectdialog.h"
|
|
|
|
|
|
+#include "ui_projectdialog.h"
|
|
|
|
|
|
-ProjectDialog::ProjectDialog(QWidget *parent) :
|
|
|
- QDialog(parent),
|
|
|
- ui(new Ui::ProjectDialog)
|
|
|
-{
|
|
|
+ProjectDialog::ProjectDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ProjectDialog) {
|
|
|
ui->setupUi(this);
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ProjectDialog::validateInput);
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProjectDialog::clearFormData);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::SetComboBoxBlast(const QJsonArray& bapoYuanArray)
|
|
|
-{
|
|
|
- blasterArray =bapoYuanArray;
|
|
|
+void ProjectDialog::SetComboBoxBlast(const QJsonArray &bapoYuanArray) {
|
|
|
+ blasterArray = bapoYuanArray;
|
|
|
ui->comboBoxBlast->clear();
|
|
|
fillComboBox(ui->comboBoxBlast, bapoYuanArray);
|
|
|
ui->comboBoxBlast->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::SetComboBoxOperator(const QJsonArray& anQuanYuanArray)
|
|
|
-{
|
|
|
- operatorArray =anQuanYuanArray;
|
|
|
+void ProjectDialog::SetComboBoxOperator(const QJsonArray &anQuanYuanArray) {
|
|
|
+ operatorArray = anQuanYuanArray;
|
|
|
ui->comboBoxOperator->clear();
|
|
|
fillComboBox(ui->comboBoxOperator, anQuanYuanArray);
|
|
|
ui->comboBoxOperator->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxOperator_currentIndexChanged(int index)
|
|
|
-{
|
|
|
+void ProjectDialog::on_comboBoxOperator_currentIndexChanged(int index) {
|
|
|
if (index >= 0 && index < operatorArray.size()) {
|
|
|
operatorId = operatorArray[index].toObject()["identity"].toString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxBlast_currentIndexChanged(int index)
|
|
|
-{
|
|
|
+void ProjectDialog::on_comboBoxBlast_currentIndexChanged(int index) {
|
|
|
if (index >= 0 && index < blasterArray.size()) {
|
|
|
blasterId = blasterArray[index].toObject()["identity"].toString();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::fillComboBox(QComboBox* comboBox, const QJsonArray& jsonArray) {
|
|
|
+void ProjectDialog::fillComboBox(QComboBox *comboBox, const QJsonArray &jsonArray) {
|
|
|
for (const QJsonValue &value : jsonArray) {
|
|
|
if (value.isObject()) {
|
|
|
QJsonObject obj = value.toObject();
|
|
|
- if (obj.contains("name")) {
|
|
|
- QString name = obj["name"].toString();
|
|
|
+ if (obj.contains("nickName")) {
|
|
|
+ QString name = obj["nickName"].toString();
|
|
|
comboBox->addItem(name);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::SetComboBoxAddress(const QJsonArray& Options)
|
|
|
-{ parentOptions = Options;
|
|
|
- ui->comboBoxAddr->clear();
|
|
|
- for (const QJsonValue &option : Options) {
|
|
|
- ui->comboBoxAddr->addItem(option.toString());
|
|
|
- }
|
|
|
- ui->comboBoxAddr->setCurrentIndex(-1);
|
|
|
+void ProjectDialog::SetComboBoxAddress(const QJsonArray &Options) {
|
|
|
+ parentOptions = Options;
|
|
|
+ ui->comboBoxAddr->clear();
|
|
|
+ for (const QJsonValue &option : Options) {
|
|
|
+ ui->comboBoxAddr->addItem(option.toString());
|
|
|
+ }
|
|
|
+ ui->comboBoxAddr->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::SetComboBoxAddress2(const QString &parentName)
|
|
|
-{
|
|
|
+void ProjectDialog::SetComboBoxAddress2(const QString &parentName) {
|
|
|
ui->comboBoxAddr_2->clear();
|
|
|
for (const QJsonValue &item : dataOptions) {
|
|
|
const QJsonObject &obj = item.toObject();
|
|
@@ -83,8 +71,7 @@ void ProjectDialog::SetComboBoxAddress2(const QString &parentName)
|
|
|
ui->comboBoxAddr_2->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::SetComboBoxAddress3(const QString &childName)
|
|
|
-{
|
|
|
+void ProjectDialog::SetComboBoxAddress3(const QString &childName) {
|
|
|
ui->comboBoxAddr_3->clear();
|
|
|
for (const QJsonValue &item : dataOptions) {
|
|
|
const QJsonArray &childrenArray = item["children"].toArray();
|
|
@@ -106,51 +93,43 @@ void ProjectDialog::SetComboBoxAddress3(const QString &childName)
|
|
|
ui->comboBoxAddr_3->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::setChildOptions( const QJsonArray& newDataOptions)
|
|
|
-{
|
|
|
+void ProjectDialog::setChildOptions(const QJsonArray &newDataOptions) {
|
|
|
dataOptions = newDataOptions;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::SetComboBoxLora(const QString &grandChildName)
|
|
|
-{
|
|
|
-
|
|
|
+void ProjectDialog::SetComboBoxLora(const QString &grandChildName) {
|
|
|
ui->comboBoxLora->clear();
|
|
|
for (const QJsonValue &item : dataOptions) {
|
|
|
- const QJsonArray &childrenArray = item["children"].toArray();
|
|
|
- for (const QJsonValue &child : childrenArray) {
|
|
|
- const QJsonObject &childObj = child.toObject();
|
|
|
- const QJsonArray &grandChildrenArray = childObj["children"].toArray();
|
|
|
- for (const QJsonValue &grandChild : grandChildrenArray) {
|
|
|
- const QJsonObject &grandChildObj = grandChild.toObject();
|
|
|
- if (grandChildObj["name"].toString() == grandChildName) {
|
|
|
- const QJsonArray &greatGrandChildrenArray = grandChildObj["children"].toArray();
|
|
|
- for (const QJsonValue &greatGrandChild : greatGrandChildrenArray) {
|
|
|
- const QJsonObject &greatGrandChildObj = greatGrandChild.toObject();
|
|
|
- qDebug() << "greatGrandChildObj " << greatGrandChildObj;
|
|
|
- QString name = greatGrandChildObj["name"].toString();
|
|
|
- QString loraSn = greatGrandChildObj["loraSn"].toString();
|
|
|
- ui->comboBoxLora->addItem(name);
|
|
|
- nameLoraSnMap.insert(name, loraSn);
|
|
|
- QHash<QString, QString>::const_iterator i;
|
|
|
- for (i = nameLoraSnMap.constBegin(); i != nameLoraSnMap.constEnd(); ++i) {
|
|
|
- qDebug() << "Key:" << i.key() << ", Value:" << i.value();
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ const QJsonArray &childrenArray = item["children"].toArray();
|
|
|
+ for (const QJsonValue &child : childrenArray) {
|
|
|
+ const QJsonObject &childObj = child.toObject();
|
|
|
+ const QJsonArray &grandChildrenArray = childObj["children"].toArray();
|
|
|
+ for (const QJsonValue &grandChild : grandChildrenArray) {
|
|
|
+ const QJsonObject &grandChildObj = grandChild.toObject();
|
|
|
+ if (grandChildObj["name"].toString() == grandChildName) {
|
|
|
+ const QJsonArray &greatGrandChildrenArray = grandChildObj["children"].toArray();
|
|
|
+ for (const QJsonValue &greatGrandChild : greatGrandChildrenArray) {
|
|
|
+ const QJsonObject &greatGrandChildObj = greatGrandChild.toObject();
|
|
|
+ qDebug() << "greatGrandChildObj " << greatGrandChildObj;
|
|
|
+ QString name = greatGrandChildObj["name"].toString();
|
|
|
+ QString loraSn = greatGrandChildObj["loraSn"].toString();
|
|
|
+ ui->comboBoxLora->addItem(name);
|
|
|
+ nameLoraSnMap.insert(name, loraSn);
|
|
|
+ QHash<QString, QString>::const_iterator i;
|
|
|
+ for (i = nameLoraSnMap.constBegin(); i != nameLoraSnMap.constEnd(); ++i) {
|
|
|
+ qDebug() << "Key:" << i.key() << ", Value:" << i.value();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
ui->comboBoxLora->setCurrentIndex(-1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void ProjectDialog::extractNames(const QJsonArray& array, QStringList& names) {
|
|
|
- for (const auto& item : array) {
|
|
|
+void ProjectDialog::extractNames(const QJsonArray &array, QStringList &names) {
|
|
|
+ for (const auto &item : array) {
|
|
|
if (item.isObject()) {
|
|
|
QJsonObject obj = item.toObject();
|
|
|
if (obj.contains("name")) {
|
|
@@ -163,62 +142,49 @@ void ProjectDialog::extractNames(const QJsonArray& array, QStringList& names) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::clearFormData()
|
|
|
-{
|
|
|
- QList<QLineEdit*> lineEdits = findChildren<QLineEdit*>();
|
|
|
- for (QLineEdit* lineEdit : lineEdits) {
|
|
|
+void ProjectDialog::clearFormData() {
|
|
|
+ QList<QLineEdit *> lineEdits = findChildren<QLineEdit *>();
|
|
|
+ for (QLineEdit *lineEdit : lineEdits) {
|
|
|
lineEdit->clear();
|
|
|
}
|
|
|
|
|
|
- QList<QComboBox*> comboBoxes = findChildren<QComboBox*>();
|
|
|
- for (QComboBox* comboBox : comboBoxes) {
|
|
|
+ QList<QComboBox *> comboBoxes = findChildren<QComboBox *>();
|
|
|
+ for (QComboBox *comboBox : comboBoxes) {
|
|
|
comboBox->setCurrentIndex(-1);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxAddr_currentIndexChanged(int index)
|
|
|
-{
|
|
|
+void ProjectDialog::on_comboBoxAddr_currentIndexChanged(int index) {
|
|
|
if (index >= 0 && index < parentOptions.size()) {
|
|
|
QString parentName = parentOptions[index].toString();
|
|
|
SetComboBoxAddress2(parentName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::on_comboBoxAddr_2_currentIndexChanged(int index)
|
|
|
-{
|
|
|
-
|
|
|
+void ProjectDialog::on_comboBoxAddr_2_currentIndexChanged(int index) {
|
|
|
if (index >= -1 && index < childOptions.size()) {
|
|
|
QString childName = childOptions[index].toObject()["name"].toString();
|
|
|
SetComboBoxAddress3(childName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxAddr_3_currentIndexChanged(int index)
|
|
|
-{
|
|
|
-
|
|
|
+void ProjectDialog::on_comboBoxAddr_3_currentIndexChanged(int index) {
|
|
|
if (index >= -1 && index < grandChildOptions.size()) {
|
|
|
QString grandChildName = grandChildOptions[index].toObject()["name"].toString();
|
|
|
SetComboBoxLora(grandChildName);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void ProjectDialog::validateInput()
|
|
|
-{
|
|
|
+void ProjectDialog::validateInput() {
|
|
|
QString detNum = ui->editDetNum->text().trimmed();
|
|
|
QString blastCount = ui->editRegCount->text().trimmed();
|
|
|
QString projectName = ui->editName->text().trimmed();
|
|
|
- QString blastName= ui->comboBoxBlast->currentText().trimmed();
|
|
|
- QString operatorName= ui->comboBoxOperator->currentText().trimmed();
|
|
|
- QString parentAddress= ui->comboBoxAddr->currentText().trimmed();
|
|
|
- QString childAddress= ui->comboBoxAddr_2->currentText().trimmed();
|
|
|
- QString grandChildAddress= ui->comboBoxAddr_3->currentText().trimmed();
|
|
|
- QString loraAddress= ui->comboBoxLora->currentText().trimmed();
|
|
|
-
|
|
|
+ QString blastName = ui->comboBoxBlast->currentText().trimmed();
|
|
|
+ QString operatorName = ui->comboBoxOperator->currentText().trimmed();
|
|
|
+ QString parentAddress = ui->comboBoxAddr->currentText().trimmed();
|
|
|
+ QString childAddress = ui->comboBoxAddr_2->currentText().trimmed();
|
|
|
+ QString grandChildAddress = ui->comboBoxAddr_3->currentText().trimmed();
|
|
|
+ QString loraAddress = ui->comboBoxLora->currentText().trimmed();
|
|
|
|
|
|
if (detNum.isEmpty() || !ui->editDetNum->hasAcceptableInput()) {
|
|
|
QMessageBox::warning(this, "输入错误", "请输入0-10000的数字!");
|
|
@@ -233,7 +199,7 @@ void ProjectDialog::validateInput()
|
|
|
// 拼接 addressUuid
|
|
|
QString addressUuid = parentAddress;
|
|
|
if (!childAddress.isEmpty()) {
|
|
|
- qDebug()<<"childAddress"<<childAddress;
|
|
|
+ qDebug() << "childAddress" << childAddress;
|
|
|
addressUuid += "/" + childAddress;
|
|
|
if (!grandChildAddress.isEmpty()) {
|
|
|
addressUuid += "/" + grandChildAddress;
|
|
@@ -245,44 +211,38 @@ void ProjectDialog::validateInput()
|
|
|
data["loraAddress"] = loraAddress;
|
|
|
data["loraSn"] = nameLoraSnMap.value(loraAddress);
|
|
|
data["blastCount"] = blastCount;
|
|
|
- if(operationStatus==0){
|
|
|
+ if (operationStatus == 0) {
|
|
|
emit validateDetNum(data);
|
|
|
- } else if (operationStatus==1) {
|
|
|
+ } else if (operationStatus == 1) {
|
|
|
emit validateDetNumUpdate(data);
|
|
|
}
|
|
|
- clearFormData(); // 清除表单数据
|
|
|
+ clearFormData(); // 清除表单数据
|
|
|
// this->accept();
|
|
|
}
|
|
|
|
|
|
-int ProjectDialog::getOperationStatus() const
|
|
|
-{
|
|
|
- return operationStatus;
|
|
|
-}
|
|
|
+int ProjectDialog::getOperationStatus() const { return operationStatus; }
|
|
|
|
|
|
-void ProjectDialog::setOperationStatus(int newOperationStatus)
|
|
|
-{
|
|
|
+void ProjectDialog::setOperationStatus(int newOperationStatus) {
|
|
|
operationStatus = newOperationStatus;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void ProjectDialog::setFormData(const HProject &Project)
|
|
|
-{
|
|
|
+void ProjectDialog::setFormData(const HProject &Project) {
|
|
|
try {
|
|
|
ui->editName->setText(Project.getName());
|
|
|
ui->editDetNum->setText(Project.getDetSum());
|
|
|
ui->editHTID->setText(Project.getHtid());
|
|
|
ui->editXMBH->setText(Project.getXmbh());
|
|
|
int indexBlast = ui->comboBoxBlast->findText(Project.getBlasterName());
|
|
|
- if (indexBlast!= -1) {
|
|
|
+ if (indexBlast != -1) {
|
|
|
ui->comboBoxBlast->setCurrentIndex(indexBlast);
|
|
|
} else {
|
|
|
- qDebug() << "未找到选项 " << "。";
|
|
|
+ qDebug() << "未找到选项 " << "。";
|
|
|
}
|
|
|
int indexOper = ui->comboBoxOperator->findText(Project.getOperatorName());
|
|
|
- if (indexOper!= -1) {
|
|
|
+ if (indexOper != -1) {
|
|
|
ui->comboBoxOperator->setCurrentIndex(indexOper);
|
|
|
} else {
|
|
|
- qDebug() << "未找到选项 " << "。";
|
|
|
+ qDebug() << "未找到选项 " << "。";
|
|
|
}
|
|
|
QStringList addressParts = Project.getAddressUuid().split("/");
|
|
|
int numAddresses = addressParts.size();
|
|
@@ -291,7 +251,6 @@ void ProjectDialog::setFormData(const HProject &Project)
|
|
|
for (int i = 0; i < numAddresses; ++i) {
|
|
|
QString part = addressParts[i];
|
|
|
addressVariables.append(part);
|
|
|
-
|
|
|
}
|
|
|
// 查找目标文本对应的索引
|
|
|
int indexAddr = ui->comboBoxAddr->findText(addressVariables[0]);
|
|
@@ -304,7 +263,7 @@ void ProjectDialog::setFormData(const HProject &Project)
|
|
|
// 如果没找到,输出提示信息
|
|
|
qDebug() << "未找到选项 " << addressVariables[0];
|
|
|
}
|
|
|
- if(addressVariables.size()>=2){
|
|
|
+ if (addressVariables.size() >= 2) {
|
|
|
int indexAddr_2 = ui->comboBoxAddr_2->findText(addressVariables[1]);
|
|
|
|
|
|
if (indexAddr_2 != -1) {
|
|
@@ -317,7 +276,7 @@ void ProjectDialog::setFormData(const HProject &Project)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(addressVariables.size()>=3){
|
|
|
+ if (addressVariables.size() >= 3) {
|
|
|
int indexAddr_3 = ui->comboBoxAddr_3->findText(addressVariables[2]);
|
|
|
|
|
|
if (indexAddr_3 != -1) {
|
|
@@ -329,21 +288,11 @@ void ProjectDialog::setFormData(const HProject &Project)
|
|
|
qDebug() << "未找到选项 " << addressVariables[2];
|
|
|
}
|
|
|
}
|
|
|
- } catch (const std::exception& e) {
|
|
|
+ } catch (const std::exception &e) {
|
|
|
qDebug() << "发生异常: " << e.what();
|
|
|
} catch (...) {
|
|
|
qDebug() << "发生未知异常";
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-ProjectDialog::~ProjectDialog()
|
|
|
-{
|
|
|
- delete ui;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ProjectDialog::~ProjectDialog() { delete ui; }
|