Fixed issue #456. Crash: broken formula + clicking on the f(x) symbol.

The method FormulaFromUser throw an exception. In many places we don't catch the
exception and i think this is wrong. New method TryFormulaFromUser was
introduced for fixing situation.
(grafted from a1a7dab0f21e7698812f44d50d7389fd36060eeb)

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2016-03-06 13:51:31 +02:00
parent 86acf37482
commit 2f07549c99
22 changed files with 50 additions and 47 deletions

View File

@ -998,19 +998,8 @@ void TMainWindow::Fx()
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this); DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
dialog->setWindowTitle(tr("Edit measurement")); dialog->setWindowTitle(tr("Edit measurement"));
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
QString text = ui->plainTextEditFormula->toPlainText(); true));
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);
const QString postfix = VDomDocument::UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch) const QString postfix = VDomDocument::UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch)
dialog->setPostfix(postfix); dialog->setPostfix(postfix);

View File

@ -358,8 +358,9 @@ bool VApplication::notify(QObject *receiver, QEvent *event)
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return true; return true;
} }
// These last two cases special. I found that we can't show here modal dialog with error message. // 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 waite untile an error dialog will be closed. But if ignore this program will hang. // 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) catch (const qmu::QmuParserError &e)
{ {
qCCritical(vApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg()))); qCCritical(vApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg())));

View File

@ -634,7 +634,7 @@ void DialogIncrements::SaveIncrFormula()
const QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator()); const QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
doc->SetIncrementFormula(nameField->text(), formula); 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) Q_UNUSED(e)
return; return;
@ -697,11 +697,8 @@ void DialogIncrements::Fx()
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(incr->GetData(), NULL_ID, this); DialogEditWrongFormula *dialog = new DialogEditWrongFormula(incr->GetData(), NULL_ID, this);
dialog->setWindowTitle(tr("Edit increment")); dialog->setWindowTitle(tr("Edit increment"));
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
QString text = ui->plainTextEditFormula->toPlainText(); qApp->Settings()->GetOsSeparator()));
text.replace("\n", " ");
text = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
dialog->SetFormula(text);
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch) dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)

View File

@ -103,7 +103,7 @@ QString VFormula::GetFormula(FormulaType type) const
} }
else else
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
} }

View File

@ -29,6 +29,7 @@
#include "vtranslatevars.h" #include "vtranslatevars.h"
#include "calculator.h" #include "calculator.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vabstractapplication.h"
#include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vgeometrydef.h"
#include "../qmuparser/qmutokenparser.h" #include "../qmuparser/qmutokenparser.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
@ -781,6 +782,20 @@ QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator
return newFormula; 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 * @brief FormulaToUser replace all known tokens in formula to user look. Also change decimal

View File

@ -54,6 +54,7 @@ public:
QString PostfixOperator(const QString &name) const; QString PostfixOperator(const QString &name) const;
QString FormulaFromUser(const QString &formula, bool osSeparator) const; QString FormulaFromUser(const QString &formula, bool osSeparator) const;
QString TryFormulaFromUser(const QString &formula, bool osSeparator) const;
QString FormulaToUser(const QString &formula) const; QString FormulaToUser(const QString &formula) const;
virtual void Retranslate() Q_DECL_OVERRIDE; virtual void Retranslate() Q_DECL_OVERRIDE;

View File

