ConfigSchemeDataWidget.cpp 4.8 KB

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