#include "MatrixPanelWidget.h" #include "MatrixTableTechMeasuresWidget.h" #include "MatrixTableWidget.h" #include "dbService/DBServiceSet.h" #include "dbService/NodeMatrixService.h" #include "ui_MatrixPanelWidget.h" #include #include #include #include MatrixPanelWidget::MatrixPanelWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MatrixPanelWidget) { ui->setupUi(this); firstLayout = new QGridLayout; firstPlainWidget = nullptr; ui->stackedWidget->widget(0)->setLayout(firstLayout); secondLayout = new QGridLayout; secondPlainWidget = nullptr; ui->stackedWidget->widget(1)->setLayout(secondLayout); ui->stackedWidget->setCurrentIndex(0); ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); ui->importBtn->setVisible(true); } MatrixPanelWidget::MatrixPanelWidget(QWidget *parent, ProfessorInfo professor) : QWidget(parent), ui(new Ui::MatrixPanelWidget) { ui->setupUi(this); firstLayout = new QGridLayout; firstPlainWidget = nullptr; ui->stackedWidget->widget(0)->setLayout(firstLayout); secondLayout = new QGridLayout; secondPlainWidget = nullptr; ui->stackedWidget->widget(1)->setLayout(secondLayout); ui->stackedWidget->setCurrentIndex(0); m_professor = professor; if (m_professor.tableMsg != "技术措施重要度评估对象") { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); } ui->importBtn->setVisible(false); ui->exportBtn->setVisible(false); } MatrixPanelWidget::~MatrixPanelWidget() { if (currentMindNodes) { delete currentMindNodes; } if (classifiedNodes) { delete classifiedNodes; } if (indexsRefClassifiedNodes) { delete indexsRefClassifiedNodes; } delete ui; } void MatrixPanelWidget::init(const QStringList indexsRef, const QStringList indexs) { qDebug() << "MatrixPanelWidget---init"; indexsRefClassifiedNodes = nullptr; if (!indexsRef.isEmpty()) { MindNodeManager *indexsRefNodes = new MindNodeManager(); // 是否参考指标体系 getMindNodes(indexsRefNodes, indexsRef); indexsRefClassifiedNodes = new QList>; sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes); delete indexsRefNodes; } if (!indexs.isEmpty()) { currentMindNodes = new MindNodeManager(); classifiedNodes = new QList>; getMindNodes(currentMindNodes, indexs); sortMindNodes(*currentMindNodes, classifiedNodes); } else { currentMindNodes = nullptr; classifiedNodes = nullptr; } ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages())); ui->currPageLabel->setText(QString("当前第0页")); QList nodeValueInfoList; // DBServiceSet().QueryNodeMatrixListByExpertIdAndEngineerId2(&nodeValueInfoList, m_professor.id, // m_professor.engineer.engineerId, // m_professor.tableMsg); if (!indexsRef.isEmpty()) { currentTab = "技术措施重要度评估对象"; initPlainTechMeasuresWidget(nodeValueInfoList); setPage(1); return; } if (!indexs.isEmpty()) { currentTab = ""; initPlainWidget(nodeValueInfoList); setPage(1); return; } } void MatrixPanelWidget::initImportData(const QStringList indexsRef, const QStringList indexs, QList nodeValueInfoList) { // qDebug() << "MatrixPanelWidget---initImportData" << endl; indexsRefClassifiedNodes = nullptr; if (!indexsRef.isEmpty()) { MindNodeManager *indexsRefNodes = new MindNodeManager(); // 是否参考指标体系 getMindNodes(indexsRefNodes, indexsRef); indexsRefClassifiedNodes = new QList>; sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes); delete indexsRefNodes; } if (!indexs.isEmpty()) { currentMindNodes = new MindNodeManager(); classifiedNodes = new QList>; getMindNodes(currentMindNodes, indexs); sortMindNodes(*currentMindNodes, classifiedNodes); } else { currentMindNodes = nullptr; classifiedNodes = nullptr; } ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages())); ui->currPageLabel->setText(QString("当前第0页")); if (!indexsRef.isEmpty()) { currentTab = "技术措施重要度评估对象"; qDebug() << "MatrixPanelWidget---init" << currentTab; initPlainTechMeasuresWidget(nodeValueInfoList); setPage(1); return; } if (!indexs.isEmpty()) { currentTab = ""; initPlainWidget(nodeValueInfoList); setPage(1); return; } } void MatrixPanelWidget::sortMindNodes(const MindNodeManager &manager, QList> *classify) { for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) { QStringList nodePonit = msg.node.split("."); while (nodePonit.count() - 1 > classify->count()) { (*classify) << QList(); } (*classify)[nodePonit.count() - 2] << msg; } } void MatrixPanelWidget::getMindNodes(MindNodeManager *manager, QStringList listNodes) { int sn[16]; memset(sn, 0, sizeof(int) * 16); int spaceNum = -1; int level = 0; MindNodeManager::NodeMessage temp; manager->setMindName(listNodes[0].trimmed()); for (int i = 1; i < listNodes.count(); i++) { int tempSpace = 0; for (QString s : listNodes[i]) { if (s == " ") { tempSpace++; } else { break; } } tempSpace /= 4; if (tempSpace == 1) { // 一级 spaceNum = tempSpace; level = 0; sn[level]++; memset((void *)&sn[1], 0, sizeof(int) * 15); } else { if (spaceNum < tempSpace) { // 空格增加 spaceNum = tempSpace; level++; sn[level]++; } else if (spaceNum == tempSpace) { // 同一级 sn[level]++; } else { memset((void *)&sn[tempSpace], 0, sizeof(int) * (16 - tempSpace)); level -= spaceNum - tempSpace; spaceNum = tempSpace; sn[level]++; } } QString node = "1"; for (int l : sn) { if (l > 0) { node += QString(".%1").arg(l); } else { break; } } if (listNodes[i].trimmed().isEmpty()) { temp.name = QString("NULL(节点%1)").arg(node); temp.node = node; temp.remark = ""; manager->pushNewMind(temp); } else { temp.name = listNodes[i].trimmed().split("\t")[0]; temp.node = node; temp.remark = listNodes[i].trimmed().split("\t")[1]; manager->pushNewMind(temp); } } } QStringList MatrixPanelWidget::getFirstIndexNodes(const MindNodeManager &manager) { QList> classify; for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) { QStringList nodePonit = msg.node.split("."); while (nodePonit.count() - 1 > classify.count()) { classify << QList(); } classify[nodePonit.count() - 2] << msg; } QStringList firstNodes; for (MindNodeManager::NodeMessage msg : classify.first()) { firstNodes << msg.name; } return firstNodes; } QStringList MatrixPanelWidget::getLastIndexNodes(const MindNodeManager &manager) { QList> classify; for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) { QStringList nodePonit = msg.node.split("."); while (nodePonit.count() - 1 > classify.count()) { classify << QList(); } classify[nodePonit.count() - 2] << msg; } QStringList lastNodes; for (MindNodeManager::NodeMessage msg : classify.last()) { lastNodes << msg.name; } return lastNodes; } int MatrixPanelWidget::getPages() { #if 0 int max = 0; for (MindNodeManager::NodeMessage msg : currentMindNodes->getMindNodes()) { QStringList nodePonit = msg.node.split("."); if (max < nodePonit.count() - 1) { max = nodePonit.count() - 1; } } return max; #else if (!classifiedNodes) { return 0; } int pages = classifiedNodes->count(); if (pages == 1) { ui->nextPageBtn->setVisible(false); ui->prePageBtn->setVisible(false); } return classifiedNodes->count(); #endif } void MatrixPanelWidget::setPage(int page) { if (page < 1 || page > getPages()) { return; } currentPage = page; ui->currPageLabel->setText(QString("当前第%1页").arg(currentPage)); if (currentPage == 1) { ui->prePageBtn->setDisabled(true); ui->nextPageBtn->setDisabled(false); } else if (currentPage == getPages()) { ui->prePageBtn->setDisabled(false); ui->nextPageBtn->setDisabled(true); } else { ui->prePageBtn->setDisabled(false); ui->nextPageBtn->setDisabled(false); } paintPlainWidget(); } // 能力重要度评估指标体系初始化 void MatrixPanelWidget::initPlainWidget(QList nodeValueInfoList) { qDeleteAll(modelList); modelList.clear(); if (getPages() == 0) { return; } if (nodeValueInfoList.size() > 0) { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(false); isAutoSave = true; } // 准备第一页,非tab的 MatrixTableWidget *table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr); table->setCurrentPage(1); table->setMsgName("总体"); table->setTableIndexAndTableMsg(0, m_professor.engineer.engineerId, m_professor.id, m_table_msg); connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady); // connect(table, &MatrixTableWidget::autoSave, this, &MatrixPanelWidget::oneTableDataSave); connect(table, &MatrixTableWidget::returnModel, this, &MatrixPanelWidget::getTableModel); connect(table, &MatrixTableWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName); if (indexsRefClassifiedNodes) { for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) { // qDebug() << msg.node << msg.name << msg.remark; table->addRowNode(msg.node, msg.name, msg.remark); } } for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) { table->addColNode(msg.node, msg.name, msg.remark); if (indexsRefClassifiedNodes == nullptr) { table->addRowNode(msg.node, msg.name, msg.remark); } } NodeMatrixService().QueryNodesByExpertNameAndEngineerId2( &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", 0); table->paintMatrixTable(nodeValueInfoList); firstLayout->addWidget(table); qDeleteAll(nodeValueInfoList); nodeValueInfoList.clear(); // 准备第二页,tab组合的 for (int p = 1; p < getPages(); ++p) { QTabWidget *tab = new QTabWidget; tab->setTabPosition(QTabWidget::South); int index = 0; for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) { ++index; QString node = msg.node; // MatrixTableWidget *table = nullptr; table = nullptr; for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) { if ((info.node.count('.') == msg.node.count('.') + 1) && (info.node.left(msg.node.count()) == msg.node)) { if (!table) { table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr); connect(table, &MatrixTableWidget::returnModel, this, &MatrixPanelWidget::getTableModel); connect(table, &MatrixTableWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName); table->setCurrentPage(2); table->setTableIndexAndTableMsg(index, m_professor.engineer.engineerId, m_professor.id, m_table_msg); } if (table) { table->addColNode(info.node, info.name, info.remark); if (!indexsRefClassifiedNodes) { table->addRowNode(info.node, info.name, info.remark); } } } } if (indexsRefClassifiedNodes) { for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) { table->addRowNode(msg.node, msg.name, msg.remark); } } if (table) { table->setMsgName(msg.name); // qDebug() << "专家界面tab" << msg.name; NodeMatrixService().QueryNodesByExpertNameAndEngineerId2( &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, QString::number(p + 1), index - 1); table->paintMatrixTable(nodeValueInfoList); tab->addTab(table, msg.name); qDebug() << "tabmes===" << msg.name; connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady); qDeleteAll(nodeValueInfoList); nodeValueInfoList.clear(); } } tabWidgets << tab; } // secondLayout->addWidget(tab); } void MatrixPanelWidget::initPlainTechMeasuresWidget(QList nodeValueInfoList) { qDeleteAll(modelList); modelList.clear(); // qDebug() << "initPlainTechMeasuresWidget" << endl; if (getPages() == 0) { return; } if (nodeValueInfoList.size() > 0) { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(false); } // 准备第一页,非tab的 MatrixTableTechMeasuresWidget *table = new MatrixTableTechMeasuresWidget(nullptr); connect(table, &MatrixTableTechMeasuresWidget::dataReady, this, &MatrixPanelWidget::oneTechMeasureTableDataReady); connect(table, &MatrixTableTechMeasuresWidget::returnModel, this, &MatrixPanelWidget::getTableModel); connect(table, &MatrixTableTechMeasuresWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName); if (indexsRefClassifiedNodes) { for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) { // qDebug() << "mes.node" << msg.name; table->addRowNode(msg.node, msg.name, msg.remark); } } for (MindNodeManager::NodeMessage msg : classifiedNodes->first()) { // qDebug() << "mes.node" << msg.name; table->addColNode(msg.node, msg.name, msg.remark); technicalCols.append(msg); if (indexsRefClassifiedNodes == nullptr) { table->addRowNode(msg.node, msg.name, msg.remark); } } NodeMatrixService().QueryNodesByExpertNameAndEngineerId2( &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", 0); table->setTableName("总体"); table->paintMatrixTable(nodeValueInfoList); firstLayout->addWidget(table); qDeleteAll(nodeValueInfoList); nodeValueInfoList.clear(); // 准备第二页,tab组合的 for (int p = 1; p < getPages(); ++p) { QTabWidget *tab = new QTabWidget; tab->setTabPosition(QTabWidget::South); int index = 0; for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) { ++index; QString node = msg.node; // MatrixTableWidget *table = nullptr; table = nullptr; for (MindNodeManager::NodeMessage info : classifiedNodes->at(p)) { if ((info.node.count('.') == msg.node.count('.') + 1) && (info.node.left(msg.node.count()) == msg.node)) { if (!table) { table = new MatrixTableTechMeasuresWidget(nullptr); connect(table, &MatrixTableTechMeasuresWidget::returnModel, this, &MatrixPanelWidget::getTableModel); connect(table, &MatrixTableTechMeasuresWidget::returnModelName, this, &MatrixPanelWidget::getTableModelName); } if (table) { table->addColNode(info.node, info.name, info.remark); if (!indexsRefClassifiedNodes) { table->addRowNode(info.node, info.name, info.remark); } } } } if (indexsRefClassifiedNodes) { for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) { table->addRowNode(msg.node, msg.name, msg.remark); } } if (table) { NodeMatrixService().QueryNodesByExpertNameAndEngineerId2( &nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, QString::number(p + 1), index - 1); table->setTableName(msg.name); table->paintMatrixTable(nodeValueInfoList); tab->addTab(table, msg.name); connect(table, &MatrixTableTechMeasuresWidget::dataReady, this, &MatrixPanelWidget::oneTechMeasureTableDataReady); qDeleteAll(nodeValueInfoList); nodeValueInfoList.clear(); } } tabWidgets << tab; } // secondLayout->addWidget(tab); } bool MatrixPanelWidget::checkTableDateReady() { bool filled = true; if (m_table_msg == "技术措施重要度评估对象") { MatrixTableTechMeasuresWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); if (!first->isDataReady()) { filled = false; } for (QTabWidget *tab : tabWidgets) { for (int t = 0; t < tab->count(); ++t) { MatrixTableTechMeasuresWidget *table = qobject_cast(tab->widget(t)); if (!table->isDataReady()) { filled = false; } } } } else { MatrixTableWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); if (!first->isDataReady()) { filled = false; } for (QTabWidget *tab : tabWidgets) { for (int t = 0; t < tab->count(); ++t) { MatrixTableWidget *table = qobject_cast(tab->widget(t)); if (!table->isDataReady()) { filled = false; } } } } return filled; } void MatrixPanelWidget::paintPlainWidget() { bool firstShow = true; if (getPages() == 0) { return; } if (currentPage > 1) { firstShow = false; } if (firstShow) { ui->stackedWidget->setCurrentIndex(0); } else { QTabWidget *newTab = tabWidgets.at(currentPage - 2); if (secondLayout->count() == 0) { secondLayout->addWidget(newTab); newTab->show(); } else { QTabWidget *currTab = qobject_cast(secondLayout->itemAt(0)->widget()); if (newTab == currTab) { qDebug() << "same tab"; } else { secondLayout->removeWidget(currTab); currTab->hide(); secondLayout->addWidget(newTab); newTab->show(); } } ui->stackedWidget->setCurrentIndex(1); } } void MatrixPanelWidget::on_prePageBtn_clicked() { setPage(currentPage - 1); } void MatrixPanelWidget::on_nextPageBtn_clicked() { setPage(currentPage + 1); } void MatrixPanelWidget::setTableMsg(QString tableMsg) { m_table_msg = tableMsg; } // 采集完成保存 void MatrixPanelWidget::on_saveBtn_clicked() { bool saveFlag = true; int tabIndex = 0; QList nodeInfoList; if (currentTab == "技术措施重要度评估对象") { if (currentPage == 1) { MatrixTableTechMeasuresWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); // 保存第一页数据 for (MatrixDataSource s : first->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = "1"; t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; nodeInfoList.append(t); if (t->nodeValue.isEmpty()) { saveFlag = false; } } } else { QTabWidget *currTab = qobject_cast(secondLayout->itemAt(0)->widget()); tabIndex = currTab->currentIndex(); // 保存第二页数据,如果有 // for (QTabWidget *tabWidget : tabWidgets) { for (int ta = 0; ta < tabWidgets.count(); ta++) { if (ta + 2 == currentPage) { for (int i = 0; i < tabWidgets[ta]->count(); ++i) { MatrixTableTechMeasuresWidget *table = dynamic_cast(tabWidgets[ta]->widget(tabIndex)); for (MatrixDataSource s : table->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = QString::number(currentPage); t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; nodeInfoList.append(t); if (t->nodeValue.isEmpty()) { saveFlag = false; } } } } } } } else { // 能力重要度 if (currentPage == 1) { MatrixTableWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); // 保存第一页数据 for (MatrixDataSource s : first->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = "1"; t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; nodeInfoList.append(t); if (t->nodeValue.isEmpty()) { saveFlag = false; } } } else { qDebug() << "currentPage--------" << currentPage; QTabWidget *currTab = qobject_cast(secondLayout->itemAt(0)->widget()); tabIndex = currTab->currentIndex(); // 保存第二页数据,如果有 // for (QTabWidget *tabWidget : tabWidgets) { for (int ta = 0; ta < tabWidgets.count(); ta++) { if (ta + 2 == currentPage) { qDebug() << "----" << tabWidgets[ta]->count(); MatrixTableWidget *table = dynamic_cast(tabWidgets[ta]->widget(tabIndex)); for (MatrixDataSource s : table->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = QString::number(currentPage); t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; qDebug() << t->abscissa << "----" << t->ordinate << "-----" << t->node << "-----" << t->nodeValue; nodeInfoList.append(t); if (t->nodeValue.isEmpty()) { saveFlag = false; } } } } } } if (saveFlag) { if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2( m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, QString::number(currentPage), tabIndex)) { qDebug() << "存在数据"; NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList); } else { qDebug() << "新插入数据"; NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList); } } else { QMessageBox::warning(this, "警告", "请先填写数据,保证数据完整性!"); return; } QMessageBox::information(this, tr("成功"), tr("数据保存成功")); qDeleteAll(nodeInfoList); } void MatrixPanelWidget::saveNodes() { if (currentTab == "技术措施重要度评估对象") { // qDebug() << "技术措施---保存" << endl; int tabIndex = 0; QList nodeInfoList; MatrixTableTechMeasuresWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); // 保存第一页数据 for (MatrixDataSource s : first->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = "1"; t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; nodeInfoList.append(t); } if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2( m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", tabIndex)) { qDebug() << "存在数据"; NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList); } else { qDebug() << "新插入数据"; NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList); } // 保存第二页数据,如果有 // for (QTabWidget *tabWidget : tabWidgets) { for (int ta = 0; ta < tabWidgets.count(); ta++) { for (int i = 0; i < tabWidgets[ta]->count(); i++) { QList secondNodeInfoList; secondNodeInfoList.clear(); MatrixTableTechMeasuresWidget *table = dynamic_cast(tabWidgets[ta]->widget(i)); for (MatrixDataSource s : table->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue == "" ? "0" : s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = QString::number(ta + 2); t->tableMsg = m_professor.tableMsg; t->tabIndex = i; secondNodeInfoList.append(t); } if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2( m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, QString::number(ta + 2), i)) { qDebug() << "存在数据"; NodeMatrixService().UpdateNodeMatrixNodeValueList2(secondNodeInfoList); } else { qDebug() << "新插入数据"; NodeMatrixService().AddNodeMatrixInfoList2(secondNodeInfoList); } } } } else { QList nodeInfoList; MatrixTableWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); // 保存第一页数据 int tabIndex = 0; for (MatrixDataSource s : first->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = "1"; t->tableMsg = m_professor.tableMsg; t->tabIndex = tabIndex; nodeInfoList.append(t); } if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2( m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, "1", tabIndex)) { qDebug() << "存在数据"; NodeMatrixService().UpdateNodeMatrixNodeValueList2(nodeInfoList); } else { qDebug() << "新插入数据"; NodeMatrixService().AddNodeMatrixInfoList2(nodeInfoList); } qDeleteAll(nodeInfoList); // 保存第二页数据,如果有 // for (QTabWidget *tabWidget : tabWidgets) { for (int ta = 0; ta < tabWidgets.count(); ta++) { for (int i = 0; i < tabWidgets[ta]->count(); i++) { QList secondNodeInfoList; secondNodeInfoList.clear(); MatrixTableWidget *table = dynamic_cast(tabWidgets[ta]->widget(i)); for (MatrixDataSource s : table->getSource()) { NodeMatrixInfo *t = new NodeMatrixInfo(); t->abscissa = s.abscissa; t->ordinate = s.ordinate; t->node = s.node; t->nodeValue = s.nodeValue; t->expertId = QString::number(m_professor.id); t->expertName = m_professor.name; t->engineerId = m_professor.engineer.engineerId; t->writeDate = m_professor.createDataTime; t->mark = QString::number(ta + 2); t->tableMsg = m_professor.tableMsg; t->tabIndex = i; secondNodeInfoList.append(t); } if (NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId2( m_professor.name, m_professor.engineer.engineerId, m_professor.tableMsg, QString::number(ta + 2), i)) { qDebug() << "存在数据"; NodeMatrixService().UpdateNodeMatrixNodeValueList2(secondNodeInfoList); } else { qDebug() << "新插入数据"; NodeMatrixService().AddNodeMatrixInfoList2(secondNodeInfoList); } qDeleteAll(secondNodeInfoList); } } } } void MatrixPanelWidget::oneTableDataSave() { if (isAutoSave) { on_saveBtn_clicked(); } } void MatrixPanelWidget::oneTableDataReady(bool status) { if (status) { bool filled = true; MatrixTableWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); if (!first->isDataReady()) { filled = false; } for (QTabWidget *tab : tabWidgets) { for (int t = 0; t < tab->count(); ++t) { MatrixTableWidget *table = qobject_cast(tab->widget(t)); if (!table->isDataReady()) { filled = false; } } } if (filled) { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(false); } else { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); } } else { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); } } void MatrixPanelWidget::oneTechMeasureTableDataReady(bool status) { if (status) { bool filled = true; MatrixTableTechMeasuresWidget *first = qobject_cast(firstLayout->itemAt(0)->widget()); if (!first->isDataReady()) { filled = false; } for (QTabWidget *tab : tabWidgets) { for (int t = 0; t < tab->count(); ++t) { MatrixTableTechMeasuresWidget *table = qobject_cast(tab->widget(t)); if (!table->isDataReady()) { filled = false; } } } if (filled) { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(false); } else { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); } } else { ui->saveBtn->setDisabled(false); ui->exportBtn->setDisabled(true); } } void MatrixPanelWidget::getTableModel(QStandardItemModel *item) { modelList.append(item); } void MatrixPanelWidget::getTableModelName(QString itemName) { qDebug() << "-----tabeName----" << itemName; modelName.append(itemName); } // 导出table数据 void MatrixPanelWidget::on_exportBtn_clicked() { if (!checkTableDateReady()) { QMessageBox::warning(this, "警告", "请确保xlsx数据的完整性!"); return; } // 文件夹路径 QFileDialog::Options options; options |= QFileDialog::DontUseNativeDialog; QString filePath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options); if (filePath.isEmpty()) { return; } QString fileName = m_professor.name + "-" + m_table_msg + "-" + m_professor.engineer.engineerName; // QString filePath = ""; // filePath = QCoreApplication::applicationDirPath(); QDir dirReportPath(filePath); if (!dirReportPath.exists()) { if (dirReportPath.mkpath(filePath)) { filePath = filePath + "/" + fileName + tr(".xlsx"); } } else { filePath = filePath + "/" + fileName + tr(".xlsx"); } QFile file(fileName); if (file.exists()) { file.remove(); } QXlsx::Format format; format.setFontSize(12); // 字体大小 // format.setFontBold(true); //加粗 // format.setFontColor(QColor(73, 88, 233)); //颜色 // 可以用rgb,也可以用系统自带 QColor(Qt::red) format.setHorizontalAlignment(QXlsx::Format::AlignHCenter); // 水平居中 format.setVerticalAlignment(QXlsx::Format::AlignVCenter); // 垂直居中 QXlsx::Document exprot; // 判断是否需要多sheet页 // QList strList; // qDebug() << "modelListSize-----------------" << modelList.size(); // if (modelList.size() > 1) { // QStandardItemModel *model = modelList.at(0); // for (int c = 0; c < model->columnCount(); c++) { // QStandardItem *head = model->horizontalHeaderItem(c); // if (head != nullptr) { // strList.append(head->text() == "" ? "总体" : head->text()); // qDebug() << "modelListSize-----------------" << head->text(); // } // } // } else { // strList.append("总体"); // } for (int i = 0; i < modelList.size(); i++) { QStandardItemModel *model = modelList.at(i); // qDebug() << strList.at(i); exprot.addSheet(modelName.at(i)); int row = model->rowCount(); int col = model->columnCount(); // 先把表头获取到添加 for (int c = 1; c < col + 1; c++) { QStandardItem *head = model->horizontalHeaderItem(c - 1); exprot.write(1, c, head->text(), format); exprot.setColumnWidth(c, head->text().size() == 0 ? 40 : head->text().size() * 4); } for (int r = 2; r < row + 2; r++) { for (int c = 1; c < col + 1; c++) { QStandardItem *item = model->item(r - 2, c - 1); exprot.write(r, c, item->text(), format); } } } // 添加专家基本信息 exprot.addSheet("专家信息"); exprot.write(1, 1, "ID", format); exprot.write(1, 2, "账号", format); exprot.write(1, 3, "单位", format); exprot.write(1, 4, "职务", format); exprot.write(1, 5, "专业", format); exprot.write(1, 6, "联系方式", format); exprot.write(1, 7, "填写时间", format); exprot.write(1, 8, "备注", format); exprot.write(2, 1, m_professor.id, format); exprot.write(2, 2, m_professor.name, format); exprot.write(2, 3, m_professor.department, format); exprot.write(2, 4, m_professor.job, format); exprot.write(2, 5, m_professor.major, format); exprot.write(2, 6, m_professor.phone, format); exprot.write(2, 7, m_professor.createDataTime, format); exprot.write(2, 8, m_professor.remark, format); exprot.saveAs(filePath); QMessageBox::information(this, tr("成功"), tr("数据导出成功")); saveNodes(); } // 导入数据 void MatrixPanelWidget::on_importBtn_clicked() { // 打开文件 QDir dir; QFileDialog::Options options; options |= QFileDialog::DontUseNativeDialog; QString selectedFilter; QString fileName = QFileDialog::getOpenFileName(this, "选择Excel文件", "", "Excel (*.xls *.xlsx)", &selectedFilter, options); if (fileName.isEmpty()) return; // 获取node节点 QList nodeValueInfoList; NodeMatrixService().QueryNodeMatrixListByExpertNameAndEngineerId(&nodeValueInfoList, m_professor.name, m_professor.engineer.engineerId); // 读取文件内容 QXlsx::Document xlsxR(fileName); QStringList str = xlsxR.sheetNames(); // 遍历sheet页 for (int i = 0; i < str.size(); i++) { xlsxR.selectSheet(str.at(i)); if (xlsxR.load()) { int row = xlsxR.dimension().lastRow(); int col = xlsxR.dimension().lastColumn(); for (int r = 2; r <= row; r++) { for (int c = 2; c <= col; c++) { QString abscissa; QString ordinate; QXlsx::Cell *cellAbscissa = xlsxR.cellAt(r, 1); if (cellAbscissa != NULL) { QVariant var = cellAbscissa->readValue(); abscissa = var.toString(); } QXlsx::Cell *cellOrdinate = xlsxR.cellAt(1, c); if (cellOrdinate != NULL) { QVariant var = cellOrdinate->readValue(); ordinate = var.toString(); } for (int index = 0; index < nodeValueInfoList.size(); index++) { NodeMatrixInfo *nodeInfo = nodeValueInfoList.at(index); if (abscissa == nodeInfo->abscissa && ordinate == nodeInfo->ordinate) { QXlsx::Cell *value = xlsxR.cellAt(r, c); if (value != NULL) { QVariant var = value->readValue(); nodeInfo->nodeValue = var.toString(); } } } } } } } emit importData(nodeValueInfoList); }