@ -349,7 +349,7 @@ void DialogEditWrongFormula::setPostfix(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogEditWrongFormula::GetFormula() const QString DialogEditWrongFormula::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -316,7 +316,7 @@ QString DialogAlongLine::GetTypeLine() const
*/ */
QString DialogAlongLine::GetFormula() const QString DialogAlongLine::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -428,7 +428,7 @@ quint32 DialogArc::GetCenter() const
*/ */
QString DialogArc::GetRadius() 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 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 QString DialogArc::GetF2() const
{ {
return qApp->TrVars()->FormulaFromUser(f2, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(f2, qApp->Settings()->GetOsSeparator());
} }

View File

@ -110,7 +110,7 @@ void DialogArcWithLength::SetCenter(const quint32 &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetRadius() const 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 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) void DialogArcWithLength::SetF1(const QString &value)
@ -157,7 +157,7 @@ void DialogArcWithLength::SetF1(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogArcWithLength::GetLength() const QString DialogArcWithLength::GetLength() const
{ {
return qApp->TrVars()->FormulaFromUser(length, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(length, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -349,7 +349,7 @@ QString DialogBisector::GetTypeLine() const
*/ */
QString DialogBisector::GetFormula() const QString DialogBisector::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -104,7 +104,7 @@ void DialogCurveIntersectAxis::SetTypeLine(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogCurveIntersectAxis::GetAngle() const QString DialogCurveIntersectAxis::GetAngle() const
{ {
return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -231,7 +231,7 @@ void DialogCutArc::SetPointName(const QString &value)
*/ */
QString DialogCutArc::GetFormula() const QString DialogCutArc::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -225,7 +225,7 @@ void DialogCutSpline::ShowVisualization()
*/ */
QString DialogCutSpline::GetFormula() const QString DialogCutSpline::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -225,7 +225,7 @@ void DialogCutSplinePath::ShowVisualization()
*/ */
QString DialogCutSplinePath::GetFormula() const QString DialogCutSplinePath::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -363,7 +363,7 @@ QString DialogEndLine::GetTypeLine() const
*/ */
QString DialogEndLine::GetFormula() 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 QString DialogEndLine::GetAngle() const
{ {
return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -113,7 +113,7 @@ void DialogLineIntersectAxis::SetTypeLine(const QString &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogLineIntersectAxis::GetAngle() const QString DialogLineIntersectAxis::GetAngle() const
{ {
return qApp->TrVars()->FormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formulaAngle, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -322,7 +322,7 @@ QString DialogNormal::GetTypeLine() const
*/ */
QString DialogNormal::GetFormula() const QString DialogNormal::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -118,7 +118,7 @@ void DialogPointFromCircleAndTangent::SetCircleCenterId(const quint32 &value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogPointFromCircleAndTangent::GetCircleRadius() const QString DialogPointFromCircleAndTangent::GetCircleRadius() const
{ {
return qApp->TrVars()->FormulaFromUser(ui->plainTextEditRadius->toPlainText(), return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditRadius->toPlainText(),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
} }

View File

@ -310,7 +310,7 @@ void DialogPointOfContact::SetPointName(const QString &value)
*/ */
QString DialogPointOfContact::getRadius() const QString DialogPointOfContact::getRadius() const
{ {
return qApp->TrVars()->FormulaFromUser(radius, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(radius, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -150,7 +150,7 @@ void DialogPointOfIntersectionCircles::SetSecondCircleCenterId(const quint32 &va
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersectionCircles::GetFirstCircleRadius() const QString DialogPointOfIntersectionCircles::GetFirstCircleRadius() const
{ {
return qApp->TrVars()->FormulaFromUser(ui->plainTextEditCircle1Radius->toPlainText(), return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditCircle1Radius->toPlainText(),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
} }
@ -175,7 +175,7 @@ void DialogPointOfIntersectionCircles::SetFirstCircleRadius(const QString &value
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersectionCircles::GetSecondCircleRadius() const QString DialogPointOfIntersectionCircles::GetSecondCircleRadius() const
{ {
return qApp->TrVars()->FormulaFromUser(ui->plainTextEditCircle2Radius->toPlainText(), return qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditCircle2Radius->toPlainText(),
qApp->Settings()->GetOsSeparator()); qApp->Settings()->GetOsSeparator());
} }

View File

@ -348,7 +348,7 @@ QString DialogShoulderPoint::GetTypeLine() const
*/ */
QString DialogShoulderPoint::GetFormula() const QString DialogShoulderPoint::GetFormula() const
{ {
return qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator()); return qApp->TrVars()->TryFormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------