From 1246aba24d35cdd7c0cc00ab33220a99d94651d2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 11:01:20 +0200 Subject: [PATCH] Alias field for tool Arc. --- .../core/vtooloptionspropertybrowser.cpp | 181 +++++++++++------- .../core/vtooloptionspropertybrowser.h | 6 + src/app/valentina/xml/vpattern.cpp | 1 + src/libs/ifc/ifcdef.cpp | 1 + src/libs/ifc/ifcdef.h | 1 + src/libs/vgeometry/vabstractarc.cpp | 3 +- src/libs/vgeometry/vabstractcubicbezier.cpp | 13 ++ src/libs/vgeometry/vabstractcubicbezier.h | 1 + .../vgeometry/vabstractcubicbezierpath.cpp | 13 ++ src/libs/vgeometry/vabstractcubicbezierpath.h | 1 + src/libs/vgeometry/vabstractcurve.cpp | 7 + src/libs/vgeometry/vabstractcurve.h | 5 +- src/libs/vgeometry/varc.cpp | 15 +- src/libs/vgeometry/varc.h | 1 + src/libs/vgeometry/vellipticalarc.cpp | 13 ++ src/libs/vgeometry/vellipticalarc.h | 1 + src/libs/vtools/dialogs/tools/dialogarc.cpp | 35 ++++ src/libs/vtools/dialogs/tools/dialogarc.h | 10 +- src/libs/vtools/dialogs/tools/dialogarc.ui | 16 +- .../drawTools/toolcurve/vabstractspline.cpp | 16 ++ .../drawTools/toolcurve/vabstractspline.h | 14 +- .../tools/drawTools/toolcurve/vtoolarc.cpp | 7 +- src/libs/vtools/tools/drawTools/vdrawtool.h | 28 ++- 23 files changed, 311 insertions(+), 78 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 75d933532..da61a7415 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -516,12 +516,32 @@ void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly) +{ + if (readOnly) + { + auto *itemName = new VPE::VLabelProperty(propertyName); + itemName->setValue(qApp->TrVars()->VarToUser(i->name())); + AddProperty(itemName, AttrName); + } + else + { + auto *itemName = new VPE::VStringProperty(propertyName); + itemName->setClearButtonEnable(true); + itemName->setValue(qApp->TrVars()->VarToUser(i->name())); + itemName->setReadOnly(readOnly); + AddProperty(itemName, AttrName); + } + +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyAlias(Tool *i, const QString &propertyName) { auto *itemName = new VPE::VStringProperty(propertyName); itemName->setClearButtonEnable(true); - itemName->setValue(qApp->TrVars()->VarToUser(i->name())); - itemName->setReadOnly(readOnly); - AddProperty(itemName, AttrName); + itemName->setValue(qApp->TrVars()->VarToUser(i->GetAliasSuffix())); + AddProperty(itemName, AttrAlias); } //--------------------------------------------------------------------------------------------------------------------- @@ -927,6 +947,26 @@ void VToolOptionsPropertyBrowser::SetNotes(VPE::VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetAlias(VPE::VProperty *property) +{ + if (auto *i = qgraphicsitem_cast(currentItem)) + { + QString notes = property->data(VPE::VProperty::DPC_Data, Qt::DisplayRole).toString(); + if (notes == i->GetAliasSuffix()) + { + return; + } + + i->SetAliasSuffix(notes); + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::SetLineType(VPE::VProperty *property) @@ -1275,6 +1315,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArc(VPE::VProperty *property) case 61: // AttrNotes SetNotes(property); break; + case 62: // AttrAlias + SetAlias(property); + break; default: qWarning()<<"Unknown property type. id = "<GetFormulaRadius(), AttrRadius); AddPropertyFormula(tr("First angle:"), i->GetFormulaF1(), AttrAngle1); AddPropertyFormula(tr("Second angle:"), i->GetFormulaF2(), AttrAngle2); + AddPropertyAlias(i, tr("Alias:")); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyApproximationScale(tr("Approximation scale:"), i->GetApproximationScale()); @@ -3002,6 +3046,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() { auto *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrName]->setValue(i->name()); + QVariant valueRadius; valueRadius.setValue(i->GetFormulaRadius()); idToProperty[AttrRadius]->setValue(valueRadius); @@ -3033,6 +3079,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() idToProperty[AttrAScale]->setValue(valueApproximationScale); idToProperty[AttrNotes]->setValue(i->GetNotes()); + + idToProperty[AttrAlias]->setValue(i->GetAliasSuffix()); } //--------------------------------------------------------------------------------------------------------------------- @@ -3844,67 +3892,70 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolEllipticalArc() //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { - static QStringList attr = QStringList() << AttrName /* 0 */ - << QLatin1String("position") /* 1 */ - << AttrBasePoint /* 2 */ - << AttrTypeLine /* 3 */ - << AttrLength /* 4 */ - << AttrAngle /* 5 */ - << AttrFirstPoint /* 6 */ - << AttrSecondPoint /* 7 */ - << AttrRadius /* 8 */ - << AttrAngle1 /* 9 */ - << AttrAngle2 /* 10 */ - << AttrCenter /* 11 */ - << AttrThirdPoint /* 12 */ - << AttrArc /* 13 */ - << VToolCutSpline::AttrSpline /* 14 */ - << VToolCutSplinePath::AttrSplinePath /* 15 */ - << AttrP1Line /* 16 */ - << AttrP2Line /* 17 */ - << AttrP1Line1 /* 18 */ - << AttrP2Line1 /* 19 */ - << AttrP1Line2 /* 20 */ - << AttrP2Line2 /* 21 */ - << AttrPShoulder /* 22 */ - << AttrAxisP1 /* 23 */ - << AttrAxisP2 /* 24 */ - << AttrKCurve /*Not used*/ /* 25 */ - << AttrLineColor /* 26 */ - << AttrColor /* 27 */ - << AttrCrossPoint /* 28 */ - << AttrC1Radius /* 29 */ - << AttrC2Radius /* 30 */ - << AttrCRadius /* 31 */ - << AttrName1 /* 32 */ - << AttrName2 /* 33 */ - << AttrVCrossPoint /* 34 */ - << AttrHCrossPoint /* 35 */ - << AttrLength1 /* 36 */ - << AttrLength2 /* 37 */ - << AttrSuffix /* 38 */ - << AttrAxisType /* 39 */ - << AttrRadius1 /* 40 */ - << AttrRadius2 /* 41 */ - << AttrRotationAngle /* 42 */ - << AttrDartP1 /* 43 */ - << AttrDartP2 /* 44 */ - << AttrDartP3 /* 45 */ - << AttrCurve /* 46 */ - << AttrFirstArc /* 47 */ - << AttrSecondArc /* 48 */ - << AttrC1Center /* 49 */ - << AttrC2Center /* 50 */ - << AttrCurve1 /* 51 */ - << AttrCurve2 /* 52 */ - << AttrCCenter /* 53 */ - << AttrTangent /* 54 */ - << AttrPoint1 /* 55 */ - << AttrPoint2 /* 56 */ - << AttrPoint3 /* 57 */ - << AttrPoint4 /* 58 */ - << AttrPenStyle /* 59 */ - << AttrAScale /* 60 */ - << AttrNotes; /* 61 */ + static QStringList attr{ + AttrName, /* 0 */ + QLatin1String("position"), /* 1 */ + AttrBasePoint, /* 2 */ + AttrTypeLine, /* 3 */ + AttrLength, /* 4 */ + AttrAngle, /* 5 */ + AttrFirstPoint, /* 6 */ + AttrSecondPoint, /* 7 */ + AttrRadius, /* 8 */ + AttrAngle1, /* 9 */ + AttrAngle2, /* 10 */ + AttrCenter, /* 11 */ + AttrThirdPoint, /* 12 */ + AttrArc, /* 13 */ + VToolCutSpline::AttrSpline, /* 14 */ + VToolCutSplinePath::AttrSplinePath, /* 15 */ + AttrP1Line, /* 16 */ + AttrP2Line, /* 17 */ + AttrP1Line1, /* 18 */ + AttrP2Line1, /* 19 */ + AttrP1Line2, /* 20 */ + AttrP2Line2, /* 21 */ + AttrPShoulder, /* 22 */ + AttrAxisP1, /* 23 */ + AttrAxisP2, /* 24 */ + AttrKCurve, /*Not used*/ /* 25 */ + AttrLineColor, /* 26 */ + AttrColor, /* 27 */ + AttrCrossPoint, /* 28 */ + AttrC1Radius, /* 29 */ + AttrC2Radius, /* 30 */ + AttrCRadius, /* 31 */ + AttrName1, /* 32 */ + AttrName2, /* 33 */ + AttrVCrossPoint, /* 34 */ + AttrHCrossPoint, /* 35 */ + AttrLength1, /* 36 */ + AttrLength2, /* 37 */ + AttrSuffix, /* 38 */ + AttrAxisType, /* 39 */ + AttrRadius1, /* 40 */ + AttrRadius2, /* 41 */ + AttrRotationAngle, /* 42 */ + AttrDartP1, /* 43 */ + AttrDartP2, /* 44 */ + AttrDartP3, /* 45 */ + AttrCurve, /* 46 */ + AttrFirstArc, /* 47 */ + AttrSecondArc, /* 48 */ + AttrC1Center, /* 49 */ + AttrC2Center, /* 50 */ + AttrCurve1, /* 51 */ + AttrCurve2, /* 52 */ + AttrCCenter, /* 53 */ + AttrTangent, /* 54 */ + AttrPoint1, /* 55 */ + AttrPoint2, /* 56 */ + AttrPoint3, /* 57 */ + AttrPoint4, /* 58 */ + AttrPenStyle, /* 59 */ + AttrAScale, /* 60 */ + AttrNotes, /* 61 */ + AttrAlias /* 62 */ + }; return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index 98dab938e..d15a5f80d 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -96,6 +96,9 @@ private: template void SetNotes(VPE::VProperty *property); + template + void SetAlias(VPE::VProperty *property); + template void SetLineType(VPE::VProperty *property); @@ -129,6 +132,9 @@ private: template void AddPropertyObjectName(Tool *i, const QString &propertyName, bool readOnly = false); + template + void AddPropertyAlias(Tool *i, const QString &propertyName); + template void AddPropertyPointName1(Tool *i, const QString &propertyName); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 3ba2781e5..da9f21dae 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2992,6 +2992,7 @@ void VPattern::ParseToolArc(VMainGraphicsScene *scene, QDomElement &domElement, initData.color = GetParametrString(domElement, AttrColor, ColorBlack); initData.penStyle = GetParametrString(domElement, AttrPenStyle, TypeLineLine); initData.approximationScale = GetParametrDouble(domElement, AttrAScale, QChar('0')); + initData.aliasSuffix = GetParametrEmptyString(domElement, AttrAlias); VToolArc::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index a75a0492d..58f304e94 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -134,6 +134,7 @@ const QString AttrVersion = QStringLiteral("version"); const QString AttrFirstToCountour = QStringLiteral("firstToCountour"); const QString AttrLastToCountour = QStringLiteral("lastToCountour"); const QString AttrNotes = QStringLiteral("notes"); +const QString AttrAlias = QStringLiteral("alias"); const QString TypeLineNone = QStringLiteral("none"); const QString TypeLineLine = QStringLiteral("hair"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 995b67ebe..3305bcdf2 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -152,6 +152,7 @@ extern const QString AttrVersion; extern const QString AttrFirstToCountour; extern const QString AttrLastToCountour; extern const QString AttrNotes; +extern const QString AttrAlias; extern const QString TypeLineNone; extern const QString TypeLineLine; diff --git a/src/libs/vgeometry/vabstractarc.cpp b/src/libs/vgeometry/vabstractarc.cpp index 91975dac1..592a12a6c 100644 --- a/src/libs/vgeometry/vabstractarc.cpp +++ b/src/libs/vgeometry/vabstractarc.cpp @@ -181,7 +181,8 @@ QString VAbstractArc::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/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 20346008d..7f892afe9 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -516,6 +516,19 @@ void VAbstractCubicBezier::CreateName() setName(name); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCubicBezier::CreateAlias() +{ + const QString aliasSuffix = GetAliasSuffix(); + if (aliasSuffix.isEmpty()) + { + SetAlias(QString()); + return; + } + + SetAlias(SPL_ + aliasSuffix); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetCubicBezierPoints return list with cubic bezier curve points. diff --git a/src/libs/vgeometry/vabstractcubicbezier.h b/src/libs/vgeometry/vabstractcubicbezier.h index 67c232cf5..dc75a20c3 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.h +++ b/src/libs/vgeometry/vabstractcubicbezier.h @@ -63,6 +63,7 @@ public: protected: virtual void CreateName() override; + virtual void CreateAlias() override; static QVector GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, qreal approximationScale); diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 0b0c11881..65c3951ce 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -288,3 +288,16 @@ void VAbstractCubicBezierPath::CreateName() } setName(name); } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCubicBezierPath::CreateAlias() +{ + const QString aliasSuffix = GetAliasSuffix(); + if (aliasSuffix.isEmpty()) + { + SetAlias(QString()); + return; + } + + SetAlias(splPath + '_' + aliasSuffix); +} diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h index 22982b7f3..fad8a30aa 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.h +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -74,6 +74,7 @@ public: protected: virtual void CreateName() override; + virtual void CreateAlias() override; virtual VPointF FirstPoint() const =0; virtual VPointF LastPoint() const =0; diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index b47699d2f..fac6f5c3b 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -603,6 +603,13 @@ qreal VAbstractCurve::LengthCurveDirectionArrow() return qApp->Settings()->GetLineWidth() * 8.0; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractCurve::SetAliasSuffix(const QString &aliasSuffix) +{ + VGObject::SetAliasSuffix(aliasSuffix); + CreateAlias(); +} + //--------------------------------------------------------------------------------------------------------------------- qreal VAbstractCurve::PathLength(const QVector &path) { diff --git a/src/libs/vgeometry/vabstractcurve.h b/src/libs/vgeometry/vabstractcurve.h index f72d8e60f..c84f321cb 100644 --- a/src/libs/vgeometry/vabstractcurve.h +++ b/src/libs/vgeometry/vabstractcurve.h @@ -105,8 +105,11 @@ public: static QPainterPath ShowDirection(const QVector &arrows, qreal width); static qreal LengthCurveDirectionArrow(); + + virtual void SetAliasSuffix(const QString &aliasSuffix) override; protected: - virtual void CreateName() =0; + virtual void CreateName() =0; + virtual void CreateAlias() =0; private: QSharedDataPointer d; diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 3312f67cd..244737781 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -378,7 +378,7 @@ QPointF VArc::CutArc(qreal length) const //--------------------------------------------------------------------------------------------------------------------- void VArc::CreateName() { - QString name = ARC_ + QString("%1").arg(this->GetCenter().name()); + QString name = ARC_ + this->GetCenter().name(); if (getMode() == Draw::Modeling && getIdObject() != NULL_ID) { @@ -397,6 +397,19 @@ void VArc::CreateName() setName(name); } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::CreateAlias() +{ + const QString aliasSuffix = GetAliasSuffix(); + if (aliasSuffix.isEmpty()) + { + SetAlias(QString()); + return; + } + + SetAlias(ARC_ + aliasSuffix); +} + //--------------------------------------------------------------------------------------------------------------------- void VArc::FindF2(qreal length) { diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index 84886dfcc..c96289514 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -85,6 +85,7 @@ public: QPointF CutArc (qreal length) const; protected: virtual void CreateName() override; + virtual void CreateAlias() override; virtual void FindF2(qreal length) override; private: QSharedDataPointer d; diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index be7ce6941..0683dde6a 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -399,6 +399,19 @@ void VEllipticalArc::CreateName() setName(name); } +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::CreateAlias() +{ + const QString aliasSuffix = GetAliasSuffix(); + if (aliasSuffix.isEmpty()) + { + SetAlias(QString()); + return; + } + + SetAlias(ELARC_ + aliasSuffix); +} + //--------------------------------------------------------------------------------------------------------------------- void VEllipticalArc::FindF2(qreal length) { diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index a54cf2297..2c23ca104 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -104,6 +104,7 @@ public: static qreal OptimizeAngle(qreal angle); protected: virtual void CreateName() override; + virtual void CreateAlias() override; virtual void FindF2(qreal length) override; private: QSharedDataPointer d; diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index bad33739d..87ff0b2c4 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #include "ui_dialogarc.h" +#include "../vgeometry/varc.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -122,6 +123,8 @@ DialogArc::DialogArc(const VContainer *data, quint32 toolId, QWidget *parent) connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArc::DeployF1TextEdit); connect(ui->pushButtonGrowLengthF2, &QPushButton::clicked, this, &DialogArc::DeployF2TextEdit); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArc::GetAliasSuffix); + vis = new VisToolArc(data); ui->tabWidget->setCurrentIndex(0); @@ -237,6 +240,19 @@ QString DialogArc::GetNotes() const return ui->plainTextEditToolNotes->toPlainText(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::SetAliasSuffix(const QString &alias) +{ + ui->lineEditAlias->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArc::GetAliasSuffix() const +{ + return ui->lineEditAlias->text(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetF1 set formula first angle of arc @@ -337,6 +353,25 @@ void DialogArc::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogArc::ValidateAlias() +{ + VArc 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 DialogArc::FXRadius() { diff --git a/src/libs/vtools/dialogs/tools/dialogarc.h b/src/libs/vtools/dialogs/tools/dialogarc.h index 09c1d30a3..9f9cec67c 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.h +++ b/src/libs/vtools/dialogs/tools/dialogarc.h @@ -76,6 +76,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; /** @@ -97,6 +100,9 @@ protected: virtual void SaveData() override; virtual void closeEvent(QCloseEvent *event) override; virtual bool IsValid() const final; + +private slots: + void ValidateAlias(); private: Q_DISABLE_COPY(DialogArc) @@ -112,6 +118,8 @@ private: /** @brief flagF2 true if value of second angle is correct */ bool flagF2; + bool flagAlias{true}; + /** @brief timerRadius timer of check formula of radius */ QTimer *timerRadius; @@ -145,7 +153,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogArc::IsValid() const { - return flagRadius && flagF1 && flagF2; + return flagRadius && flagF1 && flagF2 && flagAlias; } #endif // DIALOGARC_H diff --git a/src/libs/vtools/dialogs/tools/dialogarc.ui b/src/libs/vtools/dialogs/tools/dialogarc.ui index 4e953e4dd..bea483bc3 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.ui +++ b/src/libs/vtools/dialogs/tools/dialogarc.ui @@ -7,7 +7,7 @@ 0 0 407 - 456 + 476 @@ -662,6 +662,20 @@ + + + + Alias: + + + + + + + true + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index 155b055d3..bafe88e4d 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -332,6 +332,7 @@ void VAbstractSpline::SaveOptions(QDomElement &tag, QSharedPointer &ob doc->SetAttribute(tag, AttrColor, curve->GetColor()); doc->SetAttribute(tag, AttrPenStyle, curve->GetPenStyle()); doc->SetAttribute(tag, AttrAScale, curve->GetApproximationScale()); + doc->SetAttributeOrRemoveIf(tag, AttrAlias, curve->GetAliasSuffix(), curve->GetAliasSuffix().isEmpty()); } //--------------------------------------------------------------------------------------------------------------------- @@ -494,6 +495,21 @@ quint32 VAbstractSpline::GetDuplicate() const return VAbstractTool::data.GeometricObject(m_id)->GetDuplicate(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractSpline::GetAliasSuffix() const +{ + return ObjectAliasSuffix(m_id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::SetAliasSuffix(const QString &alias) +{ + QSharedPointer curve = VAbstractTool::data.GeometricObject(m_id); + curve->SetAliasSuffix(alias); + QSharedPointer obj = qSharedPointerCast(curve); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractSpline::GroupVisibility(quint32 object, bool visible) { diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index 83b8ddf99..5d0b2b430 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -66,6 +66,7 @@ struct VAbstractSplineInitData : VDrawToolInitData QString color; QString penStyle; qreal approximationScale; + QString aliasSuffix{}; }; class VAbstractSpline:public VDrawTool, public QGraphicsPathItem @@ -95,13 +96,16 @@ public: quint32 GetDuplicate() const; + QString GetAliasSuffix() const; + void SetAliasSuffix(const QString &alias); + virtual void GroupVisibility(quint32 object, bool visible) override; public slots: - virtual void FullUpdateFromFile () override; - virtual void Disable(bool disable, const QString &namePP) override; - virtual void DetailsMode(bool mode) override; - virtual void AllowHover(bool enabled) override; - virtual void AllowSelecting(bool enabled) override; + virtual void FullUpdateFromFile () override; + virtual void Disable(bool disable, const QString &namePP) override; + virtual void DetailsMode(bool mode) override; + virtual void AllowHover(bool enabled) override; + virtual void AllowSelecting(bool enabled) override; signals: /** * @brief setEnabledPoint disable control points. diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp index c18d7d323..84c979651 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarc.cpp @@ -91,6 +91,7 @@ void VToolArc::setDialog() dialogTool->SetPenStyle(arc->GetPenStyle()); dialogTool->SetApproximationScale(arc->GetApproximationScale()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix(arc->GetAliasSuffix()); } //--------------------------------------------------------------------------------------------------------------------- @@ -122,6 +123,7 @@ VToolArc* VToolArc::Create(const QPointer &dialog, VMainGraphicsScen initData.typeCreation = Source::FromGui; initData.approximationScale = dialogTool->GetApproximationScale(); initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix = dialogTool->GetAliasSuffix(); VToolArc* point = Create(initData); if (point != nullptr) @@ -150,6 +152,7 @@ VToolArc* VToolArc::Create(VToolArcInitData &initData) arc->SetColor(initData.color); arc->SetPenStyle(initData.penStyle); arc->SetApproximationScale(initData.approximationScale); + arc->SetAliasSuffix(initData.aliasSuffix); if (initData.typeCreation == Source::FromGui) { @@ -338,6 +341,8 @@ void VToolArc::SaveDialog(QDomElement &domElement, QList &oldDependenci doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); doc->SetAttribute(domElement, AttrPenStyle, dialogTool->GetPenStyle()); doc->SetAttribute(domElement, AttrAScale, dialogTool->GetApproximationScale()); + doc->SetAttributeOrRemoveIf(domElement, AttrAlias, dialogTool->GetAliasSuffix(), + dialogTool->GetAliasSuffix().isEmpty()); const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); @@ -398,6 +403,6 @@ QString VToolArc::MakeToolTip() const .arg(arc->GetStartAngle()) .arg(tr("End angle")) .arg(arc->GetEndAngle()) - .arg(tr("Label"), arc->name()); + .arg(tr("Label"), arc->ObjectName()); return toolTip; } diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index 95b32081a..62ae7bb15 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -138,6 +138,9 @@ protected: template QString ObjectName(quint32 id) const; + template + QString ObjectAliasSuffix(quint32 id) const; + template static void InitDrawToolConnections(VMainGraphicsScene *scene, T *tool); private: @@ -357,14 +360,35 @@ QString VDrawTool::ObjectName(quint32 id) const { try { - return data.GeometricObject(id)->name(); + return data.GeometricObject(id)->ObjectName(); } catch (const VExceptionBadId &e) { qCDebug(vTool, "Error! Couldn't get object name by id = %s. %s %s", qUtf8Printable(QString().setNum(id)), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); - return QString(QString());// Return empty string for property browser + return QString();// Return empty string for property browser + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +/** + * @brief ObjectAlias get object (point, curve, arc) alias. + * @param id object id in container. + */ +QString VDrawTool::ObjectAliasSuffix(quint32 id) const +{ + try + { + return data.GeometricObject(id)->GetAliasSuffix(); + } + catch (const VExceptionBadId &e) + { + qCDebug(vTool, "Error! Couldn't get object alias suffix by id = %s. %s %s", qUtf8Printable(QString().setNum(id)), + qUtf8Printable(e.ErrorMessage()), + qUtf8Printable(e.DetailedInformation())); + return QString();// Return empty string for property browser } }