diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index e5ef2ec4c..cb53cbbc9 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -322,6 +322,15 @@ bool MApplication::IsTestMode() const return testMode; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class. + */ +bool MApplication::IsAppInGUIMode() const +{ + return IsTestMode(); +} + //--------------------------------------------------------------------------------------------------------------------- TMainWindow *MApplication::MainWindow() { diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index 9569e8d9a..6efda298b 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -57,6 +57,7 @@ public: virtual bool notify(QObject * receiver, QEvent * event) Q_DECL_OVERRIDE; bool IsTestMode() const; + virtual bool IsAppInGUIMode() const; TMainWindow *MainWindow(); QList MainWindows(); diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index f9f6fdc67..c14082338 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -671,6 +671,15 @@ bool VApplication::IsGUIMode() return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsGuiEnabled(); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class. + */ +bool VApplication::IsAppInGUIMode() const +{ + return IsGUIMode(); +} + //--------------------------------------------------------------------------------------------------------------------- const VCommandLinePtr VApplication::CommandLine() const { diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index 6f3bd27e3..5edc5fd8f 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -78,6 +78,7 @@ public: void CollectReports() const; #endif // defined(Q_OS_WIN) && defined(Q_CC_GNU) bool static IsGUIMode(); + virtual bool IsAppInGUIMode() const; virtual void OpenSettings() Q_DECL_OVERRIDE; VSettings *ValentinaSettings(); diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index d51d1ef48..f8b02e013 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -94,6 +94,8 @@ public: QUndoStack *getUndoStack() const; + virtual bool IsAppInGUIMode()const =0; + protected slots: void SyncSettings(); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index c88291b41..20f635459 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -299,46 +299,54 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine << "--------------------------------------"; delete cal; - DialogUndo *dialogUndo = new DialogUndo(qApp->getMainWindow()); - forever + if (qApp->IsAppInGUIMode()) { - if (dialogUndo->exec() == QDialog::Accepted) + DialogUndo *dialogUndo = new DialogUndo(qApp->getMainWindow()); + forever { - const UndoButton resultUndo = dialogUndo->Result(); - if (resultUndo == UndoButton::Fix) + if (dialogUndo->exec() == QDialog::Accepted) { - DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); - dialog->setWindowTitle(tr("Edit wrong formula")); - dialog->SetFormula(formula); - if (dialog->exec() == QDialog::Accepted) + const UndoButton resultUndo = dialogUndo->Result(); + if (resultUndo == UndoButton::Fix) { - formula = dialog->GetFormula(); - /* Need delete dialog here because parser in dialog don't allow use correct separator for - * parsing here. */ - delete dialog; - Calculator *cal1 = new Calculator(); - result = cal1->EvalFormula(data->PlainVariables(), formula); - delete cal1; /* Here can be memory leak, but dialog already check this formula and probability - * very low. */ - break; + DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, + qApp->getMainWindow()); + dialog->setWindowTitle(tr("Edit wrong formula")); + dialog->SetFormula(formula); + if (dialog->exec() == QDialog::Accepted) + { + formula = dialog->GetFormula(); + /* Need delete dialog here because parser in dialog don't allow use correct separator for + * parsing here. */ + delete dialog; + Calculator *cal1 = new Calculator(); + result = cal1->EvalFormula(data->PlainVariables(), formula); + delete cal1; /* Here can be memory leak, but dialog already check this formula and + probability very low. */ + break; + } + else + { + delete dialog; + } } else { - delete dialog; + throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula)); } } else { - throw VExceptionUndo(QString("Undo wrong formula %1").arg(formula)); + delete dialogUndo; + throw; } } - else - { - delete dialogUndo; - throw; - } + delete dialogUndo; + } + else + { + throw; } - delete dialogUndo; } return result; } diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 56a782947..9317c4887 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -245,7 +245,8 @@ VALENTINA_TEST_FILES += \ tst_valentina/issue_256_correct.vit \ tst_valentina/issue_256_wrong.vit \ tst_valentina/issue_256_correct.vst \ - tst_valentina/issue_256_wrong.vit + tst_valentina/issue_256_wrong.vit \ + tst_valentina/wrong_formula.val COLLECTION_FILES += \ $${PWD}/../../app/share/tables/standard/GOST_man_ru.vst \ diff --git a/src/test/ValentinaTest/tst_valentina/wrong_formula.val b/src/test/ValentinaTest/tst_valentina/wrong_formula.val new file mode 100644 index 000000000..3bfa613b5 --- /dev/null +++ b/src/test/ValentinaTest/tst_valentina/wrong_formula.val @@ -0,0 +1,37 @@ + + + + 0.2.2 + cm + + + + issue_256_correct.vit + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+
diff --git a/src/test/ValentinaTest/tst_valentinacommandline.cpp b/src/test/ValentinaTest/tst_valentinacommandline.cpp index 5d75eb978..81884dd00 100644 --- a/src/test/ValentinaTest/tst_valentinacommandline.cpp +++ b/src/test/ValentinaTest/tst_valentinacommandline.cpp @@ -220,6 +220,11 @@ void TST_ValentinaCommandLine::TestMode_data() const QLatin1Literal("issue_256_wrong.vst")) << false << V_EX_NOINPUT; + + QTest::newRow("Wrong formula.")<< "wrong_formula.val" + << QString("--test") + << false + << V_EX_DATAERR; } //---------------------------------------------------------------------------------------------------------------------