From db8cf12d491349c6d062a37481e2c7d6ea15dc7b Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 30 May 2014 16:22:03 +0300 Subject: [PATCH] Catch exceptions in lite parsing. --HG-- branch : develop --- src/app/mainwindow.cpp | 2 ++ src/app/mainwindow.h | 2 +- src/app/xml/vpattern.cpp | 45 ++++++++++++++++++++++++++++++++++------ src/app/xml/vpattern.h | 1 + 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e0ed7f41f..a51f09f18 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -89,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent) doc = new VPattern(pattern, comboBoxDraws, &mode); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); + connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear); InitAutoSave(); @@ -1291,6 +1292,7 @@ void MainWindow::Clear() setCurrentFile(""); pattern->Clear(); doc->clear(); + doc->setPatternModified(false); sceneDraw->clear(); sceneDetails->clear(); CancelTool(); diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index fcbde5283..df9eb14b3 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -128,6 +128,7 @@ public slots: void ShowToolTip(const QString &toolTip); void OpenRecentFile(); + void Clear(); signals: /** * @brief ModelChosen emit after calculation all details. @@ -139,7 +140,6 @@ protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); virtual void closeEvent( QCloseEvent * event ); - void Clear(); private: Q_DISABLE_COPY(MainWindow) /** @brief ui keeps information about user interface */ diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 67fb89c45..0594b0563 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -40,6 +40,7 @@ #include #include "../../libs/qmuparser/qmuparsererror.h" +#include const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagCalculation = QStringLiteral("calculation"); @@ -556,11 +557,47 @@ bool VPattern::SaveDocument(const QString &fileName) //--------------------------------------------------------------------------------------------------------------------- void VPattern::FullUpdateTree() { - VMainGraphicsScene *scene = new VMainGraphicsScene(); + VMainGraphicsScene *scene = nullptr; try { + scene = new VMainGraphicsScene(); Parse(Document::LiteParse, scene, scene); } + catch (const VExceptionObjectError &e) + { + delete scene; + e.CriticalMessageBox(tr("Error parsing file.")); + emit ClearMainWindow(); + return; + } + catch (const VExceptionConversionError &e) + { + delete scene; + e.CriticalMessageBox(tr("Error can't convert value.")); + emit ClearMainWindow(); + return; + } + catch (const VExceptionEmptyParameter &e) + { + delete scene; + e.CriticalMessageBox(tr("Error empty parameter.")); + emit ClearMainWindow(); + return; + } + catch (const VExceptionWrongId &e) + { + delete scene; + e.CriticalMessageBox(tr("Error wrong id.")); + emit ClearMainWindow(); + return; + } + catch (VException &e) + { + delete scene; + e.CriticalMessageBox(tr("Error parsing file.")); + emit ClearMainWindow(); + return; + } catch (const std::bad_alloc &) { delete scene; @@ -572,13 +609,9 @@ void VPattern::FullUpdateTree() msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); + emit ClearMainWindow(); return; } - catch (...) - { - delete scene; - throw; - } delete scene; setCurrentData(); diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 8d32ed97a..ac8546813 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -236,6 +236,7 @@ signals: * @param id tool id. */ void ChangedCursor(quint32 id); + void ClearMainWindow(); public slots: /** * @brief FullUpdateTree lite parse file.