ConfigSchemeDataWidget.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "ConfigSchemeDataWidget.h"
  2. #include "ProjectManager.h"
  3. #include "common/QFDIcon.h"
  4. #include <dbService/SchemeInfoService.h>
  5. #include <Widgets/Button.h>
  6. #include <Common/Icon.h>
  7. #include <QLabel>
  8. #include <QListWidget>
  9. #include <QBoxLayout>
  10. #include <QImageReader>
  11. #include <QTextEdit>
  12. #include <QFile>
  13. #include <QDebug>
  14. ConfigSchemeDataWidget::ConfigSchemeDataWidget(QWidget *parent) : QWidget(parent)
  15. {
  16. initWidget();
  17. initLayout();
  18. connectSignalsAndSlots();
  19. }
  20. void ConfigSchemeDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
  21. {
  22. m_process = process;
  23. loadData();
  24. selectFirst();
  25. }
  26. void ConfigSchemeDataWidget::loadData()
  27. {
  28. m_schemeList.clear();
  29. m_remark->clear();
  30. m_pic->clear();
  31. if (m_process.type == SchemePlanManager::ImportEvalData) {
  32. if (m_process.indexType == ProjectManager::EfficiencyIndex) {
  33. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 1);
  34. }
  35. if (m_process.indexType == ProjectManager::OptimalIndex) {
  36. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 0);
  37. }
  38. }
  39. refreshList();
  40. }
  41. QList<SchemaEval *> ConfigSchemeDataWidget::schemeList() const
  42. {
  43. return m_schemeList;
  44. }
  45. void ConfigSchemeDataWidget::selectFirst()
  46. {
  47. if (m_listWidget->count() <= 0) {
  48. return;
  49. }
  50. m_listWidget->setCurrentRow(0);
  51. }
  52. void ConfigSchemeDataWidget::selectLast()
  53. {
  54. if (m_listWidget->count() <= 0) {
  55. return;
  56. }
  57. m_listWidget->setCurrentRow(m_listWidget->count() - 1);
  58. }
  59. void ConfigSchemeDataWidget::initWidget()
  60. {
  61. m_titleLabel = new QLabel("添加方案数据", this);
  62. m_titleLabel->setObjectName("titleLabel");
  63. m_titleLabel->setFixedHeight(50);
  64. m_titleLabel->setContentsMargins(10, 0, 0, 0);
  65. m_listTitleLabel = new QLabel("方案列表", this);
  66. m_listTitleLabel->setObjectName("listTitleLabel");
  67. m_tipsLabel = new QLabel("已导入的数据将会显示在这里", this);
  68. m_tipsLabel->setObjectName("tipsLabel");
  69. m_tipsLabel->setHidden(true);
  70. m_addButton = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this);
  71. m_addButton->setToolTip("添加方案");
  72. m_listWidget = new QListWidget(this);
  73. m_remark = new QTextEdit(this);
  74. m_remark->setMinimumHeight(150);
  75. m_remark->setReadOnly(true);
  76. m_pic = new QLabel(this);
  77. m_pic->setFixedHeight(260);
  78. setStyleSheet("#titleLabel {color:#333333; font-size:16px}"
  79. "#listTitleLabel {color:#333333; font-size:12px}"
  80. "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: "
  81. "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}"
  82. "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}"
  83. "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, "
  84. "stop: 1 #f6f7fa);}"
  85. "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}"
  86. "QListView::item {height:44;}");
  87. }
  88. void ConfigSchemeDataWidget::initLayout()
  89. {
  90. m_layout = new QVBoxLayout(this);
  91. m_layout->setMargin(0);
  92. m_layout->setSpacing(0);
  93. m_layout->addWidget(m_titleLabel);
  94. m_headerLayout = new QHBoxLayout();
  95. m_layout->addLayout(m_headerLayout);
  96. m_layout->addSpacing(10);
  97. m_layout->addWidget(m_tipsLabel);
  98. m_layout->addWidget(m_listWidget);
  99. m_layout->addSpacing(10);
  100. m_layout->addWidget(m_remark);
  101. m_layout->addSpacing(5);
  102. m_layout->addWidget(m_pic);
  103. m_headerLayout->addWidget(m_listTitleLabel);
  104. m_headerLayout->addStretch();
  105. m_headerLayout->addWidget(m_addButton);
  106. }
  107. void ConfigSchemeDataWidget::connectSignalsAndSlots()
  108. {
  109. connect(m_addButton, &PushButton::clicked, this, &ConfigSchemeDataWidget::slotAddDataClicked);
  110. connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ConfigSchemeDataWidget::slotSelectedChanged);
  111. }
  112. void ConfigSchemeDataWidget::refreshList()
  113. {
  114. m_listWidget->clear();
  115. for (int i = 0; i < m_schemeList.size(); ++i) {
  116. SchemaEval *eval = m_schemeList[i];
  117. QLabel *title = new QLabel;
  118. title->setText(eval->name);
  119. QPushButton *remove = new QPushButton(NEWFLICON(QFDIcon, Minus)->icon(), "", this);
  120. remove->setFixedSize(QSize(25, 25));
  121. remove->setIconSize(QSize(10, 10));
  122. remove->setToolTip("删除");
  123. connect(remove, &QPushButton::clicked, [this, i](int) { slotRemoveDataClicked(i); });
  124. QWidget *w = new QWidget;
  125. QHBoxLayout *lay = new QHBoxLayout(w);
  126. lay->addWidget(title);
  127. lay->addStretch();
  128. lay->addWidget(remove);
  129. QListWidgetItem *item = new QListWidgetItem;
  130. m_listWidget->addItem(item);
  131. m_listWidget->setItemWidget(item, w);
  132. }
  133. }
  134. void ConfigSchemeDataWidget::slotAddDataClicked()
  135. {
  136. qDebug() << __FUNCTION__ << __LINE__ << endl;
  137. emit sigAddScheme();
  138. }
  139. void ConfigSchemeDataWidget::slotSelectedChanged()
  140. {
  141. int row = m_listWidget->currentRow();
  142. if (m_schemeList.size() <= row || row < 0) {
  143. return;
  144. }
  145. SchemaEval *scheme = m_schemeList[row];
  146. m_remark->setText(scheme->remark);
  147. QFile file(scheme->filePath);
  148. file.open(QIODevice::ReadOnly);
  149. QByteArray data = file.readAll();
  150. QPixmap pixmap;
  151. pixmap.loadFromData(data);
  152. pixmap = pixmap.scaled(m_pic->width(), m_pic->height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
  153. m_pic->setPixmap(pixmap);
  154. }
  155. void ConfigSchemeDataWidget::slotRemoveDataClicked(int index)
  156. {
  157. bool ret = SchemeInfoService().deleteScheme(m_schemeList[index]->id);
  158. if (ret) {
  159. m_schemeList.removeAt(index);
  160. refreshList();
  161. emit sigDeleteScheme();
  162. if (m_schemeList.size() > 0) {
  163. selectFirst();
  164. }
  165. }
  166. }