|
@@ -1,6 +1,9 @@
|
|
|
#include "projectdialog.h"
|
|
|
|
|
|
+#include <QCheckBox>
|
|
|
+#include <QListView>
|
|
|
#include <QPushButton>
|
|
|
+#include <QStandardItemModel>
|
|
|
|
|
|
#include "ui_projectdialog.h"
|
|
|
|
|
@@ -12,28 +15,66 @@ ProjectDialog::ProjectDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Proj
|
|
|
|
|
|
void ProjectDialog::SetComboBoxBlast(const QJsonArray &bapoYuanArray) {
|
|
|
blasterArray = bapoYuanArray;
|
|
|
- ui->comboBoxBlast->clear();
|
|
|
- fillComboBox(ui->comboBoxBlast, bapoYuanArray);
|
|
|
- ui->comboBoxBlast->setCurrentIndex(-1);
|
|
|
+
|
|
|
+ // 创建标准项模型用于多选
|
|
|
+ QStandardItemModel *blastModel = new QStandardItemModel(ui->comboBoxBlast);
|
|
|
+
|
|
|
+ for (const QJsonValue &value : bapoYuanArray) {
|
|
|
+ if (value.isObject()) {
|
|
|
+ QJsonObject obj = value.toObject();
|
|
|
+ if (obj.contains("nickName")) {
|
|
|
+ QString name = obj["nickName"].toString();
|
|
|
+ QStandardItem *item = new QStandardItem(name);
|
|
|
+ item->setCheckable(true);
|
|
|
+ item->setData(obj["identity"].toString(), Qt::UserRole);
|
|
|
+ blastModel->appendRow(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ui->comboBoxBlast->setModel(blastModel);
|
|
|
+ ui->comboBoxBlast->setView(new QListView(ui->comboBoxBlast));
|
|
|
+ ui->comboBoxBlast->view()->setMinimumWidth(200);
|
|
|
+
|
|
|
+ // 连接项变更信号
|
|
|
+ connect(blastModel, &QStandardItemModel::itemChanged, this, &ProjectDialog::onBlasterItemChanged);
|
|
|
}
|
|
|
|
|
|
void ProjectDialog::SetComboBoxOperator(const QJsonArray &anQuanYuanArray) {
|
|
|
operatorArray = anQuanYuanArray;
|
|
|
- ui->comboBoxOperator->clear();
|
|
|
- fillComboBox(ui->comboBoxOperator, anQuanYuanArray);
|
|
|
- ui->comboBoxOperator->setCurrentIndex(-1);
|
|
|
+
|
|
|
+ // 创建标准项模型用于多选
|
|
|
+ QStandardItemModel *operatorModel = new QStandardItemModel(ui->comboBoxOperator);
|
|
|
+
|
|
|
+ for (const QJsonValue &value : anQuanYuanArray) {
|
|
|
+ if (value.isObject()) {
|
|
|
+ QJsonObject obj = value.toObject();
|
|
|
+ if (obj.contains("nickName")) {
|
|
|
+ QString name = obj["nickName"].toString();
|
|
|
+ QStandardItem *item = new QStandardItem(name);
|
|
|
+ item->setCheckable(true);
|
|
|
+ item->setData(obj["identity"].toString(), Qt::UserRole);
|
|
|
+ operatorModel->appendRow(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ui->comboBoxOperator->setModel(operatorModel);
|
|
|
+ ui->comboBoxOperator->setView(new QListView(ui->comboBoxOperator));
|
|
|
+ ui->comboBoxOperator->view()->setMinimumWidth(200);
|
|
|
+
|
|
|
+ // 连接项变更信号
|
|
|
+ connect(operatorModel, &QStandardItemModel::itemChanged, this, &ProjectDialog::onOperatorItemChanged);
|
|
|
}
|
|
|
|
|
|
void ProjectDialog::on_comboBoxOperator_currentIndexChanged(int index) {
|
|
|
- if (index >= 0 && index < operatorArray.size()) {
|
|
|
- operatorId = operatorArray[index].toObject()["identity"].toString();
|
|
|
- }
|
|
|
+ // 此槽函数保留以避免编译错误,但不再需要之前的功能
|
|
|
+ // 多选框的变更由 onOperatorItemChanged 处理
|
|
|
}
|
|
|
|
|
|
void ProjectDialog::on_comboBoxBlast_currentIndexChanged(int index) {
|
|
|
- if (index >= 0 && index < blasterArray.size()) {
|
|
|
- blasterId = blasterArray[index].toObject()["identity"].toString();
|
|
|
- }
|
|
|
+ // 此槽函数保留以避免编译错误,但不再需要之前的功能
|
|
|
+ // 多选框的变更由 onBlasterItemChanged 处理
|
|
|
}
|
|
|
|
|
|
void ProjectDialog::fillComboBox(QComboBox *comboBox, const QJsonArray &jsonArray) {
|
|
@@ -96,11 +137,45 @@ void ProjectDialog::clearFormData() {
|
|
|
lineEdit->clear();
|
|
|
}
|
|
|
|
|
|
- QList<QComboBox *> comboBoxes = findChildren<QComboBox *>();
|
|
|
- for (QComboBox *comboBox : comboBoxes) {
|
|
|
- comboBox->setCurrentIndex(-1);
|
|
|
+ // 清除多选ComboBox
|
|
|
+ if (ui->comboBoxBlast->model()) {
|
|
|
+ QStandardItemModel *blastModel = qobject_cast<QStandardItemModel *>(ui->comboBoxBlast->model());
|
|
|
+ if (blastModel) {
|
|
|
+ for (int i = 0; i < blastModel->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = blastModel->item(i);
|
|
|
+ if (item) {
|
|
|
+ item->setCheckState(Qt::Unchecked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ui->comboBoxBlast->setEditText("请选择爆破员");
|
|
|
}
|
|
|
- // for if view the data, will hide the accept button
|
|
|
+
|
|
|
+ if (ui->comboBoxOperator->model()) {
|
|
|
+ QStandardItemModel *operatorModel = qobject_cast<QStandardItemModel *>(ui->comboBoxOperator->model());
|
|
|
+ if (operatorModel) {
|
|
|
+ for (int i = 0; i < operatorModel->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = operatorModel->item(i);
|
|
|
+ if (item) {
|
|
|
+ item->setCheckState(Qt::Unchecked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ui->comboBoxOperator->setEditText("请选择操作员");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除普通ComboBox
|
|
|
+ ui->comboBoxAddr->setCurrentIndex(-1);
|
|
|
+ ui->comboBoxAddr_2->setCurrentIndex(-1);
|
|
|
+ ui->comboBoxAddr_3->setCurrentIndex(-1);
|
|
|
+
|
|
|
+ // 清除选中数据
|
|
|
+ selectedBlasters.clear();
|
|
|
+ selectedOperators.clear();
|
|
|
+ blasterIds.clear();
|
|
|
+ operatorIds.clear();
|
|
|
+
|
|
|
+ // 显示确认按钮
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setVisible(true);
|
|
|
}
|
|
|
|
|
@@ -123,14 +198,6 @@ 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 xmbh = ui->editXMBH->text().trimmed();
|
|
|
QString htid = ui->editHTID->text().trimmed();
|
|
|
|
|
@@ -138,38 +205,56 @@ void ProjectDialog::validateAndSaveProject() {
|
|
|
QMessageBox::warning(nullptr, "输入错误", "请输入0-10000的数字!");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ if (selectedBlasters.isEmpty()) {
|
|
|
+ QMessageBox::warning(nullptr, "选择错误", "请至少选择一名爆破员!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectedOperators.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;
|
|
|
+ data["operatorName"] = selectedOperators.join(", ");
|
|
|
+ data["blasterName"] = selectedBlasters.join(", ");
|
|
|
+
|
|
|
+ // 选择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["blasterIdentity"] = blasterIds.join(",");
|
|
|
+ data["operatorIdentity"] = operatorIds.join(",");
|
|
|
data["blastCount"] = blastCount;
|
|
|
+
|
|
|
if (operationStatus == 0) {
|
|
|
emit validateDetNum(data);
|
|
|
} else if (operationStatus == 1) {
|
|
|
emit validateDetNumUpdate(data);
|
|
|
}
|
|
|
+
|
|
|
clearFormData(); // 清除表单数据
|
|
|
- // this->accept();
|
|
|
}
|
|
|
|
|
|
int ProjectDialog::getOperationStatus() const { return operationStatus; }
|
|
@@ -188,18 +273,44 @@ void ProjectDialog::setFormData(const HProject &Project) {
|
|
|
ui->editXMBH->setText(Project.getXmbh());
|
|
|
ui->editRegCount->setText(Project.getBlastCount());
|
|
|
ui->level4Address->setText(Project.getLevel4Address());
|
|
|
- int indexBlast = ui->comboBoxBlast->findText(Project.getBlasterName());
|
|
|
- if (indexBlast != -1) {
|
|
|
- ui->comboBoxBlast->setCurrentIndex(indexBlast);
|
|
|
- } else {
|
|
|
- qDebug() << "indexBlast 未找到选项 " << indexBlast << "。";
|
|
|
+
|
|
|
+ // 设置爆破员多选
|
|
|
+ QStringList blasterNames = Project.getBlasterName().split(", ");
|
|
|
+ QStringList blasterIdList = Project.getBlasterIdentity().split(",");
|
|
|
+ QStandardItemModel *blastModel = qobject_cast<QStandardItemModel *>(ui->comboBoxBlast->model());
|
|
|
+ if (blastModel) {
|
|
|
+ for (int i = 0; i < blastModel->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = blastModel->item(i);
|
|
|
+ if (item && blasterNames.contains(item->text())) {
|
|
|
+ item->setCheckState(Qt::Checked);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- int indexOper = ui->comboBoxOperator->findText(Project.getOperatorName());
|
|
|
- if (indexOper != -1) {
|
|
|
- ui->comboBoxOperator->setCurrentIndex(indexOper);
|
|
|
- } else {
|
|
|
- qDebug() << "operator 未找到选项 " << Project.getOperatorName() << "。";
|
|
|
+
|
|
|
+ // 设置操作员多选
|
|
|
+ QStringList operatorNames = Project.getOperatorName().split(", ");
|
|
|
+ QStringList operatorIdList = Project.getOperatorIdentity().split(",");
|
|
|
+ QStandardItemModel *operatorModel = qobject_cast<QStandardItemModel *>(ui->comboBoxOperator->model());
|
|
|
+ if (operatorModel) {
|
|
|
+ for (int i = 0; i < operatorModel->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = operatorModel->item(i);
|
|
|
+ if (item && operatorNames.contains(item->text())) {
|
|
|
+ item->setCheckState(Qt::Checked);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // 更新已选择列表
|
|
|
+ selectedBlasters = blasterNames;
|
|
|
+ blasterIds = blasterIdList;
|
|
|
+ selectedOperators = operatorNames;
|
|
|
+ operatorIds = operatorIdList;
|
|
|
+
|
|
|
+ // 更新ComboBox显示文本
|
|
|
+ ui->comboBoxBlast->setEditText(selectedBlasters.join(", "));
|
|
|
+ ui->comboBoxOperator->setEditText(selectedOperators.join(", "));
|
|
|
+
|
|
|
+ // 设置地址选择
|
|
|
QStringList addressParts = Project.getAddressPath().split("/");
|
|
|
int numAddresses = addressParts.size();
|
|
|
QVector<QString> addressVariables;
|
|
@@ -249,4 +360,54 @@ void ProjectDialog::setFormData(const HProject &Project) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void ProjectDialog::onBlasterItemChanged(QStandardItem *item) { updateSelectedBlasters(); }
|
|
|
+
|
|
|
+void ProjectDialog::onOperatorItemChanged(QStandardItem *item) { updateSelectedOperators(); }
|
|
|
+
|
|
|
+void ProjectDialog::updateSelectedBlasters() {
|
|
|
+ selectedBlasters.clear();
|
|
|
+ blasterIds.clear();
|
|
|
+ QStandardItemModel *model = qobject_cast<QStandardItemModel *>(ui->comboBoxBlast->model());
|
|
|
+
|
|
|
+ if (!model) return;
|
|
|
+
|
|
|
+ for (int i = 0; i < model->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = model->item(i);
|
|
|
+ if (item && item->checkState() == Qt::Checked) {
|
|
|
+ selectedBlasters.append(item->text());
|
|
|
+ blasterIds.append(item->data(Qt::UserRole).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新显示的文本
|
|
|
+ if (selectedBlasters.isEmpty()) {
|
|
|
+ ui->comboBoxBlast->setEditText("请选择爆破员");
|
|
|
+ } else {
|
|
|
+ ui->comboBoxBlast->setEditText(selectedBlasters.join(", "));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ProjectDialog::updateSelectedOperators() {
|
|
|
+ selectedOperators.clear();
|
|
|
+ operatorIds.clear();
|
|
|
+ QStandardItemModel *model = qobject_cast<QStandardItemModel *>(ui->comboBoxOperator->model());
|
|
|
+
|
|
|
+ if (!model) return;
|
|
|
+
|
|
|
+ for (int i = 0; i < model->rowCount(); ++i) {
|
|
|
+ QStandardItem *item = model->item(i);
|
|
|
+ if (item && item->checkState() == Qt::Checked) {
|
|
|
+ selectedOperators.append(item->text());
|
|
|
+ operatorIds.append(item->data(Qt::UserRole).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新显示的文本
|
|
|
+ if (selectedOperators.isEmpty()) {
|
|
|
+ ui->comboBoxOperator->setEditText("请选择操作员");
|
|
|
+ } else {
|
|
|
+ ui->comboBoxOperator->setEditText(selectedOperators.join(", "));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
ProjectDialog::~ProjectDialog() { delete ui; }
|