Speed optimization for class VFormula.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-20 15:37:15 +02:00
parent e68510cc49
commit 99d6ea5152
16 changed files with 59 additions and 20 deletions

View File

@ -2286,24 +2286,28 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item)
angle1.setCheckZero(false); angle1.setCheckZero(false);
angle1.setToolId(i->getId()); angle1.setToolId(i->getId());
angle1.setPostfix(degreeSymbol); angle1.setPostfix(degreeSymbol);
angle1.Eval();
AddPropertyFormula(tr("C1: angle:"), angle1, AttrAngle1); AddPropertyFormula(tr("C1: angle:"), angle1, AttrAngle1);
VFormula length1(spl.GetC1LengthFormula(), i->getData()); VFormula length1(spl.GetC1LengthFormula(), i->getData());
length1.setCheckZero(false); length1.setCheckZero(false);
length1.setToolId(i->getId()); length1.setToolId(i->getId());
length1.setPostfix(UnitsToStr(qApp->patternUnit())); length1.setPostfix(UnitsToStr(qApp->patternUnit()));
length1.Eval();
AddPropertyFormula(tr("C1: length:"), length1, AttrLength1); AddPropertyFormula(tr("C1: length:"), length1, AttrLength1);
VFormula angle2(spl.GetEndAngleFormula(), i->getData()); VFormula angle2(spl.GetEndAngleFormula(), i->getData());
angle2.setCheckZero(false); angle2.setCheckZero(false);
angle2.setToolId(i->getId()); angle2.setToolId(i->getId());
angle2.setPostfix(degreeSymbol); angle2.setPostfix(degreeSymbol);
angle2.Eval();
AddPropertyFormula(tr("C2: angle:"), angle2, AttrAngle2); AddPropertyFormula(tr("C2: angle:"), angle2, AttrAngle2);
VFormula length2(spl.GetC2LengthFormula(), i->getData()); VFormula length2(spl.GetC2LengthFormula(), i->getData());
length2.setCheckZero(false); length2.setCheckZero(false);
length2.setToolId(i->getId()); length2.setToolId(i->getId());
length2.setPostfix(UnitsToStr(qApp->patternUnit())); length2.setPostfix(UnitsToStr(qApp->patternUnit()));
length2.Eval();
AddPropertyFormula(tr("C2: length:"), length2, AttrLength2); AddPropertyFormula(tr("C2: length:"), length2, AttrLength2);
AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics());
@ -3008,6 +3012,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline()
angle1F.setCheckZero(false); angle1F.setCheckZero(false);
angle1F.setToolId(i->getId()); angle1F.setToolId(i->getId());
angle1F.setPostfix(degreeSymbol); angle1F.setPostfix(degreeSymbol);
angle1F.Eval();
QVariant angle1; QVariant angle1;
angle1.setValue(angle1F); angle1.setValue(angle1F);
idToProperty[AttrAngle1]->setValue(angle1); idToProperty[AttrAngle1]->setValue(angle1);
@ -3016,6 +3021,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline()
length1F.setCheckZero(false); length1F.setCheckZero(false);
length1F.setToolId(i->getId()); length1F.setToolId(i->getId());
length1F.setPostfix(UnitsToStr(qApp->patternUnit())); length1F.setPostfix(UnitsToStr(qApp->patternUnit()));
length1F.Eval();
QVariant length1; QVariant length1;
length1.setValue(length1F); length1.setValue(length1F);
idToProperty[AttrLength1]->setValue(length1); idToProperty[AttrLength1]->setValue(length1);
@ -3024,6 +3030,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline()
angle2F.setCheckZero(false); angle2F.setCheckZero(false);
angle2F.setToolId(i->getId()); angle2F.setToolId(i->getId());
angle2F.setPostfix(degreeSymbol); angle2F.setPostfix(degreeSymbol);
angle2F.Eval();
QVariant angle2; QVariant angle2;
angle2.setValue(angle2F); angle2.setValue(angle2F);
idToProperty[AttrAngle2]->setValue(angle2); idToProperty[AttrAngle2]->setValue(angle2);
@ -3032,6 +3039,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline()
length2F.setCheckZero(false); length2F.setCheckZero(false);
length2F.setToolId(i->getId()); length2F.setToolId(i->getId());
length2F.setPostfix(UnitsToStr(qApp->patternUnit())); length2F.setPostfix(UnitsToStr(qApp->patternUnit()));
length2F.Eval();
QVariant length2; QVariant length2;
length2.setValue(length2F); length2.setValue(length2F);
idToProperty[AttrLength2]->setValue(length2); idToProperty[AttrLength2]->setValue(length2);

View File

@ -45,8 +45,14 @@
//VFormula //VFormula
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VFormula::VFormula() VFormula::VFormula()
:formula(QString()), value(tr("Error")), checkZero(true), data(nullptr), toolId(NULL_ID), : formula(QString()),
postfix(QString()), _error(true), dValue(0) 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) dValue(0)
{ {
this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist 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; return *this;
} }
this->formula = formula.GetFormula(); this->formula = formula.formula;
this->value = formula.getStringValue(); this->value = formula.value;
this->checkZero = formula.getCheckZero(); this->checkZero = formula.checkZero;
this->data = formula.getData(); this->data = formula.data;
this->toolId = formula.getToolId(); this->toolId = formula.toolId;
this->postfix = formula.getPostfix(); this->postfix = formula.postfix;
this->_error = formula.error(); this->_error = formula._error;
this->dValue = formula.getDoubleValue(); this->dValue = formula.dValue;
return *this; return *this;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VFormula::VFormula(const VFormula &formula) VFormula::VFormula(const VFormula &formula)
:formula(formula.GetFormula()), value(formula.getStringValue()), checkZero(formula.getCheckZero()), : formula(formula.formula),
data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()), value(formula.value),
dValue(formula.getDoubleValue()) 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; return isEqual;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VFormula::operator!=(const VFormula &formula) const bool VFormula::operator!=(const VFormula &formula) const
{ {
return !VFormula::operator==(formula); return !VFormula::operator==(formula);
@ -135,7 +146,6 @@ void VFormula::SetFormula(const QString &value, FormulaType type)
formula = value; formula = value;
} }
formula.replace("\n", " ");// Replace line return with spaces for calc if exist 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) if (checkZero != value)
{ {
checkZero = value; checkZero = value;
Eval();
} }
} }
@ -179,7 +188,6 @@ void VFormula::setData(const VContainer *value)
if (data != value && value != nullptr) if (data != value && value != nullptr)
{ {
data = value; data = value;
Eval();
} }
} }
@ -207,7 +215,6 @@ void VFormula::setPostfix(const QString &value)
if (postfix != value) if (postfix != value)
{ {
postfix = value; postfix = value;
Eval();
} }
} }

View File

@ -70,6 +70,8 @@ public:
bool error() const; bool error() const;
static int FormulaTypeId(); static int FormulaTypeId();
void Eval();
private: private:
QString formula; QString formula;
QString value; QString value;
@ -79,8 +81,6 @@ private:
QString postfix; QString postfix;
bool _error; bool _error;
qreal dValue; qreal dValue;
void Eval();
}; };
Q_DECLARE_METATYPE(VFormula) Q_DECLARE_METATYPE(VFormula)

View File

@ -348,6 +348,7 @@ VFormula VToolMove::GetFormulaAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }
@ -370,6 +371,7 @@ VFormula VToolMove::GetFormulaRotationAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }
@ -392,6 +394,7 @@ VFormula VToolMove::GetFormulaLength() const
fLength.setCheckZero(true); fLength.setCheckZero(true);
fLength.setToolId(m_id); fLength.setToolId(m_id);
fLength.setPostfix(UnitsToStr(qApp->patternUnit())); fLength.setPostfix(UnitsToStr(qApp->patternUnit()));
fLength.Eval();
return fLength; return fLength;
} }

View File

@ -281,6 +281,7 @@ VFormula VToolRotation::GetFormulaAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }

View File

@ -193,6 +193,7 @@ VFormula VToolArc::GetFormulaRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }
@ -221,6 +222,7 @@ VFormula VToolArc::GetFormulaF1() const
f1.setCheckZero(false); f1.setCheckZero(false);
f1.setToolId(m_id); f1.setToolId(m_id);
f1.setPostfix(degreeSymbol); f1.setPostfix(degreeSymbol);
f1.Eval();
return f1; return f1;
} }
@ -247,6 +249,7 @@ VFormula VToolArc::GetFormulaF2() const
f2.setCheckZero(false); f2.setCheckZero(false);
f2.setToolId(m_id); f2.setToolId(m_id);
f2.setPostfix(degreeSymbol); f2.setPostfix(degreeSymbol);
f2.Eval();
return f2; return f2;
} }

View File

@ -173,6 +173,7 @@ VFormula VToolArcWithLength::GetFormulaRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }
@ -201,6 +202,7 @@ VFormula VToolArcWithLength::GetFormulaF1() const
f1.setCheckZero(false); f1.setCheckZero(false);
f1.setToolId(m_id); f1.setToolId(m_id);
f1.setPostfix(degreeSymbol); f1.setPostfix(degreeSymbol);
f1.Eval();
return f1; return f1;
} }
@ -230,6 +232,7 @@ VFormula VToolArcWithLength::GetFormulaLength() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }

View File

@ -202,6 +202,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius1() const
radius1.setCheckZero(true); radius1.setCheckZero(true);
radius1.setToolId(m_id); radius1.setToolId(m_id);
radius1.setPostfix(UnitsToStr(qApp->patternUnit())); radius1.setPostfix(UnitsToStr(qApp->patternUnit()));
radius1.Eval();
return radius1; return radius1;
} }
@ -230,6 +231,7 @@ VFormula VToolEllipticalArc::GetFormulaRadius2() const
radius2.setCheckZero(true); radius2.setCheckZero(true);
radius2.setToolId(m_id); radius2.setToolId(m_id);
radius2.setPostfix(UnitsToStr(qApp->patternUnit())); radius2.setPostfix(UnitsToStr(qApp->patternUnit()));
radius2.Eval();
return radius2; return radius2;
} }
@ -258,6 +260,7 @@ VFormula VToolEllipticalArc::GetFormulaF1() const
f1.setCheckZero(false); f1.setCheckZero(false);
f1.setToolId(m_id); f1.setToolId(m_id);
f1.setPostfix(degreeSymbol); f1.setPostfix(degreeSymbol);
f1.Eval();
return f1; return f1;
} }
@ -283,6 +286,7 @@ VFormula VToolEllipticalArc::GetFormulaF2() const
f2.setCheckZero(false); f2.setCheckZero(false);
f2.setToolId(m_id); f2.setToolId(m_id);
f2.setPostfix(degreeSymbol); f2.setPostfix(degreeSymbol);
f2.Eval();
return f2; return f2;
} }
@ -308,6 +312,7 @@ VFormula VToolEllipticalArc::GetFormulaRotationAngle() const
rotationAngle.setCheckZero(false); rotationAngle.setCheckZero(false);
rotationAngle.setToolId(m_id); rotationAngle.setToolId(m_id);
rotationAngle.setPostfix(degreeSymbol); rotationAngle.setPostfix(degreeSymbol);
rotationAngle.Eval();
return rotationAngle; return rotationAngle;
} }

View File

@ -84,6 +84,7 @@ VFormula VToolCut::GetFormula() const
val.setCheckZero(true); val.setCheckZero(true);
val.setToolId(m_id); val.setToolId(m_id);
val.setPostfix(UnitsToStr(qApp->patternUnit())); val.setPostfix(UnitsToStr(qApp->patternUnit()));
val.Eval();
return val; return val;
} }

View File

@ -234,6 +234,7 @@ VFormula VToolCurveIntersectAxis::GetFormulaAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }

View File

@ -236,6 +236,7 @@ VFormula VToolEndLine::GetFormulaAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }

View File

@ -205,6 +205,7 @@ VFormula VToolLineIntersectAxis::GetFormulaAngle() const
fAngle.setCheckZero(false); fAngle.setCheckZero(false);
fAngle.setToolId(m_id); fAngle.setToolId(m_id);
fAngle.setPostfix(degreeSymbol); fAngle.setPostfix(degreeSymbol);
fAngle.Eval();
return fAngle; return fAngle;
} }

View File

@ -220,6 +220,7 @@ VFormula VToolLinePoint::GetFormulaLength() const
fLength.setCheckZero(true); fLength.setCheckZero(true);
fLength.setToolId(m_id); fLength.setToolId(m_id);
fLength.setPostfix(UnitsToStr(qApp->patternUnit())); fLength.setPostfix(UnitsToStr(qApp->patternUnit()));
fLength.Eval();
return fLength; return fLength;
} }

View File

@ -197,6 +197,7 @@ VFormula VToolPointFromCircleAndTangent::GetCircleRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }

View File

@ -392,6 +392,7 @@ VFormula VToolPointOfContact::getArcRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }

View File

@ -203,6 +203,7 @@ VFormula VToolPointOfIntersectionCircles::GetFirstCircleRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }
@ -227,6 +228,7 @@ VFormula VToolPointOfIntersectionCircles::GetSecondCircleRadius() const
radius.setCheckZero(true); radius.setCheckZero(true);
radius.setToolId(m_id); radius.setToolId(m_id);
radius.setPostfix(UnitsToStr(qApp->patternUnit())); radius.setPostfix(UnitsToStr(qApp->patternUnit()));
radius.Eval();
return radius; return radius;
} }