Catch exceptions in lite parsing.

--HG--
branch : develop
This commit is contained in:
dismine 2014-05-30 16:22:03 +03:00
parent bf15237296
commit db8cf12d49
4 changed files with 43 additions and 7 deletions

View File

@ -89,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent)
doc = new VPattern(pattern, comboBoxDraws, &mode); doc = new VPattern(pattern, comboBoxDraws, &mode);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified); connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
InitAutoSave(); InitAutoSave();
@ -1291,6 +1292,7 @@ void MainWindow::Clear()
setCurrentFile(""); setCurrentFile("");
pattern->Clear(); pattern->Clear();
doc->clear(); doc->clear();
doc->setPatternModified(false);
sceneDraw->clear(); sceneDraw->clear();
sceneDetails->clear(); sceneDetails->clear();
CancelTool(); CancelTool();

View File

@ -128,6 +128,7 @@ public slots:
void ShowToolTip(const QString &toolTip); void ShowToolTip(const QString &toolTip);
void OpenRecentFile(); void OpenRecentFile();
void Clear();
signals: signals:
/** /**
* @brief ModelChosen emit after calculation all details. * @brief ModelChosen emit after calculation all details.
@ -139,7 +140,6 @@ protected:
virtual void keyPressEvent ( QKeyEvent * event ); virtual void keyPressEvent ( QKeyEvent * event );
virtual void showEvent( QShowEvent *event ); virtual void showEvent( QShowEvent *event );
virtual void closeEvent( QCloseEvent * event ); virtual void closeEvent( QCloseEvent * event );
void Clear();
private: private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */

View File

@ -40,6 +40,7 @@
#include <QMessageBox> #include <QMessageBox>
#include "../../libs/qmuparser/qmuparsererror.h" #include "../../libs/qmuparser/qmuparsererror.h"
#include <exception/vexceptionemptyparameter.h>
const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagPattern = QStringLiteral("pattern");
const QString VPattern::TagCalculation = QStringLiteral("calculation"); const QString VPattern::TagCalculation = QStringLiteral("calculation");
@ -556,11 +557,47 @@ bool VPattern::SaveDocument(const QString &fileName)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::FullUpdateTree() void VPattern::FullUpdateTree()
{ {
VMainGraphicsScene *scene = new VMainGraphicsScene(); VMainGraphicsScene *scene = nullptr;
try try
{ {
scene = new VMainGraphicsScene();
Parse(Document::LiteParse, scene, scene); 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 &) catch (const std::bad_alloc &)
{ {
delete scene; delete scene;
@ -572,13 +609,9 @@ void VPattern::FullUpdateTree()
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Warning); msgBox.setIcon(QMessageBox::Warning);
msgBox.exec(); msgBox.exec();
emit ClearMainWindow();
return; return;
} }
catch (...)
{
delete scene;
throw;
}
delete scene; delete scene;
setCurrentData(); setCurrentData();

View File

@ -236,6 +236,7 @@ signals:
* @param id tool id. * @param id tool id.
*/ */
void ChangedCursor(quint32 id); void ChangedCursor(quint32 id);
void ClearMainWindow();
public slots: public slots:
/** /**
* @brief FullUpdateTree lite parse file. * @brief FullUpdateTree lite parse file.