diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index ecd491a85..1b701d720 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3926,7 +3926,7 @@ void VPattern::ParseIncrementsElement(const QDomNode &node, const Document &pars increment->SetFormula(value, formula, ok); increment->SetDescription(desc); increment->SetPreviewCalculation(node.toElement().tagName() == TagPreviewCalculations); - data->AddVariable(name, increment); + data->AddVariable(increment); } } } diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 521c4f0f7..9e15a1050 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -308,8 +308,8 @@ void VMeasurements::ReadMeasurements(qreal height, qreal size) const meash = QSharedPointer(new VMeasurement(data, static_cast(i), name, value, formula, ok, fullName, description)); } - tempData->AddVariable(name, tempMeash); - data->AddVariable(name, meash); + tempData->AddVariable(tempMeash); + data->AddVariable(meash); } } diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 7b7bd5548..45994e0a6 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -444,11 +444,8 @@ void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPoint const QSharedPointer first = GeometricObject(firstPointId); const QSharedPointer second = GeometricObject(secondPointId); - VLengthLine *length = new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit()); - AddVariable(length->GetName(), length); - - VLineAngle *angle = new VLineAngle(first.data(), firstPointId, second.data(), secondPointId); - AddVariable(angle->GetName(), angle); + AddVariable(new VLengthLine(first.data(), firstPointId, second.data(), secondPointId, *GetPatternUnit())); + AddVariable(new VLineAngle(first.data(), firstPointId, second.data(), secondPointId)); } //--------------------------------------------------------------------------------------------------------------------- @@ -460,21 +457,15 @@ void VContainer::AddArc(const QSharedPointer &arc, const quint32 { const QSharedPointer casted = arc.staticCast(); - VArcRadius *radius = new VArcRadius(id, parentId, casted.data(), *GetPatternUnit()); - AddVariable(radius->GetName(), radius); + AddVariable(new VArcRadius(id, parentId, casted.data(), *GetPatternUnit())); } else if (arc->getType() == GOType::EllipticalArc) { const QSharedPointer casted = arc.staticCast(); - VArcRadius *radius1 = new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit()); - AddVariable(radius1->GetName(), radius1); - - VArcRadius *radius2 = new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit()); - AddVariable(radius2->GetName(), radius2); - - VEllipticalArcRotation *rotation = new VEllipticalArcRotation(id, parentId, casted.data()); - AddVariable(rotation->GetName(), rotation); + AddVariable(new VArcRadius(id, parentId, casted.data(), 1, *GetPatternUnit())); + AddVariable(new VArcRadius(id, parentId, casted.data(), 2, *GetPatternUnit())); + AddVariable(new VEllipticalArcRotation(id, parentId, casted.data())); } } @@ -489,26 +480,17 @@ void VContainer::AddCurve(const QSharedPointer &curve, const qui throw VException(tr("Can't create a curve with type '%1'").arg(static_cast(curveType))); } - VCurveLength *length = new VCurveLength(id, parentId, curve.data(), *GetPatternUnit()); - AddVariable(length->GetName(), length); - - VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle); - AddVariable(startAngle->GetName(), startAngle); - - VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle); - AddVariable(endAngle->GetName(), endAngle); + AddVariable(new VCurveLength(id, parentId, curve.data(), *GetPatternUnit())); + AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::StartAngle)); + AddVariable(new VCurveAngle(id, parentId, curve.data(), CurveAngle::EndAngle)); } //--------------------------------------------------------------------------------------------------------------------- void VContainer::AddSpline(const QSharedPointer &curve, quint32 id, quint32 parentId) { AddCurve(curve, id, parentId); - - VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit()); - AddVariable(c1Length->GetName(), c1Length); - - VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit()); - AddVariable(c2Length->GetName(), c2Length); + AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C1, *GetPatternUnit())); + AddVariable(new VCurveCLength(id, parentId, curve.data(), CurveCLength::C2, *GetPatternUnit())); } //--------------------------------------------------------------------------------------------------------------------- @@ -521,22 +503,11 @@ void VContainer::AddCurveWithSegments(const QSharedPointerGetSpline(i); - VCurveLength *length = new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i); - AddVariable(length->GetName(), length); - - VCurveAngle *startAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i); - AddVariable(startAngle->GetName(), startAngle); - - VCurveAngle *endAngle = new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i); - AddVariable(endAngle->GetName(), endAngle); - - VCurveCLength *c1Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1, - *GetPatternUnit(), i); - AddVariable(c1Length->GetName(), c1Length); - - VCurveCLength *c2Length = new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2, - *GetPatternUnit(), i); - AddVariable(c2Length->GetName(), c2Length); + AddVariable(new VCurveLength(id, parentId, curve->name(), spl, *GetPatternUnit(), i)); + AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::StartAngle, i)); + AddVariable(new VCurveAngle(id, parentId, curve->name(), spl, CurveAngle::EndAngle, i)); + AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C1, *GetPatternUnit(), i)); + AddVariable(new VCurveCLength(id, parentId, curve->name(), spl, CurveCLength::C2, *GetPatternUnit(), i)); } } diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 268e97e7c..8819e4b47 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -147,7 +147,7 @@ public: VPiecePath GetPiecePath(quint32 id) const; quint32 GetPieceForPiecePath(quint32 id) const; template - QSharedPointer GetVariable(QString name) const; + QSharedPointer GetVariable(const QString &name) const; quint32 getId() const; quint32 getNextId() const; void UpdateId(quint32 newId) const; @@ -165,9 +165,9 @@ public: quint32 parentId = NULL_ID); template - void AddVariable(const QString& name, T *var); + void AddVariable(T *var); template - void AddVariable(const QString& name, const QSharedPointer &var); + void AddVariable(const QSharedPointer &var); void RemoveVariable(const QString& name); void RemovePiece(quint32 id); @@ -287,7 +287,7 @@ const QSharedPointer VContainer::GeometricObject(const quint32 &id) const * @return variable */ template -QSharedPointer VContainer::GetVariable(QString name) const +QSharedPointer VContainer::GetVariable(const QString &name) const { SCASSERT(name.isEmpty()==false) if (d->variables.contains(name)) @@ -311,35 +311,36 @@ QSharedPointer VContainer::GetVariable(QString name) const //--------------------------------------------------------------------------------------------------------------------- template -void VContainer::AddVariable(const QString& name, T *var) +void VContainer::AddVariable(T *var) { - AddVariable(name, QSharedPointer(var)); + AddVariable(QSharedPointer(var)); } //--------------------------------------------------------------------------------------------------------------------- template -void VContainer::AddVariable(const QString& name, const QSharedPointer &var) +void VContainer::AddVariable(const QSharedPointer &var) { - if (d->variables.contains(name)) + SCASSERT(not var->GetName().isEmpty()) + if (d->variables.contains(var->GetName())) { - if (d->variables.value(name)->GetType() == var->GetType()) + if (d->variables.value(var->GetName())->GetType() == var->GetType()) { - QSharedPointer v = qSharedPointerDynamicCast(d->variables.value(name)); + QSharedPointer v = qSharedPointerDynamicCast(d->variables.value(var->GetName())); if (v.isNull()) { - throw VExceptionBadId(tr("Can't cast object."), name); + throw VExceptionBadId(tr("Can't cast object."), var->GetName()); } *v = *var; } else { - throw VExceptionBadId(tr("Can't find object. Type mismatch."), name); + throw VExceptionBadId(tr("Can't find object. Type mismatch."), var->GetName()); } } else { - d->variables.insert(name, var); - uniqueNames[d->nspace].insert(name); + d->variables.insert(var->GetName(), var); + uniqueNames[d->nspace].insert(var->GetName()); } } diff --git a/src/libs/vtools/dialogs/dialogtoolbox.cpp b/src/libs/vtools/dialogs/dialogtoolbox.cpp index 78013e835..5e11c7d9f 100644 --- a/src/libs/vtools/dialogs/dialogtoolbox.cpp +++ b/src/libs/vtools/dialogs/dialogtoolbox.cpp @@ -484,5 +484,5 @@ void CurrentCurveLength(vidtype curveId, VContainer *data) SCASSERT(length != nullptr) length->SetName(currentLength); - data->AddVariable(currentLength, length); + data->AddVariable(length); } diff --git a/src/libs/vtools/dialogs/tools/dialogalongline.cpp b/src/libs/vtools/dialogs/tools/dialogalongline.cpp index 56c2c9228..3a34b3283 100644 --- a/src/libs/vtools/dialogs/tools/dialogalongline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogalongline.cpp @@ -280,7 +280,7 @@ void DialogAlongLine::SetCurrentLength() length->SetName(currentLength); VContainer *locData = const_cast (data); - locData->AddVariable(currentLength, length); + locData->AddVariable(length); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp index 1b6139e53..4ef8f1673 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogpiecepath.cpp @@ -810,7 +810,7 @@ void DialogPiecePath::EvalWidth() currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true); currentSA->SetDescription(tr("Current seam allowance")); - locData->AddVariable(currentSeamAllowance, currentSA); + locData->AddVariable(currentSA); EvalWidthBefore(); EvalWidthAfter(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 215c6d51f..59b6b3b2f 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -2147,7 +2147,7 @@ void DialogSeamAllowance::EvalWidth() currentSA->SetFormula(m_saWidth, QString().setNum(m_saWidth), true); currentSA->SetDescription(tr("Current seam allowance")); - locData->AddVariable(currentSeamAllowance, currentSA); + locData->AddVariable(currentSA); EvalWidthBefore(); EvalWidthAfter(); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 7427b3b13..b4722c49d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -129,7 +129,7 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) VCurveLength *length = new VCurveLength(initData.arcId, initData.arcId, arc.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); - initData.data->AddVariable(currentLength, length); + initData.data->AddVariable(length); const qreal result = CheckFormula(initData.id, initData.formula, initData.data); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 18734241a..2801a9ef5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -132,7 +132,7 @@ VToolCutSpline* VToolCutSpline::Create(VToolCutSplineInitData &initData) VCurveLength *length = new VCurveLength(initData.splineId, initData.splineId, spl.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); - initData.data->AddVariable(currentLength, length); + initData.data->AddVariable(length); const qreal result = CheckFormula(initData.id, initData.formula, initData.data); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index dfe90a449..56325e551 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -136,7 +136,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutSplinePathInitData &initD VCurveLength *length = new VCurveLength(initData.splinePathId, initData.splinePathId, splPath.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); - initData.data->AddVariable(currentLength, length); + initData.data->AddVariable(length); const qreal result = CheckFormula(initData.id, initData.formula, initData.data); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp index b57bd1fd6..2a9b7f52f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolalongline.cpp @@ -260,7 +260,7 @@ VToolAlongLine* VToolAlongLine::Create(VToolAlongLineInitData &initData) VLengthLine *length = new VLengthLine(firstPoint.data(), initData.firstPointId, secondPoint.data(), initData.secondPointId, *initData.data->GetPatternUnit()); length->SetName(currentLength); - initData.data->AddVariable(currentLength, length); + initData.data->AddVariable(length); line.setLength(qApp->toPixel(CheckFormula(initData.id, initData.formula, initData.data))); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index b22113396..fb1c3e6a2 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -124,7 +124,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD currentSA->SetFormula(initData.detail.GetSAWidth(), initData.width, true); currentSA->SetDescription(tr("Current seam allowance")); - initData.data->AddVariable(currentSeamAllowance, currentSA); + initData.data->AddVariable(currentSA); initData.id = initData.data->AddPiece(initData.detail); } else @@ -136,7 +136,7 @@ VToolSeamAllowance *VToolSeamAllowance::Create(VToolSeamAllowanceInitData &initD currentSA->SetFormula(calcWidth, initData.width, true); currentSA->SetDescription(tr("Current seam allowance")); - initData.data->AddVariable(currentSeamAllowance, currentSA); + initData.data->AddVariable(currentSA); initData.data->UpdatePiece(initData.id, initData.detail); if (initData.parse != Document::FullParse)