ConfigMeasureDataWidget.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "ConfigMeasureDataWidget.h"
  2. #include "ProjectManager.h"
  3. #include "common/QFDIcon.h"
  4. #include "dbService/SchemeInfoService.h"
  5. #include "dbService/NodeMatrixService.h"
  6. #include <Widgets/Button.h>
  7. #include <Common/Icon.h>
  8. #include <QLabel>
  9. #include <QListWidget>
  10. #include <QBoxLayout>
  11. #include <QDebug>
  12. ConfigMeasureDataWidget::ConfigMeasureDataWidget(QWidget *parent) : QWidget(parent)
  13. {
  14. initWidget();
  15. initLayout();
  16. connectSignalsAndSlots();
  17. }
  18. void ConfigMeasureDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
  19. {
  20. m_process = process;
  21. reloadData();
  22. }
  23. void ConfigMeasureDataWidget::reloadData()
  24. {
  25. /// 从数据库拉取数据
  26. m_nodeData.clear();
  27. m_uuidList.clear();
  28. m_listWidget->clear();
  29. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
  30. QList<NodeMatrixInfo *> dataList;
  31. bool ret = NodeMatrixService().QueryMeaureDataByProjectAndIndex(&dataList, indexName, m_process.projectId);
  32. if (ret == false) {
  33. return;
  34. }
  35. /// 使用 uuid 整理数据
  36. for (NodeMatrixInfo *info : dataList) {
  37. if (m_uuidList.contains(info->strUuid) == false) {
  38. m_uuidList.append(info->strUuid);
  39. m_nodeData[info->strUuid] = QList<NodeMatrixInfo *>();
  40. }
  41. m_nodeData[info->strUuid].append(info);
  42. }
  43. refreshList();
  44. }
  45. void ConfigMeasureDataWidget::selectFirst()
  46. {
  47. if (m_listWidget->count() <= 0) {
  48. return;
  49. }
  50. m_listWidget->setCurrentRow(0);
  51. }
  52. void ConfigMeasureDataWidget::selectLast()
  53. {
  54. if (m_listWidget->count() <= 0) {
  55. return;
  56. }
  57. m_listWidget->setCurrentRow(m_listWidget->count() - 1);
  58. }
  59. QList<NodeMatrixInfo *> ConfigMeasureDataWidget::selectedData()
  60. {
  61. int row = m_listWidget->currentRow();
  62. if (m_uuidList.size() <= 0 || row < 0 || row >= m_uuidList.size()) {
  63. QList<NodeMatrixInfo *> list;
  64. return list;
  65. }
  66. return m_nodeData[m_uuidList[row]];
  67. }
  68. void ConfigMeasureDataWidget::updateNodeValue(NodeMatrixInfo *node)
  69. {
  70. for (auto key : m_nodeData.keys()) {
  71. for (int i = 0; i < m_nodeData[key].size(); i++) {
  72. NodeMatrixInfo *exist = m_nodeData[key][i];
  73. if (exist->strUuid == node->strUuid && exist->abscissa == node->abscissa) {
  74. if (exist->ordinate.length() > 0 && exist->ordinate != node->ordinate) {
  75. continue;
  76. }
  77. m_nodeData[key][i]->nodeValue = node->nodeValue;
  78. return;
  79. }
  80. }
  81. }
  82. }
  83. void ConfigMeasureDataWidget::initWidget()
  84. {
  85. m_titleLabel = new QLabel("添加实测数据", this);
  86. m_titleLabel->setObjectName("titleLabel");
  87. m_titleLabel->setFixedHeight(50);
  88. m_titleLabel->setContentsMargins(10, 0, 0, 0);
  89. m_listTitleLabel = new QLabel("数据列表", this);
  90. m_listTitleLabel->setObjectName("listTitleLabel");
  91. m_tipsLabel = new QLabel("已导入的数据将会显示在这里", this);
  92. m_tipsLabel->setObjectName("tipsLabel");
  93. m_tipsLabel->setHidden(true);
  94. m_addButton = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this);
  95. m_addButton->setToolTip("添加数据");
  96. m_listWidget = new QListWidget(this);
  97. setStyleSheet("#titleLabel {color:#333333; font-size:16px}"
  98. "#listTitleLabel {color:#333333; font-size:12px}"
  99. "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: "
  100. "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}"
  101. "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}"
  102. "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, "
  103. "stop: 1 #f6f7fa);}"
  104. "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}"
  105. "QListView::item {height:44;}");
  106. }
  107. void ConfigMeasureDataWidget::initLayout()
  108. {
  109. m_layout = new QVBoxLayout(this);
  110. m_layout->setMargin(0);
  111. m_layout->setSpacing(0);
  112. m_layout->addWidget(m_titleLabel);
  113. m_headerLayout = new QHBoxLayout();
  114. m_layout->addLayout(m_headerLayout);
  115. m_layout->addSpacing(10);
  116. m_layout->addWidget(m_tipsLabel);
  117. m_layout->addWidget(m_listWidget);
  118. m_headerLayout->addWidget(m_listTitleLabel);
  119. m_headerLayout->addStretch();
  120. m_headerLayout->addWidget(m_addButton);
  121. }
  122. void ConfigMeasureDataWidget::connectSignalsAndSlots()
  123. {
  124. connect(m_addButton, &PushButton::clicked, this, &ConfigMeasureDataWidget::slotAddDataClicked);
  125. connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ConfigMeasureDataWidget::slotCurrentRowChanged);
  126. }
  127. void ConfigMeasureDataWidget::refreshList()
  128. {
  129. m_listWidget->clear();
  130. for (int i = 0; i < m_uuidList.size(); i++) {
  131. QLabel *title = new QLabel;
  132. title->setText(QString("数据%1").arg(i + 1));
  133. QPushButton *remove = new QPushButton(NEWFLICON(QFDIcon, Minus)->icon(), "", this);
  134. remove->setFixedSize(QSize(25, 25));
  135. remove->setIconSize(QSize(10, 10));
  136. remove->setToolTip("删除");
  137. connect(remove, &QPushButton::clicked, [this, i](int) { slotRemoveDataClicked(i); });
  138. QWidget *w = new QWidget;
  139. QHBoxLayout *lay = new QHBoxLayout(w);
  140. lay->addWidget(title);
  141. lay->addStretch();
  142. lay->addWidget(remove);
  143. QListWidgetItem *item = new QListWidgetItem;
  144. m_listWidget->addItem(item);
  145. m_listWidget->setItemWidget(item, w);
  146. }
  147. }
  148. void ConfigMeasureDataWidget::slotAddDataClicked()
  149. {
  150. emit sigAddData();
  151. }
  152. void ConfigMeasureDataWidget::slotRemoveDataClicked(int index)
  153. {
  154. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
  155. QString uuid = m_uuidList[index];
  156. bool ret = NodeMatrixService().deleteMeasureData(m_process.projectId, indexName, uuid);
  157. if (ret) {
  158. m_uuidList.removeOne(uuid);
  159. m_nodeData.remove(uuid);
  160. refreshList();
  161. if (m_uuidList.size() > 0) {
  162. selectFirst();
  163. }
  164. }
  165. }
  166. void ConfigMeasureDataWidget::slotCurrentRowChanged()
  167. {
  168. emit sigCurrentRowChanged();
  169. }