123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- #include "AnalysisTableWidget.h"
- #include "RequirementImportance.h"
- #include "algorithm/ConsistencyCheck.h"
- #include <QDebug>
- #include <QHeaderView>
- #include <QTime>
- #include <QtMath>
- #include "dbService/ClassSet.h"
- #include <dbService/DBServiceSet.h>
- #include <dbService/NodeMatrixService.h>
- #include <dbService/DemandWeightService.h>
- #include <QList>
- AnalysisTableWidget::AnalysisTableWidget(QWidget *parent) : QTableView(parent)
- {
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
- // qDebug() << "AnalysisTableWidget---init";
- model = new QStandardItemModel();
- this->setModel(model);
- paintDone = false;
- connect(model, &QStandardItemModel::itemChanged, this, &AnalysisTableWidget::nodeValueChanged);
- }
- AnalysisTableWidget::~AnalysisTableWidget() { }
- void AnalysisTableWidget::addRowNode(QString node, QString name, QString remark)
- {
- matrixRows << AnalysisTableWidget::MatrixNode(node, name, remark);
- }
- void AnalysisTableWidget::addColNode(QString node, QString name, QString remark)
- {
- matrixCols << AnalysisTableWidget::MatrixNode(node, name, remark);
- }
- QList<AnalysisDataSource> AnalysisTableWidget::getSource() const
- {
- return dataSource;
- }
- void AnalysisTableWidget::setTableWeight(QList<DemandWeight *> firstWeight, QList<DemandWeight *> secondWeight)
- {
- m_firstTableWeight = firstWeight;
- m_secondTableWeight = secondWeight;
- }
- void AnalysisTableWidget::setTableIndexAndTableMsg(int index, int engineerId, QString expertId, QString tableMsg)
- {
- m_tableIndex = index;
- m_engineerId = engineerId;
- m_expertId = expertId;
- m_table_msg = tableMsg;
- }
- void AnalysisTableWidget::setTableMethod(QString method)
- {
- m_resultMethod = method;
- }
- void AnalysisTableWidget::paintMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int type)
- {
- int row = matrixRows.count();
- int col = matrixCols.count();
- this->horizontalHeader()->setStretchLastSection(true);
- this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- this->setSelectionMode(QAbstractItemView::SingleSelection);
- this->setSelectionBehavior(QAbstractItemView::SelectItems);
- model->setHorizontalHeaderItem(0, new QStandardItem(""));
- if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
- model->horizontalHeaderItem(c + 1)->setTextAlignment(Qt::AlignCenter);
- }
- model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
- model->horizontalHeaderItem(col + 1)->setToolTip("权重");
- QStringList nodes;
- QVector<qreal> nxn((int)qPow(row, 2), 0);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- nodes << model->item(r, 0)->text().trimmed();
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 1; c < col + 1; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- if (nodeValueInfoList.size() > 0) {
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- } else {
- // data.nodeValue = "0";
- data.nodeValue = "";
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- QStringList content = model->item(r, c)->text().trimmed().split("/");
- if (content.size() == 1) {
- nxn[r * col + c - 1] = content[0].toDouble();
- } else {
- nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
- }
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 1].name;
- dataSource << data;
- }
- }
- ConsistencyCheck cc(nodes, nxn);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, col + 1,
- new QStandardItem(QString::number(cc.getWeights().at(r)) == "nan"
- ? ""
- : QString::number(cc.getWeights().at(r))));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- QStringList nodeList = cc.getNodes();
- QVector<qreal> weights = cc.getWeights();
- // qDebug() << weights;
- QList<DemandWeight *> list;
- for (int i = 0; i < weights.length(); i++) {
- DemandWeight *demandWeight = new DemandWeight();
- demandWeight->nodeName = nodeList.at(i);
- demandWeight->nodeWeight = weights.at(i);
- demandWeight->nodeValue = weights.at(i);
- demandWeight->engineerId = m_engineerId;
- demandWeight->expertId = m_expertId;
- demandWeight->isValid = 1;
- demandWeight->tableIndex = m_tableIndex;
- demandWeight->tableMsg = m_table_msg;
- demandWeight->pageIndex = 0;
- list.append(demandWeight);
- }
- if (DemandWeightService().QueryByTableIndexAndTableMsg(m_expertId, m_engineerId, m_tableIndex, m_table_msg)) {
- DemandWeightService().UpdateNodeValueList(list);
- } else {
- DemandWeightService().AddNodeWeightInfoList(list);
- }
- } else {
- // 获取到指标体系需求重要度
- model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
- model->horizontalHeaderItem(1)->setToolTip("权重");
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
- }
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- if (r >= m_secondTableWeight.count()) {
- model->setItem(r, 1, new QStandardItem(""));
- } else {
- model->setItem(r, 1,
- new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue) == "nan"
- ? ""
- : QString::number(m_secondTableWeight.at(r)->nodeValue)));
- }
- model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 2; c < col + 2; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- if (nodeValueInfoList.size() > 0) {
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- } else {
- data.nodeValue = "";
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 2].name;
- dataSource << data;
- }
- }
- for (int c = 0; c < col + 2; ++c) {
- if (c == 0) {
- model->setItem(row, c, new QStandardItem("技术重要度"));
- } else if (c > 1 && c < col + 2) {
- qreal value = 0;
- for (int r = 0; r < row; r++) {
- if (r < m_secondTableWeight.count()) {
- QStandardItem *item = model->item(r, c);
- QStringList content = item->text().trimmed().split("/");
- double itemValue = 0;
- if (content.size() == 1) {
- itemValue = content[0].toDouble();
- } else {
- itemValue = content[0].toDouble() / content[1].toDouble();
- }
- double tempValue = 0;
- if (QString::number(m_secondTableWeight.at(r)->nodeValue) != "nan") {
- tempValue = m_secondTableWeight.at(r)->nodeValue;
- }
- value += itemValue * tempValue;
- }
- }
- model->setItem(row, c, new QStandardItem(QString::number(value)));
- } else {
- model->setItem(row, c, new QStandardItem(""));
- }
- model->item(row, c)->setTextAlignment(Qt::AlignCenter);
- model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- // 保存技术重要度
- QList<TechnicalImport *> importList;
- for (int c = 0; c < col; c++) {
- QStandardItem *item = model->item(row, c + 2);
- TechnicalImport *import = new TechnicalImport();
- import->engineerId = m_engineerId;
- import->expertId = m_expertId.toInt();
- import->nodeName = matrixCols[c].name;
- import->nodeValue = item->text().toDouble();
- importList.append(import);
- }
- if (DBServiceSet().QueryTechnicalImportInfoByEngineerId(m_expertId.toInt(), m_engineerId)) {
- DBServiceSet().UpdateTechnicalImportInfoList(importList);
- } else {
- DBServiceSet().AddTechnicalImportInfoList(importList);
- }
- }
- emit returnModel(model);
- paintDone = true;
- }
- void AnalysisTableWidget::paintCompositeMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int type)
- {
- int row = matrixRows.count();
- int col = matrixCols.count();
- this->horizontalHeader()->setStretchLastSection(true);
- this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- this->setSelectionMode(QAbstractItemView::SingleSelection);
- this->setSelectionBehavior(QAbstractItemView::SelectItems);
- model->setHorizontalHeaderItem(0, new QStandardItem(""));
- if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
- }
- model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
- model->horizontalHeaderItem(col + 1)->setToolTip("权重");
- QStringList nodes;
- QVector<qreal> nxn((int)qPow(row, 2), 0);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- nodes << model->item(r, 0)->text().trimmed();
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 1; c < col + 1; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- QStringList content = model->item(r, c)->text().trimmed().split("/");
- if (content.size() == 1) {
- nxn[r * col + c - 1] = content[0].toDouble();
- } else {
- nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
- }
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 1].name;
- dataSource << data;
- }
- }
- ConsistencyCheck cc(nodes, nxn);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, col + 1, new QStandardItem(QString::number(cc.getWeights().at(r))));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- QStringList nodeList = cc.getNodes();
- QVector<qreal> weights = cc.getWeights();
- QList<DemandWeight *> list;
- for (int i = 0; i < weights.length(); i++) {
- DemandWeight *demandWeight = new DemandWeight();
- demandWeight->nodeName = nodeList.at(i);
- demandWeight->nodeWeight = weights.at(i);
- demandWeight->nodeValue = weights.at(i);
- demandWeight->engineerId = m_engineerId;
- demandWeight->expertId = m_expertId;
- demandWeight->isValid = 1;
- demandWeight->tableIndex = m_tableIndex;
- demandWeight->tableMsg = m_table_msg;
- list.append(demandWeight);
- }
- if (DemandWeightService().QueryByTableIndexAndTableMsg(m_expertId, m_engineerId, m_tableIndex, m_table_msg)) {
- DemandWeightService().UpdateNodeValueList(list);
- } else {
- DemandWeightService().AddNodeWeightInfoList(list);
- }
- } else {
- // 获取到指标体系需求重要度
- model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
- model->horizontalHeaderItem(1)->setToolTip("权重");
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
- }
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- if (r >= m_secondTableWeight.count()) {
- model->setItem(r, 1, new QStandardItem(""));
- } else {
- model->setItem(r, 1, new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue)));
- }
- model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 2; c < col + 2; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 2].name;
- dataSource << data;
- }
- }
- for (int c = 0; c < col + 2; ++c) {
- if (c == 0) {
- model->setItem(row, c, new QStandardItem("技术重要度"));
- } else if (c > 1 && c < col + 2) {
- qreal value = 0;
- for (int r = 0; r < row; r++) {
- if (r < m_secondTableWeight.count()) {
- QStandardItem *item = model->item(r, c);
- QStringList content = item->text().trimmed().split("/");
- double itemValue = 0;
- if (content.size() == 1) {
- itemValue = content[0].toDouble();
- } else {
- itemValue = content[0].toDouble() / content[1].toDouble();
- }
- value += itemValue * m_secondTableWeight.at(r)->nodeValue;
- }
- }
- model->setItem(row, c, new QStandardItem(QString::number(value)));
- } else {
- model->setItem(row, c, new QStandardItem(""));
- }
- model->item(row, c)->setTextAlignment(Qt::AlignCenter);
- model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- emit returnModel(model);
- paintDone = true;
- }
- void AnalysisTableWidget::paintSecondMatrixTable(QList<NodeMatrixInfo *> nodeValueInfoList, int page, int type,
- int index)
- {
- // qDebug() << "----------o---" << index;
- int row = matrixRows.count();
- int col = matrixCols.count();
- this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- this->setSelectionMode(QAbstractItemView::SingleSelection);
- this->setSelectionBehavior(QAbstractItemView::SelectItems);
- model->setHorizontalHeaderItem(0, new QStandardItem(""));
- if (type == IndexType::IndexTech || type == IndexType::SchemaEval) {
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].remark);
- }
- model->setHorizontalHeaderItem(col + 1, new QStandardItem("权重"));
- model->horizontalHeaderItem(col + 1)->setToolTip("权重");
- model->setHorizontalHeaderItem(col + 2, new QStandardItem("需求重要度"));
- model->horizontalHeaderItem(col + 2)->setToolTip("需求重要度");
- QStringList nodes;
- QVector<qreal> nxn((int)qPow(row, 2), 0);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- nodes << model->item(r, 0)->text().trimmed();
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 1; c < col + 1; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- if (nodeValueInfoList.size() > 0) {
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 1].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- } else {
- // data.nodeValue = "0";
- data.nodeValue = "";
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- QStringList content = model->item(r, c)->text().trimmed().split("/");
- if (content.size() == 1) {
- nxn[r * col + c - 1] = content[0].toDouble();
- } else {
- nxn[r * col + c - 1] = content[0].toDouble() / content[1].toDouble();
- }
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 1].name;
- dataSource << data;
- }
- }
- ConsistencyCheck cc(nodes, nxn);
- for (int r = 0; r < row; ++r) {
- model->setItem(r, col + 1,
- new QStandardItem(QString::number(cc.getWeights().at(r)) == "nan"
- ? ""
- : QString::number(cc.getWeights().at(r))));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- qreal firstWeight = 0;
- if (m_firstTableWeight.size() > 0) {
- firstWeight = m_firstTableWeight.at(index - 1)->nodeWeight;
- }
- qreal value = cc.getWeights().at(r) * firstWeight;
- model->setItem(r, col + 2,
- new QStandardItem(QString::number(value) == "nan" ? "" : QString::number(value)));
- model->item(r, col + 2)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 2)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- // 校验成功持久化数据
- QStringList nodeList = cc.getNodes();
- QVector<qreal> weights = cc.getWeights();
- QList<DemandWeight *> list;
- QList<DemandWeight *> firstList;
- // DBServiceSet().QueryByTableIndexAndTableMsg(&firstList, m_expertId, m_engineerId, 0, m_table_msg);
- DemandWeightService().QueryByTableIndexAndTableMsg(&firstList, m_expertId, m_engineerId, page - 1, m_table_msg);
- double weight = 0;
- // if (firstList.size() != 0) {
- weight = m_firstTableWeight.at(index - 1)->nodeWeight;
- //}
- for (int i = 0; i < weights.length(); i++) {
- DemandWeight *demandWeight = new DemandWeight();
- demandWeight->nodeName = nodeList.at(i);
- demandWeight->nodeWeight = weights.at(i);
- demandWeight->engineerId = m_engineerId;
- demandWeight->expertId = m_expertId;
- demandWeight->isValid = 1;
- demandWeight->tableIndex = m_tableIndex;
- demandWeight->tableMsg = m_table_msg;
- demandWeight->nodeValue = demandWeight->nodeWeight * weight;
- demandWeight->pageIndex = page;
- list.append(demandWeight);
- }
- if (DemandWeightService().QueryByTableIndexAndTableMsgAndPage(m_expertId, m_engineerId, m_tableIndex,
- m_table_msg, page)) {
- DemandWeightService().UpdateNodeValueList(list);
- } else {
- DemandWeightService().AddNodeWeightInfoList(list);
- }
- } else {
- model->setHorizontalHeaderItem(1, new QStandardItem("权重"));
- model->horizontalHeaderItem(1)->setToolTip("权重");
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 2, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 2)->setToolTip(matrixCols[c].remark);
- }
- for (int r = 0; r < row; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r].name));
- model->item(r, 0)->setToolTip(matrixRows[r].remark);
- model->item(r, 0)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 0)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- if (r >= m_secondTableWeight.count()) {
- model->setItem(r, 1, new QStandardItem("1"));
- } else {
- model->setItem(r, 1,
- new QStandardItem(QString::number(m_secondTableWeight.at(r)->nodeValue) == "nan"
- ? ""
- : QString::number(m_secondTableWeight.at(r)->nodeValue)));
- }
- model->item(r, 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- for (int c = 2; c < col + 2; ++c) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- if (nodeValueInfoList.size() > 0) {
- for (NodeMatrixInfo *nodeMatrixInfo : nodeValueInfoList) {
- if (nodeMatrixInfo->abscissa == matrixRows[r].name
- && nodeMatrixInfo->ordinate == matrixCols[c - 2].name) {
- data.nodeValue = nodeMatrixInfo->nodeValue;
- }
- }
- } else {
- data.nodeValue = "";
- }
- model->setItem(r, c, new QStandardItem(data.nodeValue));
- model->item(r, c)->setTextAlignment(Qt::AlignCenter);
- model->item(r, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- data.node = matrixRows[r].node;
- data.abscissa = matrixRows[r].name;
- data.ordinate = matrixCols[c - 2].name;
- dataSource << data;
- }
- }
- for (int c = 0; c < col + 2; ++c) {
- if (c == 0) {
- model->setItem(row, c, new QStandardItem("技术重要度"));
- } else if (c > 1 && c < col + 2) {
- qreal value = 0;
- for (int r = 0; r < row; r++) {
- if (r < m_secondTableWeight.count()) {
- QStandardItem *item = model->item(r, c);
- QStringList content = item->text().trimmed().split("/");
- double itemValue = 0;
- if (content.size() == 1) {
- itemValue = content[0].toDouble();
- } else {
- itemValue = content[0].toDouble() / content[1].toDouble();
- }
- double tempValue = 0;
- if (QString::number(m_secondTableWeight.at(r)->nodeValue) != "nan") {
- tempValue = m_secondTableWeight.at(r)->nodeValue;
- }
- value += itemValue * tempValue;
- }
- }
- model->setItem(row, c, new QStandardItem(QString::number(value)));
- } else {
- model->setItem(row, c, new QStandardItem(""));
- }
- model->item(row, c)->setTextAlignment(Qt::AlignCenter);
- model->item(row, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- emit returnModel(model);
- paintDone = true;
- // qDebug() << "--------ok";
- }
- void AnalysisTableWidget::nodeValueChanged(QStandardItem *item)
- {
- if (paintDone) {
- // qDebug() << item->column() << item->row() << item->text();
- }
- }
- bool AnalysisTableWidget::isDataReady() const
- {
- if (dataSource.count() == 0) {
- return false;
- }
- for (AnalysisDataSource data : dataSource) {
- if (data.changed == false) {
- return false;
- }
- }
- return true;
- }
|