123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- #include "MatrixPanelWidget.h"
- #include "ui_MatrixPanelWidget.h"
- #include "MatrixTableWidget.h"
- #include "MatrixTableTechMeasuresWidget.h"
- #include "dbService/DBServiceSet.h"
- #include <CollectKnowledgeWidget.h>
- 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(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);
- ui->saveBtn->setDisabled(true);
- m_professor = professor;
- }
- 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)
- {
- 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 = "技术措施";
- initPlainTechMeasuresWidget();
- setPage(1);
- return;
- }
- if (!indexs.isEmpty()) {
- currentTab = "";
- initPlainWidget();
- 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 {
- spaceNum = tempSpace;
- sn[level] = 0;
- level--;
- 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; }
- 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()
- {
- if (getPages() == 0) { return; }
- //准备第一页,非tab的
- MatrixTableWidget *table = new MatrixTableWidget((indexsRefClassifiedNodes == nullptr), nullptr);
- connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
- if (indexsRefClassifiedNodes) {
- for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
- 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); }
- }
- table->paintMatrixTable();
- firstLayout->addWidget(table);
- //准备第二页,tab组合的
- for (int p = 1; p < getPages(); ++p) {
- QTabWidget *tab = new QTabWidget;
- tab->setTabPosition(QTabWidget::South);
- for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
- 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); }
- 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->paintMatrixTable();
- tab->addTab(table, msg.name);
- connect(table, &MatrixTableWidget::dataReady, this, &MatrixPanelWidget::oneTableDataReady);
- }
- }
- tabWidgets << tab;
- }
- // secondLayout->addWidget(tab);
- }
- void MatrixPanelWidget::initPlainTechMeasuresWidget()
- {
- if (getPages() == 0) { return; }
- //准备第一页,非tab的
- MatrixTableTechMeasuresWidget *table = new MatrixTableTechMeasuresWidget(nullptr);
- connect(table, &MatrixTableTechMeasuresWidget::dataReady, this, &MatrixPanelWidget::oneTechMeasureTableDataReady);
- if (indexsRefClassifiedNodes) {
- for (MindNodeManager::NodeMessage msg : indexsRefClassifiedNodes->last()) {
- 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); }
- }
- table->paintMatrixTable();
- firstLayout->addWidget(table);
- //准备第二页,tab组合的
- for (int p = 1; p < getPages(); ++p) {
- QTabWidget *tab = new QTabWidget;
- tab->setTabPosition(QTabWidget::South);
- for (MindNodeManager::NodeMessage msg : classifiedNodes->at(p - 1)) {
- 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); }
- 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->paintMatrixTable();
- tab->addTab(table, msg.name);
- connect(table, &MatrixTableTechMeasuresWidget::dataReady, this,
- &MatrixPanelWidget::oneTechMeasureTableDataReady);
- }
- }
- tabWidgets << tab;
- }
- // secondLayout->addWidget(tab);
- }
- 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::on_saveBtn_clicked()
- {
- if (currentTab == "技术措施") {
- 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;
- t->expertId = m_professor.id;
- t->expertName = m_professor.name;
- t->engineerId = m_professor.engineer.engineerId;
- t->writeDate = m_professor.createDataTime;
- nodeInfoList.append(t);
- }
- DBServiceSet().AddNodeMatrixInfoList(nodeInfoList);
- //保存第二页数据,如果有
- QList<NodeMatrixInfo *> secondNodeInfoList;
- for (QTabWidget *tabWidget : tabWidgets) {
- for (int i = 0; i < tabWidget->count(); ++i) {
- MatrixTableTechMeasuresWidget *table =
- dynamic_cast<MatrixTableTechMeasuresWidget *>(tabWidget->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;
- secondNodeInfoList.append(t);
- }
- }
- }
- DBServiceSet().AddNodeMatrixInfoList(secondNodeInfoList);
- QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
- this->close();
- } else {
- QList<NodeMatrixInfo *> nodeInfoList;
- 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;
- nodeInfoList.append(t);
- }
- DBServiceSet().AddNodeMatrixInfoList(nodeInfoList);
- //保存第二页数据,如果有
- QList<NodeMatrixInfo *> secondNodeInfoList;
- for (QTabWidget *tabWidget : tabWidgets) {
- for (int i = 0; i < tabWidget->count(); ++i) {
- MatrixTableWidget *table = dynamic_cast<MatrixTableWidget *>(tabWidget->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 = m_professor.name;
- t->expertName = m_professor.name;
- t->engineerId = m_professor.engineer.engineerId;
- t->writeDate = m_professor.createDataTime;
- secondNodeInfoList.append(t);
- }
- }
- DBServiceSet().AddNodeMatrixInfoList(secondNodeInfoList);
- QMessageBox::information(this, tr("成功"), tr("数据保存成功"));
- this->close();
- }
- }
- 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);
- } else {
- ui->saveBtn->setDisabled(true);
- }
- } else {
- ui->saveBtn->setDisabled(true);
- }
- }
- void MatrixPanelWidget::oneTechMeasureTableDataReady(bool status)
- {
- qDebug() << "status = " << status;
- if (status) {
- bool filled = true;
- MatrixTableTechMeasuresWidget *first =
- qobject_cast<MatrixTableTechMeasuresWidget *>(firstLayout->itemAt(0)->widget());
- if (!first->isDataReady()) { filled = false; }
- qDebug() << "filled1 = " << filled;
- qDebug() << "tabWidgets = " << tabWidgets.size();
- for (QTabWidget *tab : tabWidgets) {
- for (int t = 0; t < tab->count(); ++t) {
- MatrixTableTechMeasuresWidget *table =
- qobject_cast<MatrixTableTechMeasuresWidget *>(tab->widget(t));
- qDebug() << "table = " << table->isDataReady();
- if (!table->isDataReady()) { filled = false; }
- }
- }
- qDebug() << "filled2 = " << filled;
- if (filled) {
- ui->saveBtn->setDisabled(false);
- } else {
- ui->saveBtn->setDisabled(true);
- }
- } else {
- ui->saveBtn->setDisabled(true);
- }
- }
|