ConfigSchemeDataWidget.cpp 4.4 KB

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