ConfigSchemeDataWidget.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <QDebug>
  11. ConfigSchemeDataWidget::ConfigSchemeDataWidget(QWidget *parent) : QWidget(parent)
  12. {
  13. initWidget();
  14. initLayout();
  15. connectSignalsAndSlots();
  16. }
  17. void ConfigSchemeDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
  18. {
  19. m_process = process;
  20. loadData();
  21. }
  22. void ConfigSchemeDataWidget::loadData()
  23. {
  24. m_schemeList.clear();
  25. m_pic->clear();
  26. if (m_process.type == SchemePlanManager::ImportEvalData) {
  27. if (m_process.indexType == ProjectManager::EfficiencyIndex) {
  28. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 1);
  29. }
  30. if (m_process.indexType == ProjectManager::OptimalIndex) {
  31. SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 0);
  32. }
  33. }
  34. refreshList();
  35. }
  36. QList<SchemaEval *> ConfigSchemeDataWidget::schemeList() const
  37. {
  38. return m_schemeList;
  39. }
  40. void ConfigSchemeDataWidget::initWidget()
  41. {
  42. m_titleLabel = new QLabel("添加方案数据", this);
  43. m_titleLabel->setObjectName("titleLabel");
  44. m_titleLabel->setFixedHeight(50);
  45. m_titleLabel->setContentsMargins(10, 0, 0, 0);
  46. m_listTitleLabel = new QLabel("方案列表", this);
  47. m_listTitleLabel->setObjectName("listTitleLabel");
  48. m_tipsLabel = new QLabel("已导入的数据将会显示在这里", this);
  49. m_tipsLabel->setObjectName("tipsLabel");
  50. m_tipsLabel->setHidden(true);
  51. m_addButton = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this);
  52. m_addButton->setToolTip("添加方案");
  53. m_listWidget = new QListWidget(this);
  54. m_pic = new QLabel(this);
  55. m_pic->setFixedHeight(160);
  56. setStyleSheet("#titleLabel {color:#333333; font-size:16px}"
  57. "#listTitleLabel {color:#333333; font-size:12px}"
  58. "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: "
  59. "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}"
  60. "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}"
  61. "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, "
  62. "stop: 1 #f6f7fa);}"
  63. "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}"
  64. "QListView::item {height:44;}");
  65. }
  66. void ConfigSchemeDataWidget::initLayout()
  67. {
  68. m_layout = new QVBoxLayout(this);
  69. m_layout->setMargin(0);
  70. m_layout->setSpacing(0);
  71. m_layout->addWidget(m_titleLabel);
  72. m_headerLayout = new QHBoxLayout();
  73. m_layout->addLayout(m_headerLayout);
  74. m_layout->addSpacing(10);
  75. m_layout->addWidget(m_tipsLabel);
  76. m_layout->addWidget(m_listWidget);
  77. m_layout->addWidget(m_pic);
  78. m_headerLayout->addWidget(m_listTitleLabel);
  79. m_headerLayout->addStretch();
  80. m_headerLayout->addWidget(m_addButton);
  81. }
  82. void ConfigSchemeDataWidget::connectSignalsAndSlots()
  83. {
  84. connect(m_addButton, &PushButton::clicked, this, &ConfigSchemeDataWidget::slotAddDataClicked);
  85. connect(m_listWidget, &QListWidget::currentRowChanged, this, &ConfigSchemeDataWidget::slotSelectedChanged);
  86. }
  87. void ConfigSchemeDataWidget::refreshList()
  88. {
  89. m_listWidget->clear();
  90. for (SchemaEval *eval : m_schemeList) {
  91. QListWidgetItem *item = new QListWidgetItem(eval->name);
  92. m_listWidget->addItem(item);
  93. }
  94. }
  95. void ConfigSchemeDataWidget::slotAddDataClicked()
  96. {
  97. qDebug() << __FUNCTION__ << __LINE__ << endl;
  98. emit sigAddScheme();
  99. }
  100. void ConfigSchemeDataWidget::slotSelectedChanged(int row)
  101. {
  102. if (m_schemeList.size() <= row || row < 0) {
  103. return;
  104. }
  105. SchemaEval *scheme = m_schemeList[row];
  106. QImage image = QImage(scheme->filePath);
  107. m_pic->setPixmap(QPixmap::fromImage(image));
  108. }