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.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-03-05 17:27:07 +02:00
parent b12ede529f
commit 504a334717
24 changed files with 70 additions and 102 deletions

View File

@ -1006,18 +1006,8 @@ void TMainWindow::Fx()
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
dialog->setWindowTitle(tr("Edit measurement"));
QString text = ui->plainTextEditFormula->toPlainText().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);

View File

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

View File

@ -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)

View File

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

View File

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

View File

@ -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;

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -429,7 +429,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());
}
//---------------------------------------------------------------------------------------------------------------------
@ -439,7 +439,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());
}
//---------------------------------------------------------------------------------------------------------------------
@ -449,5 +449,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());
}

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -267,8 +267,8 @@ void DialogSpline::FXAngle1()
{
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point angle"));
QString angle1F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditAngle1F->toPlainText(),
qApp->Settings()->GetOsSeparator());
QString angle1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText(),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle1F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted)
@ -290,8 +290,8 @@ void DialogSpline::FXAngle2()
{
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point angle"));
QString angle2F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditAngle2F->toPlainText(),
qApp->Settings()->GetOsSeparator());
QString angle2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText(),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle2F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted)
@ -313,8 +313,8 @@ void DialogSpline::FXLength1()
{
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point length"));
QString length1F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditLength1F->toPlainText(),
qApp->Settings()->GetOsSeparator());
QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText(),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length1F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted)
@ -336,8 +336,8 @@ void DialogSpline::FXLength2()
{
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point length"));
QString length2F = qApp->TrVars()->FormulaFromUser(ui->plainTextEditLength2F->toPlainText(),
qApp->Settings()->GetOsSeparator());
QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText(),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length2F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
if (dialog->exec() == QDialog::Accepted)
@ -440,10 +440,10 @@ VSpline DialogSpline::CurrentSpline() const
const bool separator = qApp->Settings()->GetOsSeparator();
angle1F = qApp->TrVars()->FormulaFromUser(angle1F, separator);
angle2F = qApp->TrVars()->FormulaFromUser(angle2F, separator);
length1F = qApp->TrVars()->FormulaFromUser(length1F, separator);
length2F = qApp->TrVars()->FormulaFromUser(length2F, separator);
angle1F = qApp->TrVars()->TryFormulaFromUser(angle1F, separator);
angle2F = qApp->TrVars()->TryFormulaFromUser(angle2F, separator);
length1F = qApp->TrVars()->TryFormulaFromUser(length1F, separator);
length2F = qApp->TrVars()->TryFormulaFromUser(length2F, separator);
VSpline spline(*GetP1(), *GetP4(), angle1, angle1F, angle2, angle2F, length1, length1F, length2, length2F);

View File

@ -424,17 +424,8 @@ void DialogSplinePath::FXAngle1()
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point angle"));
const QString formula = ui->plainTextEditAngle1F->toPlainText().replace("\n", " ");
QString angle1F;
try
{
angle1F = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
angle1F = formula;
}
QString angle1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle1F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle1F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
@ -458,17 +449,8 @@ void DialogSplinePath::FXAngle2()
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point angle"));
const QString formula = ui->plainTextEditAngle2F->toPlainText().replace("\n", " ");
QString angle2F;
try
{
angle2F = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
angle2F = formula;
}
QString angle2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditAngle2F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(angle2F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
@ -492,17 +474,8 @@ void DialogSplinePath::FXLength1()
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit first control point length"));
const QString formula = ui->plainTextEditLength1F->toPlainText().replace("\n", " ");
QString length1F;
try
{
length1F = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
length1F = formula;
}
QString length1F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength1F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length1F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));
@ -526,17 +499,8 @@ void DialogSplinePath::FXLength2()
auto dialog = new DialogEditWrongFormula(data, toolId, this);
dialog->setWindowTitle(tr("Edit second control point length"));
const QString formula = ui->plainTextEditLength2F->toPlainText().replace("\n", " ");
QString length2F;
try
{
length2F = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
catch (qmu::QmuParserError &e)
{
Q_UNUSED(e)
length2F = formula;
}
QString length2F = qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditLength2F->toPlainText().replace("\n", " "),
qApp->Settings()->GetOsSeparator());
dialog->SetFormula(length2F);
dialog->setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit(), true));