Files
MI-38/s1000d/Converter14/editormainwindow.cpp
2022-07-04 13:15:35 +03:00

2025 lines
100 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "editormainwindow.h"
#include "ui_editormainwindow.h"
#include "s1000d_manager.h"
#include <QFileDialog>
#include <QString>
#include <QMessageBox>
#include <QTextBrowser>
#include <QPalette>
#include <QColor>
#include <QLineEdit>
#include <QPushButton>
#include <QListWidget>
#include <QDebug>
#include <QLabel>
#include <QComboBox>
#include <QTimer>
#include <QDesktopServices>
#include <QDate>
//#include "private/qzipwriter_p.h"
#include <QDirIterator>
#include <QProcess>
// TODO PROCED.xml
EditorMainWindow::EditorMainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::EditorMainWindow)
{
ui->setupUi(this);
this->hide();
QList<int> sizes;
sizes << 300 << 700; ui->splitter->setSizes(sizes);
ui->toolBar->setFixedWidth(ui->treeWidget->geometry().x() + ui->treeWidget->geometry().width() + 10);
SM.item = nullptr;
isProjectOpened = false; isProjectModifyed = false;
ui->actionSwitchToCodingPage->setChecked(true); ui->actionSwitchToDataPage->setChecked(false);
ui->actionSwitchToCodingPage->setEnabled(true); ui->actionSwitchToDataPage->setEnabled(true);
ui->stackedWidget->setCurrentIndex(0);
setIsModifyed(false);
ui->toolBar->setFixedWidth(310);
ui->stackedWidget->setTabletTracking(false);
//ui->dataPageEdit->setStyleSheet("background-color: white; border: none;");
config.lastOpenedFile = "";
QFile cfgFile(qApp->applicationDirPath()+"/config.txt");//QDir::currentPath()
if (cfgFile.open(QFile::ReadOnly | QFile::Text)) {
char buf[256];
cfgFile.readLine(buf, 255);
QStringList cfg = QString(buf).split("=");
if(cfg[0] == "lastOpenedFile")
config.lastOpenedFile = cfg[1];
}
cfgFile.close();
QDir dirScorm = QDir(QCoreApplication::applicationDirPath()+"/Scorm");
if (!dirScorm.exists()) {
QMessageBox::critical(this,"Ошибка","Папка Scorm не найдена.",QMessageBox::Ok);
QTimer::singleShot(50, this, SLOT(on_actionExit_triggered()));
return;
}
// создание диалогового окна лога
// logDialogList = new QListWidget(this);
// logDialogList->setFixedHeight(800); logDialogList->setFixedWidth(1000);
// logDialogList->setObjectName("logDialogList");
// QFont logFont("Courier", 8); logDialogList->setFont(QFont(logFont));
// QPushButton* logDialogCloseButton = new QPushButton(tr("Закрыть"), this);
// logDialogCloseButton->setDefault(true);
// logDialog = new QDialog(this);
// QVBoxLayout *logDialogLayout = new QVBoxLayout(logDialog);
// logDialogLayout->setMargin(5); logDialogLayout->setSpacing(6); logDialog->setWindowTitle(QString("Log"));
// logDialogLayout->addWidget(logDialogList); logDialogLayout->addWidget(logDialogCloseButton);
// connect(logDialogCloseButton, SIGNAL(clicked()), logDialog, SLOT(close()));
// logDialog->setLayout(logDialogLayout);
ru_const.Init_RU_Const(); lyx.ru_const = &ru_const;
DBG = true; allowCodePageToSetItems = true;
ui->pmc_lb_title2->setText(ui->pmc_lb_title2->text() + " " + ru_const.companyName);
ui->pmc_btn_modelIdentCode->setText(ru_const.modelIdentCode); ui->pmc_btn_pmIssuer->setText(ru_const.pmIssuer);
ui->stackedWidget->setCurrentIndex(0);
connect(ui->pmc_t_title, SIGNAL(textChanged()), this, SLOT(codePagePM_TitleChanged()));
connect(ui->pmc_le_modelIdentCode, SIGNAL(textChanged(QString)), this, SLOT(codePagePM_EditChanged(QString)));
connect(ui->pmc_le_pmIssuer, SIGNAL(textChanged(QString)), this, SLOT(codePagePM_EditChanged(QString)));
connect(ui->pmc_le_pmNumABC, SIGNAL(textChanged(QString)), this, SLOT(codePagePM_EditChanged(QString)));
connect(ui->pmc_le_pmNum, SIGNAL(textChanged(QString)), this, SLOT(codePagePM_EditChanged(QString)));
connect(ui->pmc_le_pmVolume, SIGNAL(textChanged(QString)), this, SLOT(codePagePM_EditChanged(QString)));
connect(ui->pmc_btn_modelIdentCode, SIGNAL(pressed()), this, SLOT(pmc_btn_modelIdentCodePressed()));
connect(ui->pmc_btn_pmIssuer, SIGNAL(pressed()), this, SLOT(pmc_btn_pmIssuerPressed()));
connect(ui->pmc_cb_pmNumABC, SIGNAL(currentIndexChanged(int)), this, SLOT(pmc_cb_pmNumABC_Changed(int)));
connect(ui->pmc_cb_pmNum, SIGNAL(currentIndexChanged(int)), this, SLOT(pmc_cb_pmNum_Changed(int)));
connect(ui->pmc_cb_pmVolume, SIGNAL(currentIndexChanged(int)), this, SLOT(pmc_cb_pmVolume_Changed(int)));
ui->treeWidget->viewport()->installEventFilter(this);
allowDMCodePageCallOnChangeComboBox = false;
ui->dmc_lb_label2->setText(ui->dmc_lb_label2->text() + " " + ru_const.companyName);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setText("Да"); ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setText("Нет");
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setCheckable(true); ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(false);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setCheckable(true); ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(true);
for(int i=0;i<ru_const.dmCodeList.count();i++) {
ui->dmc_cb_InfoSets->addItem(ru_const.dmCodeList[i].chapterName+" - "+ru_const.dmCodeList[i].paraName, i);
}
connect(ui->dmc_le_modelIdentCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_systemDiffCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_systemCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_subSystemCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_subSubSystemCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_assyCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_disassyCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_disassyCodeVariant, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_infoCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_infoCodeVariant, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_itemLocationCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_learnCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_le_learnEventCode, SIGNAL(textChanged(QString)), this, SLOT(codePageDM_EditChanged(QString)));
connect(ui->dmc_te_techName, SIGNAL(textChanged()), this, SLOT(codePageDM_TitleChanged()));
connect(ui->dmc_cb_InfoSets, SIGNAL(currentIndexChanged(int)), this, SLOT(on_dmc_cb_InfoSets_currentIndexChanged(int)));
allowDMCodePageCallOnChangeComboBox = true;
ui->dml_btnBox_question->button(QDialogButtonBox::Yes)->setIcon(QIcon(":new/Icons/add.png"));
ui->dml_btnBox_question->button(QDialogButtonBox::Yes)->setIconSize(QSize(32,32));
ui->dml_btnBox_question->button(QDialogButtonBox::Yes)->setText("");
ui->dml_btnBox_question->button(QDialogButtonBox::Yes)->setFlat(true);
ui->dml_btnBox_question->button(QDialogButtonBox::No)->setIcon(QIcon(":new/Icons/delete.png"));
ui->dml_btnBox_question->button(QDialogButtonBox::No)->setIconSize(QSize(32,32));
ui->dml_btnBox_question->button(QDialogButtonBox::No)->setText("");
ui->dml_btnBox_question->button(QDialogButtonBox::No)->setFlat(true);
ui->dml_btnBox_question->button(QDialogButtonBox::Apply)->setIcon(QIcon(":new/Icons/up_arrow.png"));
ui->dml_btnBox_question->button(QDialogButtonBox::Apply)->setIconSize(QSize(32,32));
ui->dml_btnBox_question->button(QDialogButtonBox::Apply)->setText("");
ui->dml_btnBox_question->button(QDialogButtonBox::Apply)->setFlat(true);
ui->dml_btnBox_question->button(QDialogButtonBox::Reset)->setIcon(QIcon(":new/Icons/down_arrow.png"));
ui->dml_btnBox_question->button(QDialogButtonBox::Reset)->setIconSize(QSize(32,32));
ui->dml_btnBox_question->button(QDialogButtonBox::Reset)->setText("");
ui->dml_btnBox_question->button(QDialogButtonBox::Reset)->setFlat(true);
//connect(ui->dml_btnBox_question, SIGNAL(clicked(QAbstractButton*)), this, SLOT(on_dml_btnBox_question_clicked(QAbstractButton*)));
connect(ui->dml_lw_question, SIGNAL(currentRowChanged(int)), this, SLOT(on_dml_lw_question_currentRowChanged(int)));
ui->dml_btnBox_answer->button(QDialogButtonBox::Yes)->setIcon(QIcon(":new/Icons/add.png"));
ui->dml_btnBox_answer->button(QDialogButtonBox::Yes)->setIconSize(QSize(32,32));
ui->dml_btnBox_answer->button(QDialogButtonBox::Yes)->setText("");
ui->dml_btnBox_answer->button(QDialogButtonBox::Yes)->setFlat(true);
ui->dml_btnBox_answer->button(QDialogButtonBox::No)->setIcon(QIcon(":new/Icons/delete.png"));
ui->dml_btnBox_answer->button(QDialogButtonBox::No)->setIconSize(QSize(32,32));
ui->dml_btnBox_answer->button(QDialogButtonBox::No)->setText("");
ui->dml_btnBox_answer->button(QDialogButtonBox::No)->setFlat(true);
//connect(ui->dml_btnBox_answer, SIGNAL(clicked(QAbstractButton*)), this, SLOT(on_dml_btnBox_answer_clicked(QAbstractButton*)));
splash = new SplashForm(this);
exportDlg = new ExportDialog(this, &SM);
connect(exportDlg, SIGNAL(actionS1000Dexport()), this, SLOT(exportS1000D()));
connect(exportDlg, SIGNAL(actionSCORMexport()), this, SLOT(exportSCORM()));
on_action_refreshFromLyX_triggered();
this->setWindowTitle("Конвертер АУК "+version);
this->showMaximized();
}
EditorMainWindow::~EditorMainWindow()
{
delete splash;
delete exportDlg;
// QFile cfgFile(qApp->applicationDirPath()+"/config.txt");
// if (cfgFile.open(QFile::ReadWrite | QFile::Text)) {
// QString cfg = "lastOpenedFile="+config.lastOpenedFile;
// cfgFile.write(cfg.toStdString().c_str());
// cfgFile.resize(cfgFile.pos());
// }
// cfgFile.close();
//delete logDialog;
//delete ui;
}
bool EditorMainWindow::event(QEvent *e)
{
if (e->type() == QEvent::WindowActivate) {
ui->toolBar->setFixedWidth(ui->treeWidget->geometry().x() + ui->treeWidget->geometry().width() + 10);
}
return QWidget::event(e);
}
bool EditorMainWindow::eventFilter(QObject* obj, QEvent* ev)
{
if( obj == ui->treeWidget->viewport() && ev->type() == QEvent::Drop )
QTimer::singleShot(50, this, SLOT(treeWidgetDrop()));
return false;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OPEN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void EditorMainWindow::on_actionOpenFolder_triggered()
{
return; // старый подход
/*
if(isProjectModifyed) {
QMessageBox msgBox;
msgBox.setText("Сохранить изменения?");
msgBox.setWindowTitle("Проект изменен");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
on_actionSaveProject_triggered();
if(isProjectModifyed) return;
case QMessageBox::No:
break;
case QMessageBox::Cancel:
return;
}
}
SM.projectPath = QFileDialog::getExistingDirectory(this, tr("Выберите папку проекта АУК"), ""); //config.lastOpenedDir
if(SM.projectPath == "")
return;
isProjectOpened = true;
//config.lastOpenedDir = SM.projectPath;
this->setWindowTitle("Конвертер АУК - " + SM.projectPath);
ui->actionAddDM->setEnabled(true); ui->actionAddPM->setEnabled(true);
isProjectOpened = true;
setIsModifyed(false);
QString schemasPath;
//if (QSysInfo::productType() == "windows")
// schemasPath = QDir::currentPath()+QString("/Schemas/");
//else
schemasPath = QDir::currentPath()+QString("/Schemas/");
SM.OpenProjectDirectory(SM.projectPath, schemasPath);
fillTreeWidgetWithItems();
if(ui->treeWidget->topLevelItemCount() > 0) {
ui->actionDeleteItem->setEnabled(true);
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
//ui->actionSwitchToCodingPage->setEnabled(true); ui->actionSwitchToDataPage->setEnabled(true);
on_actionSwitchToCodingPage_triggered();
}
else {
ui->label_12->setText("Папка проекта выбрана,\n но не содержит публикаций и модулей. \nНачните работу с создания публикации.");
ui->stackedWidget->setCurrentIndex(0);
}
ui->actionSwitchToCodingPage->setEnabled(true); ui->actionSwitchToDataPage->setEnabled(true);
//config.lastOpenedDir = SM.projectPath;
ui->actionLyXImport->setEnabled(true);
//logDialogList->clear();
//logDialogList->addItems(SM.log);
//logDialog->show(); logDialog->exec();
//import, delete after debug
//on_actionSwitchToDataPage_triggered();
//on_actionLyXImport_triggered();
*/
}
QTreeWidgetItem* EditorMainWindow::getTreeWidgetItemByItemIndexRecurs(int itemInd, QTreeWidgetItem *node) {
QTreeWidgetItem* result=nullptr;
if(node->data(0, Qt::UserRole).toInt() == itemInd)
return node;
for(int i=0;i<node->childCount();i++) {
result = getTreeWidgetItemByItemIndexRecurs(itemInd, node->child(i));
if(result != nullptr) return result;
}
return nullptr;
}
QTreeWidgetItem* EditorMainWindow::getTreeWidgetItemByItemIndex(int itemInd) {
QList<int> fullList;
QTreeWidgetItem* result=nullptr;
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++) {
result = getTreeWidgetItemByItemIndexRecurs(itemInd, ui->treeWidget->topLevelItem(i));
if(result != nullptr) return result;
}
return nullptr;
}
QList<QTreeWidgetItem *> EditorMainWindow::makeTreeWidgetFromItems(QTreeWidgetItem *parent, QList<int> list) {
QList<QTreeWidgetItem *> res;
foreach (int treeNodeInd, list) {
QTreeWidgetItem *newItem;
SM.setCurItem(treeNodeInd);
QString isLearnigDMStr = "";
if(SM.item->moduleType == mtDM && SM.item->schemeType == stLEARNING)
isLearnigDMStr = ru_const.testQuestions+"\n";
if(SM.items[treeNodeInd].moduleType == mtPM)
newItem = new QTreeWidgetItem(parent, QStringList(
//SM.item->fileCode+"\n"+//SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.shortPmTitle") + "\n"
SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle") ));
else
newItem = new QTreeWidgetItem(parent, QStringList(
//SM.item->fileCode+" "+
isLearnigDMStr+
SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName") + "\n"
+ SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName") ));
if(SM.items[treeNodeInd].moduleType == mtPM)
if(SM.item->isQualifyed)
newItem->setIcon(0, iconFolder);
else
newItem->setIcon(0, iconFolder_ex);
else
if(SM.item->isQualifyed)
newItem->setIcon(0, iconDoc_head_blue);
else
newItem->setIcon(0, iconDoc_head_blue_ex);
newItem->setData(0, Qt::UserRole, treeNodeInd);
if(SM.items[treeNodeInd].child.count() > 0) {
QList<QTreeWidgetItem *> treeChildren = makeTreeWidgetFromItems(newItem, SM.items[treeNodeInd].child);
foreach(QTreeWidgetItem *newChild, treeChildren)
newItem->addChild(newChild);
}
res.append(newItem);
}
return res;
}
void EditorMainWindow::fillTreeWidgetWithItems() {
//if(DBG) qDebug() << " *FillTreeWidgetWithItems*";
//allowCodePageToSetItems = false;
isClearing = true;
ui->treeWidget->clear();
isClearing = false;;
QList<QTreeWidgetItem *> treeItems;
QList<int> fullList;
for(int i=0;i<SM.items.count();i++)
if(SM.items[i].parent == -1) fullList.append(i);
treeItems = makeTreeWidgetFromItems(static_cast<QTreeWidgetItem *>(nullptr), fullList);
ui->treeWidget->insertTopLevelItems(0, treeItems);
ui->treeWidget->expandAll();
//if(SM.items.count() > 0)
// ui->treeWidget->setCurrentItem(treeItems[0]);
allowCodePageToSetItems = true;
}
void EditorMainWindow::resizeEvent(QResizeEvent*)
{
ui->toolBar->setFixedWidth(ui->treeWidget->geometry().x() + ui->treeWidget->geometry().width() + 10);
}
void EditorMainWindow::on_actionAddPM_triggered()
{
int newPMInd = -1;
if(ui->treeWidget->topLevelItemCount() > 0) {
if(ui->treeWidget->currentItem()->parent() == nullptr) {
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
if(ui->treeWidget->currentItem() == ui->treeWidget->topLevelItem(i))
newPMInd = SM.createPM(-1, i);
}
else {
for(int i=0;i<ui->treeWidget->currentItem()->parent()->childCount();i++)
if(ui->treeWidget->currentItem() == ui->treeWidget->currentItem()->parent()->child(i))
newPMInd = SM.createPM(ui->treeWidget->currentItem()->parent()->data(0,Qt::UserRole).toInt(), i);
}
}
else
newPMInd = SM.createPM(-1, 0);
if(newPMInd == -1) if(DBG) qDebug() << " Error: AddPM: newPMInd == -1";
fillTreeWidgetWithItems();
QTreeWidgetItem *node = getTreeWidgetItemByItemIndex(newPMInd);
//ui->treeWidget->clearSelection(); ui->treeWidget->setItemSelected(node, true);
ui->treeWidget->setCurrentItem(node);
ui->actionDeleteItem->setEnabled(true);
setIsModifyed(true);
updateTreeWidgetNames();
Save();
}
void EditorMainWindow::on_actionAddDM_triggered()
{
int newDMInd = -1;
if(ui->treeWidget->topLevelItemCount() > 0) {
if(ui->treeWidget->currentItem()->parent() == nullptr) {
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
if(ui->treeWidget->currentItem() == ui->treeWidget->topLevelItem(i))
newDMInd = SM.createDM(-1, i, "DESCRIPT");
}
else {
for(int i=0;i<ui->treeWidget->currentItem()->parent()->childCount();i++)
if(ui->treeWidget->currentItem() == ui->treeWidget->currentItem()->parent()->child(i))
newDMInd = SM.createDM(ui->treeWidget->currentItem()->parent()->data(0,Qt::UserRole).toInt(), i, "DESCRIPT");
}
}
else
newDMInd = SM.createDM(-1, 0, "DESCRIPT");
if(newDMInd == -1) if(DBG) qDebug() << " Error: AddDM: newDMInd == -1";
fillTreeWidgetWithItems();
QTreeWidgetItem *node = getTreeWidgetItemByItemIndex(newDMInd);
ui->treeWidget->setCurrentItem(node);
ui->actionDeleteItem->setEnabled(true);
allowDMCodePageCallOnChangeComboBox = false; ui->dmc_cb_InfoSets->setCurrentIndex(-1); allowDMCodePageCallOnChangeComboBox = true;
setIsModifyed(true);
updateTreeWidgetNames();
Save();
}
void EditorMainWindow::setIsModifyed(bool flag)
{
isProjectModifyed = flag;
ui->actionSaveProject->setEnabled(flag);
}
void EditorMainWindow::on_splitter_splitterMoved(int, int)
{
ui->toolBar->setFixedWidth(ui->treeWidget->geometry().x() + ui->treeWidget->geometry().width() + 10);
}
void EditorMainWindow::on_actionSwitchToCodingPage_triggered()
{
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
ui->actionSwitchToCodingPage->setChecked(true); ui->actionSwitchToDataPage->setChecked(false);
if(SM.item != nullptr) {
if(SM.item->moduleType == mtPM)
ui->stackedWidget->setCurrentIndex(1);
if(SM.item->moduleType == mtDM)
ui->stackedWidget->setCurrentIndex(2);
}
}
void EditorMainWindow::on_actionSwitchToDataPage_triggered()
{
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
ui->actionSwitchToCodingPage->setChecked(false); ui->actionSwitchToDataPage->setChecked(true);
if(SM.item == nullptr) return;
if(SM.item->schemeType != stLEARNING)
ui->stackedWidget->setCurrentIndex(3);
else
ui->stackedWidget->setCurrentIndex(4);
}
void EditorMainWindow::on_actionSaveProject_triggered()
{
// SM.prepareSaveProject();
// for(int i=0;i<SM.items.count();i++)
// if(!SM.items[i].isReady) {
// ui->treeWidget->setCurrentItem(getTreeWidgetItemByItemIndex(i));
// if(SM.items[i].moduleType == mtPM)
// ui->stackedWidget->setCurrentIndex(1);
// if(SM.items[i].moduleType == mtDM)
// ui->stackedWidget->setCurrentIndex(2);
// QApplication::beep();
// QMessageBox msgBox;
// msgBox.setIcon(QMessageBox::Warning); msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
// msgBox.setWindowTitle("Сохранение"); msgBox.setText("Для сохранения необходимо заполнить кодировку добавленных публикаций и модулей.");
// msgBox.exec();
// return;
// }
// QStringList list;
// for(int i=0;i<SM.items.count();i++) {
// if(list.contains(SM.items[i].fileCode, Qt::CaseInsensitive)) {
// ui->treeWidget->setCurrentItem(getTreeWidgetItemByItemIndex(i));
// if(SM.items[i].moduleType == mtPM)
// ui->stackedWidget->setCurrentIndex(1);
// if(SM.items[i].moduleType == mtDM)
// ui->stackedWidget->setCurrentIndex(2);
// QApplication::beep();
// QMessageBox msgBox;
// msgBox.setIcon(QMessageBox::Warning); msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
// msgBox.setWindowTitle("Сохранение"); msgBox.setText("Сохранение отменено - обнаружено дублирование кодировки публикаций или модулей.");
// msgBox.exec();
// return;
// }
// list.append(SM.items[i].fileCode);
// }
Save();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SELECTION CHANGED ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void EditorMainWindow::on_treeWidget_itemSelectionChanged()
{
if(isClearing) return; // при вызове .clear QT вызывет для каждого элемента itemSelectionChanged
if(ui->treeWidget->currentItem() == nullptr || ui->treeWidget->topLevelItemCount() == 0 || SM.items.count() == 0) {
ui->stackedWidget->setCurrentIndex(0);
return;
}
if(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt() >= SM.items.count()) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
// <dc:identifier>BRAKE-C3002-EPWG1-00_000_01</dc:identifier>
//<pmCode modelIdentCode="BRAKE" pmIssuer="C3002" pmNumber="EPWG1" pmVolume="00"/>
//<issueInfo issueNumber="000" inWork="01"/>
if(SM.item->moduleType == mtPM) {
QString cur_title="", cur_modelIdentCode="", cur_pmIssuer="", cur_pmNumABC="", cur_pmNum="", cur_pmVolume="", cur_issueNumber="000", cur_inWork="00";
cur_title = SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
cur_modelIdentCode = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "modelIdentCode");
cur_pmIssuer = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmIssuer");
cur_pmNum = cur_pmNumABC = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmNumber");
cur_pmNumABC.replace(QRegExp("\\d"), "");
cur_pmNum.replace(QRegExp("\\D"), "");
cur_pmVolume = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmVolume");
cur_issueNumber = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.issueInfo", "issueNumber");
cur_inWork = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.issueInfo", "inWork");
allowCodePageToSetItems = false;
allowCodePageToCallOnChangeComboBox = false;
ui->pmc_cb_pmNumABC->clear(); ui->pmc_cb_pmNum->clear(); ui->pmc_cb_pmVolume->clear();
for(int i=0; i < ru_const.pmCodeList.count();i++) {
int ind = ui->pmc_cb_pmNumABC->findText(ru_const.pmCodeList[i].pmNumABC+" - "+ru_const.pmCodeList[i].pmNumABCText);
if(ind == -1)
ui->pmc_cb_pmNumABC->addItem(ru_const.pmCodeList[i].pmNumABC+" - "+ru_const.pmCodeList[i].pmNumABCText, ru_const.pmCodeList[i].pmNumABC);
}
ui->pmc_cb_pmNumABC->setCurrentIndex(-1); // повнимательнее с этим
allowCodePageToCallOnChangeComboBox = true;
int ind = ui->pmc_cb_pmNumABC->findData(cur_pmNumABC);
if(ind != -1)
ui->pmc_cb_pmNumABC->setCurrentIndex(ind);
ind = ui->pmc_cb_pmNum->findData(cur_pmNum);
if(ind != -1)
ui->pmc_cb_pmNum->setCurrentIndex(ind);
ind = ui->pmc_cb_pmVolume->findData(cur_pmVolume);
if(ind != -1)
ui->pmc_cb_pmVolume->setCurrentIndex(ind);
ui->pmc_t_title->document()->setPlainText(cur_title);
ui->pmc_le_modelIdentCode->setText(cur_modelIdentCode);
ui->pmc_le_pmIssuer->setText(cur_pmIssuer);
ui->pmc_le_pmNumABC->setText(cur_pmNumABC);
ui->pmc_le_pmNum->setText(cur_pmNum);
ui->pmc_le_pmVolume->setText(cur_pmVolume);
ui->pmc_btn_Qual->setChecked(SM.item->isQualifyed);
allowCodePageToSetItems = true;
if(ui->actionSwitchToCodingPage->isChecked())
ui->stackedWidget->setCurrentIndex(1);
if(ui->actionSwitchToDataPage->isChecked())
ui->stackedWidget->setCurrentIndex(3);
// QString htmlPMData;
// ui->dataPageEdit->document()->clear();
// htmlPMData += "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<title>";
// htmlPMData += "<font size=\"6\" color=\"blue\">Публикация</font>";
// htmlPMData += "</title>\n</head>\n<body>";
// htmlPMData += "<font size=\"6\" color=\"blue\">"+ui->pmc_t_title->toHtml()+"</font><hr>";
// htmlPMData += "<font size=\"5\"><u>Состав:</u><br>";
// for(int i=0;i<SM.item->child.count();i++) {
// SM.setCurItem(SM.item->child[i]);
// if(SM.item->moduleType == mtPM) {
// htmlPMData += " Публикация ";
// htmlPMData += SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
// htmlPMData += "<br>\n";
// }
// if(SM.item->moduleType == mtDM) {
// htmlPMData += "<i> Модуль ";
// htmlPMData += SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
// QString iName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName");
// if(iName != "") htmlPMData += " - "+iName;
// htmlPMData += "</i><br>\n";
// }
// SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
// }
// if(SM.item->child.count() == 0)
// htmlPMData += " пусто<br>\n";
// htmlPMData += "</font><hr>\n<font size=\"4\" color=\"gray\">Для изменения состава публикации и порядка следования элементов используйте перетаскивание мышью элементов дерева в левой части окна.";
// htmlPMData += "</font>\n</body>\n</html>";
// ui->dataPageEdit->document()->setHtml(htmlPMData);
ui->dmc_LyXLog->clear();
}
if(SM.item->moduleType == mtDM) {
if(ui->actionSwitchToCodingPage->isChecked())
ui->stackedWidget->setCurrentIndex(2);
if(ui->actionSwitchToDataPage->isChecked()) {
if(SM.item->schemeType != stLEARNING)
ui->stackedWidget->setCurrentIndex(3);
else
ui->stackedWidget->setCurrentIndex(4);
}
QString modelIdentCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "modelIdentCode");
QString systemDiffCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemDiffCode");
QString systemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemCode");
QString subSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSystemCode");
QString subSubSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSubSystemCode");
QString assyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "assyCode");
QString disassyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCode");
QString disassyCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCodeVariant");
QString infoCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCode");
QString infoCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCodeVariant");
QString itemLocationCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "itemLocationCode");
QString learnCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnCode");
QString learnEventCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnEventCode");
QString techName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
QString infoName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName");
allowDMCodePageToSetItems = false;
ui->dmc_te_infoName->setText(infoName); ui->dmc_te_techName->setText(techName);
ui->dmc_le_modelIdentCode->setText(modelIdentCode); ui->dmc_le_systemDiffCode->setText(systemDiffCode);
ui->dmc_le_systemCode->setText(systemCode); ui->dmc_le_subSystemCode->setText(subSystemCode);
ui->dmc_le_subSubSystemCode->setText(subSubSystemCode); ui->dmc_le_assyCode->setText(assyCode);
ui->dmc_le_disassyCode->setText(disassyCode); ui->dmc_le_disassyCodeVariant->setText(disassyCodeVariant);
ui->dmc_le_infoCode->setText(infoCode); ui->dmc_le_infoCodeVariant->setText(infoCodeVariant);
ui->dmc_le_itemLocationCode->setText(itemLocationCode);
ui->dmc_le_learnCode->setText(learnCode); ui->dmc_le_learnEventCode->setText(learnEventCode);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(SM.item->schemeType == stLEARNING);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(!(SM.item->schemeType == stLEARNING));
ui->dmc_btn_Qual->setChecked(SM.item->isQualifyed);
allowDMCodePageToSetItems = true;
allowDMCodePageCallOnChangeComboBox = false;
// if(SM.item->selectedInDMCodeList != -1) {
if(SM.item->selectedInDMCodeList > -1 && SM.item->selectedInDMCodeList < ru_const.dmCodeList.count()) {
ui->dmc_cb_InfoSets->setCurrentIndex(SM.item->selectedInDMCodeList);
ui->dmc_InfoText->document()->setHtml(ru_const.dmCodeList[SM.item->selectedInDMCodeList].text);
}
else {
ui->dmc_cb_InfoSets->setCurrentIndex(-1);
ui->dmc_InfoText->document()->clear();
}
allowDMCodePageCallOnChangeComboBox = true;
SM.item->fileCode = SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
SM.item->selectedInDMCodeList = ui->dmc_cb_InfoSets->currentIndex();
ui->dmc_lb_pageDMName->setText("Модуль данных\n"+SM.item->fileCode);
//if(SM.item->schemeType == stLEARNING) пока не нужно
// fillLearningPageWithData();
// if(SM.item->schemeType == stDESCRIPT || SM.item->schemeType == stCREW) {
// QString htmlFileName = "F:/S1000D/LYX/20201219_auk-05_mi-38.xhtml";
// QFile htmlFile(htmlFileName);
// htmlFile.open(QFile::ReadOnly | QFile::Text);
// QByteArray fileData = htmlFile.readAll(); //
// QString fileStr = QString(fileData);
// fileStr.replace("<img src='", "<img src='"+QFileInfo(htmlFileName).absolutePath()+"/");
// htmlFile.close();
// ui->dataPageEdit->document()->setHtml(fileStr);
// }
// QString htmlFileName = SM.projectPath + "/" + SM.item->fileName.replace(".xml", ".html");
// QFile htmlFile(htmlFileName);
// QStringList htmlDMData;
// if (htmlFile.open(QFile::ReadOnly | QFile::Text)) {
// while(!htmlFile.atEnd())
// htmlDMData.append(QString::fromLocal8Bit(htmlFile.readLine()).replace("\n",""));
// htmlFile.close();
// }
// ui->dataPageEdit->document()->setHtml(SM.item->html.join("\n"));
QString lyxLogFileName = SM.projectPath + "/" + SM.item->fileName+"_importlog.txt";
QFile logFile(lyxLogFileName);
QStringList lyxLogList;
if (logFile.open(QFile::ReadOnly | QFile::Text)) {
while(!logFile.atEnd())
lyxLogList.append(QString::fromUtf8(logFile.readLine()).replace("\n",""));
logFile.close();
}
QString s;
ui->dmc_LyXLog->clear();
for(int i=0;i<lyxLogList.count();i++) {
s = lyxLogList.at(i);
if(s == "") { ui->dmc_LyXLog->addItem(s); continue; }
if(s.at(0) == "!" || s.at(0) == "#") s = s.mid(1);
QListWidgetItem *logItem = new QListWidgetItem;
logItem->setText(s);
if(lyxLogList.at(i).at(0) == "#")
logItem->setForeground(QBrush(QColor(100,100,100)));
// logItem->setTextColor(QColor(100,100,100));
if(lyxLogList.at(i).at(0) == "!") {
logItem->setForeground(QBrush(QColor(150,0,0)));
// logItem->setTextColor(QColor(150,0,0));
//SM.item->isQualifyed = false;
//ui->dmc_btn_Qual->setChecked(false);
}
if(i == 0)
logItem->setForeground(QBrush(QColor(0,0,200)));
// logItem->setTextColor(QColor(0,0,200));
//logItem->setSizeHint(QSize(logItem->sizeHint().width(), 15));
logItem->setFont(QFont("Courier", 9));
logItem->setTextAlignment(Qt::AlignVCenter);
ui->dmc_LyXLog->insertItem(ui->dmc_LyXLog->count(), logItem); // >addItem(s);
}
}
if(SM.item->moduleType == mtPM || SM.item->schemeType == stLEARNING)
ui->actionOpenInBrowser->setEnabled(false);
else
ui->actionOpenInBrowser->setEnabled(true);
updateTreeWidgetNames();
}
void EditorMainWindow::pmc_btn_pmIssuerPressed() {
ui->pmc_le_pmIssuer->setText(ru_const.pmIssuer);
}
void EditorMainWindow::pmc_btn_modelIdentCodePressed() {
ui->pmc_le_modelIdentCode->setText(ru_const.modelIdentCode);
}
void EditorMainWindow::pmc_cb_pmNumABC_Changed(int) {
if(!allowCodePageToCallOnChangeComboBox) return;
allowCodePageToSetItems = false;
allowCodePageToCallOnChangeComboBox = false;
ui->pmc_cb_pmNum->clear(); ui->pmc_cb_pmVolume->clear();
bool onceFlag = true;
for(int i=0; i < ru_const.pmCodeList.count();i++) {
if((ru_const.pmCodeList[i].pmNumABC+" - "+ru_const.pmCodeList[i].pmNumABCText) == ui->pmc_cb_pmNumABC->itemText(ui->pmc_cb_pmNumABC->currentIndex())) {
if(onceFlag) {
if(ui->pmc_t_title->toPlainText() == "")
ui->pmc_t_title->setText(ru_const.pmCodeList[i].pmNumABCText);
ui->pmc_le_pmNumABC->setText(ru_const.pmCodeList[i].pmNumABC);
ui->pmc_le_pmNum->setText("");
ui->pmc_le_pmVolume->setText("");
onceFlag = false;
}
int ind = ui->pmc_cb_pmNum->findText(ru_const.pmCodeList[i].pmNumber+" - "+ru_const.pmCodeList[i].pmNumberText);
if (ind == -1)
ui->pmc_cb_pmNum->addItem(ru_const.pmCodeList[i].pmNumber+" - "+ru_const.pmCodeList[i].pmNumberText, ru_const.pmCodeList[i].pmNumber);
}
}
allowCodePageToCallOnChangeComboBox = true;
ui->pmc_cb_pmNum->setCurrentIndex(-1);
allowCodePageToSetItems = true;
codePagePM_EditChanged("");
}
void EditorMainWindow::pmc_cb_pmNum_Changed(int) {
if(!allowCodePageToCallOnChangeComboBox) return;
allowCodePageToSetItems = false;
allowCodePageToCallOnChangeComboBox = false;
ui->pmc_cb_pmVolume->clear();
bool onceFlag = true;
for(int i=0; i < ru_const.pmCodeList.count();i++) {
if( ((ru_const.pmCodeList[i].pmNumABC+" - "+ru_const.pmCodeList[i].pmNumABCText) == ui->pmc_cb_pmNumABC->itemText(ui->pmc_cb_pmNumABC->currentIndex()))
&& ((ru_const.pmCodeList[i].pmNumber+" - "+ru_const.pmCodeList[i].pmNumberText) == ui->pmc_cb_pmNum->itemText(ui->pmc_cb_pmNum->currentIndex()))) {
if(onceFlag) {
if(ui->pmc_t_title->toPlainText() == "")
ui->pmc_t_title->setText(ru_const.pmCodeList[i].pmNumABCText+" - "+ru_const.pmCodeList[i].pmNumberText);
ui->pmc_le_pmNum->setText(ru_const.pmCodeList[i].pmNumber);
ui->pmc_le_pmVolume->setText("");
}
int ind = ui->pmc_cb_pmVolume->findText(ru_const.pmCodeList[i].pmVolume+" - "+ru_const.pmCodeList[i].pmVolumeText);
if (ind == -1) {
ui->pmc_cb_pmVolume->addItem(ru_const.pmCodeList[i].pmVolume+" - "+ru_const.pmCodeList[i].pmVolumeText, ru_const.pmCodeList[i].pmVolume);
}
}
}
allowCodePageToCallOnChangeComboBox = true;
//if(ui->cb_pmVolume->count() == 1)
// ui->cb_pmVolume->setCurrentIndex(0);
//else
ui->pmc_cb_pmVolume->setCurrentIndex(-1);
allowCodePageToSetItems = true;
codePagePM_EditChanged("");
}
void EditorMainWindow::pmc_cb_pmVolume_Changed(int index) {
if(!allowCodePageToCallOnChangeComboBox) return;
if(index == -1) return;
allowCodePageToSetItems = false;
for(int i=0; i < ru_const.pmCodeList.count();i++) {
if( ((ru_const.pmCodeList[i].pmNumABC+" - "+ru_const.pmCodeList[i].pmNumABCText) == ui->pmc_cb_pmNumABC->itemText(ui->pmc_cb_pmNumABC->currentIndex()))
&& ((ru_const.pmCodeList[i].pmNumber+" - "+ru_const.pmCodeList[i].pmNumberText) == ui->pmc_cb_pmNum->itemText(ui->pmc_cb_pmNum->currentIndex()))
&& ((ru_const.pmCodeList[i].pmVolume+" - "+ru_const.pmCodeList[i].pmVolumeText) == ui->pmc_cb_pmVolume->itemText(ui->pmc_cb_pmVolume->currentIndex())) ) {
if(ui->pmc_t_title->toPlainText() == "")
ui->pmc_t_title->setText(ru_const.pmCodeList[i].pmNumABCText+" - "+ru_const.pmCodeList[i].pmNumberText+". "+ru_const.pmCodeList[i].pmVolumeText);
ui->pmc_le_pmVolume->setText(ru_const.pmCodeList[i].pmVolume);
break;
}
}
allowCodePageToSetItems = true;
codePagePM_EditChanged("");
}
void EditorMainWindow::codePagePM_TitleChanged() {
codePagePM_EditChanged("");
}
void EditorMainWindow::codePagePM_EditChanged(QString) {
QString styleRed = "background-color: rgb(255, 230, 230)";
QString styleWhite = "background-color: white";
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
SM.item->isReady = true;
if(ui->pmc_t_title->document()->toPlainText() == "")
{ ui->pmc_t_title->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_t_title->setStyleSheet(styleWhite);
if(ui->pmc_le_modelIdentCode->text() == "")
{ ui->pmc_le_modelIdentCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_le_modelIdentCode->setStyleSheet(styleWhite);
if(ui->pmc_le_pmIssuer->text() == "")
{ ui->pmc_le_pmIssuer->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_le_pmIssuer->setStyleSheet(styleWhite);
if(ui->pmc_le_pmNumABC->text() == "")
{ ui->pmc_le_pmNumABC->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_le_pmNumABC->setStyleSheet(styleWhite);
if(ui->pmc_le_pmNum->text() == "")
{ ui->pmc_le_pmNum->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_le_pmNum->setStyleSheet(styleWhite);
if(ui->pmc_le_pmVolume->text() == "")
{ ui->pmc_le_pmVolume->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->pmc_le_pmVolume->setStyleSheet(styleWhite);
if(allowCodePageToSetItems) {
//bugCnt++;
//if(DBG) qDebug() << " " << bugCnt << " - set Items";
SM.replaceCurItem_pmCode(ui->pmc_t_title->document()->toPlainText(), ui->pmc_le_modelIdentCode->text(), ui->pmc_le_pmIssuer->text(),
ui->pmc_le_pmNumABC->text()+ui->pmc_le_pmNum->text(), ui->pmc_le_pmVolume->text());
QString fCode = SM.pmIdentString("identAndStatusSection.pmAddress.pmIdent");
SM.item->fileCode = fCode;
setIsModifyed(true);
updateTreeWidgetNames();
}
}
void EditorMainWindow::updateTreeWidgetNamesRecurs(QTreeWidgetItem *node) {
if(node->data(0, Qt::UserRole).toInt() >= SM.items.count()) if(DBG) qDebug() << " Error: updateTreeWidgetNamesRecurs - node->data >= items.count";
if(node->data(0, Qt::UserRole).toInt() >= SM.items.count()) return;
SM.setCurItem(node->data(0, Qt::UserRole).toInt());
QString isLearnigDMStr = "";
if(SM.item->moduleType == mtDM && SM.item->schemeType == stLEARNING)
isLearnigDMStr = "Контроль знаний\n";
if(SM.item->moduleType == mtPM) {
node->setText(0, //SM.item->fileCode+"\n"+
SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle") );
if(SM.item->isQualifyed)
node->setIcon(0, iconFolder);
else
node->setIcon(0, iconFolder_ex);
} else {
node->setText(0, //SM.item->fileCode+" "+
isLearnigDMStr+
SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName") + "\n"
+ SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName") );
if(SM.item->isQualifyed)
node->setIcon(0, iconDoc_head_blue);
else
node->setIcon(0, iconDoc_head_blue_ex);
}
for(int i=0;i<node->childCount();i++)
updateTreeWidgetNamesRecurs(node->child(i));
}
void EditorMainWindow::updateTreeWidgetNames() {
if(!allowCodePageToSetItems) return;
int curInd = ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt();
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
updateTreeWidgetNamesRecurs(ui->treeWidget->topLevelItem(i));
if(curInd >= SM.items.count()) curInd = SM.items.count()-1;
if(curInd < 0) curInd = 0;
SM.setCurItem(curInd);
}
// у DM не может быть детей, убираем их на уровень вверх
void EditorMainWindow::treeWidgetNormalizeDMsAfterDrop(QTreeWidgetItem *node) {
int itemInd = node->data(0, Qt::UserRole).toInt();
//int childInd;
for(int i=0;i<node->childCount();i++) {
//childInd = node->child(i)->data(0, Qt::UserRole).toInt();
if(SM.items[itemInd].moduleType == mtDM) {
QTreeWidgetItem *childClone = node->child(i)->clone();
node->removeChild(node->child(i));
if(node->parent() != nullptr)
node->parent()->insertChild(node->parent()->indexOfChild(node)+1, childClone);
else
ui->treeWidget->insertTopLevelItem(ui->treeWidget->indexOfTopLevelItem(node)+1, childClone);
ui->treeWidget->setCurrentItem(childClone);
}
else
if(node->child(i)->childCount() > 0)
treeWidgetNormalizeDMsAfterDrop(node->child(i));
}
}
void EditorMainWindow::fillItemsFromTreeWidget(int parentInd, QTreeWidgetItem *node) {
int itemInd = node->data(0, Qt::UserRole).toInt();
SM.items[itemInd].child.clear();
if(SM.items[itemInd].moduleType == mtPM) {
SM.setCurItem(itemInd);
QDomNode pmEntry = SM.findElement("content.pmEntry"); // просто удаляем все Ref из PM и далее их заполняем из TreeWidget
for(int i=0;i<pmEntry.childNodes().count();i++)
if(pmEntry.childNodes().at(i).nodeName() == "pmRef" || pmEntry.childNodes().at(i).nodeName() == "dmRef") {
pmEntry.removeChild(pmEntry.childNodes().at(i));
i--;
}
int childInd;
for(int i=0;i<node->childCount();i++) {
childInd = node->child(i)->data(0, Qt::UserRole).toInt();
SM.items[itemInd].child.append(childInd);
SM.moveItemToPM(childInd, itemInd, i); // переместить xml запись элемента в другую публикацию на i-тое место
// if(DBG) qDebug() << " move item" << SM.items[childInd].fileCode << "to PM" << SM.items[itemInd].fileCode << " at pos." << i;
fillItemsFromTreeWidget(itemInd, node->child(i));
}
}
SM.items[itemInd].parent = parentInd;
}
void EditorMainWindow::treeWidgetDrop() {
for(int i=0; i<ui->treeWidget->topLevelItemCount();i++)
treeWidgetNormalizeDMsAfterDrop(ui->treeWidget->topLevelItem(i));
ui->treeWidget->update(); ui->treeWidget->repaint();
for(int i=0; i<ui->treeWidget->topLevelItemCount();i++) {
fillItemsFromTreeWidget(-1, ui->treeWidget->topLevelItem(i));
}
setIsModifyed(true);
}
void EditorMainWindow::on_actionDeleteItem_triggered()
{
if(ui->treeWidget->topLevelItemCount() == 0) return;
if(SM.items.count() <= 1) return;
int itemInd = ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt();
if(SM.items[itemInd].moduleType == mtPM && SM.items[itemInd].child.count() > 0) {
QApplication::beep();
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning); msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
msgBox.setWindowTitle("Удаление"); msgBox.setText("Невозможно удалить непустую публикацию.");
msgBox.exec();
return;
}
SM.deleteItem(itemInd);
allowCodePageToSetItems = false;
//ui->treeWidget->currentItem()->setData(0, Qt::UserRole, 0); // временно, чтобы избежать ошибок
fillTreeWidgetWithItems();
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
allowCodePageToSetItems = true;
Save();
}
void EditorMainWindow::Save() {
for(int i=0; i<ui->treeWidget->topLevelItemCount();i++)
fillItemsFromTreeWidget(-1, ui->treeWidget->topLevelItem(i));
SM.SaveProject(); setIsModifyed(false);
}
void EditorMainWindow::on_dmc_btnBox_IsLearningDM_clicked(QAbstractButton *aButton)
{
if(!allowDMCodePageToSetItems) return;
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
QDialogButtonBox::StandardButton button = ui->dmc_btnBox_IsLearningDM->standardButton(aButton);
if(button == QDialogButtonBox::Yes && ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->isChecked()) {
//ui->dmc_lb_learnCode->setEnabled(true); ui->dmc_lb_learnEventCode->setEnabled(true);
//ui->dmc_le_learnCode->setEnabled(true); ui->dmc_le_learnEventCode->setEnabled(true);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(true);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(false);
if(SM.item->schemeType != stLEARNING) {
if(SM.item->dmDataFilled) {
QApplication::beep();
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning); msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
msgBox.setWindowTitle("Внимание"); msgBox.setText("Изменить схему модуля данных? Заполенные данные будут утеряны.");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if(ret != QMessageBox::Yes) {
allowDMCodePageCallOnChangeComboBox = false;
ui->dmc_cb_InfoSets->setCurrentIndex(SM.item->selectedInDMCodeList);
allowDMCodePageCallOnChangeComboBox = true;
return;
}
SM.item->dmDataFilled = false;
}
QDomNode identAndStatusSectionClone = SM.findElement("identAndStatusSection").cloneNode();
QFile xmlFile(":new/BlankXML/learning.xml");
if (!xmlFile.open(QFile::ReadOnly | QFile::Text)) {
if(DBG) qDebug() << " Cant open :new/BlankXML/learning.xml";
QApplication::beep();
allowDMCodePageCallOnChangeComboBox = false;
ui->dmc_cb_InfoSets->setCurrentIndex(SM.item->selectedInDMCodeList);
allowDMCodePageCallOnChangeComboBox = true;
return;
}
QByteArray fileData = xmlFile.readAll();
xmlFile.close();
SM.item->doc.setContent(fileData);
SM.item->schemeType = stLEARNING;
QDomNode newIdent = SM.findElement("identAndStatusSection");
QDomNode oldIdent = SM.item->doc.importNode(identAndStatusSectionClone, true);
newIdent.parentNode().replaceChild(oldIdent, newIdent);
//qDebug() << SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
}
if(ui->dmc_cb_InfoSets->currentIndex() > -1) {
allowDMCodePageToSetItems = false;
ui->dmc_le_learnCode->setText(ru_const.dmCodeList[ui->dmc_cb_InfoSets->currentIndex()]._learnCode);
ui->dmc_le_learnEventCode->setText(ru_const.dmCodeList[ui->dmc_cb_InfoSets->currentIndex()]._learnEventCode);
allowDMCodePageToSetItems = true;
}
}
if(button == QDialogButtonBox::No && ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->isChecked()) {
//ui->dmc_lb_learnCode->setEnabled(false); ui->dmc_lb_learnEventCode->setEnabled(false);
//ui->dmc_le_learnCode->setEnabled(false); ui->dmc_le_learnEventCode->setEnabled(false);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(false);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(true);
QString newScheme;
if(ui->dmc_cb_InfoSets->currentIndex() > -1)
newScheme = ru_const.dmCodeList[ui->dmc_cb_InfoSets->currentIndex()].schemeTypeStr;
else
newScheme = "DESCRIPT";
SM.item->schemeType = SM.getSchemeTypeByStr(newScheme);
QDomNode identAndStatusSectionClone = SM.findElement("identAndStatusSection").cloneNode();
QFile xmlFile(":new/BlankXML/"+newScheme.toLower()+".xml");
if (!xmlFile.open(QFile::ReadOnly | QFile::Text)) {
if(DBG) qDebug() << " Cant open :new/BlankXML/"+newScheme.toLower()+".xml";
QApplication::beep();
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(true);
ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(false);
return;
}
QByteArray fileData = xmlFile.readAll();
xmlFile.close();
SM.item->doc.setContent(fileData);
QDomNode newIdent = SM.findElement("identAndStatusSection");
QDomNode oldIdent = SM.item->doc.importNode(identAndStatusSectionClone, true);
newIdent.parentNode().replaceChild(oldIdent, newIdent);
//qDebug() << SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
if(ui->dmc_cb_InfoSets->currentIndex() > -1) {
allowDMCodePageToSetItems = false;
ui->dmc_le_learnCode->setText(ru_const.dmCodeList[ui->dmc_cb_InfoSets->currentIndex()].learnCode);
ui->dmc_le_learnEventCode->setText(ru_const.dmCodeList[ui->dmc_cb_InfoSets->currentIndex()].learnEventCode);
allowDMCodePageToSetItems = true;
}
}
if(ui->dmc_cb_InfoSets->currentIndex() == -1) {
allowDMCodePageToSetItems = false;
ui->dmc_le_learnCode->setText("");
ui->dmc_le_learnEventCode->setText("");
allowDMCodePageToSetItems = true;
}
codePageDM_EditChanged("");
}
void EditorMainWindow::on_dmc_cb_InfoSets_currentIndexChanged(int index) {
if(!allowDMCodePageCallOnChangeComboBox) return;
if(index == -1) return;
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
//_schemeType newSchemeType = SM.getSchemeTypeByStr(ru_const.dmCodeList[index].schemeTypeStr);
//уже нельзя так делать!
// if(SM.item->schemeType != newSchemeType) {
// if(SM.item->dmDataFilled) {
// QApplication::beep();
// QMessageBox msgBox;
// msgBox.setIcon(QMessageBox::Warning); msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
// msgBox.setWindowTitle("Внимание"); msgBox.setText("Изменить схему модуля данных? Заполенные данные будут утеряны.");
// msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes);
// int ret = msgBox.exec();
// if(ret != QMessageBox::Yes) {
// allowDMCodePageCallOnChangeComboBox = false;
// ui->dmc_cb_InfoSets->setCurrentIndex(SM.item->selectedInDMCodeList);
// allowDMCodePageCallOnChangeComboBox = true;
// return;
// }
// SM.item->dmDataFilled = false;
// }
// QDomNode identAndStatusSectionClone = SM.findElement("identAndStatusSection").cloneNode();
// QFile xmlFile(":new/BlankXML/"+ru_const.dmCodeList[index].schemeTypeStr.toLower()+".xml");
// if (!xmlFile.open(QFile::ReadOnly | QFile::Text)) {
// if(DBG) qDebug() << " Cant open :new/BlankXML/"+ru_const.dmCodeList[index].schemeTypeStr.toLower()+".xml";
// QApplication::beep();
// allowDMCodePageCallOnChangeComboBox = false;
// ui->dmc_cb_InfoSets->setCurrentIndex(SM.item->selectedInDMCodeList);
// allowDMCodePageCallOnChangeComboBox = true;
// return;
// }
// QByteArray fileData = xmlFile.readAll();
// xmlFile.close();
// SM.item->doc.setContent(fileData);
// QDomNode newIdent = SM.findElement("identAndStatusSection");
// QDomNode oldIdent = SM.item->doc.importNode(identAndStatusSectionClone, true);
// newIdent.parentNode().replaceChild(oldIdent, newIdent);
// //qDebug() << SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
// }
//ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::Yes)->setChecked(false);
//ui->dmc_btnBox_IsLearningDM->button(QDialogButtonBox::No)->setChecked(true);
allowDMCodePageToSetItems = false;
ui->dmc_InfoText->document()->setHtml(ru_const.dmCodeList[index].text);
ui->dmc_le_modelIdentCode->setText(ru_const.dmCodeList[index].modelIdentCode);
ui->dmc_le_systemDiffCode->setText(ru_const.dmCodeList[index].systemDiffCode);
ui->dmc_le_systemCode->setText(ru_const.dmCodeList[index].systemCode);
ui->dmc_le_subSystemCode->setText(ru_const.dmCodeList[index].subSystemCode);
ui->dmc_le_subSubSystemCode->setText(ru_const.dmCodeList[index].subSubSystemCode);
ui->dmc_le_assyCode->setText(ru_const.dmCodeList[index].assyCode);
ui->dmc_le_disassyCode->setText(ru_const.dmCodeList[index].disassyCode);
ui->dmc_le_disassyCodeVariant->setText(ru_const.dmCodeList[index].disassyCodeVariant);
ui->dmc_le_infoCode->setText(ru_const.dmCodeList[index].infoCode);
ui->dmc_le_infoCodeVariant->setText(ru_const.dmCodeList[index].infoCodeVariant);
ui->dmc_le_itemLocationCode->setText(ru_const.dmCodeList[index].itemLocationCode);
if(SM.item->schemeType != stLEARNING) {
ui->dmc_le_learnCode->setText(ru_const.dmCodeList[index].learnCode);
ui->dmc_le_learnEventCode->setText(ru_const.dmCodeList[index].learnEventCode);
} else {
ui->dmc_le_learnCode->setText(ru_const.dmCodeList[index]._learnCode);
ui->dmc_le_learnEventCode->setText(ru_const.dmCodeList[index]._learnEventCode);
}
if(ui->dmc_te_techName->document()->toPlainText() == "") {
ui->dmc_te_techName->setText(ru_const.dmCodeList[index].techName);
ui->dmc_te_infoName->setText(ru_const.dmCodeList[index].infoName);
}
allowDMCodePageToSetItems = true;
SM.item->selectedInDMCodeList = index;
codePageDM_EditChanged("");
}
QString EditorMainWindow::delYYY(QString st) {
return st.replace("X", "").replace("Y", "").replace("N", "");
}
void EditorMainWindow::codePageDM_TitleChanged() {
codePageDM_EditChanged("");
}
void EditorMainWindow::codePageDM_EditChanged(QString) {
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
QString styleRed = "background-color: rgb(255, 230, 230)";
QString styleWhite = "background-color: white";
SM.item->isReady = true;
if(delYYY(ui->dmc_le_modelIdentCode->text()) == "")
{ ui->dmc_le_modelIdentCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_modelIdentCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_systemDiffCode->text()) == "")
{ ui->dmc_le_systemDiffCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_systemDiffCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_systemCode->text()) == "")
{ ui->dmc_le_systemCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_systemCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_subSystemCode->text()) == "")
{ ui->dmc_le_subSystemCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_subSystemCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_subSubSystemCode->text()) == "")
{ ui->dmc_le_subSubSystemCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_subSubSystemCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_assyCode->text()) == "")
{ ui->dmc_le_assyCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_assyCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_disassyCode->text()) == "")
{ ui->dmc_le_disassyCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_disassyCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_disassyCodeVariant->text()) == "")
{ ui->dmc_le_disassyCodeVariant->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_disassyCodeVariant->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_infoCode->text()) == "")
{ ui->dmc_le_infoCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_infoCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_infoCodeVariant->text()) == "")
{ ui->dmc_le_infoCodeVariant->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_infoCodeVariant->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_learnCode->text()) == "")
{ ui->dmc_le_learnCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_learnCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_learnEventCode->text()) == "")
{ ui->dmc_le_learnEventCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_learnEventCode->setStyleSheet(styleWhite);
if(delYYY(ui->dmc_le_itemLocationCode->text()) == "")
{ ui->dmc_le_itemLocationCode->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_le_itemLocationCode->setStyleSheet(styleWhite);
//if(ui->dmc_te_infoName->document()->toPlainText() == "")
// { ui->dmc_te_infoName->setStyleSheet(styleRed); SM.item->isReady = false; }
//else
// ui->dmc_te_infoName->setStyleSheet(styleWhite);
if(ui->dmc_te_techName->document()->toPlainText() == "")
{ ui->dmc_te_techName->setStyleSheet(styleRed); SM.item->isReady = false; }
else
ui->dmc_te_techName->setStyleSheet(styleWhite);
if(allowDMCodePageToSetItems) {
SM.replaceCurItem_dmCode(ui->dmc_te_techName->document()->toPlainText(), ui->dmc_te_infoName->document()->toPlainText(),
ui->dmc_le_modelIdentCode->text(), ui->dmc_le_systemDiffCode->text(),
ui->dmc_le_systemCode->text(), ui->dmc_le_subSystemCode->text(), ui->dmc_le_subSubSystemCode->text(), ui->dmc_le_assyCode->text(),
ui->dmc_le_disassyCode->text(), ui->dmc_le_disassyCodeVariant->text(),
ui->dmc_le_infoCode->text(), ui->dmc_le_infoCodeVariant->text(),
ui->dmc_le_itemLocationCode->text(), ui->dmc_le_learnCode->text(), ui->dmc_le_learnEventCode->text() );
QString fCode = SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
//qDebug() << "update DM: "+fCode;
SM.item->fileCode = fCode;
ui->dmc_lb_pageDMName->setText("Модуль данных\n"+fCode);
setIsModifyed(true);
updateTreeWidgetNames();
}
}
void EditorMainWindow::on_dml_btnBox_question_clicked(QAbstractButton *aButton)
{
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
if(SM.item->schemeType != stLEARNING) return;
QDialogButtonBox::StandardButton button = ui->dml_btnBox_question->standardButton(aButton);
if(button == QDialogButtonBox::Yes) { // Add question
QDomNode lcInteractionNode = SM.item->doc.createElement("lcInteraction");
QDomNode lcSingleSelect = SM.item->doc.createElement("lcSingleSelect");
lcInteractionNode.appendChild(lcSingleSelect);
QDomNode lcQuestion = SM.item->doc.createElement("lcQuestion");
lcSingleSelect.appendChild(lcQuestion);
QDomNode description = SM.item->doc.createElement("description");
lcQuestion.appendChild(description);
QDomNode para = SM.item->doc.createElement("para");
description.appendChild(para);
para.appendChild(SM.item->doc.createTextNode(""));
para.firstChild().toText().setData("Текст вопроса");
QDomNode lcAnswerOptionGroup = SM.item->doc.createElement("lcAnswerOptionGroup");
lcSingleSelect.appendChild(lcAnswerOptionGroup);
QDomNode lcAnswerOption = SM.item->doc.createElement("lcAnswerOption");
lcAnswerOptionGroup.appendChild(lcAnswerOption);
QDomNode lcAnswerOptionContent = SM.item->doc.createElement("lcAnswerOptionContent");
lcAnswerOption.appendChild(lcAnswerOptionContent);
description = SM.item->doc.createElement("description");
lcAnswerOptionContent.appendChild(description);
para = SM.item->doc.createElement("para");
description.appendChild(para);
para.appendChild(SM.item->doc.createTextNode(""));
para.firstChild().toText().setData("Ответ 1");
QDomNode lcCorrectResponse = SM.item->doc.createElement("lcCorrectResponse");
lcAnswerOption.appendChild(lcCorrectResponse);
lcAnswerOption = SM.item->doc.createElement("lcAnswerOption");
lcAnswerOptionGroup.appendChild(lcAnswerOption);
lcAnswerOptionContent = SM.item->doc.createElement("lcAnswerOptionContent");
lcAnswerOption.appendChild(lcAnswerOptionContent);
description = SM.item->doc.createElement("description");
lcAnswerOptionContent.appendChild(description);
para = SM.item->doc.createElement("para");
description.appendChild(para);
para.appendChild(SM.item->doc.createTextNode(""));
para.firstChild().toText().setData("Ответ 2");
SM.findElement("content.learning.learningAssessment").insertAfter(lcInteractionNode, SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(ui->dml_lw_question->currentRow())+"]"));
int ind = ui->dml_lw_question->currentRow();
fillLearningPageWithData();
ui->dml_lw_question->setCurrentRow(ind+1);
ui->dml_lw_question->editItem(ui->dml_lw_question->currentItem());
}
if(button == QDialogButtonBox::No) { // Delete question
if(ui->dml_lw_question->currentRow() < 0) return;
if(ui->dml_lw_question->currentItem() == nullptr) return;
if(ui->dml_lw_question->count() == 1) return;
QDomNode questNode;
int tmpRow=-1;
for(int i=0;i<SM.getNodeChildsWithNameCount("content.learning.learningAssessment", "lcInteraction");i++) {
questNode = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(i)+"]").firstChild();
if(questNode.nodeName() == "lcSingleSelect" || questNode.nodeName() == "lcMultipleSelect")
tmpRow++;
if(tmpRow == ui->dml_lw_question->currentRow()) {
questNode.parentNode().parentNode().removeChild(questNode.parentNode());
break;
}
}
int tmp = ui->dml_lw_question->currentRow();
fillLearningPageWithData();
if(tmp >= ui->dml_lw_question->count()) tmp = ui->dml_lw_question->count()-1;
ui->dml_lw_question->setCurrentRow(tmp);
}
if(button == QDialogButtonBox::Apply) { // move Up question
if(ui->dml_lw_question->currentItem() == nullptr) return;
if(ui->dml_lw_question->currentRow() <= 0) return;
QDomNode prevInter, curInter, tmpCur, tmpPrev;
int tmpRow=-1;
for(int i=1;i<=SM.getNodeChildsWithNameCount("content.learning.learningAssessment", "lcInteraction");i++) {
curInter = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(i-1)+"]");
if(curInter.firstChild().nodeName() == "lcSingleSelect" || curInter.firstChild().nodeName() == "lcMultipleSelect") {
tmpRow++;
if(tmpRow == ui->dml_lw_question->currentRow()-1)
prevInter = curInter;
if(tmpRow == ui->dml_lw_question->currentRow()) {
tmpCur = curInter.cloneNode(); tmpPrev = prevInter.cloneNode();
prevInter.parentNode().replaceChild(tmpCur, prevInter);
curInter.parentNode().replaceChild(tmpPrev, curInter);
int tmp = ui->dml_lw_question->currentRow();
fillLearningPageWithData();
ui->dml_lw_question->setCurrentRow(tmp-1);
break;
}
}
}
}
if(button == QDialogButtonBox::Reset) { // move Down question
if(ui->dml_lw_question->currentItem() == nullptr) return;
if(ui->dml_lw_question->currentRow() >= ui->dml_lw_question->count()-1) return;
QDomNode nextInter, curInter, tmpCur, tmpPrev;
int tmpRow=-1;
for(int i=0;i<SM.getNodeChildsWithNameCount("content.learning.learningAssessment", "lcInteraction")-1;i++) {
nextInter = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(i+1)+"]");
curInter = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(i)+"]");
if(curInter.firstChild().nodeName() == "lcSingleSelect" || curInter.firstChild().nodeName() == "lcMultipleSelect")
tmpRow++;
if(tmpRow == ui->dml_lw_question->currentRow()) {
tmpCur = curInter.cloneNode(); tmpPrev = nextInter.cloneNode();
curInter.parentNode().replaceChild(tmpCur, nextInter);
curInter.parentNode().replaceChild(tmpPrev, curInter);
int tmp = ui->dml_lw_question->currentRow();
fillLearningPageWithData();
ui->dml_lw_question->setCurrentRow(tmp+1);
break;
}
}
}
}
void EditorMainWindow::on_dml_btnBox_answer_clicked(QAbstractButton *aButton)
{
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
if(SM.item->schemeType != stLEARNING) return;
QDialogButtonBox::StandardButton button = ui->dml_btnBox_answer->standardButton(aButton);
int questInterIndex = -1;
QString questNodeName;
questInterIndex = getlcInteractionFromQuestRow(ui->dml_lw_question->currentRow());
QDomNode curInter = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(questInterIndex)+"]");
questNodeName = curInter.firstChild().nodeName();
if(questInterIndex == -1) return;
QString groupStr = "content.learning.learningAssessment.lcInteraction["+QString::number(questInterIndex)+"]."+questNodeName+".lcAnswerOptionGroup";
QDomNode lcAnswerOptionGroup = SM.findElement(groupStr);
int curRow = ui->dml_lw_answer->currentRow();
if(lcAnswerOptionGroup.isNull())
if(DBG) qDebug() << "Error: dml_btnBox_answer_clicked - lcAnswerOptionGroup.isNull " << groupStr;
if(button == QDialogButtonBox::Yes) { // Add answer
QDomNode lcAnswerOption = SM.item->doc.createElement("lcAnswerOption");
if(curRow < 0) curRow = 0;
lcAnswerOptionGroup.insertAfter(lcAnswerOption, lcAnswerOptionGroup.childNodes().at(curRow));
QDomNode lcAnswerOptionContent = SM.item->doc.createElement("lcAnswerOptionContent");
lcAnswerOption.appendChild(lcAnswerOptionContent);
QDomNode description = SM.item->doc.createElement("description");
lcAnswerOptionContent.appendChild(description);
QDomNode para = SM.item->doc.createElement("para");
description.appendChild(para);
para.appendChild(SM.item->doc.createTextNode(""));
para.firstChild().toText().setData("Новый ответ");
fillLearningPageWithData();
ui->dml_lw_question->setCurrentRow(questInterIndex);
ui->dml_lw_answer->setCurrentRow(curRow+1);
ui->dml_lw_answer->editItem(ui->dml_lw_answer->currentItem());
}
if(button == QDialogButtonBox::No) { // Delete answer
if(ui->dml_lw_answer->currentItem() == nullptr) return;
if(ui->dml_lw_answer->count() <= 1) return;
lcAnswerOptionGroup.removeChild(lcAnswerOptionGroup.childNodes().at(curRow));
ui->dml_lw_answer->takeItem(curRow);
}
setIsModifyed(true);
}
void EditorMainWindow::fillLearningPageWithData() {
allowDMLearningPageCallOnChangeLists = false; allowDMLearningPageToSetItems = false;
ui->dml_lw_question->clear(); ui->dml_lw_answer->clear();
allowDMLearningPageCallOnChangeLists = true; allowDMLearningPageToSetItems = true;
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
if(SM.item->schemeType != stLEARNING) return;
ui->dml_lb_title->setText("Модуль данных - контроль знаний\n"+SM.getNodeText("content.learning.learningAssessment.title"));
allowDMLearningPageCallOnChangeLists = false; allowDMLearningPageToSetItems = false;
QDomNode lcInteractionNode, questNode;
QString questStr = "";
QListWidgetItem *questItem;
QDomElement descriptionNode;
if(!SM.isNodeCreated("content.learning")) SM.createNode("content","learning");
if(!SM.isNodeCreated("content.learning.learningAssessment")) {
SM.createNode("content.learning","learningAssessment");
}
QDomNode learningAssessment = SM.findElement("content.learning.learningAssessment");
for(int i=0;i<learningAssessment.childNodes().count();i++) {
lcInteractionNode = learningAssessment.childNodes().at(i);
if(lcInteractionNode.nodeName() != "lcInteraction") continue;
questNode = lcInteractionNode.firstChild(); // в узле lcInteraction может быть только один child (вопрос), при загрузке проводим соответствующий фикс
if(questNode.nodeName() != "lcSingleSelect" && questNode.nodeName() != "lcMultipleSelect") continue;
descriptionNode = questNode.firstChildElement("lcQuestion").firstChildElement("description");
questStr = "";
for(int p=0;p<descriptionNode.childNodes().count();p++) {
if(descriptionNode.childNodes().at(p).nodeName() == "para") {
if(questStr != "") questStr += " # ";
questStr += descriptionNode.childNodes().at(p).toElement().text();
}
}
questItem = new QListWidgetItem(QIcon(":new/Icons/question.png"), questStr);
questItem->setFlags(questItem->flags() | Qt::ItemIsEditable);
ui->dml_lw_question->addItem(questItem);
}
allowDMLearningPageCallOnChangeLists = true; allowDMLearningPageToSetItems = true;
ui->dml_lw_question->setCurrentRow(0);
}
void EditorMainWindow::on_dml_lw_question_currentRowChanged(int) {
if(!allowDMLearningPageCallOnChangeLists) return;
allowDMLearningPageCallOnChangeLists = false; allowDMLearningPageToSetItems = false;
ui->dml_lw_answer->clear();
QString asnwerText;
QListWidgetItem *answerItem;
int curQuestInter = getlcInteractionFromQuestRow(ui->dml_lw_question->currentRow());
QDomNode questNode = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]").firstChild();
for(int j=0;j<SM.getNodeChildsWithNameCount("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+questNode.nodeName()+".lcAnswerOptionGroup", "lcAnswerOption");j++) {
asnwerText = SM.getNodeText("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+questNode.nodeName()+
".lcAnswerOptionGroup.lcAnswerOption["+QString::number(j)+"].lcAnswerOptionContent.description.para");
answerItem = new QListWidgetItem(asnwerText);
answerItem->setFlags(answerItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsEditable);
if(SM.isNodeCreated("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(j)+"].lcCorrectResponse"))
answerItem->setCheckState(Qt::Checked);
else
answerItem->setCheckState(Qt::Unchecked);
ui->dml_lw_answer->addItem(answerItem);
}
allowDMLearningPageCallOnChangeLists = true; allowDMLearningPageToSetItems = true;
}
void EditorMainWindow::on_dml_lw_question_itemChanged(QListWidgetItem *item) {
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
if(!allowDMLearningPageCallOnChangeLists) return;
if(!allowDMLearningPageToSetItems) return;
if(ui->dml_lw_question->currentItem() != item) return;
int curQuestInter = getlcInteractionFromQuestRow(ui->dml_lw_question->currentRow());
if(curQuestInter == -1) return;
QDomNode questNode = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]").firstChild();
QDomNode description = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcQuestion.description");
while(description.childNodes().count() > 0)
description.removeChild(description.firstChild());
QStringList paraList = item->text().split("#");
QDomNode para;
foreach(QString paraText, paraList) {
para = SM.item->doc.createElement("para");
para.appendChild(SM.item->doc.createTextNode(""));
para.firstChild().toText().setData(paraText);
description.appendChild(para);
}
setIsModifyed(true);
}
void EditorMainWindow::on_dml_lw_answer_itemChanged(QListWidgetItem *answerItem)
{
if(ui->treeWidget->currentItem() == nullptr) return;
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
if(!allowDMLearningPageCallOnChangeLists) return;
if(!allowDMLearningPageToSetItems) return;
ui->dml_lw_answer->setCurrentItem(answerItem);
int curQuestInter = getlcInteractionFromQuestRow(ui->dml_lw_question->currentRow());
QDomNode questNode = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]").firstChild();
QDomNode para = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(ui->dml_lw_answer->currentRow())+"]."+
"lcAnswerOptionContent.description.para");
if(para.isNull()) {
if(DBG) qDebug() << "answer_itemChanged: para is NULL" << questNode.nodeName() << curQuestInter << ui->dml_lw_answer->currentRow();
return;
}
para.firstChild().toText().setData(answerItem->text());
bool lcCorrectResponseCreated = SM.isNodeCreated("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(ui->dml_lw_answer->currentRow())+"].lcCorrectResponse");
if(answerItem->checkState() == Qt::Checked) {
if(!lcCorrectResponseCreated)
SM.createNode("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(ui->dml_lw_answer->currentRow())+"]", "lcCorrectResponse");
} else {
if(lcCorrectResponseCreated)
SM.deleteNode("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(ui->dml_lw_answer->currentRow())+"].lcCorrectResponse");
}
int checkedAnswersCnt = 0;
for(int k=0;k<SM.getNodeChildsWithNameCount("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup", "lcAnswerOption");k++) // другие ответы с галочками?
if(SM.isNodeCreated("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(k)+"].lcCorrectResponse"))
checkedAnswersCnt++;
if(checkedAnswersCnt == 0) {
SM.createNode("content.learning.learningAssessment.lcInteraction["+QString::number(curQuestInter)+"]."+
questNode.nodeName()+".lcAnswerOptionGroup.lcAnswerOption["+QString::number(ui->dml_lw_answer->currentRow())+"]", "lcCorrectResponse");
allowDMLearningPageCallOnChangeLists=false; answerItem->setCheckState(Qt::Checked); allowDMLearningPageCallOnChangeLists = true;
checkedAnswersCnt++;
}
if(checkedAnswersCnt == 1) questNode.toElement().setTagName("lcSingleSelect");
if(checkedAnswersCnt > 1) questNode.toElement().setTagName("lcMultipleSelect");
setIsModifyed(true);
}
int EditorMainWindow::getlcInteractionFromQuestRow(int row) {
QDomNode questNode;
int tmpRow=-1;
for(int i=0;i<SM.getNodeChildsWithNameCount("content.learning.learningAssessment", "lcInteraction");i++) {
questNode = SM.findElement("content.learning.learningAssessment.lcInteraction["+QString::number(i)+"]").firstChild();
if(questNode.nodeName() == "lcSingleSelect" || questNode.nodeName() == "lcMultipleSelect")
tmpRow++;
if(tmpRow == row) return i;
}
if(DBG) qDebug() << "Error: getlcInteractionFromQuestRow - node not found";
return -1;
}
void EditorMainWindow::on_actionLyXImport_triggered() {
// if(ui->treeWidget->currentItem() == nullptr) return;
// SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
// if(SM.item->moduleType != mtDM) return;
// if(SM.item->schemeType != stDESCRIPT && SM.item->schemeType != stCREW) return;
if(isProjectModifyed) {
QMessageBox msgBox;
msgBox.setText("Сохранить изменения?");
msgBox.setWindowTitle("Проект изменен");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
Save();
if(isProjectModifyed) return;
case QMessageBox::No:
break;
case QMessageBox::Cancel:
return;
}
}
QString fileName;
QFileInfo info1(config.lastOpenedFile);
fileName = QFileDialog::getOpenFileName(this, tr("Выберите файл сценария в формате LyX"), info1.absolutePath(), tr("*.lyx"));
if(fileName == "") return;
//import, delete after debug
//fileName = "F:/C++/build-S1000DEditor-Desktop_Qt_5_15_2_MinGW_64_bit-Debug/Test/LyX/auk-05_mi-38.lyx";
openLyXFile(fileName);
}
void EditorMainWindow::openLyXFile(QString fileName) {
if(fileName == "") return;
this->setWindowTitle("Конвертер АУК "+version+" - " + fileName);
ui->actionAddDM->setEnabled(true); ui->actionAddPM->setEnabled(true);
isProjectOpened = true;
setIsModifyed(false);
SM.rootLyXfile = fileName;
SM.packages.clear(); SM.timeConvert = SM.timeS1000D = SM.timeSCORM = 0;
splash->Reset(); splash->show(); splash->repaint();
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QApplication::processEvents();
QElapsedTimer timer; timer.start();
lyx.Import(&SM, fileName, splash);
html.Generate(&SM, false, splash);
splash->Reset(); splash->SetTitle("Загрузка пакетов...");
SM.LoadPackagesXML();
SM.timeConvert = (int)timer.elapsed()/1000;
splash->Reset(); splash->SetTitle("Сохранение...");
QApplication::processEvents();
//setIsModifyed(true);
fillTreeWidgetWithItems();
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(0));
Save();
splash->hide();
QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
config.lastOpenedFile = fileName;
QFile cfgFile(qApp->applicationDirPath()+"/config.txt");
if (cfgFile.open(QFile::ReadWrite | QFile::Text)) {
QString cfg = "lastOpenedFile="+config.lastOpenedFile;
cfgFile.write(cfg.toStdString().c_str());
cfgFile.resize(cfgFile.pos());
}
cfgFile.close();
//updateTreeWidgetNames();
}
// QDialog *LyXDialog; QListWidget* LyXLog;
// LyXLog = new QListWidget(this);
// LyXLog->setFixedHeight(800); LyXLog->setFixedWidth(1000);
// LyXLog->setObjectName("LyXDialogList");
// QFont logFont("Courier", 8); LyXLog->setFont(QFont(logFont));
// QPushButton* logDialogCloseButton = new QPushButton(tr("Закрыть"), this);
// logDialogCloseButton->setDefault(true);
// LyXDialog = new QDialog(this);
// QVBoxLayout *logDialogLayout = new QVBoxLayout(LyXDialog);
// logDialogLayout->setMargin(5); logDialogLayout->setSpacing(6); LyXDialog->setWindowTitle(QString("Log"));
// logDialogLayout->addWidget(LyXLog); logDialogLayout->addWidget(logDialogCloseButton);
// connect(logDialogCloseButton, SIGNAL(clicked()), LyXDialog, SLOT(close()));
// LyXDialog->setLayout(logDialogLayout);
// QString s;
// for(int i=0;i<LyXLogList.count();i++) {
// s = LyXLogList.at(i);
// if(s == "") { LyXLog->addItem(s); continue; }
// if(s.at(0) == "!" || s.at(0) == "#") s = s.mid(1);
// LyXLog->addItem(s);
// if(LyXLogList.at(i).at(0) == "#")
// LyXLog->item(LyXLog->count()-1)->setTextColor(QColor(150,150,150));
// if(LyXLogList.at(i).at(0) == "!")
// LyXLog->item(LyXLog->count()-1)->setTextColor(QColor(100,0,0));
// }
//config.lastOpenedDir = QFileInfo(fileName).absolutePath();
// LyXDialog->exec();
void EditorMainWindow::on_action_refreshFromLyX_triggered()
{
if(config.lastOpenedFile == "") return;
if(QFileInfo::exists(config.lastOpenedFile))
openLyXFile(config.lastOpenedFile);
else {
QApplication::beep();
config.lastOpenedFile = "";
}
}
void EditorMainWindow::on_actionOpenInBrowser_triggered()
{
if(SM.item == nullptr) return;
if(SM.item->moduleType == mtPM) return;
if(SM.item->schemeType == stLEARNING) return;
QString htmlFileName = SM.projectPath + "/" + SM.item->fileName.replace(".xml", ".html");
QDesktopServices::openUrl(QUrl("file:///"+htmlFileName, QUrl::TolerantMode));
}
void EditorMainWindow::on_actionExit_triggered()
{
this->close();
}
void EditorMainWindow::on_S1000D_doc_dmc_linkActivated(const QString &link) // &link
{
QDesktopServices::openUrl(QUrl("file:///"+QCoreApplication::applicationDirPath()+"/Docs/S1000D_Issue_4.1.pdf", QUrl::TolerantMode));
}
void EditorMainWindow::on_label_33_linkActivated(const QString &link)
{
QDesktopServices::openUrl(QUrl("file:///"+QCoreApplication::applicationDirPath()+"/Docs/infoCodes.txt", QUrl::TolerantMode));
}
void EditorMainWindow::on_label_34_linkActivated(const QString &link)
{
QDesktopServices::openUrl(QUrl("file:///"+QCoreApplication::applicationDirPath()+"/Docs/S1000D_Issue_4.1.pdf", QUrl::TolerantMode));
}
void EditorMainWindow::on_action_regenHTML_triggered()
{
splash->Reset(); splash->show();
splash->SetTitle("Генерация HTML...");
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QApplication::processEvents();
html.Generate(&SM, false, splash);
splash->Reset(); splash->SetTitle("Сохранение...");
QApplication::processEvents();
Save();
splash->hide();
QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
}
bool EditorMainWindow::isCodingFilled() {
tmpIntList.clear(); tmpStrList.clear();
if(ui->treeWidget->topLevelItemCount() == 0) return false;
for(int i=0;i<ui->treeWidget->topLevelItemCount();i++)
if(!isCodingFilledRecurs(ui->treeWidget->topLevelItem(i)))
return false;
return true;
}
bool EditorMainWindow::isCodingFilledRecurs(QTreeWidgetItem* treeitem) {
int ind = treeitem->data(0, Qt::UserRole).toInt();
SM.setCurItem(ind);
QString fCode, title;
if(SM.item->moduleType == mtPM) {
QString pmTitle, modelIdentCode, pmIssuer, pmNumber, pmVolume;
title = pmTitle = SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
modelIdentCode = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "modelIdentCode");
pmIssuer = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmIssuer");
pmNumber = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmNumber");
pmVolume = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmVolume");
if(pmTitle.isEmpty() || delYYY(pmIssuer).isEmpty() || delYYY(pmNumber).isEmpty() || delYYY(pmVolume).isEmpty()) {
ui->treeWidget->setCurrentItem(treeitem);
QApplication::beep();
return false;
}
fCode = SM.pmIdentString("identAndStatusSection.pmAddress.pmIdent");
}
if(SM.item->moduleType == mtDM) {
QString modelIdentCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "modelIdentCode");
QString systemDiffCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemDiffCode");
QString systemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemCode");
QString subSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSystemCode");
QString subSubSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSubSystemCode");
QString assyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "assyCode");
QString disassyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCode");
QString disassyCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCodeVariant");
QString infoCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCode");
QString infoCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCodeVariant");
QString itemLocationCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "itemLocationCode");
QString learnCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnCode");
QString learnEventCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnEventCode");
QString techName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
//QString infoName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName");
if(delYYY(modelIdentCode).isEmpty() || delYYY(systemDiffCode).isEmpty() || delYYY(systemCode).isEmpty() || delYYY(subSystemCode).isEmpty() || delYYY(subSubSystemCode).isEmpty() ||
delYYY(assyCode).isEmpty() || delYYY(disassyCode).isEmpty() || delYYY(disassyCodeVariant).isEmpty() || delYYY(infoCode).isEmpty() || delYYY(infoCodeVariant).isEmpty() ||
delYYY(itemLocationCode).isEmpty() || delYYY(learnCode).isEmpty() || delYYY(learnEventCode).isEmpty() || delYYY(techName).isEmpty() ) {
ui->treeWidget->setCurrentItem(treeitem);
QApplication::beep();
return false;
}
title = techName;
fCode = SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
}
int tmpInd = tmpStrList.indexOf(fCode);
if(tmpInd != -1) {
SM.setCurItem(tmpIntList[tmpInd]);
QString title2;
if(SM.item->moduleType == mtDM)
title2 = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
else
title2 = SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
ui->treeWidget->setCurrentItem(treeitem);
QApplication::beep();
QMessageBox::critical(this,"Ошибка","Дублирование кодов публикаций/модулей: \n - \""+title+"\"\n - \""+title2+"\"",QMessageBox::Ok);
return false;
}
tmpStrList.append(fCode); tmpIntList.append(ind);
for(int i=0;i<treeitem->childCount();i++)
if(!isCodingFilledRecurs(treeitem->child(i)))
return false;
return true;
}
void EditorMainWindow::on_action_Export_triggered()
{
if(!isCodingFilled()) return;
for(int i=0; i<ui->treeWidget->topLevelItemCount();i++)
fillItemsFromTreeWidget(-1, ui->treeWidget->topLevelItem(i));
for(int i=0;i<SM.items.count();i++) {
SM.setCurItem(i);
if(SM.item->moduleType != mtPM)
SM.item->fileCode = SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
else
SM.item->fileCode = SM.pmIdentString("identAndStatusSection.pmAddress.pmIdent");
}
QString title = SM.items[ ui->treeWidget->topLevelItem(0)->data(0, Qt::UserRole).toInt() ].doc.namedItem("pm").namedItem("rdf:Description").attributes().namedItem("atc").nodeValue();
if(title == "")
title = SM.items[ ui->treeWidget->topLevelItem(0)->data(0, Qt::UserRole).toInt() ].doc.namedItem("pm").namedItem("identAndStatusSection").namedItem("pmAddress").namedItem("pmAddressItems").namedItem("pmTitle").childNodes().at(0).nodeValue();
exportDlg->setPackTitle(title);
QString fCode = SM.items[ ui->treeWidget->topLevelItem(0)->data(0, Qt::UserRole).toInt() ].fileCode;
exportDlg->setPackName(fCode.left(fCode.length()-7));
QFileInfo info(SM.items[ ui->treeWidget->topLevelItem(0)->data(0, Qt::UserRole).toInt() ].importedFromLyX);
exportDlg->setPackDir(info.absolutePath());
exportDlg->fillTree(ui->treeWidget);
exportDlg->fillPackageList();
if(SM.packages.count() > 0)
exportDlg->setPackageListIndex(0);
exportDlg->exec();
}
// ---------------------------------------------- S1000D -------------------------------------------------
void EditorMainWindow::exportS1000D() {
if(SM.items.count() == 0) return;
QString dirName = exportDlg->getPackDir();
QString packName = exportDlg->getPackName();
QString packTitle = exportDlg->getPackTitle();
if (packName == "") {
QMessageBox::critical(this,"Ошибка","Задайте имя пакета.",QMessageBox::Ok);
return;
}
QDir dir = QDir(dirName);
if (!dir.exists()) {
QMessageBox::critical(this,"Ошибка","Папка "+dirName+" не найдена.",QMessageBox::Ok);
return;
}
if(QFile::exists(dirName+"/"+packName+".zip")) {
QMessageBox msgBox;
msgBox.setText("Файл "+dirName+"/"+packName+".zip уже существует. Перезаписать?");
msgBox.setWindowTitle("S1000D");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
msgBox.setIcon(QMessageBox::Question);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
break;
case QMessageBox::No:
return;
case QMessageBox::Cancel:
return;
}
}
splash->Reset(); splash->show();
splash->SetTitle("Формирование пакета S1000D...");
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QApplication::processEvents();
QTreeWidget* dlgTree = exportDlg->getDlgTreeWidget();
for(int i=0;i<SM.items.count();i++)
SM.items[i].toExport = false;
QList<QTreeWidgetItem*> childList;
for(int i=0;i<dlgTree->topLevelItemCount();i++)
childList.append(dlgTree->topLevelItem(i));
while(!childList.isEmpty()) {
QTreeWidgetItem* item = childList.takeFirst();
if(item->checkState(0) == Qt::Checked)
SM.items[item->data(0, Qt::UserRole).toInt()].toExport = true;
for(int i=0;i<item->childCount();i++)
childList.append(item->child(i));
}
int ind = dlgTree->topLevelItem(0)->data(0, Qt::UserRole).toInt();
QDomNode descr = SM.items[ind].doc.namedItem("pm").namedItem("rdf:Description");
if(descr.isNull()) {
descr = SM.items[ind].doc.createElement("rdf:Description");
SM.items[ind].doc.namedItem("pm").appendChild(descr);
}
descr.toElement().setAttribute("atc", packTitle);
bool res = SM.exportS1000D(dirName, packName, packTitle, splash);
if(res)
exportDlg->setS1000Dlabel("Успешно", "green");
else
exportDlg->setS1000Dlabel("Не выполнено", "red");
}
// ---------------------------------------------- SCORM -------------------------------------------------
void EditorMainWindow::exportSCORM() {
if(SM.items.count() == 0) return;
QString dirName = exportDlg->getPackDir();
QString packName = exportDlg->getPackName();
QString packTitle = exportDlg->getPackTitle();
if (packName == "") {
QMessageBox::critical(this,"Ошибка","Задайте имя пакета.",QMessageBox::Ok);
return;
}
QDir dir = QDir(dirName);
if (!dir.exists()) {
QMessageBox::critical(this,"Ошибка","Папка "+dirName+" не найдена.",QMessageBox::Ok);
return;
}
if(QFile::exists(dirName+"/"+packName+"_SCORM.zip")) {
QMessageBox msgBox;
msgBox.setText("Файл "+dirName+"/"+packName+"_SCORM.zip уже существует. Перезаписать?");
msgBox.setWindowTitle("SCORM");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.setWindowIcon(QIcon(":new/Icons/doc_config.png"));
msgBox.setIcon(QMessageBox::Question);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
break;
case QMessageBox::No:
return;
case QMessageBox::Cancel:
return;
}
}
splash->Reset(); splash->show();
splash->SetTitle("Формирование SCORM-пакета...");
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QApplication::processEvents();
QTreeWidget* dlgTree = exportDlg->getDlgTreeWidget();
for(int i=0;i<SM.items.count();i++)
SM.items[i].toExport = false;
QList<QTreeWidgetItem*> childList;
for(int i=0;i<dlgTree->topLevelItemCount();i++)
childList.append(dlgTree->topLevelItem(i));
while(!childList.isEmpty()) {
QTreeWidgetItem* item = childList.takeFirst();
if(item->checkState(0) == Qt::Checked)
SM.items[item->data(0, Qt::UserRole).toInt()].toExport = true;
for(int i=0;i<item->childCount();i++)
childList.append(item->child(i));
}
int ind = dlgTree->topLevelItem(0)->data(0, Qt::UserRole).toInt();
QDomNode descr = SM.items[ind].doc.namedItem("pm").namedItem("rdf:Description");
if(descr.isNull()) {
descr = SM.items[ind].doc.createElement("rdf:Description");
SM.items[ind].doc.namedItem("pm").appendChild(descr);
}
descr.toElement().setAttribute("atc", packTitle);
bool res = SM.exportSCORM(dirName, packName, packTitle, splash);
if(res)
exportDlg->setSCORMlabel("Успешно", "green");
else
exportDlg->setSCORMlabel("Не выполнено", "red");
}
// <item identifier="ID0E5C_2">
// <title>КОНТРОЛЬ ЗНАНИЙ</title>
// <item identifier="id_DMC-ANSAT-A-031-31-00-00A-040A-A-T80E" identifierref="DMC-ANSAT-A-031-31-00-00A-040A-A-T80E">
// <title>РЕГИСТРАТОР ПОЛЕТНЫХ ДАННЫХ - ОПИСАНИЕ И РАБОТА</title>
// </item>
// <item identifier="id_DMC-ANSAT-A-031-41-00-00A-040A-A-T80E" identifierref="DMC-ANSAT-A-031-41-00-00A-040A-A-T80E">
// <title>РЕГИСТРАТОР ПОЛЕТНЫХ ДАННЫХ - пример</title>
// </item>
// </item>
// <resource type="webcontent" adlcp:scormType="sco" identifier="DMC-ANSAT-A-031-31-00-00A-040A-A-T80E" href="DMC-ANSAT-A-031-31-00-00A-040A-A-T80E_001-00_ru-RU.xml">
// <file href="DMC-ANSAT-A-031-31-00-00A-040A-A-T80E_001-00_ru-RU.xml" />
// <file href="DMC-ANSAT-A-031-31-00-00A-040A-A-T80E_001-00_ru-RU.xml" />
// <dependency identifierref="SharedFiles" />
// </resource>
// <div class="S1000Dmultimediaobj" boardNum="video" val="video.mp4" actuate="onLoad" show="embed">
// <img src="1.1.1 XL.svg" alt="Показать" onmousemove="showZoomImg(event, '1.1.1 XL.svg');"/>
// NOT <img src="app/images/drive-drawing.svg" />
// <a href="aircraftmodel/index.html ">ИМВС</a>
// NOT <a href="#fig_002">
// onmousemove="showTooltipImg(evt, 'inline.svg');"
void EditorMainWindow::on_dmc_btn_Qual_clicked(bool checked)
{
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
SM.item->isQualifyed = checked;
setIsModifyed(true);
updateTreeWidgetNames();
}
void EditorMainWindow::on_pmc_btn_Qual_clicked(bool checked)
{
SM.setCurItem(ui->treeWidget->currentItem()->data(0, Qt::UserRole).toInt());
SM.item->isQualifyed = checked;
setIsModifyed(true);
updateTreeWidgetNames();
}