From b1f932739373a77edd548fe5341a711f7c43aa4b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 15:26:22 +0200 Subject: [PATCH] Alias field for tool Spline Path. --- .../core/vtooloptionspropertybrowser.cpp | 6 +++++ src/app/valentina/xml/vpattern.cpp | 1 + src/libs/vpatterndb/variables/vcurveangle.cpp | 20 +++++++++++--- src/libs/vpatterndb/variables/vcurveangle.h | 2 +- .../vpatterndb/variables/vcurveclength.cpp | 18 ++++++++++--- src/libs/vpatterndb/variables/vcurveclength.h | 2 +- .../vpatterndb/variables/vcurvelength.cpp | 14 +++++++--- src/libs/vpatterndb/variables/vcurvelength.h | 2 +- src/libs/vpatterndb/vcontainer.cpp | 10 +++---- .../vtools/dialogs/tools/dialogsplinepath.cpp | 27 ++++++++++++++++++- .../vtools/dialogs/tools/dialogsplinepath.h | 3 +++ .../vtools/dialogs/tools/dialogsplinepath.ui | 12 ++++++++- .../drawTools/toolcurve/vtoolsplinepath.cpp | 2 ++ 13 files changed, 98 insertions(+), 21 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index dd9ca1c0b..97895ea4d 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2099,6 +2099,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VPE::VProperty *prope case 61: // AttrNotes SetNotes(property); break; + case 62: // AttrAlias + SetAlias(property); + break; default: qWarning()<<"Unknown property type. id = "<setTitle(tr("Tool for path curve")); AddPropertyObjectName(i, tr("Name:"), true); + AddPropertyAlias(i, tr("Alias:")); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyApproximationScale(tr("Approximation scale:"), i->getSplinePath().GetApproximationScale()); @@ -3693,6 +3697,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() idToProperty[AttrAScale]->setValue(valueApproximationScale); idToProperty[AttrNotes]->setValue(i->GetNotes()); + + idToProperty[AttrAlias]->setValue(i->GetAliasSuffix()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 1e3dd94e3..aff8cb85a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2739,6 +2739,7 @@ void VPattern::ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); initData.duplicate = GetParametrUInt(domElement, AttrDuplicate, QChar('0')); initData.approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0')); + initData.aliasSuffix = GetParametrEmptyString(domElement, AttrAlias); const QDomNodeList nodeList = domElement.childNodes(); const qint32 num = nodeList.size(); diff --git a/src/libs/vpatterndb/variables/vcurveangle.cpp b/src/libs/vpatterndb/variables/vcurveangle.cpp index b10570328..df07d6d29 100644 --- a/src/libs/vpatterndb/variables/vcurveangle.cpp +++ b/src/libs/vpatterndb/variables/vcurveangle.cpp @@ -81,20 +81,32 @@ VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbst } //--------------------------------------------------------------------------------------------------------------------- -VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl, - CurveAngle angle, qint32 segment) +VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, + const VSpline &spl, CurveAngle angle, qint32 segment) :VCurveVariable(id, parentId) { + SCASSERT(baseCurve != nullptr) + SetType(VarType::CurveAngle); if (angle == CurveAngle::StartAngle) { SetValue(spl.GetStartAngle()); - SetName(angle1_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment)); + SetName(angle1_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment)); + + if (not baseCurve->GetAlias().isEmpty()) + { + SetAlias(angle1_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment)); + } } else { SetValue(spl.GetEndAngle()); - SetName(angle2_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment)); + SetName(angle2_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment)); + + if (not baseCurve->GetAlias().isEmpty()) + { + SetAlias(angle2_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment)); + } } } diff --git a/src/libs/vpatterndb/variables/vcurveangle.h b/src/libs/vpatterndb/variables/vcurveangle.h index 348283961..e624eaa7d 100644 --- a/src/libs/vpatterndb/variables/vcurveangle.h +++ b/src/libs/vpatterndb/variables/vcurveangle.h @@ -46,7 +46,7 @@ class VCurveAngle : public VCurveVariable public: VCurveAngle(); VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve, CurveAngle angle); - VCurveAngle(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl, + VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, const VSpline &spl, CurveAngle angle, qint32 segment); protected: VCurveAngle(const quint32 &id, const quint32 &parentId); diff --git a/src/libs/vpatterndb/variables/vcurveclength.cpp b/src/libs/vpatterndb/variables/vcurveclength.cpp index c6e03617d..0494db3c0 100644 --- a/src/libs/vpatterndb/variables/vcurveclength.cpp +++ b/src/libs/vpatterndb/variables/vcurveclength.cpp @@ -74,20 +74,32 @@ VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const V } //--------------------------------------------------------------------------------------------------------------------- -VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, +VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *baseCurve, const VSpline &spl, CurveCLength cType, Unit patternUnit, qint32 segment) : VCurveVariable(id, parentId) { + SCASSERT(baseCurve != nullptr) + SetType(VarType::CurveCLength); if (cType == CurveCLength::C1) { SetValue(FromPixel(spl.GetC1Length(), patternUnit)); - SetName(c1Length_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment)); + SetName(c1Length_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment)); + + if (not baseCurve->GetAlias().isEmpty()) + { + SetAlias(c1Length_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment)); + } } else { SetValue(FromPixel(spl.GetC2Length(), patternUnit)); - SetName(c2Length_V + baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment)); + SetName(c2Length_V + baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment)); + + if (not baseCurve->GetAlias().isEmpty()) + { + SetAlias(c2Length_V + baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment)); + } } } diff --git a/src/libs/vpatterndb/variables/vcurveclength.h b/src/libs/vpatterndb/variables/vcurveclength.h index 693013076..3978d2596 100644 --- a/src/libs/vpatterndb/variables/vcurveclength.h +++ b/src/libs/vpatterndb/variables/vcurveclength.h @@ -46,7 +46,7 @@ public: VCurveCLength(); VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *curve, CurveCLength cType, Unit patternUnit); - VCurveCLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl, + VCurveCLength(const quint32 &id, const quint32 &parentId, const VAbstractBezier *baseCurve, const VSpline &spl, CurveCLength cType, Unit patternUnit, qint32 segment); VCurveCLength(const VCurveCLength &var); VCurveCLength &operator=(const VCurveCLength &var); diff --git a/src/libs/vpatterndb/variables/vcurvelength.cpp b/src/libs/vpatterndb/variables/vcurvelength.cpp index bf33819a2..5a70f206b 100644 --- a/src/libs/vpatterndb/variables/vcurvelength.cpp +++ b/src/libs/vpatterndb/variables/vcurvelength.cpp @@ -60,14 +60,20 @@ VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAb } //--------------------------------------------------------------------------------------------------------------------- -VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl, - Unit patternUnit, qint32 segment) +VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, + const VSpline &spl, Unit patternUnit, qint32 segment) :VCurveVariable(id, parentId) { - SCASSERT(not baseCurveName.isEmpty()) + SCASSERT(baseCurve != nullptr) SetType(VarType::CurveLength); - SetName(baseCurveName + QLatin1String("_") + seg_ + QString().setNum(segment)); + SetName(baseCurve->name() + QLatin1String("_") + seg_ + QString().setNum(segment)); + + if (not baseCurve->GetAlias().isEmpty()) + { + SetAlias(baseCurve->GetAlias() + QLatin1String("_") + seg_ + QString().setNum(segment)); + } + SetValue(FromPixel(spl.GetLength(), patternUnit)); } diff --git a/src/libs/vpatterndb/variables/vcurvelength.h b/src/libs/vpatterndb/variables/vcurvelength.h index f6d64f645..c45403261 100644 --- a/src/libs/vpatterndb/variables/vcurvelength.h +++ b/src/libs/vpatterndb/variables/vcurvelength.h @@ -45,7 +45,7 @@ class VCurveLength : public VCurveVariable public: VCurveLength(); VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *curve, Unit patternUnit); - VCurveLength(const quint32 &id, const quint32 &parentId, const QString &baseCurveName, const VSpline &spl, + VCurveLength(const quint32 &id, const quint32 &parentId, const VAbstractCurve *baseCurve, const VSpline &spl, Unit patternUnit, qint32 segment); VCurveLength(const VCurveLength &var); VCurveLength &operator=(const VCurveLength &var); diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 70aaf35d3..44aff5aed 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -509,11 +509,11 @@ void VContainer::AddCurveWithSegments(const QSharedPointerGetSpline(i); - 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)); + AddVariable(new VCurveLength(id, parentId, curve.data(), spl, *GetPatternUnit(), i)); + AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::StartAngle, i)); + AddVariable(new VCurveAngle(id, parentId, curve.data(), spl, CurveAngle::EndAngle, i)); + AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C1, *GetPatternUnit(), i)); + AddVariable(new VCurveCLength(id, parentId, curve.data(), spl, CurveCLength::C2, *GetPatternUnit(), i)); } } diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index 8df77ebd6..d628aaca6 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -125,6 +125,8 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, quint32 toolId, QWidg connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSplinePath::DeployLength1TextEdit); connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSplinePath::DeployLength2TextEdit); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogSplinePath::ValidateAlias); + vis = new VisToolSplinePath(data); auto path = qobject_cast(vis); SCASSERT(path != nullptr) @@ -167,6 +169,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value) ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale()); + ui->lineEditAlias->setText(path.GetAliasSuffix()); + ValidateAlias(); + ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle()); ChangeCurrentData(ui->comboBoxColor, path.GetColor()); @@ -490,6 +495,25 @@ void DialogSplinePath::FXLength2() delete dialog; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::ValidateAlias() +{ + VSplinePath tempPath = path; + tempPath.SetAliasSuffix(ui->lineEditAlias->text()); + if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(tempPath.GetAlias())) + { + flagAlias = false; + ChangeColor(ui->labelAlias, errorColor); + } + else + { + flagAlias = true; + ChangeColor(ui->labelAlias, OkColor(this)); + } + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::EvalAngle1() { @@ -874,6 +898,7 @@ void DialogSplinePath::SavePath() path.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); path.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine)); path.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack)); + path.SetAliasSuffix(ui->lineEditAlias->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -945,7 +970,7 @@ bool DialogSplinePath::IsValid() const fLength2 = fLength2 && flagLength2.at(i); } - return fAngle1 && fAngle2 && fLength1 && fLength2 && flagError; + return fAngle1 && fAngle2 && fLength1 && fLength2 && flagError && flagAlias; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.h b/src/libs/vtools/dialogs/tools/dialogsplinepath.h index ebd4b806b..6e6a58dd6 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.h @@ -88,6 +88,8 @@ private slots: void FXAngle2(); void FXLength1(); void FXLength2(); + + void ValidateAlias(); private: Q_DISABLE_COPY(DialogSplinePath) @@ -111,6 +113,7 @@ private: QVector flagLength1; QVector flagLength2; bool flagError; + bool flagAlias{true}; void EvalAngle1(); void EvalAngle2(); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.ui b/src/libs/vtools/dialogs/tools/dialogsplinepath.ui index 8aabfe949..8638f1340 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.ui @@ -7,7 +7,7 @@ 0 0 460 - 647 + 677 @@ -887,6 +887,16 @@ + + + + Alias: + + + + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index ffccde2eb..189740f56 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -270,6 +270,7 @@ VToolSplinePath *VToolSplinePath::Create(VToolSplinePathInitData &initData) path->SetColor(initData.color); path->SetPenStyle(initData.penStyle); path->SetApproximationScale(initData.approximationScale); + path->SetAliasSuffix(initData.aliasSuffix); return VToolSplinePath::Create(initData, path); } @@ -402,6 +403,7 @@ void VToolSplinePath::SetSplinePathAttributes(QDomElement &domElement, const VSp doc->SetAttribute(domElement, AttrColor, path.GetColor()); doc->SetAttribute(domElement, AttrPenStyle, path.GetPenStyle()); doc->SetAttribute(domElement, AttrAScale, path.GetApproximationScale()); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias, path.GetAliasSuffix(), path.GetAliasSuffix().isEmpty()); UpdatePathPoints(doc, domElement, path); }