#include "SchemePlanWidget.h" #include "SchemeFlowWidget.h" #include "ProjectManager.h" #include #include #include #include #include #include #include #include //#include #include SchemePlanWidget::SchemePlanWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent) { setTitle("评估方案规划"); setupUI(); } void SchemePlanWidget::setType(int type) { EvalWidget::setType(type); setupTabWidget(); } void SchemePlanWidget::setupUI() { m_topLayout->addStretch(); m_export = new PushButton("保存", this); m_export->setEnabled(false); m_topLayout->addWidget(m_export); m_topLayout->addSpacing(10); m_export->setHidden(true); m_description = new QTextEdit(this); m_description->setReadOnly(true); m_description->setFixedWidth(240); m_contentLayout->addWidget(m_description); connect(m_export, &PushButton::clicked, this, &SchemePlanWidget::slotExportClicked); connect(m_tab, &QTabWidget::currentChanged, this, &SchemePlanWidget::slotTabCurrentChanged); } QList SchemePlanWidget::templateSchemes(int projId, int indexType) { QList types; switch (indexType) { case ProjectManager::AbilityIndex: { types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData, SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight, SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport }; break; } case ProjectManager::TechIndex: { types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate, SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport }; break; } case ProjectManager::OptimalIndex: { types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData, SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight, SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate, SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport }; break; } case ProjectManager::EfficiencyIndex: { types = { SchemePlanManager::IndexSystem, SchemePlanManager::ImportWeightData, SchemePlanManager::OptimizeIndex, SchemePlanManager::CalculateWeight, SchemePlanManager::ImportEvalData, SchemePlanManager::RunEvaluate, SchemePlanManager::ShowEvalResult, SchemePlanManager::GenerateReport }; break; } } QList schemes; for (int i = 0; i < types.count(); i++) { SchemePlanManager::SchemeProcessInfo process; process.projectId = projId; process.indexType = indexType; process.type = types[i]; process.step = i; QList data = SchemePlanManager::processOptionalDataSource(process); process.dSource = data.size() > 0 ? data.first() : SchemePlanManager::NoData; QList algs = SchemePlanManager::processOptionalAlgorithms(process); process.algorithm = algs.size() > 0 ? algs.first() : SchemePlanManager::NoAlg; schemes.append(process); } return schemes; } void SchemePlanWidget::setupTabWidget() { m_tab->clear(); for (int i : indexList()) { SchemeFlowWidget *m = new SchemeFlowWidget(this); connect(m, &SchemeFlowWidget::sigSchemeProcessEdited, this, &SchemePlanWidget::slotSchemeProcessEdited); QList schemes; bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(schemes, m_proj->id, i); if (ret && schemes.count() <= 0) { schemes = templateSchemes(m_proj->id, i); ret = SchemeProcessService().AddAllSchemeProcess(schemes); } if (ret) { m->loadSchemes(schemes); } ProjectManager::IndexType t = (ProjectManager::IndexType)i; QString s = ProjectManager::nameOfIndexType(t); m_tab->addTab(m, s); } } bool SchemePlanWidget::hasData(QString indexName) const { bool ret = NodeMatrixService().hasMeasureData(m_proj->id, indexName); if (ret == true) { return true; } QList cfgList; ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&cfgList, m_proj->id); if (ret == false) { return false; } for (UserConfig *cfg : cfgList) { ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId); if (ret) { return true; } } return false; } void SchemePlanWidget::updateDescription() { SchemeFlowWidget *m = (SchemeFlowWidget *)m_tab->currentWidget(); if (m == nullptr) { return; } QList schemes = m->schemes(); QString text = "方案说明\n"; for (int i = 0; i < schemes.size(); ++i) { text.append("\n"); text.append(QString("第 %1 步:\n").arg(i + 1)); text.append(SchemePlanManager::processName(schemes[i])); text.append("\n"); text.append(SchemePlanManager::processDescription(schemes[i])); text.append("\n"); } m_description->setText(text); } void SchemePlanWidget::slotExportClicked() { for (int i = 0; i < m_tab->count(); i++) { SchemeFlowWidget *w = (SchemeFlowWidget *)m_tab->widget(i); QList schemes = w->schemes(); } } void SchemePlanWidget::slotSchemeProcessEdited(const SchemePlanManager::SchemeProcessInfo &process) { qDebug() << __FUNCTION__ << __LINE__ << process.algorithm << endl; SchemeProcessService().UpdateSchemeProcess(process); updateDescription(); } void SchemePlanWidget::slotTabCurrentChanged(int c) { SchemeFlowWidget *m = (SchemeFlowWidget *)m_tab->currentWidget(); if (m == nullptr) { return; } /// 有数据时禁止编辑 bool ret = hasData(m_tab->tabText(c)); m->setAllowEdit(!ret); updateDescription(); }