#include "GroupTableWidget.h" #include "RequirementImportance.h" #include "algorithm/ConsistencyCheck.h" #include #include #include #include #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 GroupTableWidget::getSource() const { return dataSource; } void GroupTableWidget::paintDemandTable(QList> 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 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 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> 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 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 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); }