ConfigMeasureDataWidget.cpp 6.6 KB

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