ConfigMeasureDataWidget.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "ConfigMeasureDataWidget.h"
  2. #include "ProjectManager.h"
  3. #include "dbService/SchemeInfoService.h"
  4. #include "dbService/NodeMatrixService.h"
  5. #include <Widgets/Button.h>
  6. #include <Common/Icon.h>
  7. #include <QLabel>
  8. #include <QListWidget>
  9. #include <QBoxLayout>
  10. #include <QDebug>
  11. ConfigMeasureDataWidget::ConfigMeasureDataWidget(QWidget *parent) : QWidget(parent)
  12. {
  13. initWidget();
  14. initLayout();
  15. connectSignalsAndSlots();
  16. }
  17. void ConfigMeasureDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
  18. {
  19. m_process = process;
  20. reloadData();
  21. addTestData();
  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. QList<NodeMatrixInfo *> list;
  40. m_nodeData[info->strUuid] = list;
  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. if (m_uuidList.size() <= 0) {
  63. QList<NodeMatrixInfo *> list;
  64. return list;
  65. }
  66. int row = m_listWidget->currentRow();
  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].replace(i, node);
  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. QListWidgetItem *item = new QListWidgetItem;
  133. item->setText(QString("数据%1").arg(i + 1));
  134. m_listWidget->addItem(item);
  135. }
  136. }
  137. void ConfigMeasureDataWidget::addTestData()
  138. {
  139. bool rightPage = (m_process.type == SchemePlanManager::ImportWeightData
  140. && m_process.indexType == ProjectManager::OptimalIndex);
  141. bool rightProj = m_process.projectId == kDemoProjId2;
  142. if (!rightPage || !rightProj) {
  143. return;
  144. }
  145. m_listWidget->clear();
  146. for (int i = 0; i < 20; i++) {
  147. QListWidgetItem *item = new QListWidgetItem;
  148. item->setText(QString("数据%1").arg(i + 1));
  149. m_listWidget->addItem(item);
  150. }
  151. }
  152. void ConfigMeasureDataWidget::slotAddDataClicked()
  153. {
  154. emit sigAddData();
  155. }
  156. void ConfigMeasureDataWidget::slotCurrentRowChanged()
  157. {
  158. emit sigCurrentRowChanged();
  159. }