From a5f65c319c8e3460077e63ab5631fec6d97dadb6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 14:34:22 +0200 Subject: [PATCH] Alias field for tool Cubic Bezier. --- .../core/vtooloptionspropertybrowser.cpp | 6 +++++ src/app/valentina/xml/vpattern.cpp | 2 ++ src/libs/vgeometry/vabstractcubicbezier.cpp | 3 ++- .../vpatterndb/variables/vcurveclength.cpp | 10 ++++++++ .../dialogs/tools/dialogcubicbezier.cpp | 25 +++++++++++++++++++ .../vtools/dialogs/tools/dialogcubicbezier.h | 6 ++++- .../vtools/dialogs/tools/dialogcubicbezier.ui | 14 +++++++++++ .../drawTools/toolcurve/vabstractspline.cpp | 2 +- .../drawTools/toolcurve/vtoolcubicbezier.cpp | 1 + 9 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 57f520a23..f79944916 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2050,6 +2050,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezier(VPE::VProperty *prop case 61: // AttrNotes SetNotes(property); break; + case 62: // AttrAlias + SetAlias(property); + break; case 55: // AttrPoint1 (read only) case 56: // AttrPoint2 (read only) case 57: // AttrPoint3 (read only) @@ -2824,6 +2827,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCubicBezier(QGraphicsItem *item AddPropertyParentPointName(i->SecondPointName(), tr("Second point:"), AttrPoint2); AddPropertyParentPointName(i->ThirdPointName(), tr("Third point:"), AttrPoint3); AddPropertyParentPointName(i->ForthPointName(), tr("Fourth point:"), AttrPoint4); + AddPropertyAlias(i, tr("Alias:")); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyApproximationScale(tr("Approximation scale:"), i->getSpline().GetApproximationScale()); @@ -3655,6 +3659,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezier() 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 ccc3829bf..1d5e47564 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2618,6 +2618,7 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement const QString penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); const quint32 duplicate = GetParametrUInt(domElement, AttrDuplicate, QChar('0')); const qreal approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0')); + const QString alias = GetParametrEmptyString(domElement, AttrAlias); auto p1 = data->GeometricObject(point1); auto p2 = data->GeometricObject(point2); @@ -2633,6 +2634,7 @@ void VPattern::ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement initData.spline->SetPenStyle(penStyle); initData.spline->SetPenStyle(penStyle); initData.spline->SetApproximationScale(approximationScale); + initData.spline->SetAliasSuffix(alias); VToolCubicBezier::Create(initData); } diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 7f892afe9..1efcbfacc 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -475,7 +475,8 @@ QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const { name += QString("_%1").arg(GetDuplicate()); } - return name; + + return not GetAlias().isEmpty() ? QString("%1 (%2)").arg(GetAlias(), name) : name; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/variables/vcurveclength.cpp b/src/libs/vpatterndb/variables/vcurveclength.cpp index 4c31f3e79..c6e03617d 100644 --- a/src/libs/vpatterndb/variables/vcurveclength.cpp +++ b/src/libs/vpatterndb/variables/vcurveclength.cpp @@ -55,11 +55,21 @@ VCurveCLength::VCurveCLength(const quint32 &id, const quint32 &parentId, const V { SetValue(FromPixel(curve->GetC1Length(), patternUnit)); SetName(c1Length_V + curve->name()); + + if (not curve->GetAlias().isEmpty()) + { + SetAlias(c1Length_V + curve->GetAlias()); + } } else { SetValue(FromPixel(curve->GetC2Length(), patternUnit)); SetName(c2Length_V + curve->name()); + + if (not curve->GetAlias().isEmpty()) + { + SetAlias(c2Length_V + curve->GetAlias()); + } } } diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index 1079e54e6..a1ae6a29d 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -72,6 +72,8 @@ DialogCubicBezier::DialogCubicBezier(const VContainer *data, quint32 toolId, QWi connect(ui->comboBoxP4, &QComboBox::currentTextChanged, this, &DialogCubicBezier::PointNameChanged); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogCubicBezier::ValidateAlias); + vis = new VisToolCubicBezier(data); ui->tabWidget->setCurrentIndex(0); @@ -106,6 +108,9 @@ void DialogCubicBezier::SetSpline(const VCubicBezier &spline) ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); ui->doubleSpinBoxApproximationScale->setValue(spl.GetApproximationScale()); + ui->lineEditAlias->setText(spl.GetAliasSuffix()); + ValidateAlias(); + auto path = qobject_cast(vis); SCASSERT(path != nullptr) path->setApproximationScale(spl.GetApproximationScale()); @@ -241,6 +246,7 @@ void DialogCubicBezier::SaveData() spl.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); spl.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine)); spl.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack)); + spl.SetAliasSuffix(ui->lineEditAlias->text()); const quint32 d = spl.GetDuplicate();//Save previous value newDuplicate <= -1 ? spl.SetDuplicate(d) : spl.SetDuplicate(static_cast(newDuplicate)); @@ -256,6 +262,25 @@ void DialogCubicBezier::SaveData() path->RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezier::ValidateAlias() +{ + VCubicBezier spline = spl; + spline.SetAliasSuffix(ui->lineEditAlias->text()); + if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(spline.GetAlias())) + { + flagAlias = false; + ChangeColor(ui->labelAlias, errorColor); + } + else + { + flagAlias = true; + ChangeColor(ui->labelAlias, OkColor(this)); + } + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- const QSharedPointer DialogCubicBezier::GetP1() const { diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h index 62ef7a925..3b1ee58cf 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h @@ -68,6 +68,9 @@ protected: */ virtual void SaveData() override; virtual bool IsValid() const final; + +private slots: + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCubicBezier) Ui::DialogCubicBezier *ui; @@ -78,6 +81,7 @@ private: qint32 newDuplicate; bool flagError; + bool flagAlias{true}; const QSharedPointer GetP1() const; const QSharedPointer GetP2() const; @@ -88,7 +92,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCubicBezier::IsValid() const { - return flagError; + return flagError && flagAlias; } #endif // DIALOGCUBICBEZIER_H diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.ui b/src/libs/vtools/dialogs/tools/dialogcubicbezier.ui index 3a4c725a9..e4ed57e26 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.ui +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.ui @@ -154,6 +154,20 @@ + + + + Alias: + + + + + + + true + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index f66b0d9a2..739a5efa6 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -203,7 +203,7 @@ QString VAbstractSpline::MakeToolTip() const "") .arg(tr("Length")) .arg(qApp->fromPixel(curve->GetLength())) - .arg(UnitsToStr(qApp->patternUnits(), true), tr("Label"), curve->name()); + .arg(UnitsToStr(qApp->patternUnits(), true), tr("Label"), curve->ObjectName()); return toolTip; } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp index 61456c494..f28e5b3d2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolcubicbezier.cpp @@ -292,4 +292,5 @@ void VToolCubicBezier::SetSplineAttributes(QDomElement &domElement, const VCubic doc->SetAttribute(domElement, AttrPenStyle, spl.GetPenStyle()); doc->SetAttribute(domElement, AttrAScale, spl.GetApproximationScale()); doc->SetAttributeOrRemoveIf(domElement, AttrDuplicate, spl.GetDuplicate(), spl.GetDuplicate() <= 0); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias, spl.GetAliasSuffix(), spl.GetAliasSuffix().isEmpty()); }