From fbd2eadfa3b2b39c66795981d643bbf0519a4ef2 Mon Sep 17 00:00:00 2001 From: krivoshein Date: Wed, 27 Nov 2024 14:45:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B8=D0=BB=D0=BE=D1=82=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=20=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20dm/pm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docTasks/doctaskswidget.cpp | 136 +++++++++++++++++- .../docTasks/doctaskswidget.h | 16 ++- .../docTasks/doctaskswidget.ui | 14 ++ .../docTasks/module.cpp | 58 +++++++- .../InstructorsAndTrainees/docTasks/module.h | 9 ++ 5 files changed, 225 insertions(+), 8 deletions(-) diff --git a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.cpp b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.cpp index f0c5fa2..8ef50fb 100644 --- a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.cpp +++ b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.cpp @@ -10,18 +10,56 @@ DocTasksWidget::DocTasksWidget(QWidget *parent) : ui(new Ui::DocTasksWidget) { ui->setupUi(this); + treeWidget = new QTreeWidget(); + + connect(treeWidget, &QTreeWidget::currentItemChanged, this, &DocTasksWidget::on_treeWidget_currentItemChanged); + ui->horizontalLayout_2->addWidget(treeWidget); - treeWidget->setStyleSheet(QStringLiteral("font-size: 10pt;" - "font-family: Tahoma;")); + + preparationTreeWidget(); loadDocTasksFromXML(); + + updateTreeWidget(); } DocTasksWidget::~DocTasksWidget() { deleteAllModuls(); - delete ui; + delete ui; +} + +void DocTasksWidget::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + if(current == nullptr) + return; + + int id = current->text(ColumnsTree::clmn_ID).toInt(); + + Module* module = searchModuleByID(id); + + if(module) + { + QString type = "Code"; + QString code = ""; + + if(module->getType() == ModuleType::TYPE_PM) + { + PM* PMmodul = static_cast(module); + type = "PM"; + code = PMmodul->pmCode(); + } + else + { + DM* DMmodul = static_cast(module); + type = "DM"; + code = DMmodul->dmCode(); + } + + ui->label->setText(type + " Code"); + ui->editCode->setText(code); + } } void DocTasksWidget::DomElementParser(QDomElement element, Module* moduleParent) @@ -55,6 +93,8 @@ void DocTasksWidget::DomElementParser(QDomElement element, Module* moduleParent) if(moduleParent) { + PMmodul->setParentModule(moduleParent); + PM* PMmodulParent = static_cast(moduleParent); PMmodulParent->addChildModule(module); } @@ -75,9 +115,9 @@ void DocTasksWidget::DomElementParser(QDomElement element, Module* moduleParent) module = new DM(); - DM* PMmodul = static_cast(module); + DM* DMmodul = static_cast(module); - PMmodul->initialize(modelIdentCode, + DMmodul->initialize(modelIdentCode, systemDiffCode, systemCode, subSystemCode, @@ -91,6 +131,8 @@ void DocTasksWidget::DomElementParser(QDomElement element, Module* moduleParent) if(moduleParent) { + DMmodul->setParentModule(moduleParent); + PM* PMmodulParent = static_cast(moduleParent); PMmodulParent->addChildModule(module); } @@ -174,3 +216,87 @@ void DocTasksWidget::deleteAllModuls() listAllModules.clear(); } +Module *DocTasksWidget::searchModuleByID(int id) +{ + Module* ptrModule = nullptr; + + for(Module* module: listAllModules) + { + ptrModule = module->getModuleByID(id); + if(ptrModule) + return ptrModule; + } + + return nullptr; +} + +void DocTasksWidget::preparationTreeWidget() +{ + treeWidget->setColumnCount(2); + + reSetHeadTreeWidget(); + + //treeWidget->header()->setStyleSheet(QStringLiteral("font-size: 10pt;")); + treeWidget->setStyleSheet(QStringLiteral("font-size: 10pt;" + "font-family: Tahoma;")); + + treeWidget->setColumnWidth(ColumnsTree::clmn_ID, 80); + treeWidget->setColumnWidth(ColumnsTree::clmn_PMorDM, 800); + + //treeWidget->setColumnHidden(ColumnsTree::clmn_ID, true); +} + +void DocTasksWidget::reSetHeadTreeWidget() +{ + QStringList listHeaders = {tr("PM/DM"), tr("ID")}; + treeWidget->setHeaderLabels(listHeaders); +} + +void DocTasksWidget::updateTreeWidget() +{ + //Обновление дерева + treeWidget->clear(); + + for(Module* module : listAllModules) + { + addModulToTreeWidget(module); + } +} + +void DocTasksWidget::addModulToTreeWidget(Module *module, QTreeWidgetItem* parentItem) +{ + QTreeWidgetItem* itemModule = nullptr; + + QString text; + QString ID = QString::number(module->getID()); + + if(parentItem) + { + itemModule = new QTreeWidgetItem(); + parentItem->addChild(itemModule); + } + else + { + itemModule = new QTreeWidgetItem(treeWidget); + } + + if(module->getType() == ModuleType::TYPE_PM) + { + PM* PMmodul = static_cast(module); + text = PMmodul->getLangStructRus().title; + + for(Module* module : PMmodul->getListChildModules()) + { + addModulToTreeWidget(module, itemModule); + } + } + else + { + DM* DMmodul = static_cast(module); + text = DMmodul->getLangStructRus().techName; + } + + itemModule->setText(ColumnsTree::clmn_PMorDM, text); + itemModule->setText(ColumnsTree::clmn_ID, ID); +} + diff --git a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.h b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.h index 92dd9c7..0f2a14f 100644 --- a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.h +++ b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.h @@ -14,15 +14,29 @@ class DocTasksWidget : public QWidget { Q_OBJECT +private: + enum ColumnsTree{ + clmn_PMorDM = 0, + clmn_ID + }; + public: explicit DocTasksWidget(QWidget *parent = nullptr); ~DocTasksWidget(); +private Q_SLOTS: + void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + private: void DomElementParser(QDomElement element, Module* moduleParent); void loadDocTasksFromXML(); - void deleteAllModuls(); + Module* searchModuleByID(int id); + + void preparationTreeWidget(); + void reSetHeadTreeWidget(); + void updateTreeWidget(); + void addModulToTreeWidget(Module* module, QTreeWidgetItem* parentItem = nullptr); private: Ui::DocTasksWidget *ui; diff --git a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.ui b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.ui index eb6c97c..6457f3e 100644 --- a/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.ui +++ b/DB_IaT/InstructorsAndTrainees/docTasks/doctaskswidget.ui @@ -31,6 +31,20 @@ + + + + + + Code + + + + + + + + diff --git a/DB_IaT/InstructorsAndTrainees/docTasks/module.cpp b/DB_IaT/InstructorsAndTrainees/docTasks/module.cpp index 797e563..b8e6fad 100644 --- a/DB_IaT/InstructorsAndTrainees/docTasks/module.cpp +++ b/DB_IaT/InstructorsAndTrainees/docTasks/module.cpp @@ -1,10 +1,13 @@ #include "module.h" +int Module::lastID = 0; + Module::Module(): type (ModuleType::TYPE_PM), - parentModule(nullptr) + parentModule(nullptr), + ID(0) { - + ID = ++lastID; } Module::~Module() @@ -12,6 +15,29 @@ Module::~Module() } +Module *Module::getModuleByID(int id) +{ + if(getID() == id) + return this; + + if(this->getType() == ModuleType::TYPE_PM) + { + PM* PMmodul = static_cast(this); + + Module* ptrModule = nullptr; + + for(Module* module: PMmodul->getListChildModules()) + { + ptrModule = module->getModuleByID(id); + + if(ptrModule) + return ptrModule; + } + } + + return nullptr; +} + PM::PM(): @@ -51,6 +77,11 @@ void PM::setLangStructRus(QString title) langRus.title = title; } +PM::pmLangStruct PM::getLangStructRus() +{ + return langRus; +} + void PM::setLangStructEng(QString title) { langEng.title = title; @@ -61,6 +92,16 @@ void PM::addChildModule(Module *childModule) listChildModules.append(childModule); } +QList PM::getListChildModules() +{ + return listChildModules; +} + +QString PM::pmCode() +{ + return (modelIdentCode + "-" + pmIssuer + "-" + pmNumber + "-" + pmVolume).toUpper(); +} + DM::DM(): @@ -114,6 +155,11 @@ void DM::setLangStructRus(QString techName, QString infoName, QString pdf, QStri langRus.xml = xml; } +DM::dmLangStruct DM::getLangStructRus() +{ + return langRus; +} + void DM::setLangStructEng(QString techName, QString infoName, QString pdf, QString bookmark, QString xml) { langEng.techName = techName; @@ -122,3 +168,11 @@ void DM::setLangStructEng(QString techName, QString infoName, QString pdf, QStri langEng.bookmark = bookmark; langEng.xml = xml; } + +QString DM::dmCode() +{ + return (modelIdentCode + "-" + systemDiffCode + "-" + systemCode + "-" + + subSystemCode + subSubSystemCode + "-" + assyCode + "-" + + disassyCode + disassyCodeVariant + "-" + infoCode + + infoCodeVariant + "-" + itemLocationCode).toUpper(); +} diff --git a/DB_IaT/InstructorsAndTrainees/docTasks/module.h b/DB_IaT/InstructorsAndTrainees/docTasks/module.h index 8c04bf6..3c5ca8e 100644 --- a/DB_IaT/InstructorsAndTrainees/docTasks/module.h +++ b/DB_IaT/InstructorsAndTrainees/docTasks/module.h @@ -15,12 +15,16 @@ public: Module(); ~Module(); + int getID(){ return ID; }; ModuleType getType(){ return type; }; void setParentModule(Module* parentModule){ this->parentModule = parentModule; }; + Module* getModuleByID(int id); protected: ModuleType type; Module* parentModule; + int ID; + static int lastID; }; @@ -39,8 +43,11 @@ public: public: void initialize(QString modelIdentCode, QString pmIssuer, QString pmNumber, QString pmVolume); void setLangStructRus(QString title); + pmLangStruct getLangStructRus(); void setLangStructEng(QString title); void addChildModule(Module* childModule); + QList getListChildModules(); + QString pmCode(); private: QString modelIdentCode; @@ -84,7 +91,9 @@ public: QString infoCodeVariant, QString itemLocationCode); void setLangStructRus(QString techName, QString infoName, QString pdf, QString bookmark, QString xml); + dmLangStruct getLangStructRus(); void setLangStructEng(QString techName, QString infoName, QString pdf, QString bookmark, QString xml); + QString dmCode(); private: QString modelIdentCode;