123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913 |
- #include "EvalReportWidget.h"
- #include "DataTableWidget.h"
- #include "ProjectManager.h"
- #include "view/PlotView.h"
- #include "CustomPieChart.h"
- #include "common/ExportReportManager.h"
- #include <dbService/CNodeDataService.h>
- #include <dbService/ClassSet.h>
- #include <dbService/SchemeInfoService.h>
- #include <dbService/SchemeProcessService.h>
- #include <dbService/MindWeightService.h>
- #include <dbService/MindScoreService.h>
- #include <dbService/EffectResultService.h>
- #include <dbService/GradeInfoService.h>
- #include <dbService/UserConfigService.h>
- #include <dbService/NodeMatrixService.h>
- #include <QLabel>
- #include <QBoxLayout>
- #include <QGridLayout>
- #include <QComboBox>
- #include <QPushButton>
- static QSize kFigureSize = QSize(600, 600);
- EvalReportWidget::EvalReportWidget(ProjectInfo *proj, int indexType, QWidget *parent)
- : QWidget(parent), m_proj(proj), m_indexType(indexType)
- {
- initWidgets();
- initLayouts();
- loadAlgs();
- loadData();
- m_exportMngr = new ExportReportManager(this);
- m_exportMngr->setProj(m_proj);
- m_exportMngr->setEvalType(ProjectManager::evalTypeOfIndexType(indexType));
- }
- EvalReportWidget::~EvalReportWidget()
- {
- delete m_exportMngr;
- }
- void EvalReportWidget::exportReport()
- {
- m_exportMngr->exportReport();
- return;
- if (m_indexType == ProjectManager::OptimalIndex) { // 方案优选
- QString path = "D:/FireFly/QFD2/bin/dataset/方案优选评估报告.docx";
- QDesktopServices::openUrl(QUrl::fromLocalFile(path));
- } else if (m_indexType == ProjectManager::EfficiencyIndex) {
- QString path = "D:/FireFly/QFD2/bin/dataset/综合效能评估报告.docx";
- QDesktopServices::openUrl(QUrl::fromLocalFile(path));
- }
- }
- void EvalReportWidget::initWidgets()
- {
- m_view = new QWidget;
- QSize s = kFigureSize;
- m_indexTitle = new QLabel(this);
- m_indexTab = new QTabWidget(this);
- m_indexTab->setFixedSize(s);
- connect(m_indexTab, SIGNAL(currentChanged(int)), this, SLOT(slotIndexTabIndexChanged(int)));
- QVector<PlotView::Data> data;
- m_indexPlot = new PlotView(PlotView::HistogramVertical, data, "", this);
- m_indexPlot->setFixedSize(s);
- m_techTitle = new QLabel(this);
- m_techTable = new QTableView(this);
- m_techTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- m_techTable->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- m_techTable->setAlternatingRowColors(true);
- m_techTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- DataTableItemModel *techModel = new DataTableItemModel();
- m_techTable->setModel(techModel);
- m_techTable->setFixedSize(s);
- m_techPlot = new PlotView(PlotView::HistogramHorizontal, data, "", this);
- m_techPlot->setFixedSize(s);
- m_schemeTitle = new QLabel(this);
- m_schemeTable = new QTableView(this);
- m_schemeTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- m_schemeTable->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- m_schemeTable->setAlternatingRowColors(true);
- m_schemeTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- DataTableItemModel *schemeModel = new DataTableItemModel();
- m_schemeTable->setModel(schemeModel);
- m_schemeTable->setFixedSize(s);
- m_schemePlot = new PlotView(PlotView::HistogramVertical, data, "", this);
- m_schemePlot->setFixedSize(s);
- m_EffiTab = new QTabWidget(this);
- m_EffiTab->setFixedSize(s);
- connect(m_EffiTab, SIGNAL(currentChanged(int)), this, SLOT(slotEffiTabIndexChanged(int)));
- QStringList plots = { "折线图", "横向柱状图", "竖向柱状图", "曲线图", "面积图", "饼图" };
- m_indexCombo = new QComboBox(this);
- m_indexCombo->setFixedSize(QSize(150, 35));
- m_indexCombo->addItems(plots);
- m_indexCombo->setCurrentIndex(1);
- connect(m_indexCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectIndexPlotType(int)));
- // plots = QStringList { "竖向柱状图" };
- m_techCombo = new QComboBox(this);
- m_techCombo->setFixedSize(QSize(150, 35));
- m_techCombo->addItems(plots);
- m_techCombo->setCurrentIndex(1);
- connect(m_techCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectTechPlotType(int)));
- m_schemeCombo = new QComboBox(this);
- m_schemeCombo->setFixedSize(QSize(150, 35));
- m_schemeCombo->addItems(plots);
- m_schemeCombo->setCurrentIndex(2);
- connect(m_schemeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectSchemePlotType(int)));
- m_lastSchemeLev = new QPushButton("上一级指标");
- m_nextSchemeLev = new QPushButton("下一级指标");
- connect(m_lastSchemeLev, &QPushButton::clicked, this, &EvalReportWidget::slotLastSchemeLev);
- connect(m_nextSchemeLev, &QPushButton::clicked, this, &EvalReportWidget::slotNextSchemeLev);
- }
- void EvalReportWidget::initLayouts()
- {
- m_layout = new QVBoxLayout(m_view);
- m_gridLayout = new QGridLayout();
- m_layout->addLayout(m_gridLayout);
- QFont ft("Microsoft YaHei", 12);
- QStringList plots = { "折线图", "横向柱状图", "竖向柱状图", "曲线图", "面积图" };
- if (m_indexType != ProjectManager::TechIndex) {
- m_indexTitle = new QLabel(this);
- m_indexTitle->setText("指标权重");
- m_indexTitle->setFont(ft);
- m_indexTitle->setContentsMargins(0, 10, 0, 10);
- m_gridLayout->addWidget(m_indexTitle, 0, 0);
- m_gridLayout->addWidget(m_indexCombo, 0, 1);
- m_gridLayout->addWidget(m_indexTab, 1, 0);
- m_gridLayout->addWidget(m_indexPlot, 1, 1);
- } else {
- m_techTitle = new QLabel(this);
- m_techTitle->setText("技术措施重要度");
- m_techTitle->setFont(ft);
- m_techTitle->setContentsMargins(0, 10, 0, 10);
- m_gridLayout->addWidget(m_techTitle, 0, 0);
- m_gridLayout->addWidget(m_techCombo, 0, 1);
- m_gridLayout->addWidget(m_techTable, 1, 0);
- m_gridLayout->addWidget(m_techPlot, 1, 1);
- }
- if (m_indexType == ProjectManager::OptimalIndex || m_indexType == ProjectManager::EfficiencyIndex) {
- m_schemeTitle = new QLabel(this);
- m_schemeTitle->setFont(ft);
- m_schemeTitle->setFixedHeight(100);
- m_schemeTitle->setContentsMargins(0, 50, 0, 10);
- if (m_indexType == ProjectManager::OptimalIndex) {
- m_schemeTitle->setText("方案得分");
- m_gridLayout->addWidget(m_schemeTitle, 2, 0);
- m_gridLayout->addWidget(m_schemeTable, 3, 0);
- } else {
- m_schemeTitle->setText("效能分析");
- m_gridLayout->addWidget(m_schemeTitle, 2, 0);
- m_gridLayout->addWidget(m_EffiTab, 3, 0);
- QHBoxLayout *lay = new QHBoxLayout();
- lay->addWidget(m_lastSchemeLev);
- lay->addSpacing(20);
- lay->addWidget(m_nextSchemeLev);
- m_gridLayout->addLayout(lay, 4, 0);
- }
- m_gridLayout->addWidget(m_schemeCombo, 2, 1, Qt::AlignBottom);
- m_gridLayout->addWidget(m_schemePlot, 3, 1);
- }
- QScrollArea *scroll = new QScrollArea;
- scroll->setAlignment(Qt::AlignLeft);
- scroll->setWidget(m_view);
- QVBoxLayout *layout = new QVBoxLayout(this);
- layout->setMargin(0);
- layout->addWidget(scroll);
- }
- void EvalReportWidget::loadAlgs()
- {
- QList<SchemePlanManager::SchemeProcessInfo> processList;
- SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_proj->id, m_indexType);
- for (SchemePlanManager::SchemeProcessInfo process : processList) {
- QString algName = SchemePlanManager::nameOfAlgorithm(process.algorithm);
- if (process.type == SchemePlanManager::CalculateWeight) {
- m_weightAlg = process.algorithm;
- m_indexTitle->setText(m_indexTitle->text() + " (" + algName + ") ");
- } else if (process.type == SchemePlanManager::RunEvaluate) {
- m_evalAlg = process.algorithm;
- // m_techTitle->setText(m_techTitle->text() + " (" + algName + ") ");
- m_schemeTitle->setText(m_schemeTitle->text() + " (" + algName + ") ");
- }
- }
- }
- void EvalReportWidget::loadData()
- {
- QList<CNodeData> nodeList;
- CNodeDataService().QueryAllValid(nodeList, m_proj->id, m_indexType);
- m_mind = new CMind(this);
- m_mind->setNodeList(nodeList);
- if (checkDataComplete() == false) {
- return;
- }
- if (m_indexType != ProjectManager::TechIndex) {
- showIndexWeight();
- } else {
- showTechScore();
- }
- if (m_indexType == ProjectManager::OptimalIndex) {
- showSchemeScore();
- }
- if (m_indexType == ProjectManager::EfficiencyIndex) {
- showEffiResult();
- }
- }
- bool EvalReportWidget::checkDataComplete()
- {
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_indexType);
- 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 || cfgList.size() <= 0) {
- return false;
- }
- bool expertDataComplete = true;
- for (UserConfig *cfg : cfgList) {
- ret = NodeMatrixService().hasExpertData(m_proj->id, indexName, cfg->userId);
- if (ret == false) {
- expertDataComplete = false;
- break;
- }
- }
- return expertDataComplete;
- }
- void EvalReportWidget::showIndexWeight()
- {
- int levels = m_mind->levels();
- if (levels < 2) {
- return;
- }
- MindWeightInfo info;
- int indexType = m_indexType;
- if (indexType == ProjectManager::TechIndex) {
- indexType = ProjectManager::AbilityIndex;
- }
- bool ret = MindWeightService().queryWeightData(&info, m_proj->id, indexType);
- if (ret == false) {
- return;
- }
- if (info.id < 0) {
- qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
- return;
- }
- QMap<QString, double> weightData;
- QStringList weightList = info.weight.split(";");
- for (QString keyValueStr : weightList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- weightData[keyValue.first()] = keyValue.last().toDouble();
- }
- }
- for (int i = 2; i <= levels; i++) {
- QTableView *t = new QTableView();
- t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->setAlternatingRowColors(true);
- t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- // t->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
- // t->setSelectionMode(QAbstractItemView::SingleSelection);
- DataTableItemModel *model = new DataTableItemModel();
- t->setModel(model);
- QStandardItem *hHeader = new QStandardItem("权重");
- model->setHorizontalHeaderItem(0, hHeader);
- QList<CNodeData> nodeList = m_mind->nodesInLevel(i);
- for (int j = 0; j < nodeList.size(); j++) {
- CNodeData node = nodeList[j];
- QStandardItem *vHeader = new QStandardItem(node.name);
- model->setVerticalHeaderItem(j, vHeader);
- QStandardItem *item = new QStandardItem();
- item->setText(QString("%1").arg(weightData[node.name]));
- item->setEditable(false);
- model->setItem(j, 0, item);
- }
- m_indexTab->addTab(t, QString("第%1级指标").arg(i));
- }
- }
- void EvalReportWidget::showIndexWeightPlot()
- {
- QTableView *table = (QTableView *)m_indexTab->currentWidget();
- if (table == nullptr) {
- return;
- }
- DataTableItemModel *model = (DataTableItemModel *)table->model();
- if (model == nullptr) {
- return;
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < model->rowCount(); i++) {
- QStandardItem *header = model->verticalHeaderItem(i);
- QStandardItem *item = model->item(i, 0);
- PlotView::Data data { header->text(), item->text().toDouble() };
- values.append(data);
- }
- if (m_indexPlot != nullptr) {
- m_gridLayout->removeWidget(m_indexPlot);
- m_indexPlot->deleteLater();
- m_indexPlot = nullptr;
- }
- if (m_indexPie != nullptr) {
- m_gridLayout->removeWidget(m_indexPie);
- m_indexPie->deleteLater();
- m_indexPie = nullptr;
- }
- if (m_indexCombo->currentIndex() < 5) {
- PlotView::PlotType type = (PlotView::PlotType)m_indexCombo->currentIndex();
- m_indexPlot = new PlotView(type, values, "", this);
- m_indexPlot->setFixedSize(kFigureSize);
- m_indexPlot->plot();
- m_gridLayout->addWidget(m_indexPlot, 1, 1);
- } else {
- QStringList tagList;
- QList<double> dataList;
- QList<QColor> colorList;
- for (int i = 0; i < values.size(); i++) {
- tagList.append("");
- double t = values[i].value;
- dataList.append(t);
- QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
- colorList.append(color);
- }
- m_indexPie = new CustomPieChart("", tagList, dataList, colorList);
- m_indexPie->setFixedSize(kFigureSize);
- m_gridLayout->addWidget(m_indexPie, 1, 1);
- }
- }
- void EvalReportWidget::showTechScore()
- {
- int levels = m_mind->levels();
- if (levels < 2) {
- return;
- }
- DataTableItemModel *model = (DataTableItemModel *)m_techTable->model();
- if (model == nullptr) {
- return;
- }
- MindScoreInfo info;
- bool ret = MindScoreService().queryScoreData(&info, m_proj->id);
- if (ret == false || info.id < 0) {
- return;
- }
- QMap<QString, QString> scoreData;
- QStringList keyValueStringList = info.score.split(";");
- for (QString keyValueString : keyValueStringList) {
- QStringList keyValue = keyValueString.split(":");
- if (keyValue.size() == 2) {
- scoreData[keyValue.first()] = keyValue.last();
- }
- }
- QStandardItem *hHeader = new QStandardItem("重要度");
- model->setHorizontalHeaderItem(0, hHeader);
- QList<CNodeData> nodeList = m_mind->leaves();
- QVector<PlotView::Data> values;
- for (int j = 0; j < nodeList.size(); j++) {
- CNodeData node = nodeList[j];
- QStandardItem *vHeader = new QStandardItem(node.name);
- model->setVerticalHeaderItem(j, vHeader);
- QStandardItem *item = new QStandardItem();
- item->setText(scoreData[node.name]);
- item->setEditable(false);
- model->setItem(j, 0, item);
- PlotView::Data data { vHeader->text(), item->text().toDouble() };
- values.append(data);
- }
- makePlotClear(m_techPlot);
- m_techPlot->updateData(values);
- }
- void EvalReportWidget::showTechScorePlot()
- {
- DataTableItemModel *model = (DataTableItemModel *)m_techTable->model();
- if (model == nullptr) {
- return;
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < model->rowCount(); i++) {
- QStandardItem *header = model->verticalHeaderItem(i);
- QStandardItem *item = model->item(i, 0);
- PlotView::Data data { header->text(), item->text().toDouble() };
- values.append(data);
- }
- if (m_techPlot != nullptr) {
- m_gridLayout->removeWidget(m_techPlot);
- m_techPlot->deleteLater();
- m_techPlot = nullptr;
- }
- if (m_techPie != nullptr) {
- m_gridLayout->removeWidget(m_techPie);
- m_techPie->deleteLater();
- m_techPie = nullptr;
- }
- if (m_techCombo->currentIndex() < 5) {
- PlotView::PlotType type = (PlotView::PlotType)m_techCombo->currentIndex();
- m_techPlot = new PlotView(type, values, "", this);
- m_techPlot->setFixedSize(kFigureSize);
- m_techPlot->plot();
- m_gridLayout->addWidget(m_techPlot, 1, 1);
- } else {
- QStringList tagList;
- QList<double> dataList;
- QList<QColor> colorList;
- for (int i = 0; i < values.size(); i++) {
- tagList.append("");
- double t = values[i].value;
- dataList.append(t);
- QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
- colorList.append(color);
- }
- m_techPie = new CustomPieChart("", tagList, dataList, colorList);
- m_techPie->setFixedSize(kFigureSize);
- m_gridLayout->addWidget(m_techPie, 1, 1);
- }
- }
- void EvalReportWidget::showSchemeScore()
- {
- int levels = m_mind->levels();
- if (levels < 2) {
- return;
- }
- DataTableItemModel *model = (DataTableItemModel *)m_schemeTable->model();
- if (model == nullptr) {
- return;
- }
- QList<SchemaEval *> schemeList;
- QVector<PlotView::Data> values;
- if (m_indexType == ProjectManager::EfficiencyIndex) {
- SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 1);
- }
- if (m_indexType == ProjectManager::OptimalIndex) {
- SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_proj->id, 0);
- QStandardItem *hHeader = new QStandardItem("得分");
- model->setHorizontalHeaderItem(0, hHeader);
- for (int i = 0; i < schemeList.size(); i++) {
- SchemaEval *scheme = schemeList[i];
- QStandardItem *vHeader = new QStandardItem(scheme->name);
- model->setVerticalHeaderItem(i, vHeader);
- QStandardItem *item = new QStandardItem(QString::number(scheme->score, 'f', 2));
- item->setEditable(false);
- PlotView::Data data { vHeader->text(), scheme->score };
- model->setItem(i, 0, item);
- values.append(data);
- }
- }
- makePlotClear(m_schemePlot);
- m_schemePlot->updateData(values);
- }
- void EvalReportWidget::showSchemeScorePlot()
- {
- DataTableItemModel *model = (DataTableItemModel *)m_schemeTable->model();
- if (model == nullptr) {
- return;
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < model->rowCount(); i++) {
- QStandardItem *header = model->verticalHeaderItem(i);
- QStandardItem *item = model->item(i, 0);
- PlotView::Data data { header->text(), item->text().toDouble() };
- values.append(data);
- }
- if (m_schemePlot != nullptr) {
- m_gridLayout->removeWidget(m_schemePlot);
- m_schemePlot->deleteLater();
- m_schemePlot = nullptr;
- }
- if (m_schemePie != nullptr) {
- m_gridLayout->removeWidget(m_schemePie);
- m_schemePie->deleteLater();
- m_schemePie = nullptr;
- }
- if (m_schemeCombo->currentIndex() < 5) {
- PlotView::PlotType type = (PlotView::PlotType)m_schemeCombo->currentIndex();
- m_schemePlot = new PlotView(type, values, "", this);
- m_schemePlot->setFixedSize(kFigureSize);
- m_schemePlot->plot();
- m_gridLayout->addWidget(m_schemePlot, 3, 1);
- } else {
- QStringList tagList;
- QList<double> dataList;
- QList<QColor> colorList;
- for (int i = 0; i < values.size(); i++) {
- tagList.append("");
- double t = values[i].value;
- dataList.append(t);
- QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
- colorList.append(color);
- }
- m_schemePie = new CustomPieChart("", tagList, dataList, colorList);
- m_schemePie->setFixedSize(kFigureSize);
- m_gridLayout->addWidget(m_schemePie, 3, 1);
- }
- }
- void EvalReportWidget::showEffiResult()
- {
- showEffiResultLev();
- return;
- m_EffiTab->clear();
- QList<GradeInfo *> gradeInfoList;
- int type = m_evalAlg == SchemePlanManager::MEA ? 0 : 1;
- bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
- if (gradeRet == false) {
- return;
- }
- QStringList gradeNames;
- for (int i = 0; i < gradeInfoList.size(); ++i) {
- gradeNames.append(gradeInfoList[i]->gradeValue);
- }
- QList<EffectResult> effList;
- bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
- if (effRet == false) {
- return;
- }
- QMap<int, QMap<QString, QList<double>>> effData;
- QMap<int, QString> schemeNames;
- int levels = 0;
- for (EffectResult effect : effList) {
- if (effData.keys().contains(effect.schemeId) == false) {
- effData[effect.schemeId] = QMap<QString, QList<double>>();
- schemeNames[effect.schemeId] = effect.schemeName;
- }
- QStringList values = effect.value.split(",");
- levels = values.size();
- QList<double> valueList;
- for (int v = 0; v < values.size(); ++v) {
- valueList.append(values[v].toDouble());
- }
- effData[effect.schemeId][effect.indexName] = valueList;
- }
- for (int i = 0; i < effData.keys().size(); i++) {
- QTableView *t = new QTableView();
- t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->setAlternatingRowColors(true);
- t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- DataTableItemModel *model = new DataTableItemModel();
- t->setModel(model);
- for (int lev = 0; lev < levels; lev++) {
- QStandardItem *hHeader = new QStandardItem(gradeNames[lev]);
- model->setHorizontalHeaderItem(lev, hHeader);
- }
- QStandardItem *vHeader = new QStandardItem("综合");
- model->setVerticalHeaderItem(0, vHeader);
- QList<CNodeData> nodeList = m_mind->nodesInLevel(m_mind->levels());
- for (int j = 0; j < nodeList.size(); j++) {
- CNodeData node = nodeList[j];
- QStandardItem *vHeader = new QStandardItem(node.name);
- model->setVerticalHeaderItem(j + 1, vHeader);
- }
- for (int r = 0; r < model->rowCount(); ++r) {
- QStandardItem *vHeader = model->verticalHeaderItem(r);
- QList<double> rowValues = effData[effData.keys()[i]][vHeader->text()];
- for (int c = 0; c < model->columnCount(); ++c) {
- QStandardItem *item = new QStandardItem();
- if (effData.keys().size() > i && rowValues.size() > c) {
- QString text = QString("%1").arg(rowValues[c]);
- if (std::isnan(rowValues[c])) {
- text = "0";
- }
- item->setText(text);
- }
- item->setEditable(false);
- model->setItem(r, c, item);
- }
- }
- m_EffiTab->addTab(t, schemeNames[effData.keys()[i]]);
- }
- }
- void EvalReportWidget::makePlotClear(PlotView *plotView)
- {
- plotView->clearGraphs();
- plotView->clearItems();
- plotView->clearMask();
- plotView->clearPlottables();
- }
- void EvalReportWidget::showEffiResultLev()
- {
- if (m_mind->levels() < 2) {
- return;
- }
- // 获取指标权重
- MindWeightInfo info;
- int indexType = m_indexType;
- if (indexType == ProjectManager::TechIndex) {
- indexType = ProjectManager::AbilityIndex;
- }
- bool ret = MindWeightService().queryWeightData(&info, m_proj->id, indexType);
- if (ret == false) {
- return;
- }
- if (info.id < 0) {
- qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
- return;
- }
- QMap<QString, double> weightData;
- QStringList weightList = info.weight.split(";");
- for (QString keyValueStr : weightList) {
- QStringList keyValue = keyValueStr.split(":");
- if (keyValue.size() == 2) {
- weightData[keyValue.first()] = keyValue.last().toDouble();
- }
- }
- int curTabIndex = m_EffiTab->currentIndex();
- m_EffiTab->clear();
- QList<GradeInfo *> gradeInfoList;
- int type = m_evalAlg == SchemePlanManager::MEA ? 0 : 1;
- bool gradeRet = GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, m_proj->id, type);
- if (gradeRet == false) {
- return;
- }
- QStringList gradeNames;
- for (int i = 0; i < gradeInfoList.size(); ++i) {
- gradeNames.append(gradeInfoList[i]->gradeValue);
- }
- QList<EffectResult> effList;
- bool effRet = EffectResultService().queryDataList(effList, m_proj->id);
- if (effRet == false) {
- return;
- }
- QMap<int, QMap<QString, QList<double>>> effData;
- QMap<int, QString> schemeNames;
- int levels = 0; // 效能分级
- for (EffectResult effect : effList) {
- if (effData.keys().contains(effect.schemeId) == false) {
- effData[effect.schemeId] = QMap<QString, QList<double>>();
- schemeNames[effect.schemeId] = effect.schemeName;
- }
- QStringList values = effect.value.split(",");
- levels = values.size();
- QList<double> valueList;
- for (int v = 0; v < values.size(); ++v) {
- valueList.append(values[v].toDouble());
- }
- effData[effect.schemeId][effect.indexName] = valueList;
- }
- for (int i = 0; i < effData.keys().size(); i++) {
- QTableView *t = new QTableView();
- t->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
- t->setAlternatingRowColors(true);
- t->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- DataTableItemModel *model = new DataTableItemModel();
- t->setModel(model);
- for (int lev = 0; lev < levels; lev++) {
- QStandardItem *hHeader = new QStandardItem(gradeNames[lev]);
- model->setHorizontalHeaderItem(lev, hHeader);
- }
- QStandardItem *vHeader = new QStandardItem("综合");
- model->setVerticalHeaderItem(0, vHeader);
- QList<CNodeData> nodeList = m_mind->nodesInLevel(m_curSchemeLev);
- for (int j = 0; j < nodeList.size(); j++) {
- CNodeData node = nodeList[j];
- QStandardItem *vHeader = new QStandardItem(node.name);
- model->setVerticalHeaderItem(j + 1, vHeader);
- }
- for (int r = 0; r < model->rowCount(); ++r) {
- QStandardItem *vHeader = model->verticalHeaderItem(r);
- QList<double> rowValues;
- if (m_curSchemeLev == m_mind->levels() || r == 0) {
- rowValues = effData[effData.keys()[i]][vHeader->text()];
- } else {
- QList<CNodeData> subNodes = m_mind->leavesOfNode(nodeList[r - 1]);
- for (int l = 0; l < levels; l++) {
- double sumValue = 0;
- double sumWeight = 0;
- for (int n = 0; n < subNodes.count(); n++) {
- QList<double> subNodeValues = effData[effData.keys()[i]][subNodes[n].name];
- double weight = weightData[subNodes[n].name];
- sumValue += subNodeValues[l] * weight;
- sumWeight += weight;
- }
- double finalValue = 0;
- if (sumWeight > 0) {
- finalValue = sumValue / sumWeight;
- }
- rowValues.append(finalValue);
- }
- }
- for (int c = 0; c < model->columnCount(); ++c) {
- QStandardItem *item = new QStandardItem();
- if (effData.keys().size() > i && rowValues.size() > c) {
- QString text = QString("%1").arg(rowValues[c]);
- if (std::isnan(rowValues[c])) {
- text = "0";
- }
- item->setText(text);
- }
- item->setEditable(false);
- model->setItem(r, c, item);
- }
- }
- m_EffiTab->addTab(t, schemeNames[effData.keys()[i]]);
- }
- if (curTabIndex >= 0) {
- m_EffiTab->setCurrentIndex(curTabIndex);
- }
- }
- void EvalReportWidget::slotSelectIndexPlotType(int)
- {
- showIndexWeightPlot();
- }
- void EvalReportWidget::slotSelectTechPlotType(int)
- {
- showTechScorePlot();
- }
- void EvalReportWidget::slotSelectSchemePlotType(int)
- {
- if (m_indexType == ProjectManager::OptimalIndex) {
- showSchemeScorePlot();
- }
- if (m_indexType == ProjectManager::EfficiencyIndex) {
- slotEffiTabIndexChanged(m_EffiTab->currentIndex());
- }
- }
- void EvalReportWidget::slotIndexTabIndexChanged(int)
- {
- showIndexWeightPlot();
- }
- void EvalReportWidget::slotEffiTabIndexChanged(int index)
- {
- QTableView *table = (QTableView *)m_EffiTab->currentWidget();
- if (table == nullptr) {
- return;
- }
- DataTableItemModel *model = (DataTableItemModel *)table->model();
- if (model == nullptr) {
- return;
- }
- QVector<PlotView::Data> values;
- for (int i = 0; i < model->columnCount(); i++) {
- QStandardItem *header = model->horizontalHeaderItem(i);
- QStandardItem *item = model->item(0, i);
- if (item != nullptr) {
- PlotView::Data data { header->text(), item->text().toDouble() };
- values.append(data);
- }
- }
- if (m_schemePlot != nullptr) {
- m_gridLayout->removeWidget(m_schemePlot);
- m_schemePlot->deleteLater();
- m_schemePlot = nullptr;
- }
- if (m_schemePie != nullptr) {
- m_gridLayout->removeWidget(m_schemePie);
- m_schemePie->deleteLater();
- m_schemePie = nullptr;
- }
- if (m_schemeCombo->currentIndex() < 5) {
- PlotView::PlotType type = (PlotView::PlotType)m_schemeCombo->currentIndex();
- m_schemePlot = new PlotView(type, values, "", this);
- m_schemePlot->setFixedSize(kFigureSize);
- m_schemePlot->plot();
- m_gridLayout->addWidget(m_schemePlot, 3, 1);
- } else {
- QStringList tagList;
- QList<double> dataList;
- QList<QColor> colorList;
- for (int i = 0; i < values.size(); i++) {
- tagList.append("");
- double t = values[i].value;
- dataList.append(t);
- QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
- colorList.append(color);
- }
- m_schemePie = new CustomPieChart("", tagList, dataList, colorList);
- m_schemePie->setFixedSize(kFigureSize);
- m_gridLayout->addWidget(m_schemePie, 3, 1);
- }
- }
- void EvalReportWidget::slotLastSchemeLev()
- {
- if (m_curSchemeLev > 2) {
- m_curSchemeLev--;
- }
- showEffiResultLev();
- }
- void EvalReportWidget::slotNextSchemeLev()
- {
- if (m_curSchemeLev < m_mind->levels()) {
- m_curSchemeLev++;
- }
- showEffiResultLev();
- }
|