123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- #include "GroupTableWidget.h"
- #include "RequirementImportance.h"
- #include "algorithm/ConsistencyCheck.h"
- #include <QDebug>
- #include <QHeaderView>
- #include <QTime>
- #include <QtMath>
- #include "dbService/ClassSet.h"
- GroupTableWidget::GroupTableWidget(QWidget *parent) : QTableView(parent)
- {
- qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
- model = new QStandardItemModel();
- this->setModel(model);
- }
- GroupTableWidget::~GroupTableWidget() { }
- void GroupTableWidget::addRowNode(QString node, QString name, QString remark)
- {
- matrixRows << GroupTableWidget::MatrixNode(node, name, remark);
- }
- void GroupTableWidget::addColNode(QString node, QString name, QString remark)
- {
- matrixCols << GroupTableWidget::MatrixNode(node, name, remark);
- }
- void GroupTableWidget::setTableType(int type)
- {
- tableType = type;
- }
- QList<AnalysisDataSource> GroupTableWidget::getSource() const
- {
- return dataSource;
- }
- void GroupTableWidget::paintDemandTable(QList<QList<DemandWeight *>> nodeValueInfoList, QString arithmeticMethod)
- {
- 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(""));
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].name);
- }
- model->setHorizontalHeaderItem(col + 1, new QStandardItem("群策结果"));
- model->horizontalHeaderItem(col + 1)->setToolTip("群策结果");
- // 第一行权重渲染
- for (int c = 0; c < col + 1; c++) {
- if (c == 0) {
- model->setItem(0, c, new QStandardItem("专家权重"));
- model->item(0, c)->setToolTip("专家权重");
- model->item(0, c)->setTextAlignment(Qt::AlignCenter);
- model->item(0, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- } else {
- model->setItem(0, c, new QStandardItem(matrixCols[c - 1].remark));
- model->item(0, c)->setTextAlignment(Qt::AlignCenter);
- model->item(0, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- for (int r = 1; r < row + 1; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r - 1].name));
- // qDebug() << "test" << matrixRows[r - 1].name;
- model->item(r, 0)->setToolTip(matrixRows[r - 1].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) {
- QList<DemandWeight *> list = nodeValueInfoList.at(c - 1);
- for (int r = 1; r < row + 1; ++r) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- // data.nodeValue = "";
- for (DemandWeight *demandWeight : list) {
- if (demandWeight->nodeName == matrixRows[r - 1].name) {
- if (tableType == IndexType::SchemaEval) {
- double tempValue = demandWeight->nodeWeight;
- if (QString::number(tempValue) != "nan") {
- data.nodeValue = QString::number(tempValue);
- } else {
- // data.nodeValue = "0";
- }
- } else {
- double tempValue = demandWeight->nodeValue;
- if (QString::number(tempValue) != "nan") {
- data.nodeValue = QString::number(tempValue);
- } else {
- // data.nodeValue = "0";
- }
- }
- break;
- }
- }
- 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 - 1].node;
- data.abscissa = matrixRows[r - 1].name;
- data.ordinate = matrixCols[c - 1].name;
- dataSource << data;
- }
- }
- // 最后一列进行计算
- bool valid = false;
- if (arithmeticMethod == "arithmetic") {
- for (int r = 1; r < row + 1; r++) {
- qreal value = 0;
- for (int c = 1; c < col + 1; c++) {
- QStandardItem *item0 = model->item(0, c);
- QStandardItem *item = model->item(r, c);
- QString text0 = item0->text();
- QString text = item->text();
- if (text != "") {
- valid = true;
- }
- value += text0.toDouble() * text.toDouble();
- }
- model->setItem(r, col + 1, new QStandardItem(valid ? QString::number(value) : ""));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- } else {
- QList<double> valueList;
- double sum = 0;
- for (int r = 1; r < row + 1; r++) {
- qreal value = 1;
- for (int c = 1; c < col + 1; c++) {
- QStandardItem *item0 = model->item(0, c);
- QStandardItem *item = model->item(r, c);
- if (item->text() != "" && item0->text() != "") {
- valid = true;
- }
- double temp = qPow(item->text().toDouble(), item0->text().toDouble());
- value *= temp;
- }
- value = sqrt(value);
- valueList.append(value);
- sum += value;
- }
- for (int r = 1; r < row + 1; r++) {
- model->setItem(r, col + 1, new QStandardItem(valid ? QString::number(valueList.at(r - 1) / sum) : ""));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- emit returnModel(model);
- }
- void GroupTableWidget::paintTechnicalTable(QList<QList<TechnicalImport *>> nodeValueInfoList, QString arithmeticMethod)
- {
- if (nodeValueInfoList.isEmpty()) {
- return;
- }
- 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(""));
- for (int c = 0; c < col; ++c) {
- model->setHorizontalHeaderItem(c + 1, new QStandardItem(matrixCols[c].name));
- model->horizontalHeaderItem(c + 1)->setToolTip(matrixCols[c].name);
- }
- model->setHorizontalHeaderItem(col + 1, new QStandardItem("技术重要度"));
- model->horizontalHeaderItem(col + 1)->setToolTip("技术重要度");
- // 第一行权重渲染
- for (int c = 0; c < col + 1; c++) {
- if (c == 0) {
- model->setItem(0, c, new QStandardItem("专家权重"));
- model->item(0, c)->setToolTip("专家权重");
- model->item(0, c)->setTextAlignment(Qt::AlignCenter);
- model->item(0, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- } else {
- model->setItem(0, c, new QStandardItem(matrixCols[c - 1].remark));
- model->item(0, c)->setTextAlignment(Qt::AlignCenter);
- model->item(0, c)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- for (int r = 1; r < row + 1; ++r) {
- model->setItem(r, 0, new QStandardItem(matrixRows[r - 1].name));
- model->item(r, 0)->setToolTip(matrixRows[r - 1].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) {
- QList<TechnicalImport *> list = nodeValueInfoList.at(c - 1);
- for (int r = 1; r < row + 1; ++r) {
- AnalysisDataSource data;
- data.row = r;
- data.col = c;
- data.changed = true;
- for (TechnicalImport *demandWeight : list) {
- if (demandWeight->nodeName == matrixRows[r - 1].name) {
- data.nodeValue = QString::number(demandWeight->nodeValue);
- break;
- } else {
- data.nodeValue = "0";
- // 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 - 1].node;
- data.abscissa = matrixRows[r - 1].name;
- data.ordinate = matrixCols[c - 1].name;
- dataSource << data;
- }
- }
- // 最后一列进行计算
- if (arithmeticMethod == "arithmetic") {
- for (int r = 1; r < row + 1; r++) {
- qreal value = 0;
- for (int c = 1; c < col + 1; c++) {
- for (int c = 1; c < col + 1; c++) {
- QStandardItem *item0 = model->item(0, c);
- QStandardItem *item = model->item(r, c);
- value += item0->text().toDouble() * item->text().toDouble();
- }
- model->setItem(r, col + 1, new QStandardItem(QString::number(value)));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- } else {
- double sum = 0;
- QList<double> valueList;
- for (int r = 1; r < row + 1; r++) {
- qreal value = 1;
- for (int c = 1; c < col + 1; c++) {
- QStandardItem *item0 = model->item(0, c);
- QStandardItem *item = model->item(r, c);
- double temp = qPow(item->text().toDouble(), item0->text().toDouble());
- value *= temp;
- }
- value = sqrt(value);
- valueList.append(value);
- sum += value;
- model->setItem(r, col + 1, new QStandardItem(QString::number(value)));
- model->item(r, col + 1)->setTextAlignment(Qt::AlignCenter);
- model->item(r, col + 1)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
- }
- }
- emit returnModel(model);
- }
|