From 3e682b180c1bb0f51596ebf8dc3a8760b665935b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 17:58:06 +0200 Subject: [PATCH] Alias field for tool Cut Spline Path. --- .../core/vtooloptionspropertybrowser.cpp | 11 +++ src/app/valentina/xml/vpattern.cpp | 2 + src/libs/ifc/schema/pattern/v0.8.10.xsd | 2 + src/libs/vpatterndb/vcontainer.cpp | 8 ++ src/libs/vpatterndb/vcontainer.h | 1 + .../dialogs/tools/dialogcutsplinepath.cpp | 78 +++++++++++++++++++ .../dialogs/tools/dialogcutsplinepath.h | 11 ++- .../dialogs/tools/dialogcutsplinepath.ui | 32 +++++++- .../toolcut/vtoolcutsplinepath.cpp | 21 ++++- 9 files changed, 161 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index bf031bb7d..392172920 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -1576,6 +1576,12 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCutSplinePath(VPE::VProperty *pr case 61: // AttrNotes SetNotes(property); break; + case 63: // AttrAlias1 + SetAlias1(property); + break; + case 64: // AttrAlias2 + SetAlias2(property); + break; default: qWarning()<<"Unknown property type. id = "<CurveName(), tr("Curve:"), AttrCurve); + AddPropertyAlias1(i, tr("Alias1:")); + AddPropertyAlias2(i, tr("Alias2:")); AddPropertyFormula(tr("Length:"), i->GetFormulaLength(), AttrLength); AddPropertyText(tr("Notes:"), i->GetNotes(), AttrNotes); } @@ -3350,6 +3358,9 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSplinePath() idToProperty[AttrCurve]->setValue(valueCurve); idToProperty[AttrNotes]->setValue(i->GetNotes()); + + idToProperty[AttrAlias1]->setValue(i->GetAliasSuffix1()); + idToProperty[AttrAlias2]->setValue(i->GetAliasSuffix2()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b09f53dd9..072fa2379 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2086,6 +2086,8 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do initData.formula = GetParametrString(domElement, AttrLength, QChar('0')); const QString f = initData.formula;//need for saving fixed formula; initData.baseCurveId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, NULL_ID_STR); + initData.aliasSuffix1 = GetParametrEmptyString(domElement, AttrAlias1); + initData.aliasSuffix2 = GetParametrEmptyString(domElement, AttrAlias2); VToolCutSplinePath::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. diff --git a/src/libs/ifc/schema/pattern/v0.8.10.xsd b/src/libs/ifc/schema/pattern/v0.8.10.xsd index e5b2295ef..0eef3d1c6 100644 --- a/src/libs/ifc/schema/pattern/v0.8.10.xsd +++ b/src/libs/ifc/schema/pattern/v0.8.10.xsd @@ -160,6 +160,8 @@ + + diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 0e186af6e..11b6a2ef7 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -241,6 +241,14 @@ quint32 VContainer::GetPieceForPiecePath(quint32 id) const return NULL_ID; } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::RegisterUniqueName(VGObject *obj) +{ + SCASSERT(obj != nullptr) + QSharedPointer pointer(obj); + RegisterUniqueName(pointer); +} + //--------------------------------------------------------------------------------------------------------------------- void VContainer::RegisterUniqueName(const QSharedPointer &obj) { diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index a43d10012..13adf3942 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -151,6 +151,7 @@ public: void UpdateId(quint32 newId) const; static void UpdateId(quint32 newId, const QString &nspace); + void RegisterUniqueName(VGObject *obj); void RegisterUniqueName(const QSharedPointer &obj); quint32 AddGObject(VGObject *obj); diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 2dadb3746..dac741413 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -92,6 +92,9 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, quint32 toolId, connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit); connect(ui->comboBoxSplinePath, &QComboBox::currentTextChanged, this, &DialogCutSplinePath::SplinePathChanged); + connect(ui->lineEditAlias1, &QLineEdit::textEdited, this, &DialogCutSplinePath::ValidateAlias); + connect(ui->lineEditAlias2, &QLineEdit::textEdited, this, &DialogCutSplinePath::ValidateAlias); + vis = new VisToolCutSplinePath(data); ui->tabWidget->setCurrentIndex(0); @@ -208,6 +211,55 @@ void DialogCutSplinePath::SplinePathChanged() CurrentCurveLength(getSplinePathId(), const_cast (data)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::ValidateAlias() +{ + VSplinePath path1; + path1.SetAliasSuffix(GetAliasSuffix1()); + if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(path1.GetAlias())) + { + flagAlias1 = false; + ChangeColor(ui->labelAlias1, errorColor); + } + else + { + flagAlias1 = true; + ChangeColor(ui->labelAlias1, OkColor(this)); + } + + VSplinePath path2; + path2.SetAliasSuffix(GetAliasSuffix2()); + if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(path2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { + flagAlias2 = true; + ChangeColor(ui->labelAlias2, OkColor(this)); + } + + if (path1.GetAlias() == path2.GetAlias()) + { + flagAlias1 = false; + ChangeColor(ui->labelAlias1, errorColor); + + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { + flagAlias1 = true; + ChangeColor(ui->labelAlias1, OkColor(this)); + + flagAlias2 = true; + ChangeColor(ui->labelAlias2, OkColor(this)); + } + + CheckState(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogCutSplinePath::DeployFormulaTextEdit() { @@ -279,3 +331,29 @@ QString DialogCutSplinePath::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::SetAliasSuffix1(const QString &alias) +{ + ui->lineEditAlias1->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutSplinePath::GetAliasSuffix1() const +{ + return ui->lineEditAlias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::SetAliasSuffix2(const QString &alias) +{ + ui->lineEditAlias2->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutSplinePath::GetAliasSuffix2() const +{ + return ui->lineEditAlias2->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h index b6f26b3c0..5963e82cf 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h @@ -64,6 +64,12 @@ public: void SetNotes(const QString ¬es); QString GetNotes() const; + + void SetAliasSuffix1(const QString &alias); + QString GetAliasSuffix1() const; + + void SetAliasSuffix2(const QString &alias); + QString GetAliasSuffix2() const; public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; /** @@ -82,6 +88,7 @@ protected: virtual bool IsValid() const final; private slots: void SplinePathChanged(); + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCutSplinePath) @@ -99,12 +106,14 @@ private: bool flagFormula; bool flagName; + bool flagAlias1{true}; + bool flagAlias2{true}; }; //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCutSplinePath::IsValid() const { - return flagFormula; + return flagFormula && flagAlias1 && flagAlias2; } #endif // DIALOGCUTSPLINEPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui index bf2d6bf5f..fe45553d9 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.ui @@ -6,8 +6,8 @@ 0 0 - 326 - 245 + 483 + 373 @@ -255,6 +255,34 @@ + + + + Alias1: + + + + + + + Alias2: + + + + + + + true + + + + + + + true + + + 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 2636837ac..83144906c 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -88,6 +88,8 @@ void VToolCutSplinePath::setDialog() dialogTool->setSplinePathId(baseCurveId); dialogTool->SetPointName(point->name()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix1(m_aliasSuffix1); + dialogTool->SetAliasSuffix2(m_aliasSuffix2); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,6 +117,8 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const QPointer &dialo initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix1 = dialogTool->GetAliasSuffix1(); + initData.aliasSuffix2 = dialogTool->GetAliasSuffix2(); VToolCutSplinePath* point = Create(initData); if (point != nullptr) @@ -154,12 +158,18 @@ VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutInitData &initData) p->setMy(initData.my); p->SetShowLabel(initData.showLabel); + splPath1->SetAliasSuffix(initData.aliasSuffix1); + splPath2->SetAliasSuffix(initData.aliasSuffix2); + if (initData.typeCreation == Source::FromGui) { initData.id = initData.data->AddGObject(p); initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); + + initData.data->RegisterUniqueName(splPath1); + initData.data->RegisterUniqueName(splPath2); } else { @@ -168,6 +178,9 @@ VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutInitData &initData) initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); + initData.data->RegisterUniqueName(splPath1); + initData.data->RegisterUniqueName(splPath2); + if (initData.parse != Document::FullParse) { initData.doc->UpdateToolData(initData.id, initData.data); @@ -308,6 +321,10 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement, QList &old doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId())); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias1, dialogTool->GetAliasSuffix1(), + dialogTool->GetAliasSuffix1().isEmpty()); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias2, dialogTool->GetAliasSuffix2(), + dialogTool->GetAliasSuffix2().isEmpty()); const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); @@ -376,8 +393,8 @@ QString VToolCutSplinePath::MakeToolTip() const .arg(qApp->fromPixel(splPath1->GetLength())) .arg(UnitsToStr(qApp->patternUnits(), true), curveStr + QLatin1String("2 ") + lengthStr) .arg(qApp->fromPixel(splPath2->GetLength())) - .arg(curveStr + QLatin1String(" 1") + tr("label"), splPath1->name(), - curveStr + QLatin1String(" 2") + tr("label"), splPath2->name()); + .arg(curveStr + QLatin1String(" 1") + tr("label"), splPath1->ObjectName(), + curveStr + QLatin1String(" 2") + tr("label"), splPath2->ObjectName()); delete splPath1; delete splPath2;