From 99d6ea5152c9de69ee860486bf1f21f59010c274 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 20 Jan 2018 15:37:15 +0200 Subject: [PATCH] Speed optimization for class VFormula. --HG-- branch : develop --- .../core/vtooloptionspropertybrowser.cpp | 8 ++++ src/libs/vpatterndb/vformula.cpp | 43 +++++++++++-------- src/libs/vpatterndb/vformula.h | 4 +- .../tools/drawTools/operation/vtoolmove.cpp | 3 ++ .../drawTools/operation/vtoolrotation.cpp | 1 + .../tools/drawTools/toolcurve/vtoolarc.cpp | 3 ++ .../toolcurve/vtoolarcwithlength.cpp | 3 ++ .../toolcurve/vtoolellipticalarc.cpp | 5 +++ .../toolsinglepoint/toolcut/vtoolcut.cpp | 1 + .../toollinepoint/vtoolcurveintersectaxis.cpp | 1 + .../toollinepoint/vtoolendline.cpp | 1 + .../toollinepoint/vtoollineintersectaxis.cpp | 1 + .../toollinepoint/vtoollinepoint.cpp | 1 + .../vtoolpointfromcircleandtangent.cpp | 1 + .../toolsinglepoint/vtoolpointofcontact.cpp | 1 + .../vtoolpointofintersectioncircles.cpp | 2 + 16 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index c0ea2580d..4f376721b 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2286,24 +2286,28 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) angle1.setCheckZero(false); angle1.setToolId(i->getId()); angle1.setPostfix(degreeSymbol); + angle1.Eval(); AddPropertyFormula(tr("C1: angle:"), angle1, AttrAngle1); VFormula length1(spl.GetC1LengthFormula(), i->getData()); length1.setCheckZero(false); length1.setToolId(i->getId()); length1.setPostfix(UnitsToStr(qApp->patternUnit())); + length1.Eval(); AddPropertyFormula(tr("C1: length:"), length1, AttrLength1); VFormula angle2(spl.GetEndAngleFormula(), i->getData()); angle2.setCheckZero(false); angle2.setToolId(i->getId()); angle2.setPostfix(degreeSymbol); + angle2.Eval(); AddPropertyFormula(tr("C2: angle:"), angle2, AttrAngle2); VFormula length2(spl.GetC2LengthFormula(), i->getData()); length2.setCheckZero(false); length2.setToolId(i->getId()); length2.setPostfix(UnitsToStr(qApp->patternUnit())); + length2.Eval(); AddPropertyFormula(tr("C2: length:"), length2, AttrLength2); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); @@ -3008,6 +3012,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() angle1F.setCheckZero(false); angle1F.setToolId(i->getId()); angle1F.setPostfix(degreeSymbol); + angle1F.Eval(); QVariant angle1; angle1.setValue(angle1F); idToProperty[AttrAngle1]->setValue(angle1); @@ -3016,6 +3021,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() length1F.setCheckZero(false); length1F.setToolId(i->getId()); length1F.setPostfix(UnitsToStr(qApp->patternUnit())); + length1F.Eval(); QVariant length1; length1.setValue(length1F); idToProperty[AttrLength1]->setValue(length1); @@ -3024,6 +3030,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() angle2F.setCheckZero(false); angle2F.setToolId(i->getId()); angle2F.setPostfix(degreeSymbol); + angle2F.Eval(); QVariant angle2; angle2.setValue(angle2F); idToProperty[AttrAngle2]->setValue(angle2); @@ -3032,6 +3039,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() length2F.setCheckZero(false); length2F.setToolId(i->getId()); length2F.setPostfix(UnitsToStr(qApp->patternUnit())); + length2F.Eval(); QVariant length2; length2.setValue(length2F); idToProperty[AttrLength2]->setValue(length2); diff --git a/src/libs/vpatterndb/vformula.cpp b/src/libs/vpatterndb/vformula.cpp index 06bce3842..895c5cf9c 100644 --- a/src/libs/vpatterndb/vformula.cpp +++ b/src/libs/vpatterndb/vformula.cpp @@ -45,8 +45,14 @@ //VFormula //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula() - :formula(QString()), value(tr("Error")), checkZero(true), data(nullptr), toolId(NULL_ID), - postfix(QString()), _error(true), dValue(0) + : formula(QString()), + value(tr("Error")), + checkZero(true), + data(nullptr), + toolId(NULL_ID), + postfix(QString()), + _error(true), + dValue(0) {} //--------------------------------------------------------------------------------------------------------------------- @@ -61,7 +67,6 @@ VFormula::VFormula(const QString &formula, const VContainer *container) dValue(0) { this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist - Eval(); } //--------------------------------------------------------------------------------------------------------------------- @@ -71,22 +76,27 @@ VFormula &VFormula::operator=(const VFormula &formula) { return *this; } - this->formula = formula.GetFormula(); - this->value = formula.getStringValue(); - this->checkZero = formula.getCheckZero(); - this->data = formula.getData(); - this->toolId = formula.getToolId(); - this->postfix = formula.getPostfix(); - this->_error = formula.error(); - this->dValue = formula.getDoubleValue(); + this->formula = formula.formula; + this->value = formula.value; + this->checkZero = formula.checkZero; + this->data = formula.data; + this->toolId = formula.toolId; + this->postfix = formula.postfix; + this->_error = formula._error; + this->dValue = formula.dValue; return *this; } //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const VFormula &formula) - :formula(formula.GetFormula()), value(formula.getStringValue()), checkZero(formula.getCheckZero()), - data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()), - dValue(formula.getDoubleValue()) + : formula(formula.formula), + value(formula.value), + checkZero(formula.data), + data(formula.getData()), + toolId(formula.toolId), + postfix(formula.postfix), + _error(formula._error), + dValue(formula.dValue) {} //--------------------------------------------------------------------------------------------------------------------- @@ -103,6 +113,7 @@ bool VFormula::operator==(const VFormula &formula) const return isEqual; } +//--------------------------------------------------------------------------------------------------------------------- bool VFormula::operator!=(const VFormula &formula) const { return !VFormula::operator==(formula); @@ -135,7 +146,6 @@ void VFormula::SetFormula(const QString &value, FormulaType type) formula = value; } formula.replace("\n", " ");// Replace line return with spaces for calc if exist - Eval(); } } @@ -163,7 +173,6 @@ void VFormula::setCheckZero(bool value) if (checkZero != value) { checkZero = value; - Eval(); } } @@ -179,7 +188,6 @@ void VFormula::setData(const VContainer *value) if (data != value && value != nullptr) { data = value; - Eval(); } } @@ -207,7 +215,6 @@ void VFormula::setPostfix(const QString &value) if (postfix != value) { postfix = value; - Eval(); } } diff --git a/src/libs/vpatterndb/vformula.h b/src/libs/vpatterndb/vformula.h index ac7756178..f14660333 100644 --- a/src/libs/vpatterndb/vformula.h +++ b/src/libs/vpatterndb/vformula.h @@ -70,6 +70,8 @@ public: bool error() const; static int FormulaTypeId(); + + void Eval(); private: QString formula; QString value; @@ -79,8 +81,6 @@ private: QString postfix; bool _error; qreal dValue; - - void Eval(); }; Q_DECLARE_METATYPE(VFormula) diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index aa6d7c447..ed9a1e454 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -348,6 +348,7 @@ VFormula VToolMove::GetFormulaAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } @@ -370,6 +371,7 @@ VFormula VToolMove::GetFormulaRotationAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } @@ -392,6 +394,7 @@ VFormula VToolMove::GetFormulaLength() const fLength.setCheckZero(true); fLength.setToolId(m_id); fLength.setPostfix(UnitsToStr(qApp->patternUnit())); + fLength.Eval(); return fLength; } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index cc451ebc5..17df79122 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -281,6 +281,7 @@ VFormula VToolRotation::GetFormulaAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index 369323398..63adc9481 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -193,6 +193,7 @@ VFormula VToolArc::GetFormulaRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } @@ -221,6 +222,7 @@ VFormula VToolArc::GetFormulaF1() const f1.setCheckZero(false); f1.setToolId(m_id); f1.setPostfix(degreeSymbol); + f1.Eval(); return f1; } @@ -247,6 +249,7 @@ VFormula VToolArc::GetFormulaF2() const f2.setCheckZero(false); f2.setToolId(m_id); f2.setPostfix(degreeSymbol); + f2.Eval(); return f2; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 82de192b7..290cef254 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -173,6 +173,7 @@ VFormula VToolArcWithLength::GetFormulaRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } @@ -201,6 +202,7 @@ VFormula VToolArcWithLength::GetFormulaF1() const f1.setCheckZero(false); f1.setToolId(m_id); f1.setPostfix(degreeSymbol); + f1.Eval(); return f1; } @@ -230,6 +232,7 @@ VFormula VToolArcWithLength::GetFormulaLength() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp index 7591947bb..faedc812c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp @@ -202,6 +202,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius1() const radius1.setCheckZero(true); radius1.setToolId(m_id); radius1.setPostfix(UnitsToStr(qApp->patternUnit())); + radius1.Eval(); return radius1; } @@ -230,6 +231,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius2() const radius2.setCheckZero(true); radius2.setToolId(m_id); radius2.setPostfix(UnitsToStr(qApp->patternUnit())); + radius2.Eval(); return radius2; } @@ -258,6 +260,7 @@ VFormula VToolEllipticalArc::GetFormulaF1() const f1.setCheckZero(false); f1.setToolId(m_id); f1.setPostfix(degreeSymbol); + f1.Eval(); return f1; } @@ -283,6 +286,7 @@ VFormula VToolEllipticalArc::GetFormulaF2() const f2.setCheckZero(false); f2.setToolId(m_id); f2.setPostfix(degreeSymbol); + f2.Eval(); return f2; } @@ -308,6 +312,7 @@ VFormula VToolEllipticalArc::GetFormulaRotationAngle() const rotationAngle.setCheckZero(false); rotationAngle.setToolId(m_id); rotationAngle.setPostfix(degreeSymbol); + rotationAngle.Eval(); return rotationAngle; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index dde3b20e7..f82875d24 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -84,6 +84,7 @@ VFormula VToolCut::GetFormula() const val.setCheckZero(true); val.setToolId(m_id); val.setPostfix(UnitsToStr(qApp->patternUnit())); + val.Eval(); return val; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index 980f94aeb..b1b4e3cbe 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -234,6 +234,7 @@ VFormula VToolCurveIntersectAxis::GetFormulaAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp index 721698d32..795a30c55 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolendline.cpp @@ -236,6 +236,7 @@ VFormula VToolEndLine::GetFormulaAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp index f85518caa..81309b613 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollineintersectaxis.cpp @@ -205,6 +205,7 @@ VFormula VToolLineIntersectAxis::GetFormulaAngle() const fAngle.setCheckZero(false); fAngle.setToolId(m_id); fAngle.setPostfix(degreeSymbol); + fAngle.Eval(); return fAngle; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp index e6518a109..3161fe228 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoollinepoint.cpp @@ -220,6 +220,7 @@ VFormula VToolLinePoint::GetFormulaLength() const fLength.setCheckZero(true); fLength.setToolId(m_id); fLength.setPostfix(UnitsToStr(qApp->patternUnit())); + fLength.Eval(); return fLength; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp index 63c6d6d83..8e6ee91b1 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromcircleandtangent.cpp @@ -197,6 +197,7 @@ VFormula VToolPointFromCircleAndTangent::GetCircleRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp index 4a1383ab7..83be29b30 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofcontact.cpp @@ -392,6 +392,7 @@ VFormula VToolPointOfContact::getArcRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp index 96692caf0..2abb306a3 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncircles.cpp @@ -203,6 +203,7 @@ VFormula VToolPointOfIntersectionCircles::GetFirstCircleRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; } @@ -227,6 +228,7 @@ VFormula VToolPointOfIntersectionCircles::GetSecondCircleRadius() const radius.setCheckZero(true); radius.setToolId(m_id); radius.setPostfix(UnitsToStr(qApp->patternUnit())); + radius.Eval(); return radius; }