|
@@ -1,7 +1,13 @@
|
|
|
#include "projectdialog.h"
|
|
|
|
|
|
+#include <QtCore/qlogging.h>
|
|
|
+
|
|
|
+#include <QCheckBox>
|
|
|
+#include <QListView>
|
|
|
#include <QPushButton>
|
|
|
+#include <QStandardItemModel>
|
|
|
|
|
|
+#include "../components/MultiSelectComboBox.h"
|
|
|
#include "ui_projectdialog.h"
|
|
|
|
|
|
ProjectDialog::ProjectDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ProjectDialog) {
|
|
@@ -10,42 +16,52 @@ ProjectDialog::ProjectDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Proj
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProjectDialog::clearFormData);
|
|
|
}
|
|
|
|
|
|
-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;
|
|
|
- ui->comboBoxOperator->clear();
|
|
|
- fillComboBox(ui->comboBoxOperator, anQuanYuanArray);
|
|
|
- ui->comboBoxOperator->setCurrentIndex(-1);
|
|
|
-}
|
|
|
+void ProjectDialog::initComboBoxBlaster(const QJsonArray &undergroundOperators) {
|
|
|
+ MultiSelectComboBox *comboBox = new MultiSelectComboBox(this);
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxOperator_currentIndexChanged(int index) {
|
|
|
- if (index >= 0 && index < operatorArray.size()) {
|
|
|
- operatorId = operatorArray[index].toObject()["identity"].toString();
|
|
|
+ for (const QJsonValue &value : undergroundOperators) {
|
|
|
+ if (value.isObject()) {
|
|
|
+ QJsonObject obj = value.toObject();
|
|
|
+ if (obj.contains("nickName")) {
|
|
|
+ QString name = obj["nickName"].toString();
|
|
|
+ comboBox->addItem(obj["identity"].toString(), name);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ QVBoxLayout *layout = new QVBoxLayout(ui->undergroundOperatorsWidget);
|
|
|
+ layout->addWidget(comboBox);
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxBlast_currentIndexChanged(int index) {
|
|
|
- if (index >= 0 && index < blasterArray.size()) {
|
|
|
- blasterId = blasterArray[index].toObject()["identity"].toString();
|
|
|
+void ProjectDialog::initComboBoxSafetyInspectors(const QJsonArray &safeInspectors) {
|
|
|
+ MultiSelectComboBox *comboBox = new MultiSelectComboBox(this);
|
|
|
+
|
|
|
+ for (const QJsonValue &value : safeInspectors) {
|
|
|
+ if (value.isObject()) {
|
|
|
+ QJsonObject obj = value.toObject();
|
|
|
+ if (obj.contains("nickName")) {
|
|
|
+ QString name = obj["nickName"].toString();
|
|
|
+ comboBox->addItem(obj["identity"].toString(), name);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ QVBoxLayout *layout = new QVBoxLayout(ui->safetyInspectorsWidget);
|
|
|
+ layout->addWidget(comboBox);
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::fillComboBox(QComboBox *comboBox, const QJsonArray &jsonArray) {
|
|
|
- for (const QJsonValue &value : jsonArray) {
|
|
|
+void ProjectDialog::initComboBoxOperator(const QJsonArray &groundOperators) {
|
|
|
+ MultiSelectComboBox *comboBox = new MultiSelectComboBox(this);
|
|
|
+
|
|
|
+ for (const QJsonValue &value : groundOperators) {
|
|
|
if (value.isObject()) {
|
|
|
QJsonObject obj = value.toObject();
|
|
|
if (obj.contains("nickName")) {
|
|
|
QString name = obj["nickName"].toString();
|
|
|
- comboBox->addItem(name);
|
|
|
+ comboBox->addItem(obj["identity"].toString(), name);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ QVBoxLayout *layout = new QVBoxLayout(ui->groundOperatorsWidget);
|
|
|
+ layout->addWidget(comboBox);
|
|
|
}
|
|
|
|
|
|
void ProjectDialog::SetL1AddressOptions(const QJsonArray &Options) {
|
|
@@ -76,37 +92,6 @@ void ProjectDialog::updateL3AddressOptions() {
|
|
|
|
|
|
void ProjectDialog::setChildOptions(const QJsonArray &newDataOptions) { dataOptions = newDataOptions; }
|
|
|
|
|
|
-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;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- ui->comboBoxLora->setCurrentIndex(-1);
|
|
|
-}
|
|
|
-
|
|
|
void ProjectDialog::extractNames(const QJsonArray &array, QStringList &names) {
|
|
|
for (const auto &item : array) {
|
|
|
if (item.isObject()) {
|
|
@@ -126,12 +111,20 @@ void ProjectDialog::clearFormData() {
|
|
|
for (QLineEdit *lineEdit : lineEdits) {
|
|
|
lineEdit->clear();
|
|
|
}
|
|
|
-
|
|
|
- QList<QComboBox *> comboBoxes = findChildren<QComboBox *>();
|
|
|
- for (QComboBox *comboBox : comboBoxes) {
|
|
|
- comboBox->setCurrentIndex(-1);
|
|
|
+ QList<MultiSelectComboBox *> multiSelectCombos = findChildren<MultiSelectComboBox *>();
|
|
|
+ for (MultiSelectComboBox *combo : multiSelectCombos) {
|
|
|
+ combo->setCheckedKeys(QStringList());
|
|
|
}
|
|
|
- // for if view the data, will hide the accept button
|
|
|
+ ui->comboBoxAddr->setCurrentIndex(-1);
|
|
|
+ ui->comboBoxAddr_2->setCurrentIndex(-1);
|
|
|
+ ui->comboBoxAddr_3->setCurrentIndex(-1);
|
|
|
+
|
|
|
+ // 清除选中数据
|
|
|
+ selectedBlasters.clear();
|
|
|
+ selectedOperators.clear();
|
|
|
+ selectedSafetyInspectors.clear(); // Add this line
|
|
|
+
|
|
|
+ // 显示确认按钮
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setVisible(true);
|
|
|
}
|
|
|
|
|
@@ -150,26 +143,25 @@ void ProjectDialog::on_comboBoxAddr_2_currentIndexChanged(int index) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ProjectDialog::on_comboBoxAddr_3_currentIndexChanged(int index) {
|
|
|
- if (index >= 0 && index < L3AddressOptions.size()) {
|
|
|
- QString grandChildName = L3AddressOptions[index].toObject()["uuid"].toString();
|
|
|
- SetComboBoxLora(grandChildName);
|
|
|
+void ProjectDialog::validateAndSaveProject() {
|
|
|
+ for (const auto &pair :
|
|
|
+ ui->undergroundOperatorsWidget->findChild<MultiSelectComboBox *>()->checkedItemsWithKeys()) {
|
|
|
+ selectedBlasters.append(pair.first);
|
|
|
+ qDebug() << "Selected underground operator:" << pair.first;
|
|
|
+ }
|
|
|
+ for (const auto &pair : ui->groundOperatorsWidget->findChild<MultiSelectComboBox *>()->checkedItemsWithKeys()) {
|
|
|
+ selectedOperators.append(pair.first);
|
|
|
+ qDebug() << "Selected ground operator:" << pair.first;
|
|
|
+ }
|
|
|
+ for (const auto &pair : ui->safetyInspectorsWidget->findChild<MultiSelectComboBox *>()->checkedItemsWithKeys()) {
|
|
|
+ selectedSafetyInspectors.append(pair.first);
|
|
|
+
|
|
|
+ qDebug() << "Selected safety inspector:" << pair.first;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-void ProjectDialog::validateAndSaveProject() {
|
|
|
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 l1AddressUuid = ui->comboBoxAddr->currentData().toString().trimmed();
|
|
|
- QString l2AddressUuid = ui->comboBoxAddr_2->currentData().toString().trimmed();
|
|
|
- QString l3AddressUuid = ui->comboBoxAddr_3->currentData().toString().trimmed();
|
|
|
- QString l1AddressName = ui->comboBoxAddr->currentText().trimmed();
|
|
|
- QString l2AddressName = ui->comboBoxAddr_2->currentText().trimmed();
|
|
|
- QString l3AddressName = ui->comboBoxAddr_3->currentText().trimmed();
|
|
|
- QString loraAddress = ui->comboBoxLora->currentText().trimmed();
|
|
|
QString xmbh = ui->editXMBH->text().trimmed();
|
|
|
QString htid = ui->editHTID->text().trimmed();
|
|
|
|
|
@@ -177,45 +169,64 @@ void ProjectDialog::validateAndSaveProject() {
|
|
|
QMessageBox::warning(nullptr, "输入错误", "请输入0-10000的数字!");
|
|
|
return;
|
|
|
}
|
|
|
+ if (selectedBlasters.isEmpty()) {
|
|
|
+ QMessageBox::warning(nullptr, "选择错误", "请至少选择一名井下爆破员!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (selectedOperators.isEmpty()) {
|
|
|
+ QMessageBox::warning(nullptr, "选择错误", "请至少选择一名井上爆破员!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (selectedSafetyInspectors.isEmpty()) {
|
|
|
+ QMessageBox::warning(nullptr, "选择错误", "请至少选择一名安全员!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 创建一个 QMap 集合,存储数据
|
|
|
QMap<QString, QString> data;
|
|
|
data["detNum"] = detNum;
|
|
|
data["name"] = projectName;
|
|
|
data["xmbh"] = xmbh;
|
|
|
data["htid"] = htid;
|
|
|
- data["operatorName"] = operatorName;
|
|
|
- data["blasterName"] = blastName;
|
|
|
- // 选择level最低的uui:w
|
|
|
- QString addressUuid = l1AddressUuid;
|
|
|
+
|
|
|
+ // 选择level最低的uuid
|
|
|
+ QString addressUuid = ui->comboBoxAddr->currentData().toString().trimmed();
|
|
|
+ QString l2AddressUuid = ui->comboBoxAddr_2->currentData().toString().trimmed();
|
|
|
+ QString l3AddressUuid = ui->comboBoxAddr_3->currentData().toString().trimmed();
|
|
|
+ QString l1AddressName = ui->comboBoxAddr->currentText().trimmed();
|
|
|
+ QString l2AddressName = ui->comboBoxAddr_2->currentText().trimmed();
|
|
|
+ QString l3AddressName = ui->comboBoxAddr_3->currentText().trimmed();
|
|
|
+
|
|
|
if (l3AddressUuid != "") {
|
|
|
addressUuid = l3AddressUuid;
|
|
|
} else if (l2AddressUuid != "") {
|
|
|
addressUuid = l2AddressUuid;
|
|
|
- } else if (l1AddressUuid != "") {
|
|
|
- addressUuid = l1AddressUuid;
|
|
|
- } else {
|
|
|
+ } else if (addressUuid == "") {
|
|
|
QMessageBox::warning(nullptr, "输入错误", "请选择地址!");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
data["addressPath"] = l1AddressName + "/" + l2AddressName + "/" + l3AddressName;
|
|
|
data["addressUuid"] = addressUuid;
|
|
|
- data["blasterIdentity"] = blasterId;
|
|
|
- data["operatorIdentity"] = operatorId;
|
|
|
- data["loraAddress"] = loraAddress;
|
|
|
- data["loraSn"] = nameLoraSnMap.value(loraAddress);
|
|
|
+ data["blasterIdentity"] = selectedBlasters.join(",");
|
|
|
+ data["operatorIdentity"] = selectedOperators.join(",");
|
|
|
+ data["safetyInspectorIdentity"] = selectedSafetyInspectors.join(",");
|
|
|
data["blastCount"] = blastCount;
|
|
|
- if (operationStatus == 0) {
|
|
|
- emit validateDetNum(data);
|
|
|
- } else if (operationStatus == 1) {
|
|
|
- emit validateDetNumUpdate(data);
|
|
|
+
|
|
|
+ if (operationType == 0) {
|
|
|
+ qDebug() << "Project data to create:" << data;
|
|
|
+ emit createProject(data);
|
|
|
+ } else if (operationType == 1) {
|
|
|
+ qDebug() << "Project data to update:" << data;
|
|
|
+ emit saveProject(data);
|
|
|
}
|
|
|
+
|
|
|
clearFormData(); // 清除表单数据
|
|
|
- // this->accept();
|
|
|
}
|
|
|
|
|
|
-int ProjectDialog::getOperationStatus() const { return operationStatus; }
|
|
|
+int ProjectDialog::getOperationType() const { return operationType; }
|
|
|
|
|
|
-void ProjectDialog::setOperationStatus(int newOperationStatus) { operationStatus = newOperationStatus; }
|
|
|
+void ProjectDialog::setOperationType(int newOperationType) { operationType = newOperationType; }
|
|
|
|
|
|
void ProjectDialog::setFormData(const HProject &Project) {
|
|
|
try {
|
|
@@ -228,18 +239,11 @@ void ProjectDialog::setFormData(const HProject &Project) {
|
|
|
ui->editHTID->setText(Project.getHtid());
|
|
|
ui->editXMBH->setText(Project.getXmbh());
|
|
|
ui->editRegCount->setText(Project.getBlastCount());
|
|
|
- int indexBlast = ui->comboBoxBlast->findText(Project.getBlasterName());
|
|
|
- if (indexBlast != -1) {
|
|
|
- ui->comboBoxBlast->setCurrentIndex(indexBlast);
|
|
|
- } else {
|
|
|
- qDebug() << "indexBlast 未找到选项 " << indexBlast << "。";
|
|
|
- }
|
|
|
- int indexOper = ui->comboBoxOperator->findText(Project.getOperatorName());
|
|
|
- if (indexOper != -1) {
|
|
|
- ui->comboBoxOperator->setCurrentIndex(indexOper);
|
|
|
- } else {
|
|
|
- qDebug() << "operator 未找到选项 " << Project.getOperatorName() << "。";
|
|
|
- }
|
|
|
+ ui->level4Address->setText(Project.getLevel4Address());
|
|
|
+
|
|
|
+ // TODO: 这里需要处理井下爆破员和井上爆破员及安全员
|
|
|
+
|
|
|
+ // 设置地址选择
|
|
|
QStringList addressParts = Project.getAddressPath().split("/");
|
|
|
int numAddresses = addressParts.size();
|
|
|
QVector<QString> addressVariables;
|