ConfigSchemeDataWidget.cpp 4.3 KB

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