From 7673deade8832057e0945ddb5b07070a29502ff5 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 20 Sep 2014 18:00:29 +0300 Subject: [PATCH] Fix bug with calculator and tools visualization. --HG-- branch : develop --- Valentina.pri | 2 - src/app/container/calculator.cpp | 66 +++++++++++-------- src/app/container/calculator.h | 2 + src/app/tools/drawTools/vtoolalongline.cpp | 4 +- src/app/tools/drawTools/vtoolarc.cpp | 4 +- src/app/tools/drawTools/vtoolbisector.cpp | 4 +- src/app/tools/drawTools/vtoolcutarc.cpp | 4 +- src/app/tools/drawTools/vtoolcutspline.cpp | 4 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 4 +- src/app/tools/drawTools/vtoolendline.cpp | 8 +-- src/app/tools/drawTools/vtoolnormal.cpp | 4 +- .../tools/drawTools/vtoolpointofcontact.cpp | 4 +- .../tools/drawTools/vtoolshoulderpoint.cpp | 4 +- 13 files changed, 63 insertions(+), 51 deletions(-) diff --git a/Valentina.pri b/Valentina.pri index eb3a98d03..948e56931 100644 --- a/Valentina.pri +++ b/Valentina.pri @@ -42,7 +42,6 @@ defineTest(copyToDestdir) { GCC_CXXFLAGS += \ - -O0 \ -Wall \ -Wextra \ -pedantic \ @@ -84,7 +83,6 @@ GCC_CXXFLAGS += \ -ftrapv CLANG_CXXFLAGS += \ - -O0 \ -fparse-all-comments \ -Wabi \ -Wabstract-final-class \ diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index aa36c999c..e6653a7d7 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -55,8 +55,7 @@ Calculator::Calculator(const VContainer *data) InitCharacterSets(); setAllowSubexpressions(false);//Only one expression per time - SetArgSep(','); - SetDecSep('.'); + SetSepForEval(); } //--------------------------------------------------------------------------------------------------------------------- @@ -82,30 +81,7 @@ Calculator::Calculator(const QString &formula, bool fromUser) setAllowSubexpressions(false);//Only one expression per time SetVarFactory(AddVariable, this); - // Add unary operators - if (fromUser) - { - bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool(); - - if (osSeparatorValue) - { - QLocale loc = QLocale::system(); - SetDecSep(loc.decimalPoint().toLatin1()); - SetThousandsSep(loc.groupSeparator().toLatin1()); - SetArgSep(';'); - } - else - { - SetArgSep(','); - SetDecSep('.'); - } - } - else - { - - SetArgSep(','); - SetDecSep('.'); - } + SetSepForTr(fromUser); SetExpr(formula); //Need run for making tokens. Don't catch exception here, because we want know if formula has error. @@ -126,6 +102,7 @@ Calculator::~Calculator() qreal Calculator::EvalFormula(const QString &formula) { SetVarFactory(AddVariable, this); + SetSepForEval();//Reset separators options SetExpr(formula); @@ -214,7 +191,7 @@ void Calculator::InitCharacterSets() DefineOprtChars(symbols + QStringLiteral("+-*^/?<>=#!$%&|~'_")); } -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- // Factory function for creating new parser variables // This could as well be a function performing database queries. qreal* Calculator::AddVariable(const QString &a_szName, void *a_pUserData) @@ -225,3 +202,38 @@ qreal* Calculator::AddVariable(const QString &a_szName, void *a_pUserData) static qreal value = 0; return &value; } + +//--------------------------------------------------------------------------------------------------------------------- +void Calculator::SetSepForEval() +{ + SetArgSep(','); + SetDecSep('.'); +} + +//--------------------------------------------------------------------------------------------------------------------- +void Calculator::SetSepForTr(bool fromUser) +{ + if (fromUser) + { + bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool(); + + if (osSeparatorValue) + { + QLocale loc = QLocale::system(); + SetDecSep(loc.decimalPoint().toLatin1()); + SetThousandsSep(loc.groupSeparator().toLatin1()); + SetArgSep(';'); + } + else + { + SetArgSep(','); + SetDecSep('.'); + } + } + else + { + + SetArgSep(','); + SetDecSep('.'); + } +} diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 503b97682..4431edf3c 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -66,6 +66,8 @@ private: void InitVariables(const VContainer *data, const QMap &tokens, const QString &formula); void InitCharacterSets(); static qreal* AddVariable(const QString &a_szName, void *a_pUserData); + void SetSepForEval(); + void SetSepForTr(bool fromUser); }; #endif // CALCULATOR_H diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index cfb079e64..e6102d41f 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -86,7 +86,7 @@ void VToolAlongLine::FullUpdateFromFile() VisToolAlongLine * visual = qobject_cast(vis); visual->setPoint1Id(basePointId); visual->setPoint2Id(secondPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); } @@ -200,7 +200,7 @@ void VToolAlongLine::ShowVisualization(bool show) visual->setPoint1Id(basePointId); visual->setPoint2Id(secondPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); vis = visual; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 43e99971d..752574d52 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -286,7 +286,7 @@ void VToolArc::ShowVisualization(bool show) const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); visual->setPoint1Id(arc->GetCenter().id()); - visual->setRadius(arc->GetFormulaRadius()); + visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius())); visual->setF1(arc->GetFormulaF1()); visual->setF2(arc->GetFormulaF2()); visual->RefreshGeometry(); @@ -372,7 +372,7 @@ void VToolArc::RefreshGeometry() VisToolArc *visual = qobject_cast(vis); visual->setPoint1Id(arc->GetCenter().id()); - visual->setRadius(arc->GetFormulaRadius()); + visual->setRadius(qApp->FormulaToUser(arc->GetFormulaRadius())); visual->setF1(arc->GetFormulaF1()); visual->setF2(arc->GetFormulaF2()); visual->RefreshGeometry(); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 3b33c8215..3a4eefa53 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -238,7 +238,7 @@ void VToolBisector::FullUpdateFromFile() visual->setPoint1Id(firstPointId); visual->setPoint2Id(basePointId); visual->setPoint3Id(thirdPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); } @@ -355,7 +355,7 @@ void VToolBisector::ShowVisualization(bool show) visual->setPoint1Id(firstPointId); visual->setPoint2Id(basePointId); visual->setPoint3Id(thirdPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); vis = visual; diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index 86240aacc..1bdb9d222 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -194,7 +194,7 @@ void VToolCutArc::ShowVisualization(bool show) scene->addItem(visual); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); vis = visual; } @@ -226,7 +226,7 @@ void VToolCutArc::FullUpdateFromFile() { VisToolCutArc *visual = qobject_cast(vis); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); } } diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 237f36b60..f3e8408b4 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -202,7 +202,7 @@ void VToolCutSpline::ShowVisualization(bool show) scene->addItem(visual); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); vis = visual; } @@ -238,7 +238,7 @@ void VToolCutSpline::FullUpdateFromFile() { VisToolCutSpline *visual = qobject_cast(vis); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); } } diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index cafe7c916..7ab4339fd 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -257,7 +257,7 @@ void VToolCutSplinePath::ShowVisualization(bool show) scene->addItem(visual); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); vis = visual; } @@ -293,7 +293,7 @@ void VToolCutSplinePath::FullUpdateFromFile() { VisToolCutSplinePath *visual = qobject_cast(vis); visual->setPoint1Id(curveCutId); - visual->setLength(formula); + visual->setLength(qApp->FormulaToUser(formula)); visual->RefreshGeometry(); } } diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 5ddad6a71..cf694af92 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -191,8 +191,8 @@ void VToolEndLine::FullUpdateFromFile() { VisToolEndLine *visual = qobject_cast(vis); visual->setPoint1Id(basePointId); - visual->setLength(formulaLength); - visual->setAngle(formulaAngle); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->setAngle(qApp->FormulaToUser(formulaAngle)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); } @@ -287,8 +287,8 @@ void VToolEndLine::ShowVisualization(bool show) scene->addItem(visual); visual->setPoint1Id(basePointId); - visual->setLength(formulaLength); - visual->setAngle(formulaAngle); + visual->setLength(qApp->FormulaToUser(formulaLength)); + visual->setAngle(qApp->FormulaToUser(formulaAngle)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); vis = visual; diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 023bc4fa0..abf347a7f 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -216,7 +216,7 @@ void VToolNormal::FullUpdateFromFile() VisToolNormal *visual = qobject_cast(vis); visual->setPoint1Id(basePointId); visual->setPoint2Id(secondPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setAngle(angle); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); @@ -332,7 +332,7 @@ void VToolNormal::ShowVisualization(bool show) visual->setPoint1Id(basePointId); visual->setPoint2Id(secondPointId); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setAngle(angle); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index b857398ef..83af87ac8 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -236,7 +236,7 @@ void VToolPointOfContact::FullUpdateFromFile() visual->setPoint1Id(firstPointId); visual->setLineP2Id(secondPointId); visual->setRadiusId(center); - visual->setRadius(arcRadius); + visual->setRadius(qApp->FormulaToUser(arcRadius)); visual->RefreshGeometry(); } } @@ -344,7 +344,7 @@ void VToolPointOfContact::ShowVisualization(bool show) visual->setPoint1Id(firstPointId); visual->setLineP2Id(secondPointId); visual->setRadiusId(center); - visual->setRadius(arcRadius); + visual->setRadius(qApp->FormulaToUser(arcRadius)); visual->RefreshGeometry(); vis = visual; } diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 1ca8980de..311d28d9d 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -242,7 +242,7 @@ void VToolShoulderPoint::FullUpdateFromFile() visual->setPoint1Id(pShoulder); visual->setLineP1Id(basePointId); visual->setLineP2Id(p2Line); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); } @@ -359,7 +359,7 @@ void VToolShoulderPoint::ShowVisualization(bool show) visual->setPoint1Id(pShoulder); visual->setLineP1Id(basePointId); visual->setLineP2Id(p2Line); - visual->setLength(formulaLength); + visual->setLength(qApp->FormulaToUser(formulaLength)); visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); visual->RefreshGeometry(); vis = visual;