#include "ConfigSchemeDataWidget.h" #include "ProjectManager.h" #include "common/QFDIcon.h" #include #include #include #include #include #include #include #include #include #include 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 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(); } } }