diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index fcd60fde5..0f930a278 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -2258,19 +2258,22 @@ void MainWindow::LoadPattern(const QString &fileName) FullParseFile(); - bool patternModified = this->isWindowModified(); - setCurrentFile(fileName); - if (patternModified) - { - //For situation where was fixed wrong formula need return for document status was modified. - PatternWasModified(!patternModified); + if (guiEnabled) + { // No errors occurred + bool patternModified = this->isWindowModified(); + setCurrentFile(fileName); + if (patternModified) + { + //For situation where was fixed wrong formula need return for document status was modified. + PatternWasModified(!patternModified); + } + helpLabel->setText(tr("File loaded")); + + qApp->setOpeningPattern();// End opening file + + //Fit scene size to best size for first show + ZoomFirstShow(); } - helpLabel->setText(tr("File loaded")); - - qApp->setOpeningPattern();// End opening file - - //Fit scene size to best size for first show - ZoomFirstShow(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index c828ec4bb..2565a871d 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -366,16 +366,18 @@ void VPattern::Parse(const Document &parse) */ VDataTool *VPattern::getTool(const quint32 &id) { - if (tools.contains(id)) + ToolExists(id); + return tools.value(id); +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::ToolExists(const quint32 &id) const +{ + if (tools.contains(id) == false) { - return tools.value(id); + throw VExceptionBadId(tr("Can't find tool in table."), id); } - else - { - const QString error = QString(tr("Can't find tool id = %1 in table.")).arg(id); - throw VException(error); - } - return 0; } //--------------------------------------------------------------------------------------------------------------------- @@ -430,6 +432,7 @@ void VPattern::setCurrentData() } if (tools.size() > 0) { + ToolExists(id); const VDataTool *vTool = tools.value(id); *data = vTool->getData(); } @@ -460,6 +463,7 @@ void VPattern::UpdateToolData(const quint32 &id, VContainer *data) { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); SCASSERT(data != nullptr); + ToolExists(id); VDataTool *tool = tools.value(id); SCASSERT(tool != nullptr); tool->VDataTool::setData(data); @@ -473,6 +477,7 @@ void VPattern::UpdateToolData(const quint32 &id, VContainer *data) void VPattern::IncrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + ToolExists(id); VDataTool *tool = tools.value(id); SCASSERT(tool != nullptr); tool->incrementReferens(); @@ -486,6 +491,7 @@ void VPattern::IncrementReferens(quint32 id) const void VPattern::DecrementReferens(quint32 id) const { Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + ToolExists(id); VDataTool *tool = tools.value(id); SCASSERT(tool != nullptr); tool->decrementReferens(); diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index c55c7901b..e37158ae1 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -285,6 +285,7 @@ private: void ParseCurrentPP(); void CheckTagExists(const QString &tag); QString GetLabelBase(unsigned int index)const; + void ToolExists(const quint32 &id) const; }; //---------------------------------------------------------------------------------------------------------------------