123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- #include "EvalSchemeWidget.h"
- #include <CCanvas/CSchemeView.h>
- #include <CCanvas/CSchemeItem.h>
- #include <Widgets/Button.h>
- #include <Widgets/Menu.h>
- #include <Widgets/CheckBox.h>
- #include <QLabel>
- #include <QLayout>
- #include <QMetaEnum>
- #include <QDebug>
- 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<Algorithm>();
- 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<Scheme>();
- 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();
- }
|