From 99314a358f280e80cc6dbb0af663f7c1dd96c7c0 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 5 Jun 2014 15:10:16 +0300 Subject: [PATCH] New slot for full parsing. Want use in undo command. --HG-- branch : feature --- src/app/mainwindow.cpp | 165 ++++++++++++++++++++++------------------- src/app/mainwindow.h | 1 + 2 files changed, 88 insertions(+), 78 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index d1a264a8f..d63759da1 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -898,8 +898,8 @@ void MainWindow::currentDrawChanged( int index ) { if (index != -1) { - doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); + doc->setCurrentData(); if (drawMode) { ArrowTool(); @@ -1333,6 +1333,91 @@ void MainWindow::Clear() #endif } +void MainWindow::FullParseFile() +{ + try + { + doc->Parse(Document::FullParse); + } + catch (const VExceptionObjectError &e) + { + e.CriticalMessageBox(tr("Error parsing file."), this); + Clear(); + return; + } + catch (const VExceptionConversionError &e) + { + e.CriticalMessageBox(tr("Error can't convert value."), this); + Clear(); + return; + } + catch (const VExceptionEmptyParameter &e) + { + e.CriticalMessageBox(tr("Error empty parameter."), this); + Clear(); + return; + } + catch (const VExceptionWrongId &e) + { + e.CriticalMessageBox(tr("Error wrong id."), this); + Clear(); + return; + } + catch (VException &e) + { + e.CriticalMessageBox(tr("Error parsing file."), this); + Clear(); + return; + } + catch (const std::bad_alloc &) + { +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error parsing file.")); + msgBox.setInformativeText("std::bad_alloc"); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif + Clear(); + return; + } + + QString patternPiece = QString(); + if (comboBoxDraws->currentIndex() != -1) + { + patternPiece = comboBoxDraws->itemText(comboBoxDraws->currentIndex()); + } + disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + comboBoxDraws->clear(); + comboBoxDraws->addItems(doc->getPatternPieces()); + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + ui->actionPattern_properties->setEnabled(true); + + qint32 index = comboBoxDraws->findText(patternPiece); + if ( index != -1 ) + { // -1 for not found + comboBoxDraws->setCurrentIndex(index); + } + if (comboBoxDraws->count() > 0) + { + SetEnableTool(true); + } + else + { + SetEnableTool(false); + } + SetEnableWidgets(true); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewPattern create new empty pattern. @@ -1884,83 +1969,7 @@ void MainWindow::LoadPattern(const QString &fileName) return; } - try - { - doc->Parse(Document::FullParse); - } - catch (const VExceptionObjectError &e) - { - e.CriticalMessageBox(tr("Error parsing file."), this); - Clear(); - return; - } - catch (const VExceptionConversionError &e) - { - e.CriticalMessageBox(tr("Error can't convert value."), this); - Clear(); - return; - } - catch (const VExceptionEmptyParameter &e) - { - e.CriticalMessageBox(tr("Error empty parameter."), this); - Clear(); - return; - } - catch (const VExceptionWrongId &e) - { - e.CriticalMessageBox(tr("Error wrong id."), this); - Clear(); - return; - } - catch (VException &e) - { - e.CriticalMessageBox(tr("Error parsing file."), this); - Clear(); - return; - } - catch (const std::bad_alloc &) - { -#ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); -#endif - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error parsing file.")); - msgBox.setInformativeText("std::bad_alloc"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Warning); - msgBox.exec(); -#ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); -#endif - Clear(); - return; - } - - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - comboBoxDraws->clear(); - comboBoxDraws->addItems(doc->getPatternPieces()); - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - ui->actionPattern_properties->setEnabled(true); - - QString nameDraw = doc->GetNameActivDraw(); - qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) - { // -1 for not found - comboBoxDraws->setCurrentIndex(index); - } - if (comboBoxDraws->count() > 0) - { - SetEnableTool(true); - } - else - { - SetEnableTool(false); - } - SetEnableWidgets(true); + FullParseFile(); bool patternModified = doc->isPatternModified(); setCurrentFile(fileName); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 87925ea63..c041bae18 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -129,6 +129,7 @@ public slots: void ShowToolTip(const QString &toolTip); void OpenRecentFile(); void Clear(); + void FullParseFile(); signals: /** * @brief ModelChosen emit after calculation all details.