123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include "SchemePlanWidget.h"
- #include "SchemeFlowWidget.h"
- #include "ProjectManager.h"
- #include <dbService/ClassSet.h>
- #include <dbService/SchemeProcessService.h>
- #include <dbService/NodeMatrixService.h>
- #include <dbService/UserConfigService.h>
- #include <CSchemeView.h>
- #include <Widgets/Button.h>
- #include <QTabWidget>
- #include <QLayout>
- //#include <QTextEdit>
- #include <QDebug>
- 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<SchemePlanManager::SchemeProcessInfo> SchemePlanWidget::templateSchemes(int projId, int indexType)
- {
- QList<SchemePlanManager::SchemeProcessType> 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<SchemePlanManager::SchemeProcessInfo> 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<SchemePlanManager::SchemeDataSource> data = SchemePlanManager::processOptionalDataSource(process);
- process.dSource = data.size() > 0 ? data.first() : SchemePlanManager::NoData;
- QList<SchemePlanManager::Algorithm> 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<SchemePlanManager::SchemeProcessInfo> 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<UserConfig *> 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<SchemePlanManager::SchemeProcessInfo> 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<SchemePlanManager::SchemeProcessInfo> 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();
- }
|