diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 4581ad96d..3b1bc143e 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -998,19 +998,8 @@ void TMainWindow::Fx() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this); dialog->setWindowTitle(tr("Edit measurement")); - - QString text = ui->plainTextEditFormula->toPlainText(); - text.replace("\n", " "); - try - { - text = qApp->TrVars()->FormulaFromUser(text, true); - } - catch (qmu::QmuParserError &e) // Just in case something bad will happen - { - Q_UNUSED(e) - text = ui->plainTextEditFormula->toPlainText(); - } - dialog->SetFormula(text); + dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "), + true)); const QString postfix = VDomDocument::UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch) dialog->setPostfix(postfix); diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index c14082338..c0bd9c5e7 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -358,8 +358,9 @@ bool VApplication::notify(QObject *receiver, QEvent *event) qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); return true; } - // These last two cases special. I found that we can't show here modal dialog with error message. - // Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang. + // These last two cases are special. I found that we can't show here a modal dialog with an error message. + // Somehow program doesn't wait until an error dialog will be closed. But if ignore the exception the program will + // hang. catch (const qmu::QmuParserError &e) { qCCritical(vApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg()))); diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index a9cf5343c..a459061d5 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -634,7 +634,7 @@ void DialogIncrements::SaveIncrFormula() const QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator()); doc->SetIncrementFormula(nameField->text(), formula); } - catch (qmu::QmuParserError &e) // Just in case something bad happens + catch (qmu::QmuParserError &e) // Just in case something bad will happen { Q_UNUSED(e) return; @@ -697,11 +697,8 @@ void DialogIncrements::Fx() DialogEditWrongFormula *dialog = new DialogEditWrongFormula(incr->GetData(), NULL_ID, this); dialog->setWindowTitle(tr("Edit increment")); - - QString text = ui->plainTextEditFormula->toPlainText(); - text.replace("\n", " "); - text = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator()); - dialog->SetFormula(text); + dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "), + qApp->Settings()->GetOsSeparator())); const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch) diff --git a/src/libs/vpatterndb/vformula.cpp b/src/libs/vpatterndb/vformula.cpp index 94f54e73a..8d28c3aa4 100644 --- a/src/libs/vpatterndb/vformula.cpp +++ b/src/libs/vpatterndb/vformula.cpp @@ -103,7 +103,7 @@ QString VFormula::GetFormula(FormulaType type) const } else { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } } diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index 4d98d3388..fdbc344fe 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -29,6 +29,7 @@ #include "vtranslatevars.h" #include "calculator.h" #include "../vmisc/def.h" +#include "../vmisc/vabstractapplication.h" #include "../vgeometry/vgeometrydef.h" #include "../qmuparser/qmutokenparser.h" #include "../ifc/ifcdef.h" @@ -781,6 +782,20 @@ QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator return newFormula; } +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator) const +{ + try + { + return qApp->TrVars()->FormulaFromUser(formula, osSeparator); + } + catch (qmu::QmuParserError &e)// In case something bad will happen + { + Q_UNUSED(e) + return formula; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FormulaToUser replace all known tokens in formula to user look. Also change decimal diff --git a/src/libs/vpatterndb/vtranslatevars.h b/src/libs/vpatterndb/vtranslatevars.h index 6a23550f9..178377748 100644 --- a/src/libs/vpatterndb/vtranslatevars.h +++ b/src/libs/vpatterndb/vtranslatevars.h @@ -54,6 +54,7 @@ public: QString PostfixOperator(const QString &name) const; QString FormulaFromUser(const QString &formula, bool osSeparator) const; + QString TryFormulaFromUser(const QString &formula, bool osSeparator) const; QString FormulaToUser(const QString &formula) const; virtual void Retranslate() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp index a523aee33..522138e45 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.cpp @@ -349,7 +349,7 @@ void DialogEditWrongFormula::setPostfix(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogEditWrongFormula::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index a78a27a58..594fcc597 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -316,7 +316,7 @@ QString DialogAlongLine::GetTypeLine() const */ QString DialogAlongLine::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index c3b38859f..dcca134e2 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -428,7 +428,7 @@ quint32 DialogArc::GetCenter() const */ QString DialogArc::GetRadius() const { - return qApp->TrVars()->FormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -438,7 +438,7 @@ QString DialogArc::GetRadius() const */ QString DialogArc::GetF1() const { - return qApp->TrVars()->FormulaFromUser(f1, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(f1, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -448,5 +448,5 @@ QString DialogArc::GetF1() const */ QString DialogArc::GetF2() const { - return qApp->TrVars()->FormulaFromUser(f2, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(f2, qApp->Settings()->GetOsSeparator()); } diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index e79923182..2ba6e799e 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -110,7 +110,7 @@ void DialogArcWithLength::SetCenter(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogArcWithLength::GetRadius() const { - return qApp->TrVars()->FormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -134,7 +134,7 @@ void DialogArcWithLength::SetRadius(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogArcWithLength::GetF1() const { - return qApp->TrVars()->FormulaFromUser(f1, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(f1, qApp->Settings()->GetOsSeparator()); } void DialogArcWithLength::SetF1(const QString &value) @@ -157,7 +157,7 @@ void DialogArcWithLength::SetF1(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogArcWithLength::GetLength() const { - return qApp->TrVars()->FormulaFromUser(length, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(length, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogbisector.cpp b/src/libs/vtools/dialogs/tools/dialogbisector.cpp index 245322ff2..aab72ee38 100644 --- a/src/libs/vtools/dialogs/tools/dialogbisector.cpp +++ b/src/libs/vtools/dialogs/tools/dialogbisector.cpp @@ -349,7 +349,7 @@ QString DialogBisector::GetTypeLine() const */ QString DialogBisector::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp index 2fd9aaec4..f85aed521 100644 --- a/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcurveintersectaxis.cpp @@ -104,7 +104,7 @@ void DialogCurveIntersectAxis::SetTypeLine(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogCurveIntersectAxis::GetAngle() const { - return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 6afba27f1..23aa6786f 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -231,7 +231,7 @@ void DialogCutArc::SetPointName(const QString &value) */ QString DialogCutArc::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 85bf03225..d833a5da4 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -225,7 +225,7 @@ void DialogCutSpline::ShowVisualization() */ QString DialogCutSpline::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 7e2e2a737..b786a4e93 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -225,7 +225,7 @@ void DialogCutSplinePath::ShowVisualization() */ QString DialogCutSplinePath::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogendline.cpp b/src/libs/vtools/dialogs/tools/dialogendline.cpp index 479701454..34cc897c7 100644 --- a/src/libs/vtools/dialogs/tools/dialogendline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogendline.cpp @@ -363,7 +363,7 @@ QString DialogEndLine::GetTypeLine() const */ QString DialogEndLine::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formulaLength, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formulaLength, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -373,7 +373,7 @@ QString DialogEndLine::GetFormula() const */ QString DialogEndLine::GetAngle() const { - return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp index 98662d6a7..fd235f887 100644 --- a/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialoglineintersectaxis.cpp @@ -113,7 +113,7 @@ void DialogLineIntersectAxis::SetTypeLine(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogLineIntersectAxis::GetAngle() const { - return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialognormal.cpp b/src/libs/vtools/dialogs/tools/dialognormal.cpp index 1c6940534..b1f15ec99 100644 --- a/src/libs/vtools/dialogs/tools/dialognormal.cpp +++ b/src/libs/vtools/dialogs/tools/dialognormal.cpp @@ -322,7 +322,7 @@ QString DialogNormal::GetTypeLine() const */ QString DialogNormal::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp index 22605555d..179e5c71e 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointfromcircleandtangent.cpp @@ -118,8 +118,8 @@ void DialogPointFromCircleAndTangent::SetCircleCenterId(const quint32 &value) //--------------------------------------------------------------------------------------------------------------------- QString DialogPointFromCircleAndTangent::GetCircleRadius() const { - return qApp->TrVars()->FormulaFromUser(ui->plainTextEditRadius->toPlainText(), - qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditRadius->toPlainText(), + qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp index 24ba8f55f..915f3ec07 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofcontact.cpp @@ -310,7 +310,7 @@ void DialogPointOfContact::SetPointName(const QString &value) */ QString DialogPointOfContact::getRadius() const { - return qApp->TrVars()->FormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp index ff8d9a914..827602ef6 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp @@ -150,8 +150,8 @@ void DialogPointOfIntersectionCircles::SetSecondCircleCenterId(const quint32 &va //--------------------------------------------------------------------------------------------------------------------- QString DialogPointOfIntersectionCircles::GetFirstCircleRadius() const { - return qApp->TrVars()->FormulaFromUser(ui->plainTextEditCircle1Radius->toPlainText(), - qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditCircle1Radius->toPlainText(), + qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- @@ -175,8 +175,8 @@ void DialogPointOfIntersectionCircles::SetFirstCircleRadius(const QString &value //--------------------------------------------------------------------------------------------------------------------- QString DialogPointOfIntersectionCircles::GetSecondCircleRadius() const { - return qApp->TrVars()->FormulaFromUser(ui->plainTextEditCircle2Radius->toPlainText(), - qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditCircle2Radius->toPlainText(), + qApp->Settings()->GetOsSeparator()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp index dd7154bce..71196d001 100644 --- a/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/libs/vtools/dialogs/tools/dialogshoulderpoint.cpp @@ -348,7 +348,7 @@ QString DialogShoulderPoint::GetTypeLine() const */ QString DialogShoulderPoint::GetFormula() const { - return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); + return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); } //---------------------------------------------------------------------------------------------------------------------