ConfigSchemeDataWidget.cpp 4.4 KB

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