blastopepage.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #include "blastopepage.h"
  2. #include "ui_blastopepage.h"
  3. #include "countdownwidget.h"
  4. #include <QFont>
  5. BlastOpePage::BlastOpePage(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::BlastOpePage),
  8. dao(DatabaseManager::getInstance().getDatabase())
  9. {
  10. ui->setupUi(this);
  11. initPagination();
  12. }
  13. void BlastOpePage::showDownWidget(QString uuid,const QString &topic,const QString &message){
  14. CountdownWidget *countdownWidget = new CountdownWidget(this);
  15. countdownWidget->resize(200, 200);
  16. int x = (this->width() - countdownWidget->width()) / 2;
  17. int y = (this->height() - countdownWidget->height()) / 2;
  18. countdownWidget->move(x, y);
  19. countdownWidget->show();
  20. firingWidget *widget = uuidWidgetMap.value(uuid);
  21. if (widget) {
  22. connect(countdownWidget, &CountdownWidget::countdownFinished, widget, [widget,topic,message,countdownWidget](){
  23. widget->onCountdownFinished(topic,message);
  24. }, Qt::SingleShotConnection);
  25. }
  26. }
  27. void BlastOpePage::InitFace()
  28. {
  29. layout = new QVBoxLayout(this);
  30. view = new QWebEngineView(this);
  31. view->setAttribute(Qt::WA_OpaquePaintEvent);
  32. QWebEnginePage *page = view->page();
  33. QJsonObject metaInfo = getMetaInfo();
  34. QObject::connect(page, &QWebEnginePage::featurePermissionRequested, [this,page](const QUrl &securityOrigin, QWebEnginePage::Feature feature) {
  35. handleFeaturePermission(page, securityOrigin, feature);
  36. });
  37. QUrl postUrl("http://192.168.0.255:8000/api/v1/h-face-verify/pc");
  38. QJsonObject response = sendPostRequest(postUrl, metaInfo);
  39. QString certifyUrl;
  40. if (response.contains("data") && response["data"].isObject()) {
  41. QJsonObject dataObject = response["data"].toObject();
  42. if (dataObject.contains("ResultObject") && dataObject["ResultObject"].isObject()) {
  43. QJsonObject resultObject = dataObject["ResultObject"].toObject();
  44. if (resultObject.contains("CertifyId") && resultObject["CertifyId"].isString()) {
  45. certifyId= resultObject["CertifyId"].toString();
  46. }
  47. if (resultObject.contains("CertifyUrl") && resultObject["CertifyUrl"].isString()) {
  48. certifyUrl = resultObject["CertifyUrl"].toString();
  49. }
  50. }
  51. }
  52. if (!certifyUrl.isEmpty()) {
  53. view->load(QUrl(certifyUrl));
  54. layout->addWidget(view);
  55. layout->setStretchFactor(view, 1);
  56. QObject::connect(page, &QWebEnginePage::urlChanged, this, &BlastOpePage::onUrlChanged);
  57. } else {
  58. qDebug() << "Failed to get certifyUrl.";
  59. }
  60. }
  61. void BlastOpePage::closeWebViewAndRestoreUI()
  62. {
  63. if (view) {
  64. layout->removeWidget(view);
  65. delete view;
  66. view = nullptr;
  67. }
  68. if (layout) {
  69. delete layout;
  70. layout = nullptr;
  71. }
  72. }
  73. // 槽函数:处理 URL 改变事件
  74. void BlastOpePage::onUrlChanged(const QUrl &newUrl) {
  75. if (newUrl.scheme() == "https" && newUrl.host() == "www.baidu.com") {
  76. closeWebViewAndRestoreUI();
  77. QNetworkAccessManager manager;
  78. QUrl requestUrl(QString("http://localhost:8000/api/v1/h-face-verify/certifyId/%1").arg(certifyId));
  79. QNetworkRequest request(requestUrl);
  80. QNetworkReply *reply = manager.get(request);
  81. QEventLoop loop;
  82. QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
  83. loop.exec();
  84. if (reply->error() == QNetworkReply::NoError) {
  85. QByteArray responseData = reply->readAll();
  86. QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
  87. if (!jsonDoc.isNull() && jsonDoc.isObject()) {
  88. QJsonObject rootObj = jsonDoc.object();
  89. QJsonObject dataObj = rootObj["data"].toObject();
  90. QString message = dataObj["Message"].toString();
  91. QJsonObject resultObj = dataObj["ResultObject"].toObject();
  92. if (resultObj.isEmpty()) {
  93. int ret = QMessageBox::information(nullptr, "提示", message+" ,请重新认证!");
  94. if (ret == QMessageBox::Ok) {
  95. InitFace();
  96. }
  97. } else {
  98. QString passed = resultObj["Passed"].toString();
  99. if (passed == "T") {
  100. QMessageBox::information(nullptr, "提示", "操作成功!");
  101. ui->setupUi(this);
  102. initPagination();
  103. } else if (passed == "F") {
  104. int ret = QMessageBox::critical(nullptr, "提示", "操作失败,请重新认证!");
  105. if (ret == QMessageBox::Ok) {
  106. InitFace();
  107. }
  108. }
  109. }
  110. }
  111. } else {
  112. qDebug() << "Request failed:" << reply->errorString();
  113. }
  114. reply->deleteLater();
  115. }
  116. }
  117. BlastOpePage::~BlastOpePage()
  118. {
  119. delete ui;
  120. if (view) {
  121. delete view;
  122. }
  123. if (layout) {
  124. delete layout;
  125. }
  126. }
  127. QJsonObject BlastOpePage::sendPostRequest(const QUrl &url, const QJsonObject &data) {
  128. QNetworkAccessManager manager;
  129. QNetworkRequest request(url);
  130. request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
  131. QJsonDocument doc(data);
  132. QByteArray postData = doc.toJson();
  133. QNetworkReply *reply = manager.post(request, postData);
  134. QEventLoop loop;
  135. QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
  136. loop.exec();
  137. QJsonObject responseJson;
  138. if (reply->error() == QNetworkReply::NoError) {
  139. QByteArray responseData = reply->readAll();
  140. QJsonDocument responseDoc = QJsonDocument::fromJson(responseData);
  141. if (!responseDoc.isNull() && responseDoc.isObject()) {
  142. responseJson = responseDoc.object();
  143. }
  144. } else {
  145. qDebug() << "Error fetching content: " << reply->errorString();
  146. }
  147. reply->deleteLater();
  148. return responseJson;
  149. }
  150. void BlastOpePage::handleFeaturePermission(QWebEnginePage *page, const QUrl &securityOrigin, QWebEnginePage::Feature feature)
  151. {
  152. if (feature == QWebEnginePage::MediaAudioCapture ||
  153. feature == QWebEnginePage::MediaAudioVideoCapture ||
  154. feature == QWebEnginePage::MediaVideoCapture) {
  155. page->setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionGrantedByUser);
  156. } else {
  157. page->setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
  158. }
  159. }
  160. QJsonObject BlastOpePage::getMetaInfo() {
  161. QJsonObject metaInfo;
  162. metaInfo["certName"] = "";
  163. metaInfo["certNo"] = "";
  164. return metaInfo;
  165. }
  166. void BlastOpePage::initPagination(){
  167. pageWidget= new PageWidget;
  168. connect(pageWidget, &PageWidget::currentPageChanged, this, &BlastOpePage::PageChanged);
  169. connect(pageWidget->getComboBox(), QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BlastOpePage::onComboBoxIndexChanged);
  170. ui->verticalLayout_4->addWidget(pageWidget);;
  171. pageSize = 10;
  172. currentPage = 1;
  173. RefreshData();
  174. }
  175. void BlastOpePage::RefreshData()
  176. {
  177. loadDataFromSource(currentPage,pageSize);
  178. }
  179. void BlastOpePage::loadDataFromSource(int currentPage, int pageSize)
  180. {
  181. PaginatedHProjectResult result =dao.getAllHProjectsByOpera(currentPage,pageSize);
  182. QList<QSharedPointer<HProject>> projectList = result.projects;
  183. totalCount = result.totalCount;
  184. pageWidget->setMaxPage(ceil(static_cast<double>(totalCount)/pageSize));
  185. model = new QStandardItemModel(this);
  186. headers = {
  187. {"选择", ""}, // 新增选择列
  188. {"工程名称", "name"},
  189. {"操作员", "operatorName"},
  190. {"爆破员", "blasterName"},
  191. {"井下地址", "addressUuid"},
  192. {"雷管数量", "detSum"},
  193. {"起爆器数量", "blastCount"},
  194. {"起爆状态", "blastStatus"},
  195. {"进度", ""},
  196. {"操作",""},
  197. };
  198. int headerCount = headers.size();
  199. QStringList headerLabels;
  200. QMap<int, QString> propMap;
  201. for (int i = 0; i < headers.size(); ++i) {
  202. headerLabels << headers[i].label;
  203. propMap[i] = headers[i].prop;
  204. }
  205. model->setHorizontalHeaderLabels(headerLabels);
  206. for (int row = 0; row < projectList.size(); ++row) {
  207. HProject& HProject = *projectList.at(row).data();
  208. QStandardItem* uuidItem = new QStandardItem();
  209. uuidItem->setData(HProject.getUuid(), Qt::UserRole);
  210. model->setItem(row, headerCount, uuidItem);
  211. for (int col = 0; col < headerCount; ++col) {
  212. QString prop = propMap[col];
  213. QStandardItem* item = nullptr;
  214. if(col ==0){
  215. item = new QStandardItem();
  216. item->setCheckable(true);
  217. item->setCheckState(Qt::Unchecked);
  218. item->setText("");
  219. }
  220. if (!prop.isEmpty()) {
  221. QMetaProperty metaProp = HProject.metaObject()->property(HProject.metaObject()->indexOfProperty(prop.toUtf8()));
  222. QVariant value = metaProp.read(&HProject);
  223. if (prop == "blastStatus") {
  224. QString statusText;
  225. if (value.toString() == "1") {
  226. statusText = "未 注 册";
  227. item = new QStandardItem(statusText);
  228. item->setForeground(QColor("#e7c66b"));
  229. } else if (value.toString() == "2") {
  230. statusText = "待 起 爆";
  231. item = new QStandardItem(statusText);
  232. item->setForeground(QColor("#f3a361"));
  233. } else if (value.toString() == "3") {
  234. statusText = "起 爆 完 成";
  235. item = new QStandardItem(statusText);
  236. item->setForeground(QColor("#90d543"));
  237. } else {
  238. item = new QStandardItem(value.toString());
  239. }
  240. } else {
  241. item = new QStandardItem(value.toString());
  242. }
  243. }
  244. if (item) {
  245. item->setTextAlignment(Qt::AlignCenter); // 设置文本居中对齐
  246. model->setItem(row, col, item);
  247. }
  248. }
  249. }
  250. ui->tableView->setModel(model);
  251. connectionItem = QObject::connect(model, &QStandardItemModel::itemChanged, this, &BlastOpePage::onItemChanged);
  252. ui->tableView->setColumnWidth(0, 20);
  253. for (int i = 1; i < headerCount; ++i) {
  254. ui->tableView->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
  255. }
  256. ui->tableView->setColumnHidden(headerCount, true);
  257. ui->tableView->setAlternatingRowColors(true);
  258. ui->tableView->verticalHeader()->setDefaultSectionSize(50);
  259. for (int row = 0; row < projectList.size(); ++row) {
  260. int progressCol = headers.size() - 2; //
  261. QProgressBar *progressBar1 = new QProgressBar(ui->tableView);
  262. progressBar1->setRange(0, 100); // 设置范围为0到100
  263. progressBar1->setValue(0);
  264. progressBar1->setAlignment(Qt::AlignCenter);
  265. progressBar1->setStyleSheet("QProgressBar { border: 1px solid grey; border-radius: 5px; background-color: #EEEEEE; height: 10px; }"
  266. "QProgressBar::chunk { background-color: #05B8CC; width: 2px; margin: 0.5px; border - radius: 10px; }");
  267. progressBar1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  268. QProgressBar *progressBar2 = new QProgressBar(ui->tableView);
  269. progressBar2->setRange(0, 100); // 设置范围为0到100
  270. progressBar2->setValue(0);
  271. progressBar2->setAlignment(Qt::AlignRight);
  272. progressBar2->setStyleSheet("QProgressBar { border: 1px solid grey; border-radius: 5px; background-color: #EEEEEE; height: 20px; }"
  273. "QProgressBar::chunk { background-color: #05B8CC; width: 20px; margin: 0.5px; border - radius: 10px; }");
  274. progressBar2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  275. QProgressBar *progressBar3 = new QProgressBar(ui->tableView);
  276. progressBar3->setRange(0, 100); // 设置范围为0到100
  277. progressBar3->setValue(0);
  278. progressBar3->setAlignment(Qt::AlignRight);
  279. progressBar3->setStyleSheet("QProgressBar { border: 1px solid grey; border-radius: 5px; background-color: #EEEEEE; height: 20px; }"
  280. "QProgressBar::chunk { background-color: #05B8CC; width: 20px; margin: 0.5px; border - radius: 10px; }");
  281. progressBar3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  282. progressBars.append(ProgressBarTriple(progressBar1, progressBar2,progressBar3));
  283. QHBoxLayout *progressBarLayout = new QHBoxLayout;
  284. progressBarLayout->addWidget(progressBar1);
  285. progressBarLayout->addWidget(progressBar2);
  286. progressBarLayout->addWidget(progressBar3);
  287. progressBarLayout->setAlignment(Qt::AlignCenter);
  288. progressBarLayout->setContentsMargins(0, 0, 0, 0);
  289. QWidget *progressBarContainer = new QWidget(ui->tableView);
  290. progressBarContainer->setLayout(progressBarLayout);
  291. QModelIndex progressIndex = model->index(row, progressCol);
  292. if (progressIndex.isValid()) {
  293. ui->tableView->setIndexWidget(progressIndex, progressBarContainer);
  294. }
  295. int col = headers.size() - 1;
  296. // 创建一个按钮
  297. QWidget* widget = new QWidget(ui->tableView);
  298. QPushButton* button = new QPushButton(widget);
  299. button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  300. QModelIndex statusIndex = model->index(row, propMap.key("blastStatus"));
  301. if (statusIndex.isValid()) {
  302. QString blastStatus = model->data(statusIndex).toString();
  303. if (blastStatus == "起 爆 完 成") {
  304. // 为按钮添加图标,这里假设图标文件名为 icon.png,你需要根据实际情况修改
  305. QIcon icon(":/icons/icons/svg/blast.svg");
  306. button->setIcon(icon);
  307. button->setIconSize(QSize(32, 32)); // 设置图标大小
  308. button->setStyleSheet("QPushButton {"
  309. " padding: 0px;"
  310. " border: none;"
  311. " background-color: transparent;"
  312. "}"
  313. );
  314. }else{
  315. button->setText("开启起爆流程");
  316. }
  317. }
  318. QHBoxLayout* layout = new QHBoxLayout(widget);
  319. layout->addWidget(button);
  320. layout->setAlignment(Qt::AlignCenter);
  321. layout->setContentsMargins(0, 0, 0, 0);
  322. widget->setLayout(layout);
  323. QModelIndex index = model->index(row, col);
  324. if (index.isValid()) {
  325. ui->tableView->setIndexWidget(index, widget);
  326. connect(button, &QPushButton::clicked, [this, row,button]() {
  327. handleButtonClick(row,button);
  328. });
  329. }
  330. }
  331. }
  332. // 切换页数
  333. void BlastOpePage::PageChanged(int page)
  334. {
  335. currentPage = page;
  336. loadDataFromSource(currentPage,pageSize);
  337. }
  338. void BlastOpePage::onComboBoxIndexChanged(int index) {
  339. QVariant variant = pageWidget->getComboBox()->itemData(index);
  340. int value = variant.toInt();
  341. pageSize = value;
  342. currentPage = 1;
  343. loadDataFromSource(currentPage,pageSize);
  344. }
  345. void BlastOpePage::updateProgressBar(int value, int row)
  346. {
  347. if (!progressBars.isEmpty()) {
  348. QProgressBar *progressBar1 = progressBars[row].bar1;
  349. QProgressBar *progressBar2 = progressBars[row].bar2;
  350. QProgressBar *progressBar3 = progressBars[row].bar3;
  351. switch (value) {
  352. case 1:
  353. //检查状态
  354. progressBar1->setRange(0, 0); // 设置范围为0到100
  355. progressBar1->setValue(0);
  356. break;
  357. case 2:
  358. // 检查完成
  359. progressBar1->setRange(0, 100); // 设置范围为0到100
  360. progressBar1->setValue(100);
  361. break;
  362. case 3:
  363. // 充电开始
  364. progressBar2->setRange(0, 0); // 设置范围为0到100
  365. progressBar2->setValue(0);
  366. break;
  367. case 4:
  368. //充电完成
  369. progressBar2->setRange(0, 100); // 设置范围为0到100
  370. progressBar2->setValue(100);
  371. break;
  372. case 5:
  373. //起爆中
  374. progressBar3->setRange(0, 0); // 设置范围为0到100
  375. progressBar3->setValue(0);
  376. break;
  377. case 6:
  378. //充电完成
  379. progressBar3->setRange(0, 100); // 设置范围为0到100
  380. progressBar3->setValue(100);
  381. break;
  382. case 0:
  383. progressBar1->setRange(0, 100);
  384. progressBar1->setValue(0);
  385. progressBar2->setRange(0, 100);
  386. progressBar2->setValue(0);
  387. progressBar3->setRange(0, 100);
  388. progressBar3->setValue(0);
  389. break;
  390. default:
  391. break;
  392. }
  393. }
  394. }
  395. void BlastOpePage::onUpdateBlastStatus(int status ,int row)
  396. {
  397. QModelIndex index = model->index(row, 6);
  398. if (index.isValid()) {
  399. QColor customColor;
  400. QFont boldFont;
  401. boldFont.setBold(true);
  402. switch (status) {
  403. case 1:
  404. model->setData(index, "组 网 中 ...");
  405. customColor= QColor("#44035b");
  406. model->setData(index, customColor, Qt::ForegroundRole);
  407. model->setData(index, boldFont, Qt::FontRole);
  408. break;
  409. case 2:
  410. model->setData(index, "组 网 完 成");
  411. customColor = QColor("#404185");
  412. model->setData(index, customColor, Qt::ForegroundRole);
  413. break;
  414. case 3:
  415. model->setData(index, "充 电 中 ...");
  416. customColor = QColor("#31688e");
  417. model->setData(index, customColor, Qt::ForegroundRole);
  418. break;
  419. case 4:
  420. model->setData(index, "充 电 完 成");
  421. customColor = QColor("#1f918d");
  422. model->setData(index, customColor, Qt::ForegroundRole);
  423. break;
  424. case 5:
  425. model->setData(index, "起 爆 中 ...");
  426. customColor = QColor("#38b775");
  427. model->setData(index, customColor, Qt::ForegroundRole);
  428. break;
  429. case 6:
  430. model->setData(index, "起 爆 完 成");
  431. customColor = QColor("#90d543");
  432. model->setData(index, customColor, Qt::ForegroundRole);
  433. break;
  434. case 0:
  435. model->setData(index, "已 注 册");
  436. customColor = QColor("#8e620");
  437. model->setData(index, customColor, Qt::ForegroundRole);
  438. break;
  439. case 10:
  440. model->setData(index, "按 下 双 建 起 爆 ...");
  441. customColor = QColor("#8e620");
  442. model->setData(index, customColor, Qt::ForegroundRole);
  443. break;
  444. default:
  445. break;
  446. }
  447. }
  448. }
  449. void BlastOpePage::handleButtonClick(int row,QPushButton *button){
  450. QStandardItem *uuidItem = model->item(row, 10);
  451. QString uuid;
  452. if (uuidItem) {
  453. QVariant uuidVariant = uuidItem->data(Qt::UserRole);
  454. if (uuidVariant.isValid()) {
  455. uuid = uuidVariant.toString();
  456. }
  457. }
  458. if (button->text() == "开启起爆流程") {
  459. button->setText("取消起爆流程");
  460. firingWidget *widget = new firingWidget(row,false,uuid);
  461. connect(widget, &firingWidget::progressChanged, this, &BlastOpePage::updateProgressBar);
  462. connect(widget, &firingWidget::updateBlastStatus, this, &BlastOpePage::onUpdateBlastStatus);
  463. connect(widget,&firingWidget::updateButton,this,&BlastOpePage::changeButByMqtt);
  464. connect(widget,&firingWidget::countdown,this,&BlastOpePage::showDownWidget);
  465. connect(widget,&firingWidget::updateProjectStatus,this,&BlastOpePage::updateProject);
  466. connect(widget,&firingWidget::closeFiring,this,&BlastOpePage::destroyFiringWidget);
  467. widget->show();
  468. widget->setAttribute(Qt::WA_DeleteOnClose);
  469. uuidWidgetMap.insert(uuid, widget);
  470. } else if (button->text() == "取消起爆流程") {
  471. firingWidget *widget = uuidWidgetMap.value(uuid);
  472. if (widget) {
  473. widget->cancelBlasting();
  474. }
  475. }
  476. }
  477. void BlastOpePage::changeButByMqtt(int status ,int row){
  478. qDebug() << "statusButton:"<<status;
  479. QModelIndex index = model->index(row, 8);
  480. if (index.isValid()) {
  481. QWidget *widget = ui->tableView->indexWidget(index);
  482. if (widget) {
  483. QPushButton *button = widget->findChild<QPushButton*>();
  484. if (button) {
  485. // 使用样式表设置图标居中
  486. button->setStyleSheet("QPushButton {"
  487. " padding: 0px;"
  488. " border: none;"
  489. " background-color: transparent;"
  490. "}"
  491. );
  492. // 添加图标,假设图标文件名为 blast.svg,并且该文件存在于项目资源中
  493. QIcon icon(":/icons/icons/svg/blast.svg");
  494. button->setText("");
  495. button->setIcon(icon);
  496. button->setIconSize(QSize(32, 32));
  497. }
  498. }
  499. }
  500. }
  501. void BlastOpePage::updateProject(QString uuid){
  502. dao.updateBlastStatusByUuid(uuid,"3");
  503. }
  504. void BlastOpePage::destroyFiringWidget(const QString& uuid)
  505. {
  506. firingWidget *widget = uuidWidgetMap.value(uuid);
  507. if (widget) {
  508. widget->close(); // 关闭窗口
  509. widget->deleteLater(); // 释放内存
  510. uuidWidgetMap.remove(uuid); // 从映射中移除
  511. }
  512. }
  513. // 槽函数,当 item 状态改变时触发
  514. void BlastOpePage::onItemChanged(QStandardItem *item) {
  515. if (item->column() == 0) { // 仅处理第一列的勾选状态改变
  516. if (item->checkState() == Qt::Checked) {
  517. QStandardItem *uuidItem = model->item(item->row(), 10);
  518. if (uuidItem) {
  519. QVariant uuidVariant = uuidItem->data(Qt::UserRole);
  520. if (uuidVariant.isValid()) {
  521. QString uuid = uuidVariant.toString();
  522. uuidMap[item->row()] = uuid;
  523. }
  524. }
  525. } else if (item->checkState() == Qt::Unchecked) {
  526. QStandardItem *uuidItem = model->item(item->row(), 10);
  527. if (uuidItem) {
  528. // 从 item 中获取 uuid 数据
  529. QVariant uuidVariant = uuidItem->data(Qt::UserRole);
  530. if (uuidVariant.isValid()) {
  531. QString uuid = uuidVariant.toString();
  532. // 从数组中移除该 uuid
  533. uuidMap.remove(item->row());
  534. }
  535. }
  536. }
  537. }
  538. }
  539. void BlastOpePage::on_btnSelect_clicked()
  540. {
  541. // 禁用表格第一列的选项
  542. for (int row = 0; row < model->rowCount(); ++row) {
  543. QStandardItem *item = model->item(row, 0);
  544. if (item) {
  545. Qt::ItemFlags flags = item->flags();
  546. flags &= ~Qt::ItemIsEnabled;
  547. item->setFlags(flags);
  548. }
  549. }
  550. for (auto it = uuidMap.begin(); it != uuidMap.end(); ++it) {
  551. int row = it.key();
  552. QString uuid = it.value();
  553. firingWidget *widget = new firingWidget(row,true,uuid);
  554. QModelIndex index = model->index(row, 9);
  555. if (index.isValid()) {
  556. QWidget *widgetButton = ui->tableView->indexWidget(index);
  557. if (widgetButton) {
  558. QPushButton *button = widgetButton->findChild<QPushButton*>();
  559. button->setText("取消起爆流程");
  560. }
  561. }
  562. // 信号连接
  563. connect(widget, &firingWidget::progressChanged, this, &BlastOpePage::updateProgressBar);
  564. connect(widget, &firingWidget::updateBlastStatus, this, &BlastOpePage::onUpdateBlastStatus);
  565. widget->show();
  566. widget->setAttribute(Qt::WA_DeleteOnClose);
  567. }
  568. }