#include "EvalSchemeWidget.h" #include #include #include #include #include #include #include #include #include QString EvalSchemeWidget::nameOfScheme(Scheme s) { switch (s) { case Index: return "构建指标体系"; case Collect: return "收集数据"; case Process: return "处理数据"; case Output: return "生成报告"; } } QString EvalSchemeWidget::descriptionOfScheme(EvalSchemeWidget::Scheme s) { switch (s) { case Index: return "构建指标体系"; case Collect: return "收集专家数据"; case Process: return "处理数据"; case Output: return "生成报告"; } } QString EvalSchemeWidget::nameOfAlgorithm(EvalSchemeWidget::Algorithm a) { switch (a) { case Alg1: return "层次分析法"; case Alg2: return "集对分析法"; case Alg3: return "熵值法"; case Alg4: return "物元分析法"; case Alg5: return "灰色聚类评估法"; } } EvalSchemeWidget::EvalSchemeWidget(ProjectInfo *proj, QWidget *parent) : EvalWidget(proj, parent) { setTitle("评估方案规划"); // 预设方案模板 m_schemes["指标体系"] = { Index | Process | Output, Alg1 }; m_schemes["收集数据"] = { Collect | Process | Output, Alg1 }; m_schemes["指标体系和收集数据"] = { Index | Collect | Process | Output, Alg1 }; initWidgets(); initLayout(); connectSignalsAndSlots(); loadScheme(m_schemes.keys().first()); } void EvalSchemeWidget::initWidgets() { m_schemeBtn = new PushButton("加载方案模板", this); m_index = new CheckBox("指标体系", this); m_data = new CheckBox("收集数据", this); m_algBtn = new PushButton("数据处理", this); m_clear = new PushButton("清空"); m_schemeView = new CSchemeView(this); m_schemeSep = new QWidget(this); m_schemeSep->setFixedWidth(1); m_description = new QLabel("description", this); m_description->setFixedWidth(150); m_description->setAlignment(Qt::AlignTop); m_description->setWordWrap(true); m_schemeMenu = new RoundMenu("scheme", this); for (QString key : m_schemes.keys()) { QAction *act = new QAction(key); m_schemeMenu->addAction(act); connect(act, &QAction::triggered, [this, act]() { loadScheme(act->text()); }); } // 按照算法枚举值添加算法选项 m_algMenu = new RoundMenu("alg", this); QMetaEnum alg = QMetaEnum::fromType(); for (int i = 0; i < alg.keyCount(); i++) { Algorithm t = Algorithm(alg.value(i)); QAction *act = new QAction(nameOfAlgorithm(t)); m_algMenu->addAction(act); connect(act, &QAction::triggered, [this, t]() { slotSelectAlgorithm(t); }); } } void EvalSchemeWidget::initLayout() { // 总体布局 m_buttonLayout = new QHBoxLayout(); m_contentLayout->addLayout(m_buttonLayout); m_schemeLayout = new QHBoxLayout(); m_contentLayout->addLayout(m_schemeLayout); m_buttonLayout->addWidget(m_schemeBtn); m_buttonLayout->addSpacing(20); m_buttonLayout->addWidget(m_index); m_buttonLayout->addSpacing(20); m_buttonLayout->addWidget(m_data); m_buttonLayout->addSpacing(20); m_buttonLayout->addWidget(m_algBtn); m_buttonLayout->addSpacing(20); m_buttonLayout->addWidget(m_clear); m_buttonLayout->addStretch(); m_schemeLayout->addWidget(m_schemeView); m_schemeLayout->addWidget(m_seperator); m_schemeLayout->addWidget(m_description); } void EvalSchemeWidget::connectSignalsAndSlots() { connect(m_schemeBtn, &PushButton::clicked, this, &EvalSchemeWidget::slotShowSchemeMenu); connect(m_index, &CheckBox::clicked, this, &EvalSchemeWidget::slotIndexClicked); connect(m_data, &CheckBox::clicked, this, &EvalSchemeWidget::slotDataClicked); connect(m_algBtn, &PushButton::clicked, this, &EvalSchemeWidget::slotAlgBtnClicked); connect(m_clear, &PushButton::clicked, this, &EvalSchemeWidget::slotClearClicked); } void EvalSchemeWidget::refreshSchemeView() { updateButtonState(); m_schemeView->clear(); m_description->clear(); if (m_scheme <= 0) { return; } m_scheme |= Output; QString desc = QString("方案说明\n\n"); int step = 0; QMetaEnum sch = QMetaEnum::fromType(); for (int i = 0; i < sch.keyCount(); i++) { Scheme s = Scheme(sch.value(i)); if (s == Process) { for (Algorithm a : m_algs) { CSchemeItem *item = new CSchemeItem(nameOfAlgorithm(a)); m_schemeView->addItem(item); desc += QString("第 %1 步: 使用%2对数据进行处理\n\n").arg(++step).arg(nameOfAlgorithm(a)); } } else { if ((m_scheme & s) == s) { CSchemeItem *item = new CSchemeItem(nameOfScheme(s)); m_schemeView->addItem(item); desc += QString("第 %1 步: %2\n\n").arg(++step).arg(descriptionOfScheme(s)); } } } m_description->setText(desc); } void EvalSchemeWidget::loadScheme(const QString &scheme) { if (m_schemes.contains(scheme) == false) { return; } SchemeAndAlg s = m_schemes[scheme]; m_scheme = s.scheme; m_algs.clear(); m_algs.append(s.alg); refreshSchemeView(); } void EvalSchemeWidget::updateButtonState() { bool e = m_scheme > 0 && m_algs.count() > 0; m_index->setEnabled(e); m_data->setEnabled(e); m_algBtn->setEnabled(e); m_clear->setEnabled(e); m_index->setChecked((m_scheme & Index) == Index); m_data->setChecked((m_scheme & Collect) == Collect); } void EvalSchemeWidget::slotShowSchemeMenu() { QPoint pos = m_schemeBtn->mapToGlobal(QPoint()) + QPoint(m_schemeBtn->width(), -10); m_schemeMenu->exec(pos, true); } void EvalSchemeWidget::slotIndexClicked() { m_scheme ^= Index; refreshSchemeView(); } void EvalSchemeWidget::slotDataClicked() { m_scheme ^= Collect; refreshSchemeView(); } void EvalSchemeWidget::slotAlgBtnClicked() { QPoint pos = m_algBtn->mapToGlobal(QPoint()) + QPoint(m_algBtn->width(), -10); m_algMenu->exec(pos, true); } void EvalSchemeWidget::slotClearClicked() { m_scheme = 0; m_algs.clear(); refreshSchemeView(); } void EvalSchemeWidget::slotSelectAlgorithm(EvalSchemeWidget::Algorithm alg) { if (m_algs.contains(alg)) { return; } m_algs.clear(); m_algs.append(alg); refreshSchemeView(); }