From 0301c8289fe7bf6147dab4378fcdda61d7d8e643 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 13:31:32 +0200 Subject: [PATCH] Alias field for tool Elliptical arc. --- .../core/vtooloptionspropertybrowser.cpp | 8 +++++ src/app/valentina/xml/vpattern.cpp | 1 + .../dialogs/tools/dialogellipticalarc.cpp | 35 +++++++++++++++++++ .../dialogs/tools/dialogellipticalarc.h | 10 +++++- .../dialogs/tools/dialogellipticalarc.ui | 12 ++++++- .../toolcurve/vtoolellipticalarc.cpp | 7 +++- 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 80eaa1406..42643f8bf 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2401,6 +2401,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolEllipticalArc(VPE::VProperty *pr case 27://AttrColor SetLineColor(property); break; + case 62: // AttrAlias + SetAlias(property); + break; case 59: // AttrPenStyle SetPenStyle(property); break; @@ -2970,6 +2973,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEllipticalArc(QGraphicsItem *it AddPropertyFormula(tr("First angle:"), i->GetFormulaF1(), AttrAngle1); AddPropertyFormula(tr("Second angle:"), i->GetFormulaF2(), AttrAngle2); AddPropertyFormula(tr("Rotation angle:"), i->GetFormulaRotationAngle(), AttrRotationAngle); + AddPropertyAlias(i, tr("Alias:")); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyText(tr("Notes:"), i->GetNotes(), AttrNotes); } @@ -3867,6 +3871,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolEllipticalArc() { auto *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrName]->setValue(i->name()); + QVariant valueFormulaRadius1; valueFormulaRadius1.setValue(i->GetFormulaRadius1()); idToProperty[AttrRadius1]->setValue(valueFormulaRadius1); @@ -3895,6 +3901,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolEllipticalArc() idToProperty[AttrCenter]->setValue(valueCenterPoint); 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 426d6e94d..ccc3829bf 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3049,6 +3049,7 @@ void VPattern::ParseToolEllipticalArc(VMainGraphicsScene *scene, QDomElement &do initData.color = GetParametrString(domElement, AttrColor, ColorBlack); initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); initData.approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0')); + initData.aliasSuffix = GetParametrEmptyString(domElement, AttrAlias); VToolEllipticalArc::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index ba5ad6d2e..1d5766d95 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #include "ui_dialogellipticalarc.h" +#include "../vgeometry/vellipticalarc.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -154,6 +155,8 @@ DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, quint32 toolId, connect(ui->pushButtonGrowLengthRotationAngle, &QPushButton::clicked, this, &DialogEllipticalArc::DeployRotationAngleTextEdit); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogEllipticalArc::ValidateAlias); + vis = new VisToolEllipticalArc(data); ui->tabWidget->setCurrentIndex(0); @@ -592,6 +595,25 @@ void DialogEllipticalArc::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEllipticalArc::ValidateAlias() +{ + VEllipticalArc arc; + arc.SetAliasSuffix(GetAliasSuffix()); + if (not GetAliasSuffix().isEmpty() && not data->IsUnique(arc.GetAlias())) + { + flagAlias = false; + ChangeColor(ui->labelAlias, errorColor); + } + else + { + flagAlias = true; + ChangeColor(ui->labelAlias, OkColor(this)); + } + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogEllipticalArc::SetNotes(const QString ¬es) { @@ -603,3 +625,16 @@ QString DialogEllipticalArc::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEllipticalArc::SetAliasSuffix(const QString &alias) +{ + ui->lineEditAlias->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogEllipticalArc::GetAliasSuffix() const +{ + return ui->lineEditAlias->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h index 5fe122093..20338ff43 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h @@ -77,6 +77,9 @@ public: void SetNotes(const QString ¬es); QString GetNotes() const; + void SetAliasSuffix(const QString &alias); + QString GetAliasSuffix() const; + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; /** @@ -103,6 +106,9 @@ protected: virtual void closeEvent(QCloseEvent *event) override; virtual bool IsValid() const final; +private slots: + void ValidateAlias(); + private: Q_DISABLE_COPY(DialogEllipticalArc) @@ -124,6 +130,8 @@ private: /** @brief flagRotationAngle true if value of rotation angle is correct */ bool flagRotationAngle; + bool flagAlias{true}; + /** @brief timerRadius1 timer of check formula of radius1 */ QTimer *timerRadius1; @@ -172,7 +180,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogEllipticalArc::IsValid() const { - return flagRadius1 && flagRadius2 && flagF1 && flagF2 && flagRotationAngle; + return flagRadius1 && flagRadius2 && flagF1 && flagF2 && flagRotationAngle && flagAlias; } #endif // DIALOGELLIPTICALARC_H diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui b/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui index 3d2594f93..b1636b156 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.ui @@ -7,7 +7,7 @@ 0 0 396 - 575 + 595 @@ -1026,6 +1026,16 @@ + + + + Alias: + + + + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp index 00be5b2b8..ee9b1231f 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolellipticalarc.cpp @@ -93,6 +93,7 @@ void VToolEllipticalArc::setDialog() dialogTool->SetColor(elArc->GetColor()); dialogTool->SetPenStyle(elArc->GetPenStyle()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix(elArc->GetAliasSuffix()); } //--------------------------------------------------------------------------------------------------------------------- @@ -125,6 +126,7 @@ VToolEllipticalArc* VToolEllipticalArc::Create(const QPointer &dialo initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix = dialogTool->GetAliasSuffix(); //initData.approximationScale = dialogTool->GetApproximationScale(); // For future use VToolEllipticalArc* point = Create(initData); @@ -159,6 +161,7 @@ VToolEllipticalArc* VToolEllipticalArc::Create(VToolEllipticalArcInitData &initD elArc->SetColor(initData.color); elArc->SetPenStyle(initData.penStyle); elArc->SetApproximationScale(initData.approximationScale); + elArc->SetAliasSuffix(initData.aliasSuffix); if (initData.typeCreation == Source::FromGui) { @@ -385,6 +388,8 @@ void VToolEllipticalArc::SaveDialog(QDomElement &domElement, QList &old doc->SetAttribute(domElement, AttrRotationAngle, dialogTool->GetRotationAngle()); doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); doc->SetAttribute(domElement, AttrPenStyle, dialogTool->GetPenStyle()); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias, dialogTool->GetAliasSuffix(), + dialogTool->GetAliasSuffix().isEmpty()); const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); @@ -455,7 +460,7 @@ QString VToolEllipticalArc::MakeToolTip() const .arg(tr("End angle")) // 10 .arg(elArc->GetEndAngle()) // 11 .arg(tr("Label"), // 12 - elArc->name(), // 13 + elArc->ObjectName(), // 13 tr("Rotation")) // 14 .arg(elArc->GetRotationAngle()); // 15 return toolTip;