123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #include "ConfigSchemeDataWidget.h"
- #include "ProjectManager.h"
- #include "common/QFDIcon.h"
- #include <dbService/SchemeInfoService.h>
- #include <Widgets/Button.h>
- #include <Common/Icon.h>
- #include <QLabel>
- #include <QListWidget>
- #include <QBoxLayout>
- #include <QImageReader>
- #include <QTextEdit>
- #include <QFile>
- #include <QDebug>
- ConfigSchemeDataWidget::ConfigSchemeDataWidget(QWidget *parent) : QWidget(parent)
- {
- initWidget();
- initLayout();
- connectSignalsAndSlots();
- }
- void ConfigSchemeDataWidget::setProcess(SchemePlanManager::SchemeProcessInfo process)
- {
- m_process = process;
- loadData();
- selectFirst();
- }
- void ConfigSchemeDataWidget::loadData()
- {
- clearInfo();
- if (m_process.type == SchemePlanManager::ImportEvalData) {
- if (m_process.indexType == ProjectManager::EfficiencyIndex) {
- SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 1);
- }
- if (m_process.indexType == ProjectManager::OptimalIndex) {
- SchemeInfoService().QuerySchemeInfoByEngineerId(&m_schemeList, m_process.projectId, 0);
- }
- }
- refreshList();
- }
- QList<SchemaEval *> ConfigSchemeDataWidget::schemeList() const
- {
- return m_schemeList;
- }
- void ConfigSchemeDataWidget::selectFirst()
- {
- if (m_listWidget->count() <= 0) {
- return;
- }
- m_listWidget->setCurrentRow(0);
- }
- void ConfigSchemeDataWidget::selectLast()
- {
- if (m_listWidget->count() <= 0) {
- return;
- }
- m_listWidget->setCurrentRow(m_listWidget->count() - 1);
- }
- void ConfigSchemeDataWidget::initWidget()
- {
- m_titleLabel = new QLabel("添加方案数据", this);
- m_titleLabel->setObjectName("titleLabel");
- m_titleLabel->setFixedHeight(50);
- m_titleLabel->setContentsMargins(10, 0, 0, 0);
- m_listTitleLabel = new QLabel("方案列表", this);
- m_listTitleLabel->setObjectName("listTitleLabel");
- m_tipsLabel = new QLabel("已导入的数据将会显示在这里", this);
- m_tipsLabel->setObjectName("tipsLabel");
- m_tipsLabel->setHidden(true);
- m_addButton = new QPushButton(NEWFLICON(FluentIcon, ADD)->icon(), "", this);
- m_addButton->setToolTip("添加方案");
- m_listWidget = new QListWidget(this);
- m_remark = new QTextEdit(this);
- m_remark->setMinimumHeight(150);
- m_remark->setReadOnly(true);
- m_pic = new QLabel(this);
- m_pic->setFixedHeight(300);
- m_pic->setAlignment(Qt::AlignCenter);
- setStyleSheet("#titleLabel {color:#333333; font-size:16px}"
- "#listTitleLabel {color:#333333; font-size:12px}"
- "QPushButton {border: 0;background-color: qlineargradient(x1: 0, y1: 0, x2: "
- "0, y2: 1,stop: 0 #f8f8f8, stop: 1 #f8f8f8);}"
- "QPushButton::hover {border: 1px solid rgba(0, 0, 0, 0.073);}"
- "QPushButton::pressed {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #dadbde, "
- "stop: 1 #f6f7fa);}"
- "QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);}"
- "QListView::item {height:44;}");
- }
- void ConfigSchemeDataWidget::initLayout()
- {
- m_layout = new QVBoxLayout(this);
- m_layout->setMargin(0);
- m_layout->setSpacing(0);
- m_layout->addWidget(m_titleLabel);
- m_headerLayout = new QHBoxLayout();
- m_layout->addLayout(m_headerLayout);
- m_layout->addSpacing(10);
- m_layout->addWidget(m_tipsLabel);
- m_layout->addWidget(m_listWidget);
- m_layout->addSpacing(10);
- m_layout->addWidget(m_remark);
- m_layout->addSpacing(5);
- m_layout->addWidget(m_pic);
- m_headerLayout->addWidget(m_listTitleLabel);
- m_headerLayout->addStretch();
- m_headerLayout->addWidget(m_addButton);
- }
- void ConfigSchemeDataWidget::connectSignalsAndSlots()
- {
- connect(m_addButton, &PushButton::clicked, this, &ConfigSchemeDataWidget::slotAddDataClicked);
- connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ConfigSchemeDataWidget::slotSelectedChanged);
- }
- void ConfigSchemeDataWidget::refreshList()
- {
- m_listWidget->clear();
- for (int i = 0; i < m_schemeList.size(); ++i) {
- SchemaEval *eval = m_schemeList[i];
- QLabel *title = new QLabel;
- title->setText(eval->name);
- QPushButton *remove = new QPushButton(NEWFLICON(QFDIcon, Minus)->icon(), "", this);
- remove->setFixedSize(QSize(25, 25));
- remove->setIconSize(QSize(10, 10));
- remove->setToolTip("删除");
- connect(remove, &QPushButton::clicked, [this, i](int) { slotRemoveDataClicked(i); });
- QWidget *w = new QWidget;
- QHBoxLayout *lay = new QHBoxLayout(w);
- lay->addWidget(title);
- lay->addStretch();
- lay->addWidget(remove);
- QListWidgetItem *item = new QListWidgetItem;
- m_listWidget->addItem(item);
- m_listWidget->setItemWidget(item, w);
- }
- }
- void ConfigSchemeDataWidget::clearInfo()
- {
- m_schemeList.clear();
- m_remark->clear();
- m_pic->clear();
- }
- void ConfigSchemeDataWidget::resizeEvent(QResizeEvent *event)
- {
- Q_UNUSED(event)
- slotSelectedChanged();
- }
- void ConfigSchemeDataWidget::showEvent(QShowEvent *event)
- {
- QWidget::showEvent(event);
- }
- void ConfigSchemeDataWidget::slotAddDataClicked()
- {
- emit sigAddScheme();
- }
- void ConfigSchemeDataWidget::slotSelectedChanged()
- {
- int row = m_listWidget->currentRow();
- if (m_schemeList.size() <= row || row < 0) {
- return;
- }
- SchemaEval *scheme = m_schemeList[row];
- m_remark->setText(scheme->remark);
- QFile file(scheme->filePath);
- file.open(QIODevice::ReadOnly);
- QByteArray data = file.readAll();
- QPixmap pixmap;
- pixmap.loadFromData(data);
- pixmap = pixmap.scaled(m_pic->width(), m_pic->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
- m_pic->setPixmap(pixmap);
- }
- void ConfigSchemeDataWidget::slotRemoveDataClicked(int index)
- {
- bool ret = SchemeInfoService().deleteScheme(m_schemeList[index]->id);
- if (ret) {
- m_schemeList.removeAt(index);
- refreshList();
- emit sigDeleteScheme();
- if (m_schemeList.size() > 0) {
- selectFirst();
- } else {
- clearInfo();
- }
- }
- }
|