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);
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();

View File

@ -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 */

View File

@ -40,6 +40,7 @@
#include <QMessageBox>
#include "../../libs/qmuparser/qmuparsererror.h"
#include <exception/vexceptionemptyparameter.h>
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();

View File

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