12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076 |
- #include "MatrixPanelWidget.h"
- #include "MatrixTableTechMeasuresWidget.h"
- #include "MatrixTableWidget.h"
- #include "dbService/DBServiceSet.h"
- #include "dbService/NodeMatrixService.h"
- #include "ui_MatrixPanelWidget.h"
- #include <xlsxdocument.h>
- #include <QDebug>
- #include <QMessageBox>
- #include <QFileDialog>
- 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<QList<MindNodeManager::NodeMessage>>;
- sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
- delete indexsRefNodes;
- }
- if (!indexs.isEmpty()) {
- currentMindNodes = new MindNodeManager();
- classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
- getMindNodes(currentMindNodes, indexs);
- sortMindNodes(*currentMindNodes, classifiedNodes);
- } else {
- currentMindNodes = nullptr;
- classifiedNodes = nullptr;
- }
- ui->toatalPagesLabel->setText(QString("共%1页").arg(getPages()));
- ui->currPageLabel->setText(QString("当前第0页"));
- QList<NodeMatrixInfo *> 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<NodeMatrixInfo *> nodeValueInfoList)
- {
- // qDebug() << "MatrixPanelWidget---initImportData" << endl;
- indexsRefClassifiedNodes = nullptr;
- if (!indexsRef.isEmpty()) {
- MindNodeManager *indexsRefNodes = new MindNodeManager(); // 是否参考指标体系
- getMindNodes(indexsRefNodes, indexsRef);
- indexsRefClassifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
- sortMindNodes(*indexsRefNodes, indexsRefClassifiedNodes);
- delete indexsRefNodes;
- }
- if (!indexs.isEmpty()) {
- currentMindNodes = new MindNodeManager();
- classifiedNodes = new QList<QList<MindNodeManager::NodeMessage>>;
- 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<QList<MindNodeManager::NodeMessage>> *classify)
- {
- for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
- QStringList nodePonit = msg.node.split(".");
- while (nodePonit.count() - 1 > classify->count()) {
- (*classify) << QList<MindNodeManager::NodeMessage>();
- }
- (*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<QList<MindNodeManager::NodeMessage>> classify;
- for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
- QStringList nodePonit = msg.node.split(".");
- while (nodePonit.count() - 1 > classify.count()) {
- classify << QList<MindNodeManager::NodeMessage>();
- }
- 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<QList<MindNodeManager::NodeMessage>> classify;
- for (MindNodeManager::NodeMessage msg : manager.getMindNodes()) {
- QStringList nodePonit = msg.node.split(".");
- while (nodePonit.count() - 1 > classify.count()) {
- classify << QList<MindNodeManager::NodeMessage>();
- }
- 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<NodeMatrixInfo *> 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<NodeMatrixInfo *> 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<MatrixTableTechMeasuresWidget *>(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<MatrixTableTechMeasuresWidget *>(tab->widget(t));
- if (!table->isDataReady()) {
- filled = false;
- }
- }
- }
- } else {
- MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(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<MatrixTableWidget *>(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<QTabWidget *>(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<NodeMatrixInfo *> nodeInfoList;
- if (currentTab == "技术措施重要度评估对象") {
- if (currentPage == 1) {
- MatrixTableTechMeasuresWidget *first =
- qobject_cast<MatrixTableTechMeasuresWidget *>(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<QTabWidget *>(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<MatrixTableTechMeasuresWidget *>(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<MatrixTableWidget *>(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<QTabWidget *>(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<MatrixTableWidget *>(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<NodeMatrixInfo *> nodeInfoList;
- MatrixTableTechMeasuresWidget *first =
- qobject_cast<MatrixTableTechMeasuresWidget *>(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<NodeMatrixInfo *> secondNodeInfoList;
- secondNodeInfoList.clear();
- MatrixTableTechMeasuresWidget *table =
- dynamic_cast<MatrixTableTechMeasuresWidget *>(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<NodeMatrixInfo *> nodeInfoList;
- MatrixTableWidget *first = qobject_cast<MatrixTableWidget *>(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<NodeMatrixInfo *> secondNodeInfoList;
- secondNodeInfoList.clear();
- MatrixTableWidget *table = dynamic_cast<MatrixTableWidget *>(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<MatrixTableWidget *>(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<MatrixTableWidget *>(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<MatrixTableTechMeasuresWidget *>(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<MatrixTableTechMeasuresWidget *>(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<QString> 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<NodeMatrixInfo *> 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);
- }
|