From 37722788bb773193e935cb66404f6f1cd5dfd146 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 13:31:43 +0200 Subject: [PATCH 01/23] New pattern format version. --- src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.8.10.xsd | 1082 +++++++++++++++++++++++ src/libs/ifc/xml/vpatternconverter.cpp | 23 +- src/libs/ifc/xml/vpatternconverter.h | 3 +- 4 files changed, 1104 insertions(+), 5 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.8.10.xsd diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c775ca329..62bba0903 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -61,6 +61,7 @@ schema/pattern/v0.8.7.xsd schema/pattern/v0.8.8.xsd schema/pattern/v0.8.9.xsd + schema/pattern/v0.8.10.xsd schema/multisize_measurements/v0.3.0.xsd schema/multisize_measurements/v0.4.0.xsd schema/multisize_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.8.10.xsd b/src/libs/ifc/schema/pattern/v0.8.10.xsd new file mode 100644 index 000000000..e5b2295ef --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.8.10.xsd @@ -0,0 +1,1082 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index a3521fd6a..7316ab6dc 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -59,8 +59,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.4"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.9"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.9.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.8.10"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.8.10.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -239,7 +239,8 @@ QString VPatternConverter::XSDSchema(int ver) const std::make_pair(FORMAT_VERSION(0, 8, 6), QStringLiteral("://schema/pattern/v0.8.6.xsd")), std::make_pair(FORMAT_VERSION(0, 8, 7), QStringLiteral("://schema/pattern/v0.8.7.xsd")), std::make_pair(FORMAT_VERSION(0, 8, 8), QStringLiteral("://schema/pattern/v0.8.8.xsd")), - std::make_pair(FORMAT_VERSION(0, 8, 9), CurrentSchema) + std::make_pair(FORMAT_VERSION(0, 8, 9), QStringLiteral("://schema/pattern/v0.8.9.xsd")), + std::make_pair(FORMAT_VERSION(0, 8, 10), CurrentSchema) }; if (schemas.contains(ver)) @@ -496,6 +497,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(FORMAT_VERSION(0, 8, 9))); Q_FALLTHROUGH(); case (FORMAT_VERSION(0, 8, 9)): + ToV0_8_10(); + ValidateXML(XSDSchema(FORMAT_VERSION(0, 8, 10))); + Q_FALLTHROUGH(); + case (FORMAT_VERSION(0, 8, 10)): break; default: InvalidVersion(m_ver); @@ -513,7 +518,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FORMAT_VERSION(0, 8, 9), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == FORMAT_VERSION(0, 8, 10), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -1174,6 +1179,16 @@ void VPatternConverter::ToV0_8_9() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_8_10() +{ + // TODO. Delete if minimal supported version is 0.8.10 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 8, 10), + "Time to refactor the code."); + SetVersion(QStringLiteral("0.8.10")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index b973fc7c9..6fea9583b 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -53,7 +53,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static Q_DECL_CONSTEXPR const int PatternMinVer = FORMAT_VERSION(0, 1, 4); - static Q_DECL_CONSTEXPR const int PatternMaxVer = FORMAT_VERSION(0, 8, 9); + static Q_DECL_CONSTEXPR const int PatternMaxVer = FORMAT_VERSION(0, 8, 10); protected: virtual int MinVer() const override; @@ -132,6 +132,7 @@ private: void ToV0_8_7(); void ToV0_8_8(); void ToV0_8_9(); + void ToV0_8_10(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From 8a6003752e5865fcfcf52b6f34269baae0c54060 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 10:53:49 +0200 Subject: [PATCH 02/23] Fix property value update. Default handler doesn't work in our cases. --- .../vpropertyexplorer/plugins/vlabelproperty.cpp | 11 +++++++++++ .../vpropertyexplorer/plugins/vlabelproperty.h | 3 +++ .../vpropertyexplorer/plugins/vstringproperty.cpp | 14 ++++++++++++++ .../vpropertyexplorer/plugins/vstringproperty.h | 3 +++ .../vpropertyexplorer/plugins/vtextproperty.cpp | 11 +++++++++++ src/libs/vpropertyexplorer/plugins/vtextproperty.h | 3 +++ 6 files changed, 45 insertions(+) diff --git a/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp b/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp index c295809bc..976f0bfb2 100644 --- a/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vlabelproperty.cpp @@ -70,6 +70,17 @@ QWidget *VPE::VLabelProperty::createEditor(QWidget *parent, const QStyleOptionVi return d_ptr->editor; } +bool VPE::VLabelProperty::setEditorData(QWidget *editor) +{ + if (QLabel* tmpWidget = qobject_cast(editor)) + { + tmpWidget->setText(d_ptr->VariantValue.toString()); + return true; + } + + return false; +} + QVariant VPE::VLabelProperty::getEditorData(const QWidget *editor) const { const QLabel* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vlabelproperty.h b/src/libs/vpropertyexplorer/plugins/vlabelproperty.h index c4385793e..f67c63316 100644 --- a/src/libs/vpropertyexplorer/plugins/vlabelproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vlabelproperty.h @@ -63,6 +63,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override; diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 9c843a7ef..72bf5e6d1 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -65,6 +65,20 @@ QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionV return d_ptr->editor; } +bool VPE::VStringProperty::setEditorData(QWidget *editor) +{ + if (QLineEdit* tmpWidget = qobject_cast(editor)) + { + if (not readOnly) + { + tmpWidget->setText(d_ptr->VariantValue.toString()); + } + return true; + } + + return false; +} + QVariant VPE::VStringProperty::getEditorData(const QWidget *editor) const { const QLineEdit* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index ad0959ce1..794eddff0 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -55,6 +55,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override; diff --git a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp index 69d1a9781..3e250eff0 100644 --- a/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vtextproperty.cpp @@ -86,6 +86,17 @@ QWidget *VPE::VTextProperty::createEditor(QWidget *parent, const QStyleOptionVie return d_ptr->editor; } +bool VPE::VTextProperty::setEditorData(QWidget *editor) +{ + if (QPlainTextEdit* tmpWidget = qobject_cast(editor)) + { + tmpWidget->setPlainText(d_ptr->VariantValue.toString()); + return true; + } + + return false; +} + QVariant VPE::VTextProperty::getEditorData(const QWidget *editor) const { const QPlainTextEdit* tmpEditor = qobject_cast(editor); diff --git a/src/libs/vpropertyexplorer/plugins/vtextproperty.h b/src/libs/vpropertyexplorer/plugins/vtextproperty.h index 91ddec63d..2bbdfa57d 100644 --- a/src/libs/vpropertyexplorer/plugins/vtextproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vtextproperty.h @@ -52,6 +52,9 @@ public: virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) override; + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor) override; + //! Gets the data from the widget virtual QVariant getEditorData(const QWidget* editor) const override; From 788aa92d44ff73b81a5f7a858059b7fea87f50d3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 10:55:34 +0200 Subject: [PATCH 03/23] Add alias attribute for geometric object. --- src/libs/vgeometry/vgobject.cpp | 30 ++++++++++++++++++++++++++++++ src/libs/vgeometry/vgobject.h | 8 ++++++++ src/libs/vgeometry/vgobject_p.h | 27 +++++++++++++++++++-------- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index b49269a4f..5f30ba6b6 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -243,6 +243,36 @@ void VGObject::setId(const quint32 &id) d->_id = id; } +//--------------------------------------------------------------------------------------------------------------------- +void VGObject::SetAlias(const QString &alias) +{ + d->m_alias = alias; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VGObject::GetAlias() const +{ + return d->m_alias; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGObject::SetAliasSuffix(const QString &aliasSuffix) +{ + d->m_aliasSuffix = aliasSuffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VGObject::GetAliasSuffix() const +{ + return d->m_aliasSuffix; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VGObject::ObjectName() const +{ + return not d->m_alias.isEmpty() ? QString("%1 (%2)").arg(d->m_alias, d->_name) : d->_name; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VGObject::getIdTool() const { diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index e402ad037..2078d40c8 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -78,6 +78,14 @@ public: quint32 id() const; virtual void setId(const quint32 &id); + void SetAlias(const QString &alias); + QString GetAlias() const; + + virtual void SetAliasSuffix(const QString &aliasSuffix); + QString GetAliasSuffix() const; + + QString ObjectName() const; + quint32 getIdTool() const; virtual QJsonObject ToJson() const; diff --git a/src/libs/vgeometry/vgobject_p.h b/src/libs/vgeometry/vgobject_p.h index cddf99acf..963956e87 100644 --- a/src/libs/vgeometry/vgobject_p.h +++ b/src/libs/vgeometry/vgobject_p.h @@ -42,33 +42,44 @@ class VGObjectData : public QSharedData { public: VGObjectData() - :_id(NULL_ID), type(GOType::Unknown), idObject(NULL_ID), _name(QString()), mode(Draw::Calculation) {} VGObjectData(const GOType &type, const quint32 &idObject, const Draw &mode) - :_id(NULL_ID), type(type), idObject(idObject), _name(QString()), mode(mode) + :type(type), + idObject(idObject), + mode(mode) {} VGObjectData(const VGObjectData &obj) - :QSharedData(obj), _id(obj._id), type(obj.type), idObject(obj.idObject), _name(obj._name), mode(obj.mode) + :QSharedData(obj), + _id(obj._id), + type(obj.type), + idObject(obj.idObject), + _name(obj._name), + mode(obj.mode), + m_alias(obj.m_alias), + m_aliasSuffix(obj.m_aliasSuffix) {} virtual ~VGObjectData(); /** @brief _id id in container. Ned for arcs, spline and spline paths. */ - quint32 _id; + quint32 _id{NULL_ID}; /** @brief type type of graphical object */ - GOType type; + GOType type{GOType::Unknown}; /** @brief idObject id of parent object. */ - quint32 idObject; + quint32 idObject{NULL_ID}; /** @brief _name object name */ - QString _name; + QString _name{}; /** @brief mode object created in calculation or drawing mode */ - Draw mode; + Draw mode{Draw::Calculation}; + + QString m_alias{}; + QString m_aliasSuffix{}; private: Q_DISABLE_ASSIGN(VGObjectData) From 8b49ea68c8679e9324d6d30b7a543c99383b6f6d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 10:58:57 +0200 Subject: [PATCH 04/23] Add alias support for internal variables. --- src/libs/vpatterndb/variables/varcradius.cpp | 13 +++++++- src/libs/vpatterndb/variables/vcurveangle.cpp | 15 +++++++++ .../vpatterndb/variables/vcurvelength.cpp | 6 ++++ .../vpatterndb/variables/vcurvevariable_p.h | 9 +++--- .../variables/vinternalvariable.cpp | 12 +++++++ .../vpatterndb/variables/vinternalvariable.h | 3 ++ .../variables/vinternalvariable_p.h | 15 +++++---- src/libs/vpatterndb/vcontainer.h | 32 +++++++++++++++---- 8 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/libs/vpatterndb/variables/varcradius.cpp b/src/libs/vpatterndb/variables/varcradius.cpp index 0777f8f36..fbfdc2d56 100644 --- a/src/libs/vpatterndb/variables/varcradius.cpp +++ b/src/libs/vpatterndb/variables/varcradius.cpp @@ -49,7 +49,12 @@ VArcRadius::VArcRadius(const quint32 &id, const quint32 &parentId, const VArc *a SCASSERT(arc != nullptr) SetType(VarType::ArcRadius); - SetName(radius_V + QString("%1").arg(arc->name())); + SetName(radius_V + arc->name()); + + if (not arc->GetAlias().isEmpty()) + { + SetAlias(radius_V + arc->GetAlias()); + } SetValue(FromPixel(arc->GetRadius(), patternUnit)); } @@ -62,6 +67,12 @@ VArcRadius::VArcRadius(const quint32 &id, const quint32 &parentId, const VEllipt SetType(VarType::ArcRadius); SetName(radius_V + QString("%1%2").arg(numberRadius).arg(elArc->name())); + + if (not elArc->GetAlias().isEmpty()) + { + SetAlias(radius_V + elArc->GetAlias()); + } + if (numberRadius == 1) { SetValue(FromPixel(elArc->GetRadius1(), patternUnit)); diff --git a/src/libs/vpatterndb/variables/vcurveangle.cpp b/src/libs/vpatterndb/variables/vcurveangle.cpp index 48a0fee25..b10570328 100644 --- a/src/libs/vpatterndb/variables/vcurveangle.cpp +++ b/src/libs/vpatterndb/variables/vcurveangle.cpp @@ -62,11 +62,21 @@ VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbst { SetValue(curve->GetStartAngle()); SetName(angle1_V + curve->name()); + + if (not curve->GetAlias().isEmpty()) + { + SetAlias(angle1_V + curve->GetAlias()); + } } else { SetValue(curve->GetEndAngle()); SetName(angle2_V + curve->name()); + + if (not curve->GetAlias().isEmpty()) + { + SetAlias(angle2_V + curve->GetAlias()); + } } } @@ -103,4 +113,9 @@ VEllipticalArcRotation::VEllipticalArcRotation(const quint32 &id, const quint32 SCASSERT(elArc != nullptr) SetValue(elArc->GetRotationAngle()); SetName(rotation_V + elArc->name()); + + if (not elArc->GetAlias().isEmpty()) + { + SetAlias(rotation_V + elArc->GetAlias()); + } } diff --git a/src/libs/vpatterndb/variables/vcurvelength.cpp b/src/libs/vpatterndb/variables/vcurvelength.cpp index 8be4e6ead..bf33819a2 100644 --- a/src/libs/vpatterndb/variables/vcurvelength.cpp +++ b/src/libs/vpatterndb/variables/vcurvelength.cpp @@ -50,6 +50,12 @@ VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAb SetType(VarType::CurveLength); SCASSERT(curve != nullptr) SetName(curve->name()); + + if (not curve->GetAlias().isEmpty()) + { + SetAlias(curve->GetAlias()); + } + SetValue(FromPixel(curve->GetLength(), patternUnit)); } diff --git a/src/libs/vpatterndb/variables/vcurvevariable_p.h b/src/libs/vpatterndb/variables/vcurvevariable_p.h index 7a65498ee..d0ab9f480 100644 --- a/src/libs/vpatterndb/variables/vcurvevariable_p.h +++ b/src/libs/vpatterndb/variables/vcurvevariable_p.h @@ -45,7 +45,6 @@ class VCurveVariableData : public QSharedData public: VCurveVariableData() - :id(NULL_ID), parentId(NULL_ID) {} VCurveVariableData(const quint32 &id, const quint32 &parentId) @@ -53,13 +52,15 @@ public: {} VCurveVariableData(const VCurveVariableData &var) - :QSharedData(var), id(var.id), parentId(var.parentId) + :QSharedData(var), + id(var.id), + parentId(var.parentId) {} virtual ~VCurveVariableData(); - quint32 id; - quint32 parentId; + quint32 id{NULL_ID}; + quint32 parentId{NULL_ID}; private: Q_DISABLE_ASSIGN(VCurveVariableData) diff --git a/src/libs/vpatterndb/variables/vinternalvariable.cpp b/src/libs/vpatterndb/variables/vinternalvariable.cpp index 19ff3db1b..b9a99e618 100644 --- a/src/libs/vpatterndb/variables/vinternalvariable.cpp +++ b/src/libs/vpatterndb/variables/vinternalvariable.cpp @@ -123,3 +123,15 @@ void VInternalVariable::SetType(const VarType &type) { d->type = type; } + +//--------------------------------------------------------------------------------------------------------------------- +void VInternalVariable::SetAlias(const QString &alias) +{ + d->alias = alias; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VInternalVariable::GetAlias() const +{ + return d->alias; +} diff --git a/src/libs/vpatterndb/variables/vinternalvariable.h b/src/libs/vpatterndb/variables/vinternalvariable.h index ca44c7cc0..118f89519 100644 --- a/src/libs/vpatterndb/variables/vinternalvariable.h +++ b/src/libs/vpatterndb/variables/vinternalvariable.h @@ -61,6 +61,9 @@ public: VarType GetType() const; void SetType(const VarType &type); + void SetAlias(const QString &alias); + QString GetAlias() const; + virtual bool Filter(quint32 id); virtual bool IsNotUsed() const; diff --git a/src/libs/vpatterndb/variables/vinternalvariable_p.h b/src/libs/vpatterndb/variables/vinternalvariable_p.h index 2d4194563..0ef0b61e8 100644 --- a/src/libs/vpatterndb/variables/vinternalvariable_p.h +++ b/src/libs/vpatterndb/variables/vinternalvariable_p.h @@ -42,23 +42,26 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") class VInternalVariableData : public QSharedData { public: - VInternalVariableData() - :type(VarType::Unknown), value(0), name(QString()) {} VInternalVariableData(const VInternalVariableData &var) - :QSharedData(var), type(var.type), value(var.value), name(var.name) + :QSharedData(var), + type(var.type), + value(var.value), + name(var.name), + alias(var.alias) {} virtual ~VInternalVariableData(); - VarType type; + VarType type{VarType::Unknown}; /** @brief value variable's value */ - qreal value; + qreal value{0}; - QString name; + QString name{}; + QString alias{}; private: Q_DISABLE_ASSIGN(VInternalVariableData) diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index a4e987da1..987affa53 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -227,6 +227,9 @@ private: void AddCurve(const QSharedPointer &curve, const quint32 &id, quint32 parentId = NULL_ID); + template + void AddVariable(const QSharedPointer &var, const QString &name); + template uint qHash( const QSharedPointer &p ); @@ -334,25 +337,42 @@ template void VContainer::AddVariable(const QSharedPointer &var) { SCASSERT(not var->GetName().isEmpty()) - if (d->variables.contains(var->GetName())) + AddVariable(var, var->GetName()); + + if (not var->GetAlias().isEmpty()) { - if (d->variables.value(var->GetName())->GetType() == var->GetType()) + AddVariable(var, var->GetAlias()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VContainer::AddVariable(const QSharedPointer &var, const QString &name) +{ + if (name.isEmpty()) + { + return; + } + + if (d->variables.contains(name)) + { + if (d->variables.value(name)->GetType() == var->GetType()) { - QSharedPointer v = qSharedPointerDynamicCast(d->variables.value(var->GetName())); + QSharedPointer v = qSharedPointerDynamicCast(d->variables.value(name)); if (v.isNull()) { - throw VExceptionBadId(tr("Can't cast object."), var->GetName()); + throw VExceptionBadId(tr("Can't cast object."), name); } *v = *var; } else { - throw VExceptionBadId(tr("Can't find object. Type mismatch."), var->GetName()); + throw VExceptionBadId(tr("Can't find object. Type mismatch."), name); } } else { - d->variables.insert(var->GetName(), var); + d->variables.insert(name, var); } } From 1246aba24d35cdd7c0cc00ab33220a99d94651d2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 11:01:20 +0200 Subject: [PATCH 05/23] 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 } } From 7542fc5dc2474b4d62349f4066abd505fc516c24 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 17:36:40 +0200 Subject: [PATCH 06/23] Alias field for tool Arc with length. --- .../core/vtooloptionspropertybrowser.cpp | 8 +++++ src/app/valentina/xml/vpattern.cpp | 1 + src/libs/vpatterndb/vcontainer.cpp | 6 ++++ src/libs/vpatterndb/vcontainer.h | 5 +++ src/libs/vtools/dialogs/tools/dialogarc.cpp | 2 +- .../dialogs/tools/dialogarcwithlength.cpp | 35 +++++++++++++++++++ .../dialogs/tools/dialogarcwithlength.h | 10 +++++- .../dialogs/tools/dialogarcwithlength.ui | 14 ++++++++ .../drawTools/toolcurve/vabstractspline.cpp | 14 ++++++-- .../toolcurve/vtoolarcwithlength.cpp | 7 +++- 10 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index da61a7415..80eaa1406 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -1359,6 +1359,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolArcWithLength(VPE::VProperty *pr 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("Length:"), i->GetFormulaLength(), AttrLength); + AddPropertyAlias(i, tr("Alias:")); AddPropertyCurvePenStyle(i, tr("Pen style:"), CurvePenStylesPics()); AddPropertyLineColor(i, tr("Color:"), VAbstractTool::ColorsList(), AttrColor); AddPropertyApproximationScale(tr("Approximation scale:"), i->GetApproximationScale()); @@ -3088,6 +3092,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArcWithLength() { auto *i = qgraphicsitem_cast(currentItem); + idToProperty[AttrName]->setValue(i->name()); + QVariant valueRadius; valueRadius.setValue(i->GetFormulaRadius()); idToProperty[AttrRadius]->setValue(valueRadius); @@ -3119,6 +3125,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolArcWithLength() 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 da9f21dae..426d6e94d 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3182,6 +3182,7 @@ void VPattern::ParseToolArcWithLength(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); VToolArcWithLength::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 2a4169ece..70aaf35d3 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -266,6 +266,12 @@ quint32 VContainer::AddGObject(const QSharedPointer &obj) } uniqueNames[d->nspace].insert(obj->name()); + + if (not obj->GetAlias().isEmpty()) + { + uniqueNames[d->nspace].insert(obj->GetAlias()); + } + const quint32 id = getNextId(); obj->setId(id); diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 987affa53..5bb839bbf 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -403,6 +403,11 @@ void VContainer::UpdateGObject(quint32 id, const QSharedPointer &obj) SCASSERT(not obj.isNull()) UpdateObject(id, obj); uniqueNames[d->nspace].insert(obj->name()); + + if (not obj->GetAlias().isEmpty()) + { + uniqueNames[d->nspace].insert(obj->GetAlias()); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index 87ff0b2c4..363c47d92 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -123,7 +123,7 @@ 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); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArc::ValidateAlias); vis = new VisToolArc(data); diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 84c8d25f0..2709d6304 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vcommonsettings.h" #include "../../visualization/visualization.h" #include "ui_dialogarcwithlength.h" +#include "../vgeometry/varc.h" //--------------------------------------------------------------------------------------------------------------------- DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent) @@ -115,6 +116,8 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArcWithLength::DeployF1TextEdit); connect(ui->pushButtonGrowLengthArcLength, &QPushButton::clicked, this, &DialogArcWithLength::DeployLengthTextEdit); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogArcWithLength::ValidateAlias); + vis = new VisToolArcWithLength(data); ui->tabWidget->setCurrentIndex(0); @@ -263,6 +266,19 @@ QString DialogArcWithLength::GetNotes() const return ui->plainTextEditToolNotes->toPlainText(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::SetAliasSuffix(const QString &alias) +{ + ui->lineEditAlias->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogArcWithLength::GetAliasSuffix() const +{ + return ui->lineEditAlias->text(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type) { @@ -374,6 +390,25 @@ void DialogArcWithLength::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogArcWithLength::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 DialogArcWithLength::Radius() { diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.h b/src/libs/vtools/dialogs/tools/dialogarcwithlength.h index 27fa4b967..107230fa0 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.h +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.h @@ -74,6 +74,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; /** @@ -96,6 +99,9 @@ protected: virtual void closeEvent(QCloseEvent *event) override; virtual bool IsValid() const final; +private slots: + void ValidateAlias(); + private: Q_DISABLE_COPY(DialogArcWithLength) Ui::DialogArcWithLength *ui; @@ -108,6 +114,8 @@ private: bool flagLength; + bool flagAlias{true}; + /** @brief timerRadius timer of check formula of radius */ QTimer *timerRadius; @@ -137,7 +145,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogArcWithLength::IsValid() const { - return flagRadius && flagF1 && flagLength; + return flagRadius && flagF1 && flagLength && flagAlias; } #endif // DIALOGARCWITHLENGTH_H diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.ui b/src/libs/vtools/dialogs/tools/dialogarcwithlength.ui index f8b26604b..2639a01e7 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.ui +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.ui @@ -651,6 +651,20 @@ + + + + Alias: + + + + + + + true + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp index bafe88e4d..f66b0d9a2 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.cpp @@ -505,9 +505,19 @@ QString VAbstractSpline::GetAliasSuffix() const void VAbstractSpline::SetAliasSuffix(const QString &alias) { QSharedPointer curve = VAbstractTool::data.GeometricObject(m_id); + + const QString oldAliasSuffix = curve->GetAliasSuffix(); curve->SetAliasSuffix(alias); - QSharedPointer obj = qSharedPointerCast(curve); - SaveOption(obj); + + if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) + { + QSharedPointer obj = qSharedPointerCast(curve); + SaveOption(obj); + } + else + { + curve->SetAliasSuffix(oldAliasSuffix); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp index 46014c9a2..6da50512b 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolarcwithlength.cpp @@ -84,6 +84,7 @@ void VToolArcWithLength::setDialog() dialogTool->SetPenStyle(arc->GetPenStyle()); dialogTool->SetApproximationScale(arc->GetApproximationScale()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix(arc->GetAliasSuffix()); } //--------------------------------------------------------------------------------------------------------------------- @@ -108,6 +109,7 @@ VToolArcWithLength *VToolArcWithLength::Create(const QPointer &dialo initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix = dialogTool->GetAliasSuffix(); VToolArcWithLength* point = Create(initData); if (point != nullptr) @@ -131,6 +133,7 @@ VToolArcWithLength *VToolArcWithLength::Create(VToolArcWithLengthInitData &initD arc->SetColor(initData.color); arc->SetPenStyle(initData.penStyle); arc->SetApproximationScale(initData.approximationScale); + arc->SetAliasSuffix(initData.aliasSuffix); if (initData.typeCreation == Source::FromGui) { @@ -317,6 +320,8 @@ void VToolArcWithLength::SaveDialog(QDomElement &domElement, QList &old 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()); @@ -377,6 +382,6 @@ QString VToolArcWithLength::MakeToolTip() const .arg(arc->GetStartAngle()) .arg(tr("End angle")) .arg(arc->GetEndAngle()) - .arg(tr("Label"), arc->name()); + .arg(tr("Label"), arc->ObjectName()); return toolTip; } From 0301c8289fe7bf6147dab4378fcdda61d7d8e643 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 13:31:32 +0200 Subject: [PATCH 07/23] 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; From c77d4c9bd2a617b36e0343b31063430dcdaa381e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 14:33:40 +0200 Subject: [PATCH 08/23] Improve object name translation. --- .../valentina/core/vtooloptionspropertybrowser.cpp | 12 ++++++------ src/libs/vgeometry/vgobject.cpp | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 42643f8bf..57f520a23 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -520,14 +520,14 @@ void VToolOptionsPropertyBrowser::AddPropertyObjectName(Tool *i, const QString & if (readOnly) { auto *itemName = new VPE::VLabelProperty(propertyName); - itemName->setValue(qApp->TrVars()->VarToUser(i->name())); + itemName->setValue(i->name()); AddProperty(itemName, AttrName); } else { auto *itemName = new VPE::VStringProperty(propertyName); itemName->setClearButtonEnable(true); - itemName->setValue(qApp->TrVars()->VarToUser(i->name())); + itemName->setValue(i->name()); itemName->setReadOnly(readOnly); AddProperty(itemName, AttrName); } @@ -3566,7 +3566,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() auto *i = qgraphicsitem_cast(currentItem); const VSpline spl = i->getSpline(); - idToProperty[AttrName]->setValue(qApp->TrVars()->VarToUser(i->name())); + idToProperty[AttrName]->setValue(i->name()); VFormula angle1F(spl.GetStartAngleFormula(), i->getData()); angle1F.setCheckZero(false); @@ -3624,7 +3624,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezier() { auto *i = qgraphicsitem_cast(currentItem); - idToProperty[AttrName]->setValue(qApp->TrVars()->VarToUser(i->name())); + idToProperty[AttrName]->setValue(i->name()); { const qint32 index = VPE::VLineTypeProperty::IndexOfStyle(CurvePenStylesPics(), i->GetPenStyle()); @@ -3662,7 +3662,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() { auto *i = qgraphicsitem_cast(currentItem); - idToProperty[AttrName]->setValue(qApp->TrVars()->VarToUser(i->name())); + idToProperty[AttrName]->setValue(i->name()); { const qint32 index = VPE::VLineTypeProperty::IndexOfStyle(CurvePenStylesPics(), i->GetPenStyle()); @@ -3684,7 +3684,7 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezierPath() { auto *i = qgraphicsitem_cast(currentItem); - idToProperty[AttrName]->setValue(qApp->TrVars()->VarToUser(i->name())); + idToProperty[AttrName]->setValue(i->name()); { const qint32 index = VPE::VLineTypeProperty::IndexOfStyle(CurvePenStylesPics(), i->GetPenStyle()); diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 5f30ba6b6..fd8c3d196 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -41,6 +41,7 @@ #include "../vmisc/compatibility.h" #include "../ifc/ifcdef.h" #include "vgobject_p.h" +#include "../vmisc/vabstractapplication.h" namespace { @@ -270,7 +271,9 @@ QString VGObject::GetAliasSuffix() const //--------------------------------------------------------------------------------------------------------------------- QString VGObject::ObjectName() const { - return not d->m_alias.isEmpty() ? QString("%1 (%2)").arg(d->m_alias, d->_name) : d->_name; + const QString alias = qApp->TrVars()->VarToUser(d->m_alias); + const QString name = qApp->TrVars()->VarToUser(d->_name); + return not d->m_alias.isEmpty() ? QString("%1 (%2)").arg(alias, name) : name; } //--------------------------------------------------------------------------------------------------------------------- From a5f65c319c8e3460077e63ab5631fec6d97dadb6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 14:34:22 +0200 Subject: [PATCH 09/23] 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()); } From 38e60d59055cae95ad5de4c8e6b3f9d339f86685 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 14:50:17 +0200 Subject: [PATCH 10/23] Fix name for history with alias. --- src/libs/vgeometry/vabstractarc.cpp | 9 ++++++++- src/libs/vgeometry/vabstractcubicbezier.cpp | 9 ++++++++- src/libs/vgeometry/vabstractcubicbezierpath.cpp | 10 +++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libs/vgeometry/vabstractarc.cpp b/src/libs/vgeometry/vabstractarc.cpp index 592a12a6c..3aee72f97 100644 --- a/src/libs/vgeometry/vabstractarc.cpp +++ b/src/libs/vgeometry/vabstractarc.cpp @@ -182,7 +182,14 @@ QString VAbstractArc::NameForHistory(const QString &toolName) const name += QString("_%1").arg(GetDuplicate()); } - return not GetAlias().isEmpty() ? QString("%1 (%2)").arg(GetAlias(), name) : name; + QString alias; + + if (not GetAliasSuffix().isEmpty()) + { + alias = QString("%1 %2").arg(toolName, GetAliasSuffix()); + } + + return not alias.isEmpty() ? QString("%1 (%2)").arg(alias, name) : name; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 1efcbfacc..3f2831de7 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -476,7 +476,14 @@ QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const name += QString("_%1").arg(GetDuplicate()); } - return not GetAlias().isEmpty() ? QString("%1 (%2)").arg(GetAlias(), name) : name; + QString alias; + + if (not GetAliasSuffix().isEmpty()) + { + alias = QString("%1 %2").arg(toolName, GetAliasSuffix()); + } + + return not alias.isEmpty() ? QString("%1 (%2)").arg(alias, name) : name; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 65c3951ce..3a9144e6d 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -265,7 +265,15 @@ QString VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const name += QString("_%1").arg(GetDuplicate()); } } - return name; + + QString alias; + + if (not GetAliasSuffix().isEmpty()) + { + alias = QString("%1 %2").arg(toolName, GetAliasSuffix()); + } + + return not alias.isEmpty() ? QString("%1 (%2)").arg(alias, name) : name; } //--------------------------------------------------------------------------------------------------------------------- From 7fe316c876159e337395d23762d8fae64596cc6c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 14:50:58 +0200 Subject: [PATCH 11/23] Alias field for tool Cubic Bezier Path. --- .../core/vtooloptionspropertybrowser.cpp | 6 +++++ src/app/valentina/xml/vpattern.cpp | 2 ++ .../dialogs/tools/dialogcubicbezierpath.cpp | 25 +++++++++++++++++++ .../dialogs/tools/dialogcubicbezierpath.h | 4 ++- .../dialogs/tools/dialogcubicbezierpath.ui | 14 +++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index f79944916..2868d7c99 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2134,6 +2134,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCubicBezierPath(VPE::VProperty * case 61: // AttrNotes SetNotes(property); break; + case 62: // AttrAlias + SetAlias(property); + break; default: qWarning()<<"Unknown property type. id = "<setTitle(tr("Tool cubic bezier 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()); @@ -3705,6 +3709,8 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCubicBezierPath() 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 1d5e47564..3552b695f 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2830,6 +2830,7 @@ void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomEle 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); QVector points; @@ -2861,6 +2862,7 @@ void VPattern::ParseToolCubicBezierPath(VMainGraphicsScene *scene, const QDomEle initData.path->SetColor(color); initData.path->SetPenStyle(penStyle); initData.path->SetApproximationScale(approximationScale); + initData.path->SetAliasSuffix(alias); VToolCubicBezierPath::Create(initData); } diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index a734d8fa3..92831ef3b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -80,6 +80,8 @@ DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, quint32 too connect(ui->comboBoxPoint, QOverload::of(&QComboBox::currentIndexChanged), this, &DialogCubicBezierPath::currentPointChanged); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogCubicBezierPath::ValidateAlias); + vis = new VisToolCubicBezierPath(data); ui->tabWidget->setCurrentIndex(0); @@ -112,6 +114,9 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &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()); @@ -200,6 +205,7 @@ void DialogCubicBezierPath::SaveData() path.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine)); path.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack)); path.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); + path.SetAliasSuffix(ui->lineEditAlias->text()); auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr) @@ -245,6 +251,25 @@ void DialogCubicBezierPath::currentPointChanged(int index) CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCubicBezierPath::ValidateAlias() +{ + VCubicBezierPath 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 DialogCubicBezierPath::NewItem(const VPointF &point) { diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h index e59f3c156..60f91bfe8 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -69,6 +69,7 @@ protected: private slots: void PointChanged(int row); void currentPointChanged(int index); + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCubicBezierPath) @@ -80,6 +81,7 @@ private: qint32 newDuplicate; bool flagError; + bool flagAlias{true}; void NewItem(const VPointF &point); void DataPoint(const VPointF &p); @@ -93,7 +95,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCubicBezierPath::IsValid() const { - return flagError; + return flagError && flagAlias; } #endif // DIALOGCUBICBEZIERPATH_H diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui index da939fe8b..1c08b7a2b 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.ui @@ -138,6 +138,20 @@ + + + + Alias: + + + + + + + true + + + From 648d1f18977aa271f6503c3c2428027dcc0ea320 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 15:25:23 +0200 Subject: [PATCH 12/23] Alias field for tool Spline. --- .../core/vtooloptionspropertybrowser.cpp | 6 +++++ src/app/valentina/xml/vpattern.cpp | 1 + .../vtools/dialogs/tools/dialogspline.cpp | 25 +++++++++++++++++++ src/libs/vtools/dialogs/tools/dialogspline.h | 5 +++- src/libs/vtools/dialogs/tools/dialogspline.ui | 16 +++++++++++- .../tools/drawTools/toolcurve/vtoolspline.cpp | 2 ++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 2868d7c99..dd9ca1c0b 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -2012,6 +2012,9 @@ void VToolOptionsPropertyBrowser::ChangeDataToolSpline(VPE::VProperty *property) case 61: // AttrNotes SetNotes(property); break; + case 62: // AttrAlias + SetAlias(property); + break; default: qWarning()<<"Unknown property type. id = "<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 3552b695f..1e3dd94e3 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2557,6 +2557,7 @@ void VPattern::ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElemen 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); VToolSpline *spl = VToolSpline::Create(initData); diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index a9abdb46e..94cde26a4 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -148,6 +148,8 @@ DialogSpline::DialogSpline(const VContainer *data, quint32 toolId, QWidget *pare connect(ui->pushButtonGrowLength1, &QPushButton::clicked, this, &DialogSpline::DeployLength1TextEdit); connect(ui->pushButtonGrowLength2, &QPushButton::clicked, this, &DialogSpline::DeployLength2TextEdit); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogSpline::ValidateAlias); + vis = new VisToolSpline(data); auto path = qobject_cast(vis); SCASSERT(path != nullptr) @@ -432,6 +434,25 @@ void DialogSpline::EvalLength2() Eval(formulaData, flagLength2); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSpline::ValidateAlias() +{ + VSpline 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(); +} + //--------------------------------------------------------------------------------------------------------------------- VSpline DialogSpline::CurrentSpline() const { @@ -458,6 +479,7 @@ VSpline DialogSpline::CurrentSpline() const spline.SetApproximationScale(ui->doubleSpinBoxApproximationScale->value()); spline.SetPenStyle(GetComboBoxCurrentData(ui->comboBoxPenStyle, TypeLineLine)); spline.SetColor(GetComboBoxCurrentData(ui->comboBoxColor, ColorBlack)); + spline.SetAliasSuffix(ui->lineEditAlias->text()); return spline; } @@ -588,6 +610,9 @@ void DialogSpline::SetSpline(const VSpline &spline) ui->plainTextEditLength2F->setPlainText(length2F); ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); + ui->lineEditAlias->setText(spl.GetAliasSuffix()); + ValidateAlias(); + auto path = qobject_cast(vis); SCASSERT(path != nullptr) diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index 214e26d39..c268cc825 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -88,6 +88,8 @@ private slots: void EvalAngle2(); void EvalLength1(); void EvalLength2(); + + void ValidateAlias(); private: Q_DISABLE_COPY(DialogSpline) @@ -117,6 +119,7 @@ private: bool flagLength1; bool flagLength2; bool flagError; + bool flagAlias{true}; const QSharedPointer GetP1() const; const QSharedPointer GetP4() const; @@ -127,7 +130,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogSpline::IsValid() const { - return flagAngle1 && flagAngle2 && flagLength1 && flagLength2 && flagError; + return flagAngle1 && flagAngle2 && flagLength1 && flagLength2 && flagError && flagAlias; } #endif // DIALOGSPLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogspline.ui b/src/libs/vtools/dialogs/tools/dialogspline.ui index 9a16011a9..9afc1f1cf 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.ui +++ b/src/libs/vtools/dialogs/tools/dialogspline.ui @@ -7,7 +7,7 @@ 0 0 532 - 452 + 482 @@ -925,6 +925,20 @@ + + + + Alias: + + + + + + + true + + + diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index 60d6abf7b..2e0e6d6f0 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -227,6 +227,7 @@ VToolSpline *VToolSpline::Create(VToolSplineInitData &initData) spline->SetColor(initData.color); spline->SetPenStyle(initData.penStyle); spline->SetApproximationScale(initData.approximationScale); + spline->SetAliasSuffix(initData.aliasSuffix); return VToolSpline::Create(initData, spline); } @@ -651,6 +652,7 @@ void VToolSpline::SetSplineAttributes(QDomElement &domElement, const VSpline &sp 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()); if (domElement.hasAttribute(AttrKCurve)) { From b1f932739373a77edd548fe5341a711f7c43aa4b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 15:26:22 +0200 Subject: [PATCH 13/23] 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); } From 2574ecda0e0586d4a269a721eaa0a022dde59e95 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 18:14:21 +0200 Subject: [PATCH 14/23] Alias field for tool Cut Arc. --- .../core/vtooloptionspropertybrowser.cpp | 75 +++++++++++++++- .../core/vtooloptionspropertybrowser.h | 12 +++ src/app/valentina/xml/vpattern.cpp | 14 +-- src/libs/ifc/ifcdef.cpp | 2 + src/libs/ifc/ifcdef.h | 2 + src/libs/vpatterndb/vcontainer.cpp | 20 +++-- src/libs/vpatterndb/vcontainer.h | 9 +- .../vtools/dialogs/tools/dialogcutarc.cpp | 78 ++++++++++++++++ src/libs/vtools/dialogs/tools/dialogcutarc.h | 26 ++++-- src/libs/vtools/dialogs/tools/dialogcutarc.ui | 32 ++++++- .../toolsinglepoint/toolcut/vtoolcut.cpp | 89 +++++++++++++++++-- .../toolsinglepoint/toolcut/vtoolcut.h | 30 ++++++- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 53 +++++++---- .../toolsinglepoint/toolcut/vtoolcutarc.h | 16 +--- .../toolcut/vtoolcutspline.cpp | 28 +++--- .../toolsinglepoint/toolcut/vtoolcutspline.h | 16 +--- .../toolcut/vtoolcutsplinepath.cpp | 28 +++--- .../toolcut/vtoolcutsplinepath.h | 16 +--- 18 files changed, 417 insertions(+), 129 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 97895ea4d..b3ac5507c 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -544,6 +544,26 @@ void VToolOptionsPropertyBrowser::AddPropertyAlias(Tool *i, const QString &prope AddProperty(itemName, AttrAlias); } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyAlias1(Tool *i, const QString &propertyName) +{ + auto *itemName = new VPE::VStringProperty(propertyName); + itemName->setClearButtonEnable(true); + itemName->setValue(qApp->TrVars()->VarToUser(i->GetAliasSuffix1())); + AddProperty(itemName, AttrAlias1); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyAlias2(Tool *i, const QString &propertyName) +{ + auto *itemName = new VPE::VStringProperty(propertyName); + itemName->setClearButtonEnable(true); + itemName->setValue(qApp->TrVars()->VarToUser(i->GetAliasSuffix2())); + AddProperty(itemName, AttrAlias2); +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyPointName1(Tool *i, const QString &propertyName) @@ -967,6 +987,46 @@ void VToolOptionsPropertyBrowser::SetAlias(VPE::VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetAlias1(VPE::VProperty *property) +{ + if (auto *i = qgraphicsitem_cast(currentItem)) + { + QString notes = property->data(VPE::VProperty::DPC_Data, Qt::DisplayRole).toString(); + if (notes == i->GetAliasSuffix1()) + { + return; + } + + i->SetAliasSuffix1(notes); + } + else + { + qWarning()<<"Can't cast item"; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetAlias2(VPE::VProperty *property) +{ + if (auto *i = qgraphicsitem_cast(currentItem)) + { + QString notes = property->data(VPE::VProperty::DPC_Data, Qt::DisplayRole).toString(); + if (notes == i->GetAliasSuffix2()) + { + return; + } + + i->SetAliasSuffix2(notes); + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::SetLineType(VPE::VProperty *property) @@ -1452,6 +1512,12 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCutArc(VPE::VProperty *property) 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("Arc:"), AttrArc); + AddPropertyAlias1(i, tr("Alias1:")); + AddPropertyAlias2(i, tr("Alias2:")); AddPropertyFormula(tr("Length:"), i->GetFormulaLength(), AttrLength); AddPropertyText(tr("Notes:"), i->GetNotes(), AttrNotes); } @@ -3232,6 +3300,9 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() idToProperty[AttrArc]->setValue(valueArc); idToProperty[AttrNotes]->setValue(i->GetNotes()); + + idToProperty[AttrAlias1]->setValue(i->GetAliasSuffix1()); + idToProperty[AttrAlias2]->setValue(i->GetAliasSuffix2()); } //--------------------------------------------------------------------------------------------------------------------- @@ -3995,7 +4066,9 @@ QStringList VToolOptionsPropertyBrowser::PropertiesList() const AttrPenStyle, /* 59 */ AttrAScale, /* 60 */ AttrNotes, /* 61 */ - AttrAlias /* 62 */ + AttrAlias, /* 62 */ + AttrAlias1, /* 63 */ + AttrAlias2 /* 64 */ }; return attr; } diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.h b/src/app/valentina/core/vtooloptionspropertybrowser.h index d15a5f80d..cee994701 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.h +++ b/src/app/valentina/core/vtooloptionspropertybrowser.h @@ -99,6 +99,12 @@ private: template void SetAlias(VPE::VProperty *property); + template + void SetAlias1(VPE::VProperty *property); + + template + void SetAlias2(VPE::VProperty *property); + template void SetLineType(VPE::VProperty *property); @@ -135,6 +141,12 @@ private: template void AddPropertyAlias(Tool *i, const QString &propertyName); + template + void AddPropertyAlias1(Tool *i, const QString &propertyName); + + template + void AddPropertyAlias2(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 aff8cb85a..b1a7c77f9 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2030,7 +2030,7 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle try { - VToolCutSplineInitData initData; + VToolCutInitData initData; initData.scene = scene; initData.doc = this; initData.data = data; @@ -2040,7 +2040,7 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle PointsCommonAttributes(domElement, initData); initData.formula = GetParametrString(domElement, AttrLength, QChar('0')); const QString f = initData.formula;//need for saving fixed formula; - initData.splineId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); + initData.baseCurveId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); VToolCutSpline::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2073,7 +2073,7 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do try { - VToolCutSplinePathInitData initData; + VToolCutInitData initData; initData.scene = scene; initData.doc = this; initData.data = data; @@ -2083,7 +2083,7 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do PointsCommonAttributes(domElement, initData); initData.formula = GetParametrString(domElement, AttrLength, QChar('0')); const QString f = initData.formula;//need for saving fixed formula; - initData.splinePathId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, NULL_ID_STR); + initData.baseCurveId = GetParametrUInt(domElement, VToolCutSplinePath::AttrSplinePath, NULL_ID_STR); VToolCutSplinePath::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. @@ -2116,7 +2116,7 @@ void VPattern::ParseToolCutArc(VMainGraphicsScene *scene, QDomElement &domElemen try { - VToolCutArcInitData initData; + VToolCutInitData initData; initData.scene = scene; initData.doc = this; initData.data = data; @@ -2126,7 +2126,9 @@ void VPattern::ParseToolCutArc(VMainGraphicsScene *scene, QDomElement &domElemen PointsCommonAttributes(domElement, initData); initData.formula = GetParametrString(domElement, AttrLength, QChar('0')); const QString f = initData.formula;//need for saving fixed formula; - initData.arcId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); + initData.baseCurveId = GetParametrUInt(domElement, AttrArc, NULL_ID_STR); + initData.aliasSuffix1 = GetParametrEmptyString(domElement, AttrAlias1); + initData.aliasSuffix2 = GetParametrEmptyString(domElement, AttrAlias2); VToolCutArc::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 58f304e94..ed39c11ec 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -135,6 +135,8 @@ const QString AttrFirstToCountour = QStringLiteral("firstToCountour"); const QString AttrLastToCountour = QStringLiteral("lastToCountour"); const QString AttrNotes = QStringLiteral("notes"); const QString AttrAlias = QStringLiteral("alias"); +const QString AttrAlias1 = QStringLiteral("alias1"); +const QString AttrAlias2 = QStringLiteral("alias2"); 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 3305bcdf2..cd32a74e6 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -153,6 +153,8 @@ extern const QString AttrFirstToCountour; extern const QString AttrLastToCountour; extern const QString AttrNotes; extern const QString AttrAlias; +extern const QString AttrAlias1; +extern const QString AttrAlias2; extern const QString TypeLineNone; extern const QString TypeLineLine; diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 44aff5aed..0e186af6e 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -241,6 +241,19 @@ quint32 VContainer::GetPieceForPiecePath(quint32 id) const return NULL_ID; } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::RegisterUniqueName(const QSharedPointer &obj) +{ + SCASSERT(not obj.isNull()) + + uniqueNames[d->nspace].insert(obj->name()); + + if (not obj->GetAlias().isEmpty()) + { + uniqueNames[d->nspace].insert(obj->GetAlias()); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddGObject add new GObject to container @@ -265,12 +278,7 @@ quint32 VContainer::AddGObject(const QSharedPointer &obj) return NULL_ID; } - uniqueNames[d->nspace].insert(obj->name()); - - if (not obj->GetAlias().isEmpty()) - { - uniqueNames[d->nspace].insert(obj->GetAlias()); - } + RegisterUniqueName(obj); const quint32 id = getNextId(); obj->setId(id); diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 5bb839bbf..a43d10012 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -151,6 +151,8 @@ public: void UpdateId(quint32 newId) const; static void UpdateId(quint32 newId, const QString &nspace); + void RegisterUniqueName(const QSharedPointer &obj); + quint32 AddGObject(VGObject *obj); quint32 AddGObject(const QSharedPointer &obj); quint32 AddPiece(const VPiece &detail); @@ -402,12 +404,7 @@ void VContainer::UpdateGObject(quint32 id, const QSharedPointer &obj) { SCASSERT(not obj.isNull()) UpdateObject(id, obj); - uniqueNames[d->nspace].insert(obj->name()); - - if (not obj->GetAlias().isEmpty()) - { - uniqueNames[d->nspace].insert(obj->GetAlias()); - } + RegisterUniqueName(obj); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 4c9ae5de1..24a24e356 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -93,6 +93,9 @@ DialogCutArc::DialogCutArc(const VContainer *data, quint32 toolId, QWidget *pare connect(ui->comboBoxArc, &QComboBox::currentTextChanged, this, &DialogCutArc::ArcChanged); + connect(ui->lineEditAlias1, &QLineEdit::textEdited, this, &DialogCutArc::ValidateAlias); + connect(ui->lineEditAlias2, &QLineEdit::textEdited, this, &DialogCutArc::ValidateAlias); + vis = new VisToolCutArc(data); ui->tabWidget->setCurrentIndex(0); @@ -201,6 +204,55 @@ void DialogCutArc::ArcChanged() CurrentCurveLength(getArcId(), const_cast (data)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::ValidateAlias() +{ + VArc arc1; + arc1.SetAliasSuffix(GetAliasSuffix1()); + if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(arc1.GetAlias())) + { + flagAlias1 = false; + ChangeColor(ui->labelAlias1, errorColor); + } + else + { + flagAlias1 = true; + ChangeColor(ui->labelAlias1, OkColor(this)); + } + + VArc arc2; + arc2.SetAliasSuffix(GetAliasSuffix2()); + if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(arc2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { + flagAlias2 = true; + ChangeColor(ui->labelAlias2, OkColor(this)); + } + + if (arc1.GetAlias() == arc2.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(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setArcId set id of arc @@ -279,3 +331,29 @@ QString DialogCutArc::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::SetAliasSuffix1(const QString &alias) +{ + ui->lineEditAlias1->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutArc::GetAliasSuffix1() const +{ + return ui->lineEditAlias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutArc::SetAliasSuffix2(const QString &alias) +{ + ui->lineEditAlias2->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutArc::GetAliasSuffix2() const +{ + return ui->lineEditAlias2->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.h b/src/libs/vtools/dialogs/tools/dialogcutarc.h index ec88a1598..385023b96 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.h +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.h @@ -54,17 +54,24 @@ public: DialogCutArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr); virtual ~DialogCutArc() override; - QString GetPointName() const; - void SetPointName(const QString &value); + QString GetPointName() const; + void SetPointName(const QString &value); - QString GetFormula() const; - void SetFormula(const QString &value); + QString GetFormula() const; + void SetFormula(const QString &value); - quint32 getArcId() const; - void setArcId(quint32 value); + quint32 getArcId() const; + void setArcId(quint32 value); 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; /** @@ -84,6 +91,7 @@ protected: virtual bool IsValid() const final; private slots: void ArcChanged(); + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCutArc) /** @brief ui keeps information about user interface */ @@ -94,18 +102,20 @@ private: QString pointName; /** @brief formulaBaseHeight base height defined by dialogui */ - int formulaBaseHeight; + int formulaBaseHeight; QTimer *timerFormula; bool flagFormula; bool flagName; + bool flagAlias1{true}; + bool flagAlias2{true}; }; //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCutArc::IsValid() const { - return flagFormula && flagName; + return flagFormula && flagName && flagAlias1 && flagAlias2; } #endif // DIALOGCUTARC_H diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.ui b/src/libs/vtools/dialogs/tools/dialogcutarc.ui index b50e73564..3bd921c16 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.ui @@ -6,8 +6,8 @@ 0 0 - 334 - 247 + 573 + 295 @@ -255,6 +255,34 @@ + + + + Alias1: + + + + + + + true + + + + + + + Alias2: + + + + + + + true + + + diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index d20aac17c..7c4e747d5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -44,14 +44,15 @@ #include "../vtoolsinglepoint.h" //--------------------------------------------------------------------------------------------------------------------- -VToolCut::VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &curveCutId, const QString ¬es, QGraphicsItem *parent) - : VToolSinglePoint(doc, data, id, notes, parent), - formula(formula), - curveCutId(curveCutId), - detailsMode(qApp->Settings()->IsShowCurveDetails()) +VToolCut::VToolCut(const VToolCutInitData &initData, QGraphicsItem *parent) + : VToolSinglePoint(initData.doc, initData.data, initData.id, initData.notes, parent), + formula(initData.formula), + baseCurveId(initData.baseCurveId), + detailsMode(qApp->Settings()->IsShowCurveDetails()), + m_aliasSuffix1(initData.aliasSuffix1), + m_aliasSuffix2(initData.aliasSuffix2) { - Q_ASSERT_X(curveCutId != 0, Q_FUNC_INFO, "curveCutId == 0"); //-V654 //-V712 + Q_ASSERT_X(initData.baseCurveId != 0, Q_FUNC_INFO, "curveCutId == 0"); //-V654 //-V712 } //--------------------------------------------------------------------------------------------------------------------- @@ -100,10 +101,62 @@ void VToolCut::SetFormulaLength(const VFormula &value) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolCut::GetAliasSuffix1() const +{ + return m_aliasSuffix1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::SetAliasSuffix1(const QString &alias) +{ + QSharedPointer curve = VAbstractTool::data.GeometricObject(baseCurveId); + + const QString oldAliasSuffix = curve->GetAliasSuffix(); + curve->SetAliasSuffix(alias); + + if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) + { + m_aliasSuffix1 = alias; + QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); + SaveOption(obj); + } + else + { + curve->SetAliasSuffix(oldAliasSuffix); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolCut::GetAliasSuffix2() const +{ + return m_aliasSuffix2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::SetAliasSuffix2(const QString &alias) +{ + QSharedPointer curve = VAbstractTool::data.GeometricObject(baseCurveId); + + const QString oldAliasSuffix = curve->GetAliasSuffix(); + curve->SetAliasSuffix(alias); + + if (alias.isEmpty() || VAbstractTool::data.IsUnique(curve->GetAlias())) + { + m_aliasSuffix2 = alias; + QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); + SaveOption(obj); + } + else + { + curve->SetAliasSuffix(oldAliasSuffix); + } +} + //--------------------------------------------------------------------------------------------------------------------- QString VToolCut::CurveName() const { - return VAbstractTool::data.GetGObject(curveCutId)->name(); + return VAbstractTool::data.GetGObject(baseCurveId)->name(); } //--------------------------------------------------------------------------------------------------------------------- @@ -121,7 +174,25 @@ void VToolCut::RefreshGeometry() */ void VToolCut::RemoveReferens() { - const auto curve = VAbstractTool::data.GetGObject(curveCutId); + const auto curve = VAbstractTool::data.GetGObject(baseCurveId); doc->DecrementReferens(curve->getIdTool()); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VToolSinglePoint::SaveOptions(tag, obj); + + doc->SetAttributeOrRemoveIf(tag, AttrAlias1, m_aliasSuffix1, m_aliasSuffix1.isEmpty()); + doc->SetAttributeOrRemoveIf(tag, AttrAlias2, m_aliasSuffix2, m_aliasSuffix2.isEmpty()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::ReadToolAttributes(const QDomElement &domElement) +{ + VToolSinglePoint::ReadToolAttributes(domElement); + + m_aliasSuffix1 = doc->GetParametrEmptyString(domElement, AttrAlias1); + m_aliasSuffix2 = doc->GetParametrEmptyString(domElement, AttrAlias2); +} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h index 7dfff48e6..d18ef52d6 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h @@ -45,18 +45,35 @@ class VFormula; +struct VToolCutInitData : VToolSinglePointInitData +{ + VToolCutInitData() + : VToolSinglePointInitData() + {} + + quint32 baseCurveId{NULL_ID}; + QString formula{}; + QString aliasSuffix1{}; + QString aliasSuffix2{}; +}; + class VToolCut : public VToolSinglePoint { Q_OBJECT public: - VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, - const quint32 &curveCutId, const QString ¬es, QGraphicsItem * parent = nullptr); + explicit VToolCut(const VToolCutInitData &initData, QGraphicsItem * parent = nullptr); virtual int type() const override {return Type;} enum { Type = UserType + static_cast(Tool::Cut)}; VFormula GetFormulaLength() const; void SetFormulaLength(const VFormula &value); + QString GetAliasSuffix1() const; + void SetAliasSuffix1(const QString &alias); + + QString GetAliasSuffix2() const; + void SetAliasSuffix2(const QString &alias); + QString CurveName() const; public slots: @@ -67,11 +84,16 @@ protected: /** @brief formula keep formula of length */ QString formula; - quint32 curveCutId; + quint32 baseCurveId; bool detailsMode; + QString m_aliasSuffix1{}; + QString m_aliasSuffix2{}; + void RefreshGeometry(); virtual void RemoveReferens() override; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) override; + virtual void ReadToolAttributes(const QDomElement &domElement) override; template void ShowToolVisualization(bool show); @@ -104,7 +126,7 @@ inline void VToolCut::ShowToolVisualization(bool show) delete vis; } - VDataTool *parent = VAbstractPattern::getTool(VAbstractTool::data.GetGObject(curveCutId)->getIdTool()); + VDataTool *parent = VAbstractPattern::getTool(VAbstractTool::data.GetGObject(baseCurveId)->getIdTool()); if (VAbstractSpline *parentCurve = qobject_cast(parent)) { detailsMode ? parentCurve->ShowHandles(detailsMode) : parentCurve->ShowHandles(show); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 6fa112a1b..8792e66f7 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -62,8 +62,8 @@ const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); * @param initData init data. * @param parent parent object. */ -VToolCutArc::VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem * parent) - :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.arcId, initData.notes, parent) +VToolCutArc::VToolCutArc(const VToolCutInitData &initData, QGraphicsItem * parent) + :VToolCut(initData, parent) { ToolCreation(initData.typeCreation); } @@ -79,9 +79,11 @@ void VToolCutArc::setDialog() SCASSERT(not dialogTool.isNull()) const QSharedPointer point = VAbstractTool::data.GeometricObject(m_id); dialogTool->SetFormula(formula); - dialogTool->setArcId(curveCutId); + dialogTool->setArcId(baseCurveId); dialogTool->SetPointName(point->name()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix1(m_aliasSuffix1); + dialogTool->SetAliasSuffix2(m_aliasSuffix2); } //--------------------------------------------------------------------------------------------------------------------- @@ -99,9 +101,9 @@ VToolCutArc* VToolCutArc::Create(const QPointer &dialog, VMainGraphi const QPointer dialogTool = qobject_cast(dialog); SCASSERT(not dialogTool.isNull()) - VToolCutArcInitData initData; + VToolCutInitData initData; initData.formula = dialogTool->GetFormula(); - initData.arcId = dialogTool->getArcId(); + initData.baseCurveId = dialogTool->getArcId(); initData.name = dialogTool->GetPointName(); initData.scene = scene; initData.doc = doc; @@ -109,6 +111,8 @@ VToolCutArc* VToolCutArc::Create(const QPointer &dialog, VMainGraphi initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix1 = dialogTool->GetAliasSuffix1(); + initData.aliasSuffix2 = dialogTool->GetAliasSuffix2(); VToolCutArc* point = Create(initData); if (point != nullptr) @@ -123,12 +127,12 @@ VToolCutArc* VToolCutArc::Create(const QPointer &dialog, VMainGraphi * @brief Create help create tool. * @param initData init data. */ -VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) +VToolCutArc* VToolCutArc::Create(VToolCutInitData &initData) { - const QSharedPointer arc = initData.data->GeometricObject(initData.arcId); + const QSharedPointer arc = initData.data->GeometricObject(initData.baseCurveId); //Declare special variable "CurrentLength" - VCurveLength *length = new VCurveLength(initData.arcId, initData.arcId, arc.data(), + VCurveLength *length = new VCurveLength(initData.baseCurveId, initData.baseCurveId, arc.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); initData.data->AddVariable(length); @@ -139,6 +143,9 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) VArc arc2; QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2); + arc1.SetAliasSuffix(initData.aliasSuffix1); + arc1.SetAliasSuffix(initData.aliasSuffix2); + VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); p->SetShowLabel(initData.showLabel); @@ -147,17 +154,25 @@ VToolCutArc* VToolCutArc::Create(VToolCutArcInitData &initData) if (initData.typeCreation == Source::FromGui) { initData.id = initData.data->AddGObject(p); + a1->setId(initData.data->getNextId()); - a2->setId(initData.data->getNextId()); + initData.data->RegisterUniqueName(a1); initData.data->AddArc(a1, a1->id(), initData.id); + + a2->setId(initData.data->getNextId()); + initData.data->RegisterUniqueName(a2); initData.data->AddArc(a2, a2->id(), initData.id); } else { initData.data->UpdateGObject(initData.id, p); + a1->setId(initData.id + 1); - a2->setId(initData.id + 2); + initData.data->RegisterUniqueName(a1); initData.data->AddArc(a1, a1->id(), initData.id); + + a2->setId(initData.id + 2); + initData.data->RegisterUniqueName(a2); initData.data->AddArc(a2, a2->id(), initData.id); if (initData.parse != Document::FullParse) @@ -212,12 +227,16 @@ void VToolCutArc::SaveDialog(QDomElement &domElement, QList &oldDepende const QPointer dialogTool = qobject_cast(m_dialog); SCASSERT(not dialogTool.isNull()) - AddDependence(oldDependencies, curveCutId); + AddDependence(oldDependencies, baseCurveId); AddDependence(newDependencies, dialogTool->getArcId()); doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId())); + 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()); @@ -230,7 +249,7 @@ void VToolCutArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrLength, formula); - doc->SetAttribute(tag, AttrArc, curveCutId); + doc->SetAttribute(tag, AttrArc, baseCurveId); } //--------------------------------------------------------------------------------------------------------------------- @@ -239,7 +258,7 @@ void VToolCutArc::ReadToolAttributes(const QDomElement &domElement) VToolCut::ReadToolAttributes(domElement); formula = doc->GetParametrString(domElement, AttrLength, QString()); - curveCutId = doc->GetParametrUInt(domElement, AttrArc, NULL_ID_STR); + baseCurveId = doc->GetParametrUInt(domElement, AttrArc, NULL_ID_STR); } //--------------------------------------------------------------------------------------------------------------------- @@ -250,10 +269,10 @@ void VToolCutArc::SetVisualization() VisToolCutArc *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->setObject1Id(curveCutId); + visual->setObject1Id(baseCurveId); visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(curveCutId); + const QSharedPointer curve = VAbstractTool::data.GeometricObject(baseCurveId); visual->setLineStyle(LineStyleToPenStyle(curve->GetPenStyle())); visual->RefreshGeometry(); @@ -263,7 +282,7 @@ void VToolCutArc::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- QString VToolCutArc::MakeToolTip() const { - const QSharedPointer arc = VAbstractTool::data.GeometricObject(curveCutId); + const QSharedPointer arc = VAbstractTool::data.GeometricObject(baseCurveId); const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables()); @@ -296,7 +315,7 @@ QString VToolCutArc::MakeToolTip() const .arg(arc.GetStartAngle()) .arg(arcStr + arcNumber + QChar(QChar::Space) + endAngleStr) .arg(arc.GetEndAngle()) - .arg(arcStr + arcNumber + QChar(QChar::Space) + tr("label"), arc.name()); + .arg(arcStr + arcNumber + QChar(QChar::Space) + tr("label"), arc.ObjectName()); return toolTip; }; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h index 785875651..0dc8c464d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h @@ -43,18 +43,6 @@ template class QSharedPointer; -struct VToolCutArcInitData : VToolSinglePointInitData -{ - VToolCutArcInitData() - : VToolSinglePointInitData(), - formula(), - arcId(NULL_ID) - {} - - QString formula; - quint32 arcId; -}; - /** * @brief The VToolCutArc class tool for cutting arc. */ @@ -65,7 +53,7 @@ public: virtual void setDialog() override; static VToolCutArc* Create(const QPointer &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutArc* Create(VToolCutArcInitData &initData); + static VToolCutArc* Create(VToolCutInitData &initData); static const QString ToolType; virtual int type() const override {return Type;} enum { Type = UserType + static_cast(Tool::CutArc)}; @@ -82,7 +70,7 @@ protected: private: Q_DISABLE_COPY(VToolCutArc) - VToolCutArc(const VToolCutArcInitData &initData, QGraphicsItem *parent = nullptr); + explicit VToolCutArc(const VToolCutInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLCUTARC_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 3c7308148..293408b87 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -65,8 +65,8 @@ const QString VToolCutSpline::AttrSpline = QStringLiteral("spline"); * @param initData init data. * @param parent parent object. */ -VToolCutSpline::VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem *parent) - :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splineId, initData.notes, parent) +VToolCutSpline::VToolCutSpline(const VToolCutInitData &initData, QGraphicsItem *parent) + :VToolCut(initData, parent) { ToolCreation(initData.typeCreation); } @@ -82,7 +82,7 @@ void VToolCutSpline::setDialog() SCASSERT(not dialogTool.isNull()) const QSharedPointer point = VAbstractTool::data.GeometricObject(m_id); dialogTool->SetFormula(formula); - dialogTool->setSplineId(curveCutId); + dialogTool->setSplineId(baseCurveId); dialogTool->SetPointName(point->name()); dialogTool->SetNotes(m_notes); } @@ -102,9 +102,9 @@ VToolCutSpline* VToolCutSpline::Create(const QPointer &dialog, VMain const QPointer dialogTool = qobject_cast(dialog); SCASSERT(not dialogTool.isNull()) - VToolCutSplineInitData initData; + VToolCutInitData initData; initData.formula = dialogTool->GetFormula(); - initData.splineId = dialogTool->getSplineId(); + initData.baseCurveId = dialogTool->getSplineId(); initData.name = dialogTool->GetPointName(); initData.scene = scene; initData.doc = doc; @@ -126,12 +126,12 @@ VToolCutSpline* VToolCutSpline::Create(const QPointer &dialog, VMain * @brief Create help create tool. * @param initData init data. */ -VToolCutSpline* VToolCutSpline::Create(VToolCutSplineInitData &initData) +VToolCutSpline* VToolCutSpline::Create(VToolCutInitData &initData) { - const auto spl = initData.data->GeometricObject(initData.splineId); + const auto spl = initData.data->GeometricObject(initData.baseCurveId); //Declare special variable "CurrentLength" - VCurveLength *length = new VCurveLength(initData.splineId, initData.splineId, spl.data(), + VCurveLength *length = new VCurveLength(initData.baseCurveId, initData.baseCurveId, spl.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); initData.data->AddVariable(length); @@ -211,7 +211,7 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement, QList &oldDepe const QPointer dialogTool = qobject_cast(m_dialog); SCASSERT(not dialogTool.isNull()) - AddDependence(oldDependencies, curveCutId); + AddDependence(oldDependencies, baseCurveId); AddDependence(newDependencies, dialogTool->getSplineId()); doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); @@ -229,7 +229,7 @@ void VToolCutSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrLength, formula); - doc->SetAttribute(tag, AttrSpline, curveCutId); + doc->SetAttribute(tag, AttrSpline, baseCurveId); } //--------------------------------------------------------------------------------------------------------------------- @@ -238,7 +238,7 @@ void VToolCutSpline::ReadToolAttributes(const QDomElement &domElement) VToolCut::ReadToolAttributes(domElement); formula = doc->GetParametrString(domElement, AttrLength, QString()); - curveCutId = doc->GetParametrUInt(domElement, AttrSpline, NULL_ID_STR); + baseCurveId = doc->GetParametrUInt(domElement, AttrSpline, NULL_ID_STR); } //--------------------------------------------------------------------------------------------------------------------- @@ -249,10 +249,10 @@ void VToolCutSpline::SetVisualization() VisToolCutSpline *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->setObject1Id(curveCutId); + visual->setObject1Id(baseCurveId); visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(curveCutId); + const QSharedPointer curve = VAbstractTool::data.GeometricObject(baseCurveId); visual->setLineStyle(LineStyleToPenStyle(curve->GetPenStyle())); visual->RefreshGeometry(); @@ -262,7 +262,7 @@ void VToolCutSpline::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- QString VToolCutSpline::MakeToolTip() const { - const auto spl = VAbstractTool::data.GeometricObject(curveCutId); + const auto spl = VAbstractTool::data.GeometricObject(baseCurveId); const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables()); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h index f309ae03a..ed7f7d6fe 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h @@ -43,18 +43,6 @@ template class QSharedPointer; -struct VToolCutSplineInitData : VToolSinglePointInitData -{ - VToolCutSplineInitData() - : VToolSinglePointInitData(), - formula(), - splineId(NULL_ID) - {} - - QString formula; - quint32 splineId; -}; - /** * @brief The VToolCutSpline class for tool CutSpline. This tool find point on spline and cut spline on two. */ @@ -65,7 +53,7 @@ public: virtual void setDialog() override; static VToolCutSpline *Create(const QPointer &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutSpline *Create(VToolCutSplineInitData &initData); + static VToolCutSpline *Create(VToolCutInitData &initData); static const QString ToolType; static const QString AttrSpline; virtual int type() const override {return Type;} @@ -83,7 +71,7 @@ protected: private: Q_DISABLE_COPY(VToolCutSpline) - VToolCutSpline(const VToolCutSplineInitData &initData, QGraphicsItem * parent = nullptr); + VToolCutSpline(const VToolCutInitData &initData, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTSPLINE_H 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 f184679cc..2636837ac 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -68,8 +68,8 @@ const QString VToolCutSplinePath::AttrSplinePath = QStringLiteral("splinePath"); * @param initData init data. * @param parent parent object. */ -VToolCutSplinePath::VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent) - :VToolCut(initData.doc, initData.data, initData.id, initData.formula, initData.splinePathId, initData.notes, parent) +VToolCutSplinePath::VToolCutSplinePath(const VToolCutInitData &initData, QGraphicsItem *parent) + :VToolCut(initData, parent) { ToolCreation(initData.typeCreation); } @@ -85,7 +85,7 @@ void VToolCutSplinePath::setDialog() SCASSERT(not dialogTool.isNull()) const QSharedPointer point = VAbstractTool::data.GeometricObject(m_id); dialogTool->SetFormula(formula); - dialogTool->setSplinePathId(curveCutId); + dialogTool->setSplinePathId(baseCurveId); dialogTool->SetPointName(point->name()); dialogTool->SetNotes(m_notes); } @@ -105,9 +105,9 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const QPointer &dialo const QPointer dialogTool = qobject_cast(dialog); SCASSERT(not dialogTool.isNull()) - VToolCutSplinePathInitData initData; + VToolCutInitData initData; initData.formula = dialogTool->GetFormula(); - initData.splinePathId = dialogTool->getSplinePathId(); + initData.baseCurveId = dialogTool->getSplinePathId(); initData.name = dialogTool->GetPointName(); initData.scene = scene; initData.doc = doc; @@ -129,13 +129,13 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const QPointer &dialo * @brief Create help create tool. * @param initData init data. */ -VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutSplinePathInitData &initData) +VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutInitData &initData) { - const auto splPath = initData.data->GeometricObject(initData.splinePathId); + const auto splPath = initData.data->GeometricObject(initData.baseCurveId); SCASSERT(splPath != nullptr) //Declare special variable "CurrentLength" - VCurveLength *length = new VCurveLength(initData.splinePathId, initData.splinePathId, splPath.data(), + VCurveLength *length = new VCurveLength(initData.baseCurveId, initData.baseCurveId, splPath.data(), *initData.data->GetPatternUnit()); length->SetName(currentLength); initData.data->AddVariable(length); @@ -302,7 +302,7 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement, QList &old const QPointer dialogTool = qobject_cast(m_dialog); SCASSERT(not dialogTool.isNull()) - AddDependence(oldDependencies, curveCutId); + AddDependence(oldDependencies, baseCurveId); AddDependence(newDependencies, dialogTool->getSplinePathId()); doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); @@ -320,7 +320,7 @@ void VToolCutSplinePath::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrLength, formula); - doc->SetAttribute(tag, AttrSplinePath, curveCutId); + doc->SetAttribute(tag, AttrSplinePath, baseCurveId); } //--------------------------------------------------------------------------------------------------------------------- @@ -329,7 +329,7 @@ void VToolCutSplinePath::ReadToolAttributes(const QDomElement &domElement) VToolCut::ReadToolAttributes(domElement); formula = doc->GetParametrString(domElement, AttrLength, QString()); - curveCutId = doc->GetParametrUInt(domElement, AttrSplinePath, NULL_ID_STR); + baseCurveId = doc->GetParametrUInt(domElement, AttrSplinePath, NULL_ID_STR); } //--------------------------------------------------------------------------------------------------------------------- @@ -340,10 +340,10 @@ void VToolCutSplinePath::SetVisualization() VisToolCutSplinePath *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->setObject1Id(curveCutId); + visual->setObject1Id(baseCurveId); visual->setLength(qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator())); - const QSharedPointer curve = VAbstractTool::data.GeometricObject(curveCutId); + const QSharedPointer curve = VAbstractTool::data.GeometricObject(baseCurveId); visual->setLineStyle(LineStyleToPenStyle(curve->GetPenStyle())); visual->RefreshGeometry(); @@ -353,7 +353,7 @@ void VToolCutSplinePath::SetVisualization() //--------------------------------------------------------------------------------------------------------------------- QString VToolCutSplinePath::MakeToolTip() const { - const auto splPath = VAbstractTool::data.GeometricObject(curveCutId); + const auto splPath = VAbstractTool::data.GeometricObject(baseCurveId); const QString expression = qApp->TrVars()->FormulaToUser(formula, qApp->Settings()->GetOsSeparator()); const qreal length = Visualization::FindValFromUser(expression, VAbstractTool::data.DataVariables()); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h index 7a31ba963..d800b297f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h @@ -44,18 +44,6 @@ class VSplinePath; template class QSharedPointer; -struct VToolCutSplinePathInitData : VToolSinglePointInitData -{ - VToolCutSplinePathInitData() - : VToolSinglePointInitData(), - formula(), - splinePathId(NULL_ID) - {} - - QString formula; - quint32 splinePathId; -}; - /** * @brief The VToolCutSplinePath class for tool CutSplinePath. This tool find point on splinePath and cut splinePath on * two. @@ -67,7 +55,7 @@ public: virtual void setDialog() override; static VToolCutSplinePath *Create(const QPointer &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); - static VToolCutSplinePath *Create(VToolCutSplinePathInitData &initData); + static VToolCutSplinePath *Create(VToolCutInitData &initData); static const QString ToolType; static const QString AttrSplinePath; virtual int type() const override {return Type;} @@ -90,7 +78,7 @@ protected: private: Q_DISABLE_COPY(VToolCutSplinePath) - VToolCutSplinePath(const VToolCutSplinePathInitData &initData, QGraphicsItem *parent = nullptr); + VToolCutSplinePath(const VToolCutInitData &initData, QGraphicsItem *parent = nullptr); }; #endif // VTOOLCUTSPLINEPATH_H From abff41813abfe4acbd1b1149ae4c817726080fda Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 17:40:02 +0200 Subject: [PATCH 15/23] Alias field for tool Cut Spline. --- .../core/vtooloptionspropertybrowser.cpp | 11 +++ src/app/valentina/xml/vpattern.cpp | 2 + .../vtools/dialogs/tools/dialogcutspline.cpp | 78 +++++++++++++++++++ .../vtools/dialogs/tools/dialogcutspline.h | 11 ++- .../vtools/dialogs/tools/dialogcutspline.ui | 24 +++++- .../toolcut/vtoolcutspline.cpp | 21 ++++- .../toolsinglepoint/toolcut/vtoolcutspline.h | 4 +- 7 files changed, 144 insertions(+), 7 deletions(-) diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index b3ac5507c..bf031bb7d 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -1544,6 +1544,12 @@ void VToolOptionsPropertyBrowser::ChangeDataToolCutSpline(VPE::VProperty *proper 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); } @@ -3321,6 +3329,9 @@ void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSpline() 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 b1a7c77f9..b09f53dd9 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -2041,6 +2041,8 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle initData.formula = GetParametrString(domElement, AttrLength, QChar('0')); const QString f = initData.formula;//need for saving fixed formula; initData.baseCurveId = GetParametrUInt(domElement, VToolCutSpline::AttrSpline, NULL_ID_STR); + initData.aliasSuffix1 = GetParametrEmptyString(domElement, AttrAlias1); + initData.aliasSuffix2 = GetParametrEmptyString(domElement, AttrAlias2); VToolCutSpline::Create(initData); //Rewrite attribute formula. Need for situation when we have wrong formula. diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 5834b2ecd..8d1d860c0 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -92,6 +92,9 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit); connect(ui->comboBoxSpline, &QComboBox::currentTextChanged, this, &DialogCutSpline::SplineChanged); + connect(ui->lineEditAlias1, &QLineEdit::textEdited, this, &DialogCutSpline::ValidateAlias); + connect(ui->lineEditAlias2, &QLineEdit::textEdited, this, &DialogCutSpline::ValidateAlias); + vis = new VisToolCutSpline(data); ui->tabWidget->setCurrentIndex(0); @@ -208,6 +211,55 @@ void DialogCutSpline::SplineChanged() CurrentCurveLength(getSplineId(), const_cast (data)); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSpline::ValidateAlias() +{ + VSpline spl1; + spl1.SetAliasSuffix(GetAliasSuffix1()); + if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(spl1.GetAlias())) + { + flagAlias1 = false; + ChangeColor(ui->labelAlias1, errorColor); + } + else + { + flagAlias1 = true; + ChangeColor(ui->labelAlias1, OkColor(this)); + } + + VSpline spl2; + spl2.SetAliasSuffix(GetAliasSuffix2()); + if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(spl2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { + flagAlias2 = true; + ChangeColor(ui->labelAlias2, OkColor(this)); + } + + if (spl1.GetAlias() == spl2.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 DialogCutSpline::DeployFormulaTextEdit() { @@ -279,3 +331,29 @@ QString DialogCutSpline::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSpline::SetAliasSuffix1(const QString &alias) +{ + ui->lineEditAlias1->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutSpline::GetAliasSuffix1() const +{ + return ui->lineEditAlias1->text(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSpline::SetAliasSuffix2(const QString &alias) +{ + ui->lineEditAlias2->setText(alias); + ValidateAlias(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogCutSpline::GetAliasSuffix2() const +{ + return ui->lineEditAlias2->text(); +} diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.h b/src/libs/vtools/dialogs/tools/dialogcutspline.h index 004baa916..060cb9d8a 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.h +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.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 SplineChanged(); + void ValidateAlias(); private: Q_DISABLE_COPY(DialogCutSpline) @@ -100,12 +107,14 @@ private: bool flagFormula; bool flagName; + bool flagAlias1{true}; + bool flagAlias2{true}; }; //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCutSpline::IsValid() const { - return flagFormula && flagName; + return flagFormula && flagName && flagAlias1 && flagAlias2; } #endif // DIALOGCUTSPLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.ui b/src/libs/vtools/dialogs/tools/dialogcutspline.ui index eb70a1e36..bd7071a13 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.ui +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.ui @@ -6,8 +6,8 @@ 0 0 - 324 - 240 + 527 + 379 @@ -255,6 +255,26 @@ + + + + Alias1: + + + + + + + + + + Alias2: + + + + + + diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 293408b87..84435bcd8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -85,6 +85,8 @@ void VToolCutSpline::setDialog() dialogTool->setSplineId(baseCurveId); dialogTool->SetPointName(point->name()); dialogTool->SetNotes(m_notes); + dialogTool->SetAliasSuffix1(m_aliasSuffix1); + dialogTool->SetAliasSuffix2(m_aliasSuffix2); } //--------------------------------------------------------------------------------------------------------------------- @@ -112,6 +114,8 @@ VToolCutSpline* VToolCutSpline::Create(const QPointer &dialog, VMain initData.parse = Document::FullParse; initData.typeCreation = Source::FromGui; initData.notes = dialogTool->GetNotes(); + initData.aliasSuffix1 = dialogTool->GetAliasSuffix1(); + initData.aliasSuffix2 = dialogTool->GetAliasSuffix2(); VToolCutSpline* point = Create(initData); if (point != nullptr) @@ -147,11 +151,17 @@ VToolCutSpline* VToolCutSpline::Create(VToolCutInitData &initData) auto spline1 = QSharedPointer(new VSpline(spl->GetP1(), spl1p2, spl1p3, *p)); auto spline2 = QSharedPointer(new VSpline(*p, spl2p2, spl2p3, spl->GetP4())); + spline1->SetAliasSuffix(initData.aliasSuffix1); + spline2->SetAliasSuffix(initData.aliasSuffix2); + if (initData.typeCreation == Source::FromGui) { initData.id = initData.data->AddGObject(p); initData.data->AddSpline(spline1, NULL_ID, initData.id); initData.data->AddSpline(spline2, NULL_ID, initData.id); + + initData.data->RegisterUniqueName(spline1); + initData.data->RegisterUniqueName(spline2); } else { @@ -159,6 +169,9 @@ VToolCutSpline* VToolCutSpline::Create(VToolCutInitData &initData) initData.data->AddSpline(spline1, NULL_ID, initData.id); initData.data->AddSpline(spline2, NULL_ID, initData.id); + initData.data->RegisterUniqueName(spline1); + initData.data->RegisterUniqueName(spline2); + if (initData.parse != Document::FullParse) { initData.doc->UpdateToolData(initData.id, initData.data); @@ -217,6 +230,10 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement, QList &oldDepe doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName()); doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula()); doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId())); + 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()); @@ -286,8 +303,8 @@ QString VToolCutSpline::MakeToolTip() const .arg(qApp->fromPixel(spline1.GetLength())) .arg(UnitsToStr(qApp->patternUnits(), true), curveStr + QLatin1String("2 ") + lengthStr) .arg(qApp->fromPixel(spline2.GetLength())) - .arg(curveStr + QLatin1String(" 1") + tr("label"), spline1.name(), - curveStr + QLatin1String(" 2") + tr("label"), spline2.name()); + .arg(curveStr + QLatin1String(" 1") + tr("label"), spline1.ObjectName(), + curveStr + QLatin1String(" 2") + tr("label"), spline2.ObjectName()); return toolTip; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h index ed7f7d6fe..953a1a18e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h @@ -51,7 +51,7 @@ class VToolCutSpline : public VToolCut Q_OBJECT public: virtual void setDialog() override; - static VToolCutSpline *Create(const QPointer &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, + static VToolCutSpline *Create(const QPointer &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, VContainer *data); static VToolCutSpline *Create(VToolCutInitData &initData); static const QString ToolType; @@ -71,7 +71,7 @@ protected: private: Q_DISABLE_COPY(VToolCutSpline) - VToolCutSpline(const VToolCutInitData &initData, QGraphicsItem * parent = nullptr); + explicit VToolCutSpline(const VToolCutInitData &initData, QGraphicsItem * parent = nullptr); }; #endif // VTOOLCUTSPLINE_H From 3e682b180c1bb0f51596ebf8dc3a8760b665935b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 17:58:06 +0200 Subject: [PATCH 16/23] 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; From 061c9b502af5ed20d4b9b12132b534f08b5398f1 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 6 Nov 2020 14:48:37 +0200 Subject: [PATCH 17/23] Use a regex to validate alias. --- src/libs/vtools/dialogs/tools/dialogarc.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogcutarc.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogcutspline.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogspline.cpp | 5 ++++- src/libs/vtools/dialogs/tools/dialogsplinepath.cpp | 5 ++++- 10 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index 363c47d92..a3f263ee9 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -48,6 +48,7 @@ #include "../vmisc/vcommonsettings.h" #include "ui_dialogarc.h" #include "../vgeometry/varc.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -356,9 +357,11 @@ void DialogArc::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogArc::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && not data->IsUnique(arc.GetAlias())) + if (not GetAliasSuffix().isEmpty() && + (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 2709d6304..53889f68b 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -48,6 +48,7 @@ #include "../../visualization/visualization.h" #include "ui_dialogarcwithlength.h" #include "../vgeometry/varc.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent) @@ -393,9 +394,11 @@ void DialogArcWithLength::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && not data->IsUnique(arc.GetAlias())) + if (not GetAliasSuffix().isEmpty() && + (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index a1ae6a29d..0abe851dc 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -42,6 +42,7 @@ #include "../vpatterndb/vcontainer.h" #include "dialogtool.h" #include "ui_dialogcubicbezier.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- DialogCubicBezier::DialogCubicBezier(const VContainer *data, quint32 toolId, QWidget *parent) @@ -265,9 +266,11 @@ void DialogCubicBezier::SaveData() //--------------------------------------------------------------------------------------------------------------------- void DialogCubicBezier::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VCubicBezier spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(spline.GetAlias())) + if (not ui->lineEditAlias->text().isEmpty() && + (not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index 92831ef3b..6b10de924 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -54,6 +54,7 @@ #include "../vwidgets/vabstractmainwindow.h" #include "dialogtool.h" #include "ui_dialogcubicbezierpath.h" +#include "../qmuparser/qmudef.h" class QWidget; @@ -254,9 +255,11 @@ void DialogCubicBezierPath::currentPointChanged(int index) //--------------------------------------------------------------------------------------------------------------------- void DialogCubicBezierPath::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VCubicBezierPath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(tempPath.GetAlias())) + if (not ui->lineEditAlias->text().isEmpty() && + (not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 24a24e356..41aa68a61 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vcommonsettings.h" #include "ui_dialogcutarc.h" #include "../vgeometry/varc.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -207,9 +208,11 @@ void DialogCutArc::ArcChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogCutArc::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VArc arc1; arc1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(arc1.GetAlias())) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(arc1.GetAlias()).hasMatch() || not data->IsUnique(arc1.GetAlias()))) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 8d1d860c0..854caaf70 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vcommonsettings.h" #include "ui_dialogcutspline.h" #include "../vgeometry/vspline.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -214,9 +215,11 @@ void DialogCutSpline::SplineChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogCutSpline::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VSpline spl1; spl1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(spl1.GetAlias())) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(spl1.GetAlias()).hasMatch() || not data->IsUnique(spl1.GetAlias()))) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index dac741413..412caa5c7 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -47,6 +47,7 @@ #include "../vmisc/vcommonsettings.h" #include "ui_dialogcutsplinepath.h" #include "../vgeometry/vsplinepath.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -214,9 +215,11 @@ void DialogCutSplinePath::SplinePathChanged() //--------------------------------------------------------------------------------------------------------------------- void DialogCutSplinePath::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VSplinePath path1; path1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && not data->IsUnique(path1.GetAlias())) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(path1.GetAlias()).hasMatch() || not data->IsUnique(path1.GetAlias()))) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 1d5766d95..058913369 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -48,6 +48,7 @@ #include "../vmisc/vcommonsettings.h" #include "ui_dialogellipticalarc.h" #include "../vgeometry/vellipticalarc.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -598,9 +599,11 @@ void DialogEllipticalArc::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogEllipticalArc::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VEllipticalArc arc; arc.SetAliasSuffix(GetAliasSuffix()); - if (not GetAliasSuffix().isEmpty() && not data->IsUnique(arc.GetAlias())) + if (not GetAliasSuffix().isEmpty() && + (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 94cde26a4..9c8404846 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -56,6 +56,7 @@ #include "../vwidgets/vmaingraphicsscene.h" #include "ui_dialogspline.h" #include "vtranslatevars.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -437,9 +438,11 @@ void DialogSpline::EvalLength2() //--------------------------------------------------------------------------------------------------------------------- void DialogSpline::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VSpline spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(spline.GetAlias())) + if (not ui->lineEditAlias->text().isEmpty() && + (not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index d628aaca6..b8637dddc 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -63,6 +63,7 @@ #include "../vwidgets/vmaingraphicsscene.h" #include "ui_dialogsplinepath.h" #include "vtranslatevars.h" +#include "../qmuparser/qmudef.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -498,9 +499,11 @@ void DialogSplinePath::FXLength2() //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::ValidateAlias() { + QRegularExpression rx(NameRegExp()); VSplinePath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); - if (not ui->lineEditAlias->text().isEmpty() && not data->IsUnique(tempPath.GetAlias())) + if (not ui->lineEditAlias->text().isEmpty() && + (not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); From 3feddb9ce99d4b1bf0b207684ca19f8d12144f68 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 11:18:13 +0200 Subject: [PATCH 18/23] Fix alias validation bug. --- src/libs/vtools/dialogs/tools/dialogarc.cpp | 6 +- src/libs/vtools/dialogs/tools/dialogarc.h | 2 + .../dialogs/tools/dialogarcwithlength.cpp | 6 +- .../dialogs/tools/dialogarcwithlength.h | 2 + .../dialogs/tools/dialogcubicbezier.cpp | 6 +- .../vtools/dialogs/tools/dialogcubicbezier.h | 2 + .../dialogs/tools/dialogcubicbezierpath.cpp | 6 +- .../dialogs/tools/dialogcubicbezierpath.h | 2 + .../vtools/dialogs/tools/dialogcutarc.cpp | 47 ++-- src/libs/vtools/dialogs/tools/dialogcutarc.h | 3 + .../vtools/dialogs/tools/dialogcutspline.cpp | 47 ++-- .../vtools/dialogs/tools/dialogcutspline.h | 3 + .../dialogs/tools/dialogcutsplinepath.cpp | 47 ++-- .../dialogs/tools/dialogcutsplinepath.h | 3 + .../dialogs/tools/dialogellipticalarc.cpp | 6 +- .../dialogs/tools/dialogellipticalarc.h | 2 + .../dialogs/tools/dialogflippingbyaxis.cpp | 207 ++++++++++++++++-- .../vtools/dialogs/tools/dialogspline.cpp | 8 +- src/libs/vtools/dialogs/tools/dialogspline.h | 2 + .../vtools/dialogs/tools/dialogsplinepath.cpp | 8 +- .../vtools/dialogs/tools/dialogsplinepath.h | 2 + 21 files changed, 307 insertions(+), 110 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index a3f263ee9..83ce97da4 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -244,7 +244,8 @@ QString DialogArc::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogArc::SetAliasSuffix(const QString &alias) { - ui->lineEditAlias->setText(alias); + originAliasSuffix = alias; + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); } @@ -361,7 +362,8 @@ void DialogArc::ValidateAlias() VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); if (not GetAliasSuffix().isEmpty() && - (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) + (not rx.match(arc.GetAlias()).hasMatch() || + (originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogarc.h b/src/libs/vtools/dialogs/tools/dialogarc.h index 9f9cec67c..9eb896f49 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.h +++ b/src/libs/vtools/dialogs/tools/dialogarc.h @@ -146,6 +146,8 @@ private: qreal angleF1; qreal angleF2; + QString originAliasSuffix{}; + void EvalRadius(); void EvalF(); }; diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 53889f68b..c1ec97df7 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -270,7 +270,8 @@ QString DialogArcWithLength::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogArcWithLength::SetAliasSuffix(const QString &alias) { - ui->lineEditAlias->setText(alias); + originAliasSuffix = alias; + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); } @@ -398,7 +399,8 @@ void DialogArcWithLength::ValidateAlias() VArc arc; arc.SetAliasSuffix(GetAliasSuffix()); if (not GetAliasSuffix().isEmpty() && - (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) + (not rx.match(arc.GetAlias()).hasMatch() || + (originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.h b/src/libs/vtools/dialogs/tools/dialogarcwithlength.h index 107230fa0..ea69c1bbc 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.h +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.h @@ -137,6 +137,8 @@ private: int formulaBaseHeightF1; int formulaBaseHeightLength; + QString originAliasSuffix{}; + void Radius(); void Length(); void EvalF(); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp index 0abe851dc..306423f6a 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.cpp @@ -109,7 +109,8 @@ void DialogCubicBezier::SetSpline(const VCubicBezier &spline) ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); ui->doubleSpinBoxApproximationScale->setValue(spl.GetApproximationScale()); - ui->lineEditAlias->setText(spl.GetAliasSuffix()); + originAliasSuffix = spl.GetAliasSuffix(); + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); auto path = qobject_cast(vis); @@ -270,7 +271,8 @@ void DialogCubicBezier::ValidateAlias() VCubicBezier spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); if (not ui->lineEditAlias->text().isEmpty() && - (not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) + (not rx.match(spline.GetAlias()).hasMatch() || + (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h index 3b1ee58cf..a16a5b593 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezier.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezier.h @@ -83,6 +83,8 @@ private: bool flagError; bool flagAlias{true}; + QString originAliasSuffix{}; + const QSharedPointer GetP1() const; const QSharedPointer GetP2() const; const QSharedPointer GetP3() const; diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp index 6b10de924..e583126a0 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.cpp @@ -115,7 +115,8 @@ void DialogCubicBezierPath::SetPath(const VCubicBezierPath &value) ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale()); - ui->lineEditAlias->setText(path.GetAliasSuffix()); + originAliasSuffix = path.GetAliasSuffix(); + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle()); @@ -259,7 +260,8 @@ void DialogCubicBezierPath::ValidateAlias() VCubicBezierPath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); if (not ui->lineEditAlias->text().isEmpty() && - (not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) + (not rx.match(tempPath.GetAlias()).hasMatch() || + (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h index 60f91bfe8..ecea40812 100644 --- a/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h +++ b/src/libs/vtools/dialogs/tools/dialogcubicbezierpath.h @@ -83,6 +83,8 @@ private: bool flagError; bool flagAlias{true}; + QString originAliasSuffix{}; + void NewItem(const VPointF &point); void DataPoint(const VPointF &p); void SavePath(); diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp index 41aa68a61..eea074655 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.cpp @@ -209,46 +209,37 @@ void DialogCutArc::ArcChanged() void DialogCutArc::ValidateAlias() { QRegularExpression rx(NameRegExp()); + VArc arc1; arc1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && - (not rx.match(arc1.GetAlias()).hasMatch() || not data->IsUnique(arc1.GetAlias()))) - { - flagAlias1 = false; - ChangeColor(ui->labelAlias1, errorColor); - } - else - { - flagAlias1 = true; - ChangeColor(ui->labelAlias1, OkColor(this)); - } VArc arc2; arc2.SetAliasSuffix(GetAliasSuffix2()); - if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(arc2.GetAlias())) - { - flagAlias2 = false; - ChangeColor(ui->labelAlias2, errorColor); - } - else - { - flagAlias2 = true; - ChangeColor(ui->labelAlias2, OkColor(this)); - } - if (arc1.GetAlias() == arc2.GetAlias()) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(arc1.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(arc1.GetAlias())) || + arc1.GetAlias() == arc2.GetAlias())) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); - - flagAlias2 = false; - ChangeColor(ui->labelAlias2, errorColor); } else { flagAlias1 = true; ChangeColor(ui->labelAlias1, OkColor(this)); + } + if (not GetAliasSuffix2().isEmpty() && + (not rx.match(arc2.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(arc2.GetAlias())) || + arc1.GetAlias() == arc2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { flagAlias2 = true; ChangeColor(ui->labelAlias2, OkColor(this)); } @@ -338,7 +329,8 @@ QString DialogCutArc::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutArc::SetAliasSuffix1(const QString &alias) { - ui->lineEditAlias1->setText(alias); + originAliasSuffix1 = alias; + ui->lineEditAlias1->setText(originAliasSuffix1); ValidateAlias(); } @@ -351,7 +343,8 @@ QString DialogCutArc::GetAliasSuffix1() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutArc::SetAliasSuffix2(const QString &alias) { - ui->lineEditAlias2->setText(alias); + originAliasSuffix2 = alias; + ui->lineEditAlias2->setText(originAliasSuffix2); ValidateAlias(); } diff --git a/src/libs/vtools/dialogs/tools/dialogcutarc.h b/src/libs/vtools/dialogs/tools/dialogcutarc.h index 385023b96..f4ba43101 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutarc.h +++ b/src/libs/vtools/dialogs/tools/dialogcutarc.h @@ -110,6 +110,9 @@ private: bool flagName; bool flagAlias1{true}; bool flagAlias2{true}; + + QString originAliasSuffix1{}; + QString originAliasSuffix2{}; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp index 854caaf70..0f41f71a9 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.cpp @@ -216,46 +216,37 @@ void DialogCutSpline::SplineChanged() void DialogCutSpline::ValidateAlias() { QRegularExpression rx(NameRegExp()); + VSpline spl1; spl1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && - (not rx.match(spl1.GetAlias()).hasMatch() || not data->IsUnique(spl1.GetAlias()))) - { - flagAlias1 = false; - ChangeColor(ui->labelAlias1, errorColor); - } - else - { - flagAlias1 = true; - ChangeColor(ui->labelAlias1, OkColor(this)); - } VSpline spl2; spl2.SetAliasSuffix(GetAliasSuffix2()); - if (not GetAliasSuffix2().isEmpty() && not data->IsUnique(spl2.GetAlias())) - { - flagAlias2 = false; - ChangeColor(ui->labelAlias2, errorColor); - } - else - { - flagAlias2 = true; - ChangeColor(ui->labelAlias2, OkColor(this)); - } - if (spl1.GetAlias() == spl2.GetAlias()) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(spl1.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(spl1.GetAlias())) || + spl1.GetAlias() == spl2.GetAlias())) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); - - flagAlias2 = false; - ChangeColor(ui->labelAlias2, errorColor); } else { flagAlias1 = true; ChangeColor(ui->labelAlias1, OkColor(this)); + } + if (not GetAliasSuffix2().isEmpty() && + (not rx.match(spl2.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(spl2.GetAlias())) || + spl1.GetAlias() == spl2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { flagAlias2 = true; ChangeColor(ui->labelAlias2, OkColor(this)); } @@ -338,7 +329,8 @@ QString DialogCutSpline::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutSpline::SetAliasSuffix1(const QString &alias) { - ui->lineEditAlias1->setText(alias); + originAliasSuffix1 = alias; + ui->lineEditAlias1->setText(originAliasSuffix1); ValidateAlias(); } @@ -351,7 +343,8 @@ QString DialogCutSpline::GetAliasSuffix1() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutSpline::SetAliasSuffix2(const QString &alias) { - ui->lineEditAlias2->setText(alias); + originAliasSuffix2 = alias; + ui->lineEditAlias2->setText(originAliasSuffix2); ValidateAlias(); } diff --git a/src/libs/vtools/dialogs/tools/dialogcutspline.h b/src/libs/vtools/dialogs/tools/dialogcutspline.h index 060cb9d8a..04cd0fecd 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutspline.h +++ b/src/libs/vtools/dialogs/tools/dialogcutspline.h @@ -109,6 +109,9 @@ private: bool flagName; bool flagAlias1{true}; bool flagAlias2{true}; + + QString originAliasSuffix1{}; + QString originAliasSuffix2{}; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp index 412caa5c7..f49581936 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.cpp @@ -216,46 +216,37 @@ void DialogCutSplinePath::SplinePathChanged() void DialogCutSplinePath::ValidateAlias() { QRegularExpression rx(NameRegExp()); + VSplinePath path1; path1.SetAliasSuffix(GetAliasSuffix1()); - if (not GetAliasSuffix1().isEmpty() && - (not rx.match(path1.GetAlias()).hasMatch() || 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()) + if (not GetAliasSuffix1().isEmpty() && + (not rx.match(path1.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix1() && not data->IsUnique(path1.GetAlias())) || + path1.GetAlias() == path2.GetAlias())) { flagAlias1 = false; ChangeColor(ui->labelAlias1, errorColor); - - flagAlias2 = false; - ChangeColor(ui->labelAlias2, errorColor); } else { flagAlias1 = true; ChangeColor(ui->labelAlias1, OkColor(this)); + } + if (not GetAliasSuffix2().isEmpty() && + (not rx.match(path2.GetAlias()).hasMatch() || + (originAliasSuffix2 != GetAliasSuffix2() && not data->IsUnique(path2.GetAlias())) || + path1.GetAlias() == path2.GetAlias())) + { + flagAlias2 = false; + ChangeColor(ui->labelAlias2, errorColor); + } + else + { flagAlias2 = true; ChangeColor(ui->labelAlias2, OkColor(this)); } @@ -338,7 +329,8 @@ QString DialogCutSplinePath::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutSplinePath::SetAliasSuffix1(const QString &alias) { - ui->lineEditAlias1->setText(alias); + originAliasSuffix1 = alias; + ui->lineEditAlias1->setText(originAliasSuffix1); ValidateAlias(); } @@ -351,7 +343,8 @@ QString DialogCutSplinePath::GetAliasSuffix1() const //--------------------------------------------------------------------------------------------------------------------- void DialogCutSplinePath::SetAliasSuffix2(const QString &alias) { - ui->lineEditAlias2->setText(alias); + originAliasSuffix2 = alias; + ui->lineEditAlias2->setText(originAliasSuffix2); ValidateAlias(); } diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h index 5963e82cf..41e132e31 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h @@ -108,6 +108,9 @@ private: bool flagName; bool flagAlias1{true}; bool flagAlias2{true}; + + QString originAliasSuffix1{}; + QString originAliasSuffix2{}; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 058913369..9ec1af735 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -603,7 +603,8 @@ void DialogEllipticalArc::ValidateAlias() VEllipticalArc arc; arc.SetAliasSuffix(GetAliasSuffix()); if (not GetAliasSuffix().isEmpty() && - (not rx.match(arc.GetAlias()).hasMatch() || not data->IsUnique(arc.GetAlias()))) + (not rx.match(arc.GetAlias()).hasMatch() || + (originAliasSuffix != GetAliasSuffix() && not data->IsUnique(arc.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); @@ -632,7 +633,8 @@ QString DialogEllipticalArc::GetNotes() const //--------------------------------------------------------------------------------------------------------------------- void DialogEllipticalArc::SetAliasSuffix(const QString &alias) { - ui->lineEditAlias->setText(alias); + originAliasSuffix = alias; + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); } diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h index 20338ff43..69d798775 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.h +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.h @@ -173,6 +173,8 @@ private: qreal angleF2; qreal angleRotation; + QString originAliasSuffix{}; + void EvalRadiuses(); void EvalAngles(); }; diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp index 0f5d6d7d6..9cb7a6c04 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp @@ -64,7 +64,6 @@ DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogFlippingByAxis), - objects(), stage1(true), m_suffix(), flagName(true), @@ -87,6 +86,9 @@ DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolI connect(ui->comboBoxOriginPoint, &QComboBox::currentTextChanged, this, &DialogFlippingByAxis::PointChanged); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogFlippingByAxis::ShowSourceDetails); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogFlippingByAxis::AliasChanged); + vis = new VisToolFlippingByAxis(data); ui->tabWidget->setCurrentIndex(0); @@ -147,12 +149,6 @@ void DialogFlippingByAxis::SetSuffix(const QString &value) ui->lineEditSuffix->setText(value); } -//--------------------------------------------------------------------------------------------------------------------- -QVector DialogFlippingByAxis::GetObjects() const -{ - return ConvertToVector(objects); -} - //--------------------------------------------------------------------------------------------------------------------- QString DialogFlippingByAxis::GetVisibilityGroupName() const { @@ -201,7 +197,7 @@ void DialogFlippingByAxis::ShowDialog(bool click) { if (stage1 && not click) { - if (objects.isEmpty()) + if (sourceObjects.isEmpty()) { return; } @@ -214,7 +210,7 @@ void DialogFlippingByAxis::ShowDialog(bool click) VisToolFlippingByAxis *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->VisualMode(); scene->ToggleArcSelection(false); @@ -229,6 +225,8 @@ void DialogFlippingByAxis::ShowDialog(bool click) qApp->getSceneView()->AllowRubberBand(false); + FillSourceList(); + emit ToolTip(tr("Select origin point")); } else if (not stage1 && prepare && click) @@ -240,6 +238,19 @@ void DialogFlippingByAxis::ShowDialog(bool click) } } +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByAxis::GetSourceObjects() const +{ + return sourceObjects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetSourceObjects(const QVector &value) +{ + sourceObjects = value; + FillSourceList(); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type) { @@ -247,7 +258,10 @@ void DialogFlippingByAxis::ChosenObject(quint32 id, const SceneObject &type) { if (type == SceneObject::Point) { - if (objects.contains(id)) + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); + + if (obj != sourceObjects.end()) { emit ToolTip(tr("Select origin point that is not part of the list of objects")); return; @@ -272,16 +286,23 @@ void DialogFlippingByAxis::SelectedObject(bool selected, quint32 object, quint32 Q_UNUSED(tool) if (stage1) { + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [object](const SourceItem &sItem) { return sItem.id == object; }); if (selected) { - if (not objects.contains(object)) + if (obj == sourceObjects.cend()) { - objects.append(object); + SourceItem item; + item.id = object; + sourceObjects.append(item); } } else { - objects.removeOne(object); + if (obj != sourceObjects.end()) + { + sourceObjects.erase(obj); + } } } } @@ -297,6 +318,7 @@ void DialogFlippingByAxis::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -313,6 +335,7 @@ void DialogFlippingByAxis::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -337,6 +360,7 @@ void DialogFlippingByAxis::GroupNameChanged() { flagGroupName = false; ChangeColor(ui->labelGroupName, errorColor); + ui->labelStatus->setText(tr("Invalid group name")); CheckState(); return; } @@ -347,6 +371,63 @@ void DialogFlippingByAxis::GroupNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ShowSourceDetails(int row) +{ + ui->lineEditAlias->setDisabled(true); + + if (ui->listWidget->count() == 0) + { + return; + } + + const auto sourceItem = qvariant_cast(ui->listWidget->item(row)->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:")); + + ui->lineEditAlias->blockSignals(true); + ui->lineEditAlias->setText(sourceItem.alias); + ui->lineEditAlias->setEnabled(true); + ui->lineEditAlias->blockSignals(false); + + QRegularExpression rx(NameRegExp()); + if (not rx.match(sourceItem.alias).hasMatch() || not data->IsUnique(sourceItem.alias)) + { + flagAlias = false; + ChangeColor(ui->labelAlias, errorColor); + ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + CheckState(); + return; + } + else + { + flagAlias = true; + ChangeColor(ui->labelAlias, errorColor); + CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::AliasChanged(const QString &text) +{ + if (ui->listWidget->count() == 0) + { + return; + } + + if (auto *item = ui->listWidget->currentItem()) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceItem.alias = text; + + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + + ValidateSourceAliases(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByAxis::ShowVisualization() { @@ -358,10 +439,22 @@ void DialogFlippingByAxis::SaveData() { m_suffix = ui->lineEditSuffix->text(); + sourceObjects.clear(); + sourceObjects.reserve(ui->listWidget->count()); + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceObjects.append(sourceItem); + } + } + VisToolFlippingByAxis *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->SetOriginPointId(GetOriginPointId()); operation->SetAxisType(GetAxisType()); operation->RefreshGeometry(); @@ -383,9 +476,13 @@ void DialogFlippingByAxis::SaveData() void DialogFlippingByAxis::PointChanged() { QColor color; - if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) + quint32 id = getCurrentObjectId(ui->comboBoxOriginPoint); + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); + if (obj != sourceObjects.end()) { flagError = false; + ui->labelStatus->setText(tr("Invalid point")); color = errorColor; } else @@ -406,6 +503,73 @@ void DialogFlippingByAxis::FillComboBoxAxisType(QComboBox *box) box->addItem(tr("Horizontal axis"), QVariant(static_cast(AxisType::HorizontalAxis))); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::FillSourceList() +{ + ui->listWidget->blockSignals(true); + + ui->listWidget->clear(); + + int row = -1; + + for (auto &sourceItem : sourceObjects) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + auto *item = new QListWidgetItem(obj->ObjectName()); + item->setToolTip(obj->ObjectName()); + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + ui->listWidget->insertItem(++row, item); + } + + ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } + + ValidateSourceAliases(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::ValidateSourceAliases() +{ + QRegularExpression rx(NameRegExp()); + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + QString name; + + if (obj->getType() == GOType::Point) + { + name = sourceItem.alias; + } + else + { + const QString oldAlias = obj->GetAliasSuffix(); + obj->SetAliasSuffix(sourceItem.alias); + name = obj->GetAlias(); + obj->SetAliasSuffix(oldAlias); + } + + if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + { + flagAlias = false; + ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + CheckState(); + return; + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByAxis::SetNotes(const QString ¬es) { @@ -417,3 +581,16 @@ QString DialogFlippingByAxis::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogFlippingByAxis::IsValid() const +{ + bool ready = flagError && flagName && flagGroupName && flagAlias; + + if (ready) + { + ui->labelStatus->setText(tr("Ready")); + } + + return ready; +} diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index 9c8404846..a781a2bf6 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -439,10 +439,13 @@ void DialogSpline::EvalLength2() void DialogSpline::ValidateAlias() { QRegularExpression rx(NameRegExp()); + VSpline spline = spl; spline.SetAliasSuffix(ui->lineEditAlias->text()); + if (not ui->lineEditAlias->text().isEmpty() && - (not rx.match(spline.GetAlias()).hasMatch() || not data->IsUnique(spline.GetAlias()))) + (not rx.match(spline.GetAlias()).hasMatch() || + (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(spline.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); @@ -613,7 +616,8 @@ void DialogSpline::SetSpline(const VSpline &spline) ui->plainTextEditLength2F->setPlainText(length2F); ui->lineEditSplineName->setText(qApp->TrVars()->VarToUser(spl.name())); - ui->lineEditAlias->setText(spl.GetAliasSuffix()); + originAliasSuffix = spl.GetAliasSuffix(); + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); auto path = qobject_cast(vis); diff --git a/src/libs/vtools/dialogs/tools/dialogspline.h b/src/libs/vtools/dialogs/tools/dialogspline.h index c268cc825..92f40a14f 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.h +++ b/src/libs/vtools/dialogs/tools/dialogspline.h @@ -121,6 +121,8 @@ private: bool flagError; bool flagAlias{true}; + QString originAliasSuffix{}; + const QSharedPointer GetP1() const; const QSharedPointer GetP4() const; diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index b8637dddc..38340b41a 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -170,7 +170,8 @@ void DialogSplinePath::SetPath(const VSplinePath &value) ui->lineEditSplPathName->setText(qApp->TrVars()->VarToUser(path.name())); ui->doubleSpinBoxApproximationScale->setValue(path.GetApproximationScale()); - ui->lineEditAlias->setText(path.GetAliasSuffix()); + originAliasSuffix = path.GetAliasSuffix(); + ui->lineEditAlias->setText(originAliasSuffix); ValidateAlias(); ChangeCurrentData(ui->comboBoxPenStyle, path.GetPenStyle()); @@ -500,10 +501,13 @@ void DialogSplinePath::FXLength2() void DialogSplinePath::ValidateAlias() { QRegularExpression rx(NameRegExp()); + VSplinePath tempPath = path; tempPath.SetAliasSuffix(ui->lineEditAlias->text()); + if (not ui->lineEditAlias->text().isEmpty() && - (not rx.match(tempPath.GetAlias()).hasMatch() || not data->IsUnique(tempPath.GetAlias()))) + (not rx.match(tempPath.GetAlias()).hasMatch() || + (originAliasSuffix != ui->lineEditAlias->text() && not data->IsUnique(tempPath.GetAlias())))) { flagAlias = false; ChangeColor(ui->labelAlias, errorColor); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.h b/src/libs/vtools/dialogs/tools/dialogsplinepath.h index 6e6a58dd6..36f68bbea 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.h @@ -115,6 +115,8 @@ private: bool flagError; bool flagAlias{true}; + QString originAliasSuffix{}; + void EvalAngle1(); void EvalAngle2(); void EvalLength1(); From 99985d43e0d93b57329f01a7cba6f1e8419dd2cc Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 15:02:30 +0200 Subject: [PATCH 19/23] Alias support for group operations. --- src/libs/ifc/schema/pattern/v0.8.10.xsd | 1 + src/libs/vgeometry/varc.cpp | 18 ++ src/libs/vgeometry/vcubicbezier.cpp | 18 ++ src/libs/vgeometry/vcubicbezierpath.cpp | 18 ++ src/libs/vgeometry/vellipticalarc.cpp | 18 ++ src/libs/vgeometry/vgobject.h | 8 +- src/libs/vgeometry/vpointf.cpp | 15 ++ src/libs/vgeometry/vpointf.h | 3 + src/libs/vgeometry/vspline.cpp | 18 ++ src/libs/vgeometry/vsplinepath.cpp | 18 ++ .../dialogs/tools/dialogflippingbyaxis.cpp | 68 +++--- .../dialogs/tools/dialogflippingbyaxis.h | 22 +- .../dialogs/tools/dialogflippingbyaxis.ui | 46 +++- .../dialogs/tools/dialogflippingbyline.cpp | 216 +++++++++++++++-- .../dialogs/tools/dialogflippingbyline.h | 22 +- .../dialogs/tools/dialogflippingbyline.ui | 46 +++- src/libs/vtools/dialogs/tools/dialogmove.cpp | 213 +++++++++++++++-- src/libs/vtools/dialogs/tools/dialogmove.h | 23 +- src/libs/vtools/dialogs/tools/dialogmove.ui | 47 +++- .../vtools/dialogs/tools/dialogrotation.cpp | 219 ++++++++++++++++-- .../vtools/dialogs/tools/dialogrotation.h | 22 +- .../vtools/dialogs/tools/dialogrotation.ui | 40 +++- .../operation/flipping/vabstractflipping.cpp | 74 +++--- .../operation/flipping/vabstractflipping.h | 72 +++--- .../flipping/vtoolflippingbyaxis.cpp | 19 +- .../flipping/vtoolflippingbyline.cpp | 19 +- .../operation/vabstractoperation.cpp | 97 +++++--- .../drawTools/operation/vabstractoperation.h | 13 +- .../tools/drawTools/operation/vtoolmove.cpp | 144 +++++++----- .../tools/drawTools/operation/vtoolmove.h | 38 +-- .../drawTools/operation/vtoolrotation.cpp | 117 ++++++---- .../tools/drawTools/operation/vtoolrotation.h | 20 +- src/libs/vtools/tools/tools.pri | 2 + src/libs/vtools/tools/toolsdef.cpp | 105 +++++++++ src/libs/vtools/tools/toolsdef.h | 53 +++++ .../line/operation/visoperation.cpp | 2 +- .../line/operation/visoperation.h | 2 +- 37 files changed, 1513 insertions(+), 383 deletions(-) create mode 100644 src/libs/vtools/tools/toolsdef.cpp create mode 100644 src/libs/vtools/tools/toolsdef.h diff --git a/src/libs/ifc/schema/pattern/v0.8.10.xsd b/src/libs/ifc/schema/pattern/v0.8.10.xsd index 0eef3d1c6..73dbb01e0 100644 --- a/src/libs/ifc/schema/pattern/v0.8.10.xsd +++ b/src/libs/ifc/schema/pattern/v0.8.10.xsd @@ -183,6 +183,7 @@ + diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 244737781..545b2f98f 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -145,6 +145,12 @@ VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &pref VArc arc(center, GetRadius(), f1, f2); arc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + arc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + arc.SetColor(GetColor()); arc.SetPenStyle(GetPenStyle()); arc.SetFlipped(IsFlipped()); @@ -165,6 +171,12 @@ VArc VArc::Flip(const QLineF &axis, const QString &prefix) const VArc arc(center, GetRadius(), f1, f2); arc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + arc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + arc.SetColor(GetColor()); arc.SetPenStyle(GetPenStyle()); arc.SetFlipped(not IsFlipped()); @@ -185,6 +197,12 @@ VArc VArc::Move(qreal length, qreal angle, const QString &prefix) const VArc arc(center, GetRadius(), f1, f2); arc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + arc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + arc.SetColor(GetColor()); arc.SetPenStyle(GetPenStyle()); arc.SetFlipped(IsFlipped()); diff --git a/src/libs/vgeometry/vcubicbezier.cpp b/src/libs/vgeometry/vcubicbezier.cpp index 66559bc69..2f2303f2a 100644 --- a/src/libs/vgeometry/vcubicbezier.cpp +++ b/src/libs/vgeometry/vcubicbezier.cpp @@ -88,6 +88,12 @@ VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, con const VPointF p4 = GetP4().Rotate(originPoint, degrees); VCubicBezier curve(p1, p2, p3, p4); curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); @@ -103,6 +109,12 @@ VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const const VPointF p4 = GetP4().Flip(axis); VCubicBezier curve(p1, p2, p3, p4); curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); @@ -118,6 +130,12 @@ VCubicBezier VCubicBezier::Move(qreal length, qreal angle, const QString &prefix const VPointF p4 = GetP4().Move(length, angle); VCubicBezier curve(p1, p2, p3, p4); curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); diff --git a/src/libs/vgeometry/vcubicbezierpath.cpp b/src/libs/vgeometry/vcubicbezierpath.cpp index 2e2261092..ca94123a7 100644 --- a/src/libs/vgeometry/vcubicbezierpath.cpp +++ b/src/libs/vgeometry/vcubicbezierpath.cpp @@ -104,6 +104,12 @@ VCubicBezierPath VCubicBezierPath::Rotate(const QPointF &originPoint, qreal degr curve.append(point.Rotate(originPoint, degrees)); } curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); @@ -120,6 +126,12 @@ VCubicBezierPath VCubicBezierPath::Flip(const QLineF &axis, const QString &prefi curve.append(point.Flip(axis)); } curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); @@ -136,6 +148,12 @@ VCubicBezierPath VCubicBezierPath::Move(qreal length, qreal angle, const QString curve.append(point.Move(length, angle)); } curve.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + curve.SetAliasSuffix(GetAliasSuffix() + prefix); + } + curve.SetColor(GetColor()); curve.SetPenStyle(GetPenStyle()); curve.SetApproximationScale(GetApproximationScale()); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 0683dde6a..68b878de3 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -153,6 +153,12 @@ VEllipticalArc VEllipticalArc::Rotate(QPointF originPoint, qreal degrees, const VEllipticalArc elArc(VAbstractArc::GetCenter(), GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(), VAbstractArc::GetEndAngle(), GetRotationAngle()); elArc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + elArc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + elArc.SetColor(GetColor()); elArc.SetPenStyle(GetPenStyle()); elArc.SetFlipped(IsFlipped()); @@ -166,6 +172,12 @@ VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) c VEllipticalArc elArc(VAbstractArc::GetCenter(), GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(), VAbstractArc::GetEndAngle(), GetRotationAngle()); elArc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + elArc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + elArc.SetColor(GetColor()); elArc.SetPenStyle(GetPenStyle()); elArc.SetFlipped(not IsFlipped()); @@ -188,6 +200,12 @@ VEllipticalArc VEllipticalArc::Move(qreal length, qreal angle, const QString &pr VEllipticalArc elArc(oldCenter, GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(), VAbstractArc::GetEndAngle(), GetRotationAngle()); elArc.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + elArc.SetAliasSuffix(GetAliasSuffix() + prefix); + } + elArc.SetColor(GetColor()); elArc.SetPenStyle(GetPenStyle()); elArc.SetFlipped(IsFlipped()); diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index 2078d40c8..05f80a0e8 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -78,11 +78,11 @@ public: quint32 id() const; virtual void setId(const quint32 &id); - void SetAlias(const QString &alias); - QString GetAlias() const; + virtual void SetAlias(const QString &alias); + QString GetAlias() const; - virtual void SetAliasSuffix(const QString &aliasSuffix); - QString GetAliasSuffix() const; + virtual void SetAliasSuffix(const QString &aliasSuffix); + QString GetAliasSuffix() const; QString ObjectName() const; diff --git a/src/libs/vgeometry/vpointf.cpp b/src/libs/vgeometry/vpointf.cpp index cada4323c..ed15998d6 100644 --- a/src/libs/vgeometry/vpointf.cpp +++ b/src/libs/vgeometry/vpointf.cpp @@ -147,6 +147,7 @@ VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const const QPointF p = MovePF(toQPointF(), length, angle); VPointF moved(p, name() + prefix, mx(), my()); moved.SetShowLabel(IsShowLabel()); + return moved; } @@ -260,6 +261,20 @@ QJsonObject VPointF::ToJson() const return object; } +//--------------------------------------------------------------------------------------------------------------------- +void VPointF::SetAlias(const QString &alias) +{ + Q_UNUSED(alias); + // do nothing +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPointF::SetAliasSuffix(const QString &aliasSuffix) +{ + Q_UNUSED(aliasSuffix); + // do nothing +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees) { diff --git a/src/libs/vgeometry/vpointf.h b/src/libs/vgeometry/vpointf.h index 820afeebc..4381b2f2d 100644 --- a/src/libs/vgeometry/vpointf.h +++ b/src/libs/vgeometry/vpointf.h @@ -85,6 +85,9 @@ public: virtual QJsonObject ToJson() const override; + virtual void SetAlias(const QString &alias) override; + virtual void SetAliasSuffix(const QString &aliasSuffix) override; + static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees); static QPointF FlipPF(const QLineF &axis, const QPointF &point); static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle); diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 02e158c87..a9c6eaea9 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -122,6 +122,12 @@ VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString VSpline spl(p1, p2, p3, p4); spl.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + spl.SetAliasSuffix(GetAliasSuffix() + prefix); + } + spl.SetColor(GetColor()); spl.SetPenStyle(GetPenStyle()); spl.SetApproximationScale(GetApproximationScale()); @@ -139,6 +145,12 @@ VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const VSpline spl(p1, p2, p3, p4); spl.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + spl.SetAliasSuffix(GetAliasSuffix() + prefix); + } + spl.SetColor(GetColor()); spl.SetPenStyle(GetPenStyle()); spl.SetApproximationScale(GetApproximationScale()); @@ -156,6 +168,12 @@ VSpline VSpline::Move(qreal length, qreal angle, const QString &prefix) const VSpline spl(p1, p2, p3, p4); spl.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + spl.SetAliasSuffix(GetAliasSuffix() + prefix); + } + spl.SetColor(GetColor()); spl.SetPenStyle(GetPenStyle()); spl.SetApproximationScale(GetApproximationScale()); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 6e791eeee..e3ec4e726 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -122,6 +122,12 @@ VSplinePath VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const VSplinePath splPath(newPoints); splPath.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + splPath.SetAliasSuffix(GetAliasSuffix() + prefix); + } + splPath.SetColor(GetColor()); splPath.SetPenStyle(GetPenStyle()); splPath.SetApproximationScale(GetApproximationScale()); @@ -147,6 +153,12 @@ VSplinePath VSplinePath::Flip(const QLineF &axis, const QString &prefix) const VSplinePath splPath(newPoints); splPath.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + splPath.SetAliasSuffix(GetAliasSuffix() + prefix); + } + splPath.SetColor(GetColor()); splPath.SetPenStyle(GetPenStyle()); splPath.SetApproximationScale(GetApproximationScale()); @@ -172,6 +184,12 @@ VSplinePath VSplinePath::Move(qreal length, qreal angle, const QString &prefix) VSplinePath splPath(newPoints); splPath.setName(name() + prefix); + + if (not GetAliasSuffix().isEmpty()) + { + splPath.SetAliasSuffix(GetAliasSuffix() + prefix); + } + splPath.SetColor(GetColor()); splPath.SetPenStyle(GetPenStyle()); splPath.SetApproximationScale(GetApproximationScale()); diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp index 9cb7a6c04..b45d2a359 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.cpp @@ -249,6 +249,10 @@ void DialogFlippingByAxis::SetSourceObjects(const QVector &value) { sourceObjects = value; FillSourceList(); + + VisToolFlippingByAxis *operation = qobject_cast(vis); + SCASSERT(operation != nullptr) + operation->SetObjects(SourceToObjects(sourceObjects)); } //--------------------------------------------------------------------------------------------------------------------- @@ -392,21 +396,8 @@ void DialogFlippingByAxis::ShowSourceDetails(int row) ui->lineEditAlias->setEnabled(true); ui->lineEditAlias->blockSignals(false); - QRegularExpression rx(NameRegExp()); - if (not rx.match(sourceItem.alias).hasMatch() || not data->IsUnique(sourceItem.alias)) - { - flagAlias = false; - ChangeColor(ui->labelAlias, errorColor); - ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); - CheckState(); - return; - } - else - { - flagAlias = true; - ChangeColor(ui->labelAlias, errorColor); - CheckState(); - } + SetAliasValid(sourceItem.id, SourceAliasValid(sourceItem, obj, data, + OriginAlias(sourceItem.id, sourceObjects, obj))); } //--------------------------------------------------------------------------------------------------------------------- @@ -515,8 +506,9 @@ void DialogFlippingByAxis::FillSourceList() for (auto &sourceItem : sourceObjects) { const QSharedPointer obj = data->GetGObject(sourceItem.id); + bool valid = SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj)); - auto *item = new QListWidgetItem(obj->ObjectName()); + auto *item = new QListWidgetItem(valid ? obj->ObjectName() : obj->ObjectName() + '*'); item->setToolTip(obj->ObjectName()); item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); ui->listWidget->insertItem(++row, item); @@ -535,8 +527,6 @@ void DialogFlippingByAxis::FillSourceList() //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByAxis::ValidateSourceAliases() { - QRegularExpression rx(NameRegExp()); - for (int i=0; ilistWidget->count(); ++i) { if (const QListWidgetItem *item = ui->listWidget->item(i)) @@ -545,27 +535,39 @@ void DialogFlippingByAxis::ValidateSourceAliases() const QSharedPointer obj = data->GetGObject(sourceItem.id); - QString name; - - if (obj->getType() == GOType::Point) - { - name = sourceItem.alias; - } - else - { - const QString oldAlias = obj->GetAliasSuffix(); - obj->SetAliasSuffix(sourceItem.alias); - name = obj->GetAlias(); - obj->SetAliasSuffix(oldAlias); - } - - if (not rx.match(name).hasMatch() || not data->IsUnique(name)) + if (not SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj))) { flagAlias = false; ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + SetAliasValid(sourceItem.id, false); CheckState(); return; } + else + { + SetAliasValid(sourceItem.id, true); + } + } + } + + flagAlias = true; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByAxis::SetAliasValid(quint32 id, bool valid) +{ + if (ui->listWidget->currentRow() != -1) + { + auto *item = ui->listWidget->item(ui->listWidget->currentRow()); + const auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + if (id == sourceItem.id) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + item->setText(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + + ChangeColor(ui->labelAlias, valid ? OkColor(this) : errorColor); } } } diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h index 4f62e5004..2128c8048 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.h @@ -40,6 +40,7 @@ #include #include "../vmisc/def.h" +#include "../../tools/toolsdef.h" namespace Ui { @@ -63,8 +64,6 @@ public: QString GetSuffix() const; void SetSuffix(const QString &value); - QVector GetObjects() const; - QString GetVisibilityGroupName() const; void SetVisibilityGroupName(const QString &name); @@ -81,6 +80,9 @@ public: virtual void ShowDialog(bool click) override; + QVector GetSourceObjects() const; + void SetSourceObjects(const QVector &value); + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override; @@ -88,6 +90,8 @@ public slots: private slots: void SuffixChanged(); void GroupNameChanged(); + void ShowSourceDetails(int row); + void AliasChanged(const QString &text); protected: virtual void ShowVisualization() override; @@ -104,7 +108,7 @@ private: Ui::DialogFlippingByAxis *ui; - QList objects; + QVector sourceObjects{}; bool stage1; @@ -113,16 +117,16 @@ private: bool flagName; bool flagGroupName; bool flagError; + bool flagAlias{true}; QStringList m_groupTags{}; static void FillComboBoxAxisType(QComboBox *box); + + void FillSourceList(); + + void ValidateSourceAliases(); + void SetAliasValid(quint32 id, bool valid); }; -//--------------------------------------------------------------------------------------------------------------------- -inline bool DialogFlippingByAxis::IsValid() const -{ - return flagError && flagName && flagGroupName; -} - #endif // DIALOGFLIPPINGBYAXIS_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui index df35b0448..dada02ff6 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyaxis.ui @@ -6,8 +6,8 @@ 0 0 - 304 - 296 + 415 + 464 @@ -28,6 +28,35 @@ Tool + + + + Qt::Horizontal + + + + + + + + Alias: + + + + + + + false + + + true + + + + + + + @@ -48,7 +77,11 @@ - + + + true + + @@ -117,6 +150,13 @@ + + + + Ready + + + diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp index 6c050756a..d664e0f2e 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.cpp @@ -64,7 +64,6 @@ DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, quint32 toolId, QWidget *parent) : DialogTool(data, toolId, parent), ui(new Ui::DialogFlippingByLine), - objects(), stage1(true), m_suffix(), flagName(true), @@ -142,12 +141,6 @@ void DialogFlippingByLine::SetSuffix(const QString &value) ui->lineEditSuffix->setText(value); } -//--------------------------------------------------------------------------------------------------------------------- -QVector DialogFlippingByLine::GetObjects() const -{ - return ConvertToVector(objects); -} - //--------------------------------------------------------------------------------------------------------------------- QString DialogFlippingByLine::GetVisibilityGroupName() const { @@ -196,7 +189,7 @@ void DialogFlippingByLine::ShowDialog(bool click) { if (stage1 && not click) { - if (objects.isEmpty()) + if (sourceObjects.isEmpty()) { return; } @@ -209,7 +202,7 @@ void DialogFlippingByLine::ShowDialog(bool click) VisToolFlippingByLine *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->VisualMode(); scene->ToggleArcSelection(false); @@ -224,6 +217,8 @@ void DialogFlippingByLine::ShowDialog(bool click) qApp->getSceneView()->AllowRubberBand(false); + FillSourceList(); + emit ToolTip(tr("Select first line point")); } else if (not stage1 && prepare && click) @@ -234,6 +229,23 @@ void DialogFlippingByLine::ShowDialog(bool click) } } +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogFlippingByLine::GetSourceObjects() const +{ + return sourceObjects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetSourceObjects(const QVector &value) +{ + sourceObjects = value; + FillSourceList(); + + VisToolFlippingByLine *operation = qobject_cast(vis); + SCASSERT(operation != nullptr) + operation->SetObjects(SourceToObjects(sourceObjects)); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) { @@ -241,10 +253,12 @@ void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) { if (type == SceneObject::Point) { + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); switch (number) { case 0: - if (objects.contains(id)) + if (obj != sourceObjects.end()) { emit ToolTip(tr("Select first line point that is not part of the list of objects")); return; @@ -260,7 +274,7 @@ void DialogFlippingByLine::ChosenObject(quint32 id, const SceneObject &type) } break; case 1: - if (objects.contains(id)) + if (obj != sourceObjects.end()) { emit ToolTip(tr("Select second line point that is not part of the list of objects")); return; @@ -296,16 +310,23 @@ void DialogFlippingByLine::SelectedObject(bool selected, quint32 object, quint32 Q_UNUSED(tool) if (stage1) { + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [object](const SourceItem &sItem) { return sItem.id == object; }); if (selected) { - if (not objects.contains(object)) + if (obj == sourceObjects.cend()) { - objects.append(object); + SourceItem item; + item.id = object; + sourceObjects.append(item); } } else { - objects.removeOne(object); + if (obj != sourceObjects.end()) + { + sourceObjects.erase(obj); + } } } } @@ -321,6 +342,7 @@ void DialogFlippingByLine::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -337,6 +359,7 @@ void DialogFlippingByLine::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -361,6 +384,7 @@ void DialogFlippingByLine::GroupNameChanged() { flagGroupName = false; ChangeColor(ui->labelGroupName, errorColor); + ui->labelStatus->setText(tr("Invalid group name")); CheckState(); return; } @@ -371,6 +395,50 @@ void DialogFlippingByLine::GroupNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ShowSourceDetails(int row) +{ + ui->lineEditAlias->setDisabled(true); + + if (ui->listWidget->count() == 0) + { + return; + } + + const auto sourceItem = qvariant_cast(ui->listWidget->item(row)->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:")); + + ui->lineEditAlias->blockSignals(true); + ui->lineEditAlias->setText(sourceItem.alias); + ui->lineEditAlias->setEnabled(true); + ui->lineEditAlias->blockSignals(false); + + SetAliasValid(sourceItem.id, SourceAliasValid(sourceItem, obj, data, + OriginAlias(sourceItem.id, sourceObjects, obj))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::AliasChanged(const QString &text) +{ + if (ui->listWidget->count() == 0) + { + return; + } + + if (auto *item = ui->listWidget->currentItem()) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceItem.alias = text; + + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + + ValidateSourceAliases(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByLine::ShowVisualization() { @@ -382,10 +450,22 @@ void DialogFlippingByLine::SaveData() { m_suffix = ui->lineEditSuffix->text(); + sourceObjects.clear(); + sourceObjects.reserve(ui->listWidget->count()); + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceObjects.append(sourceItem); + } + } + VisToolFlippingByLine *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->SetFirstLinePointId(GetFirstLinePointId()); operation->SetSecondLinePointId(GetSecondLinePointId()); operation->RefreshGeometry(); @@ -411,29 +491,118 @@ void DialogFlippingByLine::PointChanged() ChangeColor(ui->labelFirstLinePoint, color); ChangeColor(ui->labelSecondLinePoint, color); + quint32 id1 = getCurrentObjectId(ui->comboBoxFirstLinePoint); + auto obj1 = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id1](const SourceItem &sItem) { return sItem.id == id1; }); + + quint32 id2 = getCurrentObjectId(ui->comboBoxSecondLinePoint); + auto obj2 = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id2](const SourceItem &sItem) { return sItem.id == id2; }); + if (getCurrentObjectId(ui->comboBoxFirstLinePoint) == getCurrentObjectId(ui->comboBoxSecondLinePoint)) { flagError = false; color = errorColor; ChangeColor(ui->labelFirstLinePoint, color); ChangeColor(ui->labelSecondLinePoint, color); + ui->labelStatus->setText(tr("Invalid line points")); } - else if (objects.contains(getCurrentObjectId(ui->comboBoxFirstLinePoint))) + else if (obj1 != sourceObjects.end()) { flagError = false; color = errorColor; ChangeColor(ui->labelFirstLinePoint, color); + ui->labelStatus->setText(tr("Invalid first line point")); } - else if (objects.contains(getCurrentObjectId(ui->comboBoxSecondLinePoint))) + else if (obj2 != sourceObjects.end()) { flagError = false; color = errorColor; ChangeColor(ui->labelSecondLinePoint, color); + ui->labelStatus->setText(tr("Invalid second line point")); } CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::FillSourceList() +{ + ui->listWidget->blockSignals(true); + + ui->listWidget->clear(); + + int row = -1; + + for (auto &sourceItem : sourceObjects) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + bool valid = SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj)); + + auto *item = new QListWidgetItem(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + item->setToolTip(obj->ObjectName()); + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + ui->listWidget->insertItem(++row, item); + } + + ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } + + ValidateSourceAliases(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::ValidateSourceAliases() +{ + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + if (not SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj))) + { + flagAlias = false; + ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + SetAliasValid(sourceItem.id, false); + CheckState(); + return; + } + else + { + SetAliasValid(sourceItem.id, true); + } + } + } + + flagAlias = true; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFlippingByLine::SetAliasValid(quint32 id, bool valid) +{ + if (ui->listWidget->currentRow() != -1) + { + auto *item = ui->listWidget->item(ui->listWidget->currentRow()); + const auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + if (id == sourceItem.id) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + item->setText(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + + ChangeColor(ui->labelAlias, valid ? OkColor(this) : errorColor); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogFlippingByLine::SetNotes(const QString ¬es) { @@ -445,3 +614,16 @@ QString DialogFlippingByLine::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogFlippingByLine::IsValid() const +{ + bool ready = flagError && flagName && flagGroupName && flagAlias; + + if (ready) + { + ui->labelStatus->setText(tr("Ready")); + } + + return ready; +} diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.h b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h index a00139c81..4a4dbf029 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.h +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.h @@ -40,6 +40,7 @@ #include #include "../vmisc/def.h" +#include "../../tools/toolsdef.h" namespace Ui { @@ -63,8 +64,6 @@ public: QString GetSuffix() const; void SetSuffix(const QString &value); - QVector GetObjects() const; - QString GetVisibilityGroupName() const; void SetVisibilityGroupName(const QString &name); @@ -81,6 +80,9 @@ public: virtual void ShowDialog(bool click) override; + QVector GetSourceObjects() const; + void SetSourceObjects(const QVector &value); + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override; @@ -88,6 +90,8 @@ public slots: private slots: void SuffixChanged(); void GroupNameChanged(); + void ShowSourceDetails(int row); + void AliasChanged(const QString &text); protected: virtual void ShowVisualization() override; @@ -104,7 +108,7 @@ private: Ui::DialogFlippingByLine *ui; - QList objects; + QVector sourceObjects{}; bool stage1; @@ -113,14 +117,14 @@ private: bool flagName; bool flagGroupName; bool flagError; + bool flagAlias{true}; QStringList m_groupTags{}; + + void FillSourceList(); + + void ValidateSourceAliases(); + void SetAliasValid(quint32 id, bool valid); }; -//--------------------------------------------------------------------------------------------------------------------- -inline bool DialogFlippingByLine::IsValid() const -{ - return flagError && flagName && flagGroupName; -} - #endif // DIALOGFLIPPINGBYLINE_H diff --git a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui index 41d39c969..3596a163c 100644 --- a/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui +++ b/src/libs/vtools/dialogs/tools/dialogflippingbyline.ui @@ -6,8 +6,8 @@ 0 0 - 319 - 301 + 387 + 440 @@ -28,6 +28,35 @@ Tool + + + + Qt::Horizontal + + + + + + + + Alias: + + + + + + + false + + + true + + + + + + + @@ -48,7 +77,11 @@ - + + + true + + @@ -117,6 +150,13 @@ + + + + Ready + + + diff --git a/src/libs/vtools/dialogs/tools/dialogmove.cpp b/src/libs/vtools/dialogs/tools/dialogmove.cpp index 43bcd90ec..95264f4d8 100644 --- a/src/libs/vtools/dialogs/tools/dialogmove.cpp +++ b/src/libs/vtools/dialogs/tools/dialogmove.cpp @@ -78,7 +78,6 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent) formulaBaseHeightAngle(0), formulaBaseHeightRotationAngle(0), formulaBaseHeightLength(0), - objects(), stage1(true), stage2(false), m_suffix(), @@ -143,6 +142,9 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent) connect(ui->pushButtonGrowRotationAngle, &QPushButton::clicked, this, &DialogMove::DeployRotationAngleTextEdit); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogMove::DeployLengthTextEdit); + connect(ui->listWidget, &QListWidget::currentRowChanged, this, &DialogMove::ShowSourceDetails); + connect(ui->lineEditAlias, &QLineEdit::textEdited, this, &DialogMove::AliasChanged); + vis = new VisToolMove(data); SetRotationOrigPointId(NULL_ID); @@ -257,12 +259,6 @@ void DialogMove::SetRotationOrigPointId(const quint32 &value) operation->SetRotationOriginPointId(value); } -//--------------------------------------------------------------------------------------------------------------------- -QVector DialogMove::GetObjects() const -{ - return ConvertToVector(objects); -} - //--------------------------------------------------------------------------------------------------------------------- QString DialogMove::GetVisibilityGroupName() const { @@ -311,7 +307,7 @@ void DialogMove::ShowDialog(bool click) { if (stage1 && not click) { - if (objects.isEmpty()) + if (sourceObjects.isEmpty()) { return; } @@ -325,7 +321,7 @@ void DialogMove::ShowDialog(bool click) VisToolMove *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->VisualMode(); VAbstractMainWindow *window = qobject_cast(qApp->getMainWindow()); @@ -343,6 +339,8 @@ void DialogMove::ShowDialog(bool click) scene->ToggleSplinePathHover(false); qApp->getSceneView()->AllowRubberBand(false); + + FillSourceList(); } else if (not stage2 && not stage1 && prepare && click) { @@ -416,16 +414,23 @@ void DialogMove::SelectedObject(bool selected, quint32 object, quint32 tool) Q_UNUSED(tool) if (stage1) { + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [object](const SourceItem &sItem) { return sItem.id == object; }); if (selected) { - if (not objects.contains(object)) + if (obj == sourceObjects.cend()) { - objects.append(object); + SourceItem item; + item.id = object; + sourceObjects.append(item); } } else { - objects.removeOne(object); + if (obj != sourceObjects.end()) + { + sourceObjects.erase(obj); + } } } } @@ -501,6 +506,7 @@ void DialogMove::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -517,6 +523,7 @@ void DialogMove::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -541,6 +548,7 @@ void DialogMove::GroupNameChanged() { flagGroupName = false; ChangeColor(ui->labelGroupName, errorColor); + ui->labelStatus->setText(tr("Invalid group name")); CheckState(); return; } @@ -551,6 +559,50 @@ void DialogMove::GroupNameChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::ShowSourceDetails(int row) +{ + ui->lineEditAlias->setDisabled(true); + + if (ui->listWidget->count() == 0) + { + return; + } + + const auto sourceItem = qvariant_cast(ui->listWidget->item(row)->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:")); + + ui->lineEditAlias->blockSignals(true); + ui->lineEditAlias->setText(sourceItem.alias); + ui->lineEditAlias->setEnabled(true); + ui->lineEditAlias->blockSignals(false); + + SetAliasValid(sourceItem.id, SourceAliasValid(sourceItem, obj, data, + OriginAlias(sourceItem.id, sourceObjects, obj))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::AliasChanged(const QString &text) +{ + if (ui->listWidget->count() == 0) + { + return; + } + + if (auto *item = ui->listWidget->currentItem()) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceItem.alias = text; + + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + + ValidateSourceAliases(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogMove::ShowVisualization() { @@ -565,10 +617,22 @@ void DialogMove::SaveData() formulaRotationAngle = ui->plainTextEditRotationAngle->toPlainText(); formulaLength = ui->plainTextEditLength->toPlainText(); + sourceObjects.clear(); + sourceObjects.reserve(ui->listWidget->count()); + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceObjects.append(sourceItem); + } + } + VisToolMove *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->SetAngle(formulaAngle); operation->SetLength(formulaLength); operation->SetRotationAngle(formulaRotationAngle); @@ -597,6 +661,23 @@ void DialogMove::closeEvent(QCloseEvent *event) DialogTool::closeEvent(event); } +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogMove::GetSourceObjects() const +{ + return sourceObjects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SetSourceObjects(const QVector &value) +{ + sourceObjects = value; + FillSourceList(); + + VisToolMove *operation = qobject_cast(vis); + SCASSERT(operation != nullptr) + operation->SetObjects(SourceToObjects(sourceObjects)); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogMove::EvalAngle() { @@ -609,6 +690,11 @@ void DialogMove::EvalAngle() formulaData.checkZero = false; Eval(formulaData, flagAngle); + + if (not flagAngle) + { + ui->labelStatus->setText(tr("Invalid angle formula")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -623,6 +709,11 @@ void DialogMove::EvalRotationAngle() formulaData.checkZero = false; Eval(formulaData, flagRotationAngle); + + if (not flagRotationAngle) + { + ui->labelStatus->setText(tr("Invalid rotation angle formula")); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -636,6 +727,89 @@ void DialogMove::EvalLength() formulaData.postfix = UnitsToStr(qApp->patternUnits(), true); Eval(formulaData, flagLength); + + if (not flagLength) + { + ui->labelStatus->setText(tr("Invalid length formula")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::FillSourceList() +{ + ui->listWidget->blockSignals(true); + + ui->listWidget->clear(); + + int row = -1; + + for (auto &sourceItem : sourceObjects) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + bool valid = SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj)); + + auto *item = new QListWidgetItem(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + item->setToolTip(obj->ObjectName()); + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + ui->listWidget->insertItem(++row, item); + } + + ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } + + ValidateSourceAliases(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::ValidateSourceAliases() +{ + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + if (not SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj))) + { + flagAlias = false; + ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + SetAliasValid(sourceItem.id, false); + CheckState(); + return; + } + else + { + SetAliasValid(sourceItem.id, true); + } + } + } + + flagAlias = true; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogMove::SetAliasValid(quint32 id, bool valid) +{ + if (ui->listWidget->currentRow() != -1) + { + auto *item = ui->listWidget->item(ui->listWidget->currentRow()); + const auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + if (id == sourceItem.id) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + item->setText(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + + ChangeColor(ui->labelAlias, valid ? OkColor(this) : errorColor); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -649,3 +823,16 @@ QString DialogMove::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogMove::IsValid() const +{ + bool ready = flagAngle && flagRotationAngle && flagLength && flagName && flagGroupName && flagAlias; + + if (ready) + { + ui->labelStatus->setText(tr("Ready")); + } + + return ready; +} diff --git a/src/libs/vtools/dialogs/tools/dialogmove.h b/src/libs/vtools/dialogs/tools/dialogmove.h index c67a4669e..f01c87198 100644 --- a/src/libs/vtools/dialogs/tools/dialogmove.h +++ b/src/libs/vtools/dialogs/tools/dialogmove.h @@ -39,6 +39,7 @@ #include "../vmisc/def.h" #include "dialogtool.h" +#include "../../tools/toolsdef.h" namespace Ui { @@ -68,8 +69,6 @@ public: quint32 GetRotationOrigPointId() const; void SetRotationOrigPointId(const quint32 &value); - QVector GetObjects() const; - QString GetVisibilityGroupName() const; void SetVisibilityGroupName(const QString &name); @@ -86,6 +85,9 @@ public: virtual void ShowDialog(bool click) override; + QVector GetSourceObjects() const; + void SetSourceObjects(const QVector &value); + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override; @@ -103,6 +105,9 @@ private slots: void SuffixChanged(); void GroupNameChanged(); + void ShowSourceDetails(int row); + void AliasChanged(const QString &text); + protected: virtual void ShowVisualization() override; @@ -130,7 +135,7 @@ private: int formulaBaseHeightRotationAngle; int formulaBaseHeightLength; - QList objects; + QVector sourceObjects{}; bool stage1; bool stage2; @@ -145,18 +150,18 @@ private: bool flagLength; bool flagName; bool flagGroupName; + bool flagAlias{true}; QStringList m_groupTags{}; void EvalAngle(); void EvalRotationAngle(); void EvalLength(); + + void FillSourceList(); + + void ValidateSourceAliases(); + void SetAliasValid(quint32 id, bool valid); }; -//--------------------------------------------------------------------------------------------------------------------- -inline bool DialogMove::IsValid() const -{ - return flagAngle && flagRotationAngle && flagLength && flagName && flagGroupName; -} - #endif // DIALOGMOVING_H diff --git a/src/libs/vtools/dialogs/tools/dialogmove.ui b/src/libs/vtools/dialogs/tools/dialogmove.ui index c8bb1b2d0..c9010c470 100644 --- a/src/libs/vtools/dialogs/tools/dialogmove.ui +++ b/src/libs/vtools/dialogs/tools/dialogmove.ui @@ -2,12 +2,15 @@ DialogMove + + true + 0 0 - 411 - 498 + 536 + 669 @@ -28,6 +31,39 @@ Tool + + + + Qt::Horizontal + + + + QAbstractItemView::CurrentChanged + + + + + + + + Alias: + + + + + + + false + + + true + + + + + + + @@ -656,6 +692,13 @@ + + + + Ready + + + diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.cpp b/src/libs/vtools/dialogs/tools/dialogrotation.cpp index 4d64cb5a1..2eab16690 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.cpp +++ b/src/libs/vtools/dialogs/tools/dialogrotation.cpp @@ -72,7 +72,6 @@ DialogRotation::DialogRotation(const VContainer *data, quint32 toolId, QWidget * timerAngle(new QTimer(this)), formulaAngle(), formulaBaseHeightAngle(0), - objects(), stage1(true), m_suffix(), m_firstRelease(false), @@ -170,12 +169,6 @@ void DialogRotation::SetSuffix(const QString &value) ui->lineEditSuffix->setText(value); } -//--------------------------------------------------------------------------------------------------------------------- -QVector DialogRotation::GetObjects() const -{ - return ConvertToVector(objects); -} - //--------------------------------------------------------------------------------------------------------------------- QString DialogRotation::GetVisibilityGroupName() const { @@ -224,7 +217,7 @@ void DialogRotation::ShowDialog(bool click) { if (stage1 && not click) { - if (objects.isEmpty()) + if (sourceObjects.isEmpty()) { return; } @@ -237,7 +230,7 @@ void DialogRotation::ShowDialog(bool click) VisToolRotation *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->VisualMode(); scene->ToggleArcSelection(false); @@ -252,6 +245,8 @@ void DialogRotation::ShowDialog(bool click) qApp->getSceneView()->AllowRubberBand(false); + FillSourceList(); + emit ToolTip(tr("Select origin point")); } else if (not stage1 && prepare && click) @@ -294,6 +289,23 @@ void DialogRotation::ShowDialog(bool click) } } +//--------------------------------------------------------------------------------------------------------------------- +QVector DialogRotation::GetSourceObjects() const +{ + return sourceObjects; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetSourceObjects(const QVector &value) +{ + sourceObjects = value; + FillSourceList(); + + VisToolRotation *operation = qobject_cast(vis); + SCASSERT(operation != nullptr) + operation->SetObjects(SourceToObjects(sourceObjects)); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogRotation::ChosenObject(quint32 id, const SceneObject &type) { @@ -304,14 +316,17 @@ void DialogRotation::ChosenObject(quint32 id, const SceneObject &type) VisToolRotation *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - if (objects.contains(id)) + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); + + if (obj != sourceObjects.end()) { - if (objects.size() > 1) + if (sourceObjects.size() > 1) { // It's not really logical for a user that a center of rotation no need to select. // To fix this issue we just silently remove it from the list. - objects.removeOne(id); - operation->SetObjects(ConvertToVector(objects)); + sourceObjects.erase(obj); + operation->SetObjects(SourceToObjects(sourceObjects)); } else { @@ -341,16 +356,23 @@ void DialogRotation::SelectedObject(bool selected, quint32 object, quint32 tool) Q_UNUSED(tool) if (stage1) { + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [object](const SourceItem &sItem) { return sItem.id == object; }); if (selected) { - if (not objects.contains(object)) + if (obj == sourceObjects.cend()) { - objects.append(object); + SourceItem item; + item.id = object; + sourceObjects.append(item); } } else { - objects.removeOne(object); + if (obj != sourceObjects.end()) + { + sourceObjects.erase(obj); + } } } } @@ -386,6 +408,7 @@ void DialogRotation::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -402,6 +425,7 @@ void DialogRotation::SuffixChanged() { flagName = false; ChangeColor(ui->labelSuffix, errorColor); + ui->labelStatus->setText(tr("Invalid suffix")); CheckState(); return; } @@ -426,6 +450,7 @@ void DialogRotation::GroupNameChanged() { flagGroupName = false; ChangeColor(ui->labelGroupName, errorColor); + ui->labelStatus->setText(tr("Invalid group name")); CheckState(); return; } @@ -448,10 +473,22 @@ void DialogRotation::SaveData() m_suffix = ui->lineEditSuffix->text(); formulaAngle = ui->plainTextEditFormula->toPlainText(); + sourceObjects.clear(); + sourceObjects.reserve(ui->listWidget->count()); + + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceObjects.append(sourceItem); + } + } + VisToolRotation *operation = qobject_cast(vis); SCASSERT(operation != nullptr) - operation->SetObjects(ConvertToVector(objects)); + operation->SetObjects(SourceToObjects(sourceObjects)); operation->SetOriginPointId(GetOrigPointId()); operation->SetAngle(formulaAngle); operation->RefreshGeometry(); @@ -479,11 +516,17 @@ void DialogRotation::closeEvent(QCloseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void DialogRotation::PointChanged() { + quint32 id = getCurrentObjectId(ui->comboBoxOriginPoint); + + auto obj = std::find_if(sourceObjects.begin(), sourceObjects.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); + QColor color; - if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint))) + if (obj != sourceObjects.end()) { flagError = false; color = errorColor; + ui->labelStatus->setText(tr("Invalid rotation point")); } else { @@ -494,6 +537,84 @@ void DialogRotation::PointChanged() CheckState(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::FillSourceList() +{ + ui->listWidget->blockSignals(true); + + ui->listWidget->clear(); + + int row = -1; + + for (auto &sourceItem : sourceObjects) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + bool valid = SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj)); + + auto *item = new QListWidgetItem(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + item->setToolTip(obj->ObjectName()); + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + ui->listWidget->insertItem(++row, item); + } + + ui->listWidget->blockSignals(false); + + if (ui->listWidget->count() > 0) + { + ui->listWidget->setCurrentRow(0); + } + + ValidateSourceAliases(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ValidateSourceAliases() +{ + for (int i=0; ilistWidget->count(); ++i) + { + if (const QListWidgetItem *item = ui->listWidget->item(i)) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + if (not SourceAliasValid(sourceItem, obj, data, OriginAlias(sourceItem.id, sourceObjects, obj))) + { + flagAlias = false; + ui->labelStatus->setText(obj->getType() == GOType::Point ? tr("Invalid label") : tr("Invalid alias")); + SetAliasValid(sourceItem.id, false); + CheckState(); + return; + } + else + { + SetAliasValid(sourceItem.id, true); + } + } + } + + flagAlias = true; + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::SetAliasValid(quint32 id, bool valid) +{ + if (ui->listWidget->currentRow() != -1) + { + auto *item = ui->listWidget->item(ui->listWidget->currentRow()); + const auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + + if (id == sourceItem.id) + { + const QSharedPointer obj = data->GetGObject(sourceItem.id); + item->setText(valid ? obj->ObjectName() : obj->ObjectName() + '*'); + + ChangeColor(ui->labelAlias, valid ? OkColor(this) : errorColor); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogRotation::EvalAngle() { @@ -506,6 +627,55 @@ void DialogRotation::EvalAngle() formulaData.checkZero = false; Eval(formulaData, flagAngle); + + if (not flagAngle) + { + ui->labelStatus->setText(tr("Invalid angle formula")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::ShowSourceDetails(int row) +{ + ui->lineEditAlias->setDisabled(true); + + if (ui->listWidget->count() == 0) + { + return; + } + + const auto sourceItem = qvariant_cast(ui->listWidget->item(row)->data(Qt::UserRole)); + + const QSharedPointer obj = data->GetGObject(sourceItem.id); + + ui->labelAlias->setText(obj->getType() == GOType::Point ? tr("Label:") : tr("Alias:")); + + ui->lineEditAlias->blockSignals(true); + ui->lineEditAlias->setText(sourceItem.alias); + ui->lineEditAlias->setEnabled(true); + ui->lineEditAlias->blockSignals(false); + + SetAliasValid(sourceItem.id, SourceAliasValid(sourceItem, obj, data, + OriginAlias(sourceItem.id, sourceObjects, obj))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogRotation::AliasChanged(const QString &text) +{ + if (ui->listWidget->count() == 0) + { + return; + } + + if (auto *item = ui->listWidget->currentItem()) + { + auto sourceItem = qvariant_cast(item->data(Qt::UserRole)); + sourceItem.alias = text; + + item->setData(Qt::UserRole, QVariant::fromValue(sourceItem)); + + ValidateSourceAliases(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -519,3 +689,16 @@ QString DialogRotation::GetNotes() const { return ui->plainTextEditToolNotes->toPlainText(); } + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogRotation::IsValid() const +{ + bool ready = flagAngle && flagName && flagError && flagGroupName && flagAlias; + + if (ready) + { + ui->labelStatus->setText(tr("Ready")); + } + + return ready; +} diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.h b/src/libs/vtools/dialogs/tools/dialogrotation.h index 087736055..525911668 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.h +++ b/src/libs/vtools/dialogs/tools/dialogrotation.h @@ -39,6 +39,7 @@ #include "../vmisc/def.h" #include "dialogtool.h" +#include "../../tools/toolsdef.h" namespace Ui { @@ -61,8 +62,6 @@ public: QString GetSuffix() const; void SetSuffix(const QString &value); - QVector GetObjects() const; - QString GetVisibilityGroupName() const; void SetVisibilityGroupName(const QString &name); @@ -79,6 +78,9 @@ public: virtual void ShowDialog(bool click) override; + QVector GetSourceObjects() const; + void SetSourceObjects(const QVector &value); + public slots: virtual void ChosenObject(quint32 id, const SceneObject &type) override; virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override; @@ -90,6 +92,8 @@ private slots: void SuffixChanged(); void GroupNameChanged(); void EvalAngle(); + void ShowSourceDetails(int row); + void AliasChanged(const QString &text); protected: virtual void ShowVisualization() override; @@ -115,7 +119,7 @@ private: /** @brief formulaBaseHeightAngle base height defined by dialogui */ int formulaBaseHeightAngle; - QList objects; + QVector sourceObjects{}; bool stage1; @@ -128,14 +132,14 @@ private: bool flagName; bool flagGroupName; bool flagError; + bool flagAlias{true}; QStringList m_groupTags{}; + + void FillSourceList(); + + void ValidateSourceAliases(); + void SetAliasValid(quint32 id, bool valid); }; -//--------------------------------------------------------------------------------------------------------------------- -inline bool DialogRotation::IsValid() const -{ - return flagAngle && flagName && flagError && flagGroupName; -} - #endif // DIALOGROTATION_H diff --git a/src/libs/vtools/dialogs/tools/dialogrotation.ui b/src/libs/vtools/dialogs/tools/dialogrotation.ui index 238755e7f..7bb65120f 100644 --- a/src/libs/vtools/dialogs/tools/dialogrotation.ui +++ b/src/libs/vtools/dialogs/tools/dialogrotation.ui @@ -6,8 +6,8 @@ 0 0 - 304 - 338 + 410 + 485 @@ -28,6 +28,35 @@ Tool + + + + Qt::Horizontal + + + + + + + + Alias + + + + + + + false + + + true + + + + + + + @@ -287,6 +316,13 @@ + + + + Ready + + + diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp index bf3f542ea..5b920afa4 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.cpp @@ -38,12 +38,9 @@ #include "../vgeometry/vsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- -VAbstractFlipping::VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, - const QVector &source, const QVector &destination, - const QString ¬es, QGraphicsItem *parent) - : VAbstractOperation(doc, data, id, suffix, source, destination, notes, parent) -{ -} +VAbstractFlipping::VAbstractFlipping(const VAbstractOperationInitData &initData, QGraphicsItem *parent) + : VAbstractOperation(initData, parent) +{} //--------------------------------------------------------------------------------------------------------------------- void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint, @@ -55,9 +52,9 @@ void VAbstractFlipping::CreateDestination(VAbstractOperationInitData &initData, initData.id = initData.data->getNextId();//Just reserve id for tool - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - const QSharedPointer obj = initData.data->GetGObject(idObject); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -67,32 +64,32 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - initData.destination.append(CreatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.destination.append(CreatePoint(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::Arc: - initData.destination.append(CreateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, + initData.destination.append(CreateArc(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::EllipticalArc: - initData.destination.append(CreateArc(initData.id, idObject, fPoint, sPoint, + initData.destination.append(CreateArc(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::Spline: - initData.destination.append(CreateCurve(initData.id, idObject, fPoint, sPoint, + initData.destination.append(CreateCurve(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::SplinePath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, fPoint, + initData.destination.append(CreateCurveWithSegments(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::CubicBezier: - initData.destination.append(CreateCurve(initData.id, idObject, fPoint, sPoint, + initData.destination.append(CreateCurve(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, fPoint, + initData.destination.append(CreateCurveWithSegments(initData.id, object, fPoint, sPoint, initData.suffix, initData.data)); break; @@ -108,8 +105,8 @@ QT_WARNING_POP { for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = initData.source.at(i); - const QSharedPointer obj = initData.data->GetGObject(idObject); + const SourceItem object = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -121,31 +118,31 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") case GOType::Point: { const DestinationItem &item = initData.destination.at(i); - UpdatePoint(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, item); + UpdatePoint(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, item); break; } case GOType::Arc: - UpdateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + UpdateArc(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + UpdateArc(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + UpdateCurve(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(initData.id, idObject, fPoint, sPoint, initData.suffix, + UpdateCurveWithSegments(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(initData.id, idObject, fPoint, sPoint, initData.suffix, initData.data, + UpdateCurve(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(initData.id, idObject, fPoint, sPoint, initData.suffix, + UpdateCurveWithSegments(initData.id, object, fPoint, sPoint, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::Unknown: @@ -163,13 +160,18 @@ QT_WARNING_POP } //--------------------------------------------------------------------------------------------------------------------- -DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); rotated.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + rotated.setName(sItem.alias); + } + DestinationItem item; item.mx = rotated.mx(); item.my = rotated.my(); @@ -180,33 +182,39 @@ DestinationItem VAbstractFlipping::CreatePoint(quint32 idTool, quint32 idItem, c //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +DestinationItem VAbstractFlipping::CreateArc(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, firstPoint, secondPoint, suffix, data); data->AddArc(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractFlipping::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +void VAbstractFlipping::UpdatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, const DestinationItem &item) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF rotated = point->Flip(QLineF(firstPoint, secondPoint), suffix); rotated.setIdObject(idTool); rotated.setMx(item.mx); rotated.setMy(item.my); rotated.SetShowLabel(item.showLabel); + + if (not sItem.alias.isEmpty()) + { + rotated.setName(sItem.alias); + } + data->UpdateGObject(item.id, new VPointF(rotated)); } //--------------------------------------------------------------------------------------------------------------------- template -void VAbstractFlipping::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id) +void VAbstractFlipping::UpdateArc(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + UpdateItem(idTool, sItem, firstPoint, secondPoint, suffix, data, id); data->AddArc(data->GeometricObject(id), id); } diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h index 7af3b971a..ff662f328 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -39,41 +39,40 @@ class VAbstractFlipping : public VAbstractOperation public: virtual ~VAbstractFlipping() Q_DECL_EQ_DEFAULT; protected: - VAbstractFlipping(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, - const QVector &source, const QVector &destination, const QString ¬es, - QGraphicsItem *parent = nullptr); + explicit VAbstractFlipping(const VAbstractOperationInitData &initData, QGraphicsItem *parent = nullptr); static void CreateDestination(VAbstractOperationInitData &initData, const QPointF &fPoint, const QPointF &sPoint); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static DestinationItem CreatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); template - static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static DestinationItem CreateItem(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); template - static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static DestinationItem CreateArc(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static DestinationItem CreateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static DestinationItem CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data); - static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, const DestinationItem &item); + static void UpdatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, + const DestinationItem &item); template - static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); + static void UpdateItem(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); + static void UpdateArc(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, const QPointF &secondPoint, - const QString &suffix, VContainer *data, quint32 id); + static void UpdateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, + const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, + static void UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id); private: @@ -82,13 +81,18 @@ private: //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); rotated.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + rotated.SetAliasSuffix(sItem.alias); + } + DestinationItem item; item.mx = INT_MAX; item.my = INT_MAX; @@ -98,52 +102,58 @@ DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, quint32 idItem, co //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VAbstractFlipping::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +DestinationItem VAbstractFlipping::CreateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, firstPoint, secondPoint, suffix, data); data->AddSpline(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VAbstractFlipping::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, - const QPointF &secondPoint, const QString &suffix, - VContainer *data) +DestinationItem VAbstractFlipping::CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, + const QPointF &firstPoint, const QPointF &secondPoint, + const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, firstPoint, secondPoint, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, firstPoint, secondPoint, suffix, data); data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- template -void VAbstractFlipping::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +void VAbstractFlipping::UpdateItem(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item rotated = i->Flip(QLineF(firstPoint, secondPoint), suffix); rotated.setIdObject(idTool); + + if (not sItem.alias.isEmpty()) + { + rotated.SetAliasSuffix(sItem.alias); + } + data->UpdateGObject(id, new Item(rotated)); } //--------------------------------------------------------------------------------------------------------------------- template -void VAbstractFlipping::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +void VAbstractFlipping::UpdateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + UpdateItem(idTool, sItem, firstPoint, secondPoint, suffix, data, id); data->AddSpline(data->GeometricObject(id), id); } //--------------------------------------------------------------------------------------------------------------------- template -void VAbstractFlipping::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &firstPoint, +void VAbstractFlipping::UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &firstPoint, const QPointF &secondPoint, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, firstPoint, secondPoint, suffix, data, id); + UpdateItem(idTool, sItem, firstPoint, secondPoint, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp index bcac26423..e4aed0b78 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyaxis.cpp @@ -75,6 +75,7 @@ void VToolFlippingByAxis::setDialog() dialogTool->SetAxisType(m_axisType); dialogTool->SetSuffix(suffix); dialogTool->SetNotes(m_notes); + dialogTool->SetSourceObjects(source); SetDialogVisibilityGroupData(dialogTool); } @@ -91,7 +92,7 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(const QPointer &dia initData.originPointId = dialogTool->GetOriginPointId(); initData.axisType = dialogTool->GetAxisType(); initData.suffix = dialogTool->GetSuffix(); - initData.source = dialogTool->GetObjects(); + initData.source = dialogTool->GetSourceObjects(); initData.hasLinkedVisibilityGroup = dialogTool->HasLinkedVisibilityGroup(); initData.visibilityGroupName = dialogTool->GetVisibilityGroupName(); initData.visibilityGroupTags = dialogTool->GetVisibilityGroupTags(); @@ -141,9 +142,9 @@ VToolFlippingByAxis *VToolFlippingByAxis::Create(VToolFlippingByAxisInitData ini InitOperationToolConnections(initData.scene, tool); VAbstractPattern::AddTool(initData.id, tool); initData.doc->IncrementReferens(originPoint.getIdTool()); - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - initData.doc->IncrementReferens(initData.data->GetGObject(idObject)->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool()); } if (initData.typeCreation == Source::FromGui && initData.hasLinkedVisibilityGroup) @@ -206,7 +207,7 @@ void VToolFlippingByAxis::SetVisualization() VisToolFlippingByAxis *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->SetObjects(source); + visual->SetObjects(SourceToObjects(source)); visual->SetOriginPointId(m_originPointId); visual->SetAxisType(m_axisType); visual->RefreshGeometry(); @@ -231,6 +232,9 @@ void VToolFlippingByAxis::SaveDialog(QDomElement &domElement, QList &ol const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); + source = dialogTool->GetSourceObjects(); + SaveSourceDestination(domElement); + // Save visibility data for later use SaveVisibilityGroupData(dialogTool); } @@ -242,7 +246,6 @@ void VToolFlippingByAxis::ReadToolAttributes(const QDomElement &domElement) m_originPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); m_axisType = static_cast(doc->GetParametrUInt(domElement, AttrAxisType, QChar('1'))); - suffix = doc->GetParametrString(domElement, AttrSuffix); } //--------------------------------------------------------------------------------------------------------------------- @@ -253,9 +256,6 @@ void VToolFlippingByAxis::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrCenter, QString().setNum(m_originPointId)); doc->SetAttribute(tag, AttrAxisType, QString().setNum(static_cast(m_axisType))); - doc->SetAttribute(tag, AttrSuffix, suffix); - - SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -269,8 +269,7 @@ QString VToolFlippingByAxis::MakeToolTip() const //--------------------------------------------------------------------------------------------------------------------- VToolFlippingByAxis::VToolFlippingByAxis(const VToolFlippingByAxisInitData &initData, QGraphicsItem *parent) - : VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source, - initData.destination, initData.notes, parent), + : VAbstractFlipping(initData, parent), m_originPointId(initData.originPointId), m_axisType(initData.axisType) { diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp index 5c70ec11b..f1bf49012 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vtoolflippingbyline.cpp @@ -75,6 +75,7 @@ void VToolFlippingByLine::setDialog() dialogTool->SetSecondLinePointId(m_secondLinePointId); dialogTool->SetSuffix(suffix); dialogTool->SetNotes(m_notes); + dialogTool->SetSourceObjects(source); SetDialogVisibilityGroupData(dialogTool); } @@ -91,7 +92,7 @@ VToolFlippingByLine *VToolFlippingByLine::Create(const QPointer &dia initData.firstLinePointId = dialogTool->GetFirstLinePointId(); initData.secondLinePointId = dialogTool->GetSecondLinePointId(); initData.suffix = dialogTool->GetSuffix(); - initData.source = dialogTool->GetObjects(); + initData.source = dialogTool->GetSourceObjects(); initData.hasLinkedVisibilityGroup = dialogTool->HasLinkedVisibilityGroup(); initData.visibilityGroupName = dialogTool->GetVisibilityGroupName(); initData.visibilityGroupTags = dialogTool->GetVisibilityGroupTags(); @@ -135,9 +136,9 @@ VToolFlippingByLine *VToolFlippingByLine::Create(VToolFlippingByLineInitData ini VAbstractPattern::AddTool(initData.id, tool); initData.doc->IncrementReferens(firstPoint.getIdTool()); initData.doc->IncrementReferens(secondPoint.getIdTool()); - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - initData.doc->IncrementReferens(initData.data->GetGObject(idObject)->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool()); } if (initData.typeCreation == Source::FromGui && initData.hasLinkedVisibilityGroup) @@ -191,7 +192,7 @@ void VToolFlippingByLine::SetVisualization() VisToolFlippingByLine *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->SetObjects(source); + visual->SetObjects(SourceToObjects(source)); visual->SetFirstLinePointId(m_firstLinePointId); visual->SetSecondLinePointId(m_secondLinePointId); visual->RefreshGeometry(); @@ -218,6 +219,9 @@ void VToolFlippingByLine::SaveDialog(QDomElement &domElement, QList &ol const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); + source = dialogTool->GetSourceObjects(); + SaveSourceDestination(domElement); + // Save visibility data for later use SaveVisibilityGroupData(dialogTool); } @@ -229,7 +233,6 @@ void VToolFlippingByLine::ReadToolAttributes(const QDomElement &domElement) m_firstLinePointId = doc->GetParametrUInt(domElement, AttrP1Line, NULL_ID_STR); m_secondLinePointId = doc->GetParametrUInt(domElement, AttrP2Line, NULL_ID_STR); - suffix = doc->GetParametrString(domElement, AttrSuffix); } //--------------------------------------------------------------------------------------------------------------------- @@ -240,9 +243,6 @@ void VToolFlippingByLine::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrP1Line, QString().setNum(m_firstLinePointId)); doc->SetAttribute(tag, AttrP2Line, QString().setNum(m_secondLinePointId)); - doc->SetAttribute(tag, AttrSuffix, suffix); - - SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -258,8 +258,7 @@ QString VToolFlippingByLine::MakeToolTip() const //--------------------------------------------------------------------------------------------------------------------- VToolFlippingByLine::VToolFlippingByLine(const VToolFlippingByLineInitData &initData, QGraphicsItem *parent) - : VAbstractFlipping(initData.doc, initData.data, initData.id, initData.suffix, initData.source, - initData.destination, initData.notes, parent), + : VAbstractFlipping(initData, parent), m_firstLinePointId(initData.firstLinePointId), m_secondLinePointId(initData.secondLinePointId) { diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 0a284f22b..05a987b92 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -46,15 +46,15 @@ namespace * @param source list with source objects * @return visibility group data */ -QMap VisibilityGroupDataFromSource(const VContainer *data, const QVector &source) +QMap VisibilityGroupDataFromSource(const VContainer *data, const QVector &source) { QMap groupData; - for (auto &sId : source) + for (auto &sItem : source) { try { - groupData.insert(sId, data->GetGObject(sId)->getIdTool()); + groupData.insert(sItem.id, data->GetGObject(sItem.id)->getIdTool()); } catch (const VExceptionBadId &) { @@ -98,7 +98,7 @@ QVector VAbstractOperation::SourceItems() const { for (auto &item : source) { - itemNames.append(VAbstractTool::data.GetGObject(item)->name()); + itemNames.append(VAbstractTool::data.GetGObject(item.id)->ObjectName()); } } catch (const VExceptionBadId &e) @@ -201,27 +201,49 @@ void VAbstractOperation::SetLabelVisible(quint32 id, bool visible) //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData) { + initData.source = ExtractSourceData(domElement); + initData.destination = ExtractDestinationData(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractOperation::ExtractSourceData(const QDomElement &domElement) +{ + QVector source; const QDomNodeList nodeList = domElement.childNodes(); for (qint32 i = 0; i < nodeList.size(); ++i) { const QDomElement dataElement = nodeList.at(i).toElement(); if (not dataElement.isNull() && dataElement.tagName() == TagSource) { - initData.source.clear(); const QDomNodeList srcList = dataElement.childNodes(); for (qint32 j = 0; j < srcList.size(); ++j) { const QDomElement element = srcList.at(j).toElement(); if (not element.isNull()) { - initData.source.append(VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR)); + SourceItem item; + item.id = VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR); + item.alias = VDomDocument::GetParametrEmptyString(element, AttrAlias); + source.append(item); } } + return source; } + } + return source; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VAbstractOperation::ExtractDestinationData(const QDomElement &domElement) +{ + QVector destination; + const QDomNodeList nodeList = domElement.childNodes(); + for (qint32 i = 0; i < nodeList.size(); ++i) + { + const QDomElement dataElement = nodeList.at(i).toElement(); if (not dataElement.isNull() && dataElement.tagName() == TagDestination) { - initData.destination.clear(); const QDomNodeList srcList = dataElement.childNodes(); for (qint32 j = 0; j < srcList.size(); ++j) { @@ -233,11 +255,15 @@ void VAbstractOperation::ExtractData(const QDomElement &domElement, VAbstractOpe d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); d.showLabel = VDomDocument::GetParametrBool(element, AttrShowLabel, trueStr); - initData.destination.append(d); + destination.append(d); } } + + return destination; } } + + return destination; } //--------------------------------------------------------------------------------------------------------------------- @@ -520,17 +546,15 @@ void VAbstractOperation::LabelChangePosition(const QPointF &pos, quint32 labelId } //--------------------------------------------------------------------------------------------------------------------- -VAbstractOperation::VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, - const QVector &source, const QVector &destination, - const QString ¬es, QGraphicsItem *parent) - : VDrawTool(doc, data, id, notes), +VAbstractOperation::VAbstractOperation(const VAbstractOperationInitData &initData, QGraphicsItem *parent) + : VDrawTool(initData.doc, initData.data, initData.id, initData.notes), QGraphicsLineItem(parent), - suffix(suffix), - source(source), - destination(destination), + suffix(initData.suffix), + source(initData.source), + destination(initData.destination), operatedObjects() { - connect(doc, &VAbstractPattern::UpdateToolTip, this, [this]() + connect(initData.doc, &VAbstractPattern::UpdateToolTip, this, [this]() { QMapIterator i(operatedObjects); while (i.hasNext()) @@ -669,6 +693,26 @@ void VAbstractOperation::PerformDelete() } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::ReadToolAttributes(const QDomElement &domElement) +{ + VDrawTool::ReadToolAttributes(domElement); + + source = ExtractSourceData(domElement); + destination = ExtractDestinationData(domElement); + suffix = doc->GetParametrString(domElement, AttrSuffix); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractOperation::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + VDrawTool::SaveOptions(tag, obj); + + doc->SetAttribute(tag, AttrSuffix, suffix); + + SaveSourceDestination(tag); +} + //--------------------------------------------------------------------------------------------------------------------- void VAbstractOperation::UpdateNamePosition(quint32 id, const QPointF &pos) { @@ -695,10 +739,11 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag) doc->RemoveAllChildren(tag); QDomElement tagObjects = doc->createElement(TagSource); - for (auto id : qAsConst(source)) + for (auto sItem : qAsConst(source)) { QDomElement item = doc->createElement(TagItem); - doc->SetAttribute(item, AttrIdObject, id); + doc->SetAttribute(item, AttrIdObject, sItem.id); + doc->SetAttributeOrRemoveIf(item, AttrAlias, sItem.alias, sItem.alias.isEmpty()); tagObjects.appendChild(item); } tag.appendChild(tagObjects); @@ -709,13 +754,13 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag) QDomElement item = doc->createElement(TagItem); doc->SetAttribute(item, AttrIdObject, dItem.id); - if (not VFuzzyComparePossibleNulls(dItem.mx, INT_MAX) && - not VFuzzyComparePossibleNulls(dItem.my, INT_MAX)) - { - doc->SetAttribute(item, AttrMx, qApp->fromPixel(dItem.mx)); - doc->SetAttribute(item, AttrMy, qApp->fromPixel(dItem.my)); - doc->SetAttribute(item, AttrShowLabel, dItem.showLabel); - } + VAbstractSimple *obj = operatedObjects.value(dItem.id); + + doc->SetAttributeOrRemoveIf(item, AttrMx, qApp->fromPixel(dItem.mx), + obj && obj->GetType() != GOType::Point); + doc->SetAttributeOrRemoveIf(item, AttrMy, qApp->fromPixel(dItem.my), + obj && obj->GetType() != GOType::Point); + doc->SetAttributeOrRemoveIf(item, AttrShowLabel, dItem.showLabel, dItem.showLabel); tagObjects.appendChild(item); } @@ -888,7 +933,7 @@ QString VAbstractOperation::ComplexCurveToolTip(quint32 itemId) const " %3: %4 %5 " "%6" "") - .arg(tr("Label"), curve->name(), tr("Length")) + .arg(tr("Label"), curve->ObjectName(), tr("Length")) .arg(qApp->fromPixel(curve->GetLength())) .arg(UnitsToStr(qApp->patternUnits(), true), MakeToolTip()); return toolTip; diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 57eb6ff06..d23b88bbc 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -41,6 +41,7 @@ #include "../vdrawtool.h" #include "../vwidgets/vsimplecurve.h" #include "../vwidgets/vsimplepoint.h" +#include "../../toolsdef.h" struct DestinationItem { @@ -57,7 +58,7 @@ struct VAbstractOperationInitData : VDrawToolInitData {} QString suffix{}; - QVector source{}; + QVector source{}; QVector destination{}; QString visibilityGroupName{}; QStringList visibilityGroupTags{}; @@ -95,6 +96,8 @@ public: virtual void SetLabelVisible(quint32 id, bool visible) override; static void ExtractData(const QDomElement &domElement, VAbstractOperationInitData &initData); + static QVector ExtractSourceData(const QDomElement &domElement); + static QVector ExtractDestinationData(const QDomElement &domElement); public slots: virtual void FullUpdateFromFile() override; @@ -128,7 +131,7 @@ public slots: protected: QString suffix; - QVector source; + QVector source; QVector destination; QMap operatedObjects; @@ -137,15 +140,15 @@ protected: QString groupName{}; QStringList groupTags{}; - VAbstractOperation(VAbstractPattern *doc, VContainer *data, quint32 id, const QString &suffix, - const QVector &source, const QVector &destination, - const QString ¬es, QGraphicsItem *parent = nullptr); + explicit VAbstractOperation(const VAbstractOperationInitData &initData, QGraphicsItem *parent = nullptr); virtual void AddToFile() override; virtual void ChangeLabelVisibility(quint32 id, bool visible) override; virtual void ApplyToolOptions(const QList &oldDependencies, const QList &newDependencies, const QDomElement &oldDomElement, const QDomElement &newDomElement) override; virtual void PerformDelete() override; + virtual void ReadToolAttributes(const QDomElement &domElement) override; + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) override; void UpdateNamePosition(quint32 id, const QPointF &pos); void SaveSourceDestination(QDomElement &tag); diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index df6489f4e..8646ad2c4 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -78,13 +78,13 @@ namespace { QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") -QPointF GetOriginPoint(const QVector objects, const VContainer *data, qreal calcLength, qreal calcAngle) +QPointF GetOriginPoint(const QVector &objects, const VContainer *data, qreal calcLength, qreal calcAngle) { QPolygonF originObjects; - for (auto id : objects) + for (auto object : objects) { - const QSharedPointer obj = data->GetGObject(id); + const QSharedPointer obj = data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -92,7 +92,7 @@ QPointF GetOriginPoint(const QVector objects, const VContainer *data, q switch(static_cast(obj->getType())) { case GOType::Point: - originObjects.append(data->GeometricObject(id)->toQPointF()); + originObjects.append(data->GeometricObject(object.id)->toQPointF()); break; case GOType::Arc: case GOType::EllipticalArc: @@ -100,7 +100,7 @@ QPointF GetOriginPoint(const QVector objects, const VContainer *data, q case GOType::SplinePath: case GOType::CubicBezier: case GOType::CubicBezierPath: - AppendTo(originObjects, data->GeometricObject(id)->GetPoints()); + AppendTo(originObjects, data->GeometricObject(object.id)->GetPoints()); break; case GOType::Unknown: case GOType::PlaceLabel: @@ -129,6 +129,7 @@ void VToolMove::setDialog() dialogTool->SetSuffix(suffix); dialogTool->SetRotationOrigPointId(origPointId); dialogTool->SetNotes(m_notes); + dialogTool->SetSourceObjects(source); SetDialogVisibilityGroupData(dialogTool); } @@ -147,7 +148,7 @@ VToolMove *VToolMove::Create(const QPointer &dialog, VMainGraphicsSc initData.formulaLength = dialogTool->GetLength(); initData.rotationOrigin = dialogTool->GetRotationOrigPointId(); initData.suffix = dialogTool->GetSuffix(); - initData.source = dialogTool->GetObjects(); + initData.source = dialogTool->GetSourceObjects(); initData.hasLinkedVisibilityGroup = dialogTool->HasLinkedVisibilityGroup(); initData.visibilityGroupName = dialogTool->GetVisibilityGroupName(); initData.visibilityGroupTags = dialogTool->GetVisibilityGroupTags(); @@ -196,9 +197,9 @@ VToolMove *VToolMove::Create(VToolMoveInitData &initData) initData.id = initData.data->getNextId();//Just reserve id for tool - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - const QSharedPointer obj = initData.data->GetGObject(idObject); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -208,38 +209,38 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - initData.destination.append(CreatePoint(initData.id, idObject, calcAngle, calcLength, + initData.destination.append(CreatePoint(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::Arc: - initData.destination.append(CreateArc(initData.id, idObject, calcAngle, calcLength, + initData.destination.append(CreateArc(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::EllipticalArc: - initData.destination.append(CreateArc(initData.id, idObject, calcAngle, calcLength, + initData.destination.append(CreateArc(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::Spline: - initData.destination.append(CreateCurve(initData.id, idObject, calcAngle, calcLength, + initData.destination.append(CreateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::SplinePath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, calcAngle, + initData.destination.append(CreateCurveWithSegments(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::CubicBezier: - initData.destination.append(CreateCurve(initData.id, idObject, calcAngle, calcLength, + initData.destination.append(CreateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, + initData.destination.append(CreateCurveWithSegments(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, @@ -258,8 +259,8 @@ QT_WARNING_POP { for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = initData.source.at(i); - const QSharedPointer obj = initData.data->GetGObject(idObject); + const SourceItem object = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -269,34 +270,34 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - UpdatePoint(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, rotationOrigin, + UpdatePoint(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data, initData.destination.at(i)); break; case GOType::Arc: - UpdateArc(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, rotationOrigin, + UpdateArc(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, + UpdateArc(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, + UpdateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(initData.id, idObject, calcAngle, calcLength, + UpdateCurveWithSegments(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin,initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(initData.id, idObject, calcAngle, calcLength, calcRotationAngle, + UpdateCurve(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin,initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(initData.id, idObject, calcAngle, calcLength, + UpdateCurveWithSegments(initData.id, object, calcAngle, calcLength, calcRotationAngle, rotationOrigin, initData.suffix, initData.data, initData.destination.at(i).id); @@ -332,9 +333,9 @@ QT_WARNING_POP initData.doc->IncrementReferens(originPoint->getIdTool()); } - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - initData.doc->IncrementReferens(initData.data->GetGObject(idObject)->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool()); } if (initData.typeCreation == Source::FromGui && initData.hasLinkedVisibilityGroup) @@ -458,7 +459,7 @@ void VToolMove::SetVisualization() VisToolMove *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->SetObjects(source); + visual->SetObjects(SourceToObjects(source)); visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); visual->SetRotationAngle(qApp->TrVars()->FormulaToUser(formulaRotationAngle, qApp->Settings()->GetOsSeparator())); @@ -487,6 +488,9 @@ void VToolMove::SaveDialog(QDomElement &domElement, QList &oldDependenc const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); + source = dialogTool->GetSourceObjects(); + SaveSourceDestination(domElement); + // Save visibility data for later use SaveVisibilityGroupData(dialogTool); } @@ -500,7 +504,6 @@ void VToolMove::ReadToolAttributes(const QDomElement &domElement) formulaAngle = doc->GetParametrString(domElement, AttrAngle, QChar('0')); formulaRotationAngle = doc->GetParametrString(domElement, AttrRotationAngle, QChar('0')); formulaLength = doc->GetParametrString(domElement, AttrLength, QChar('0')); - suffix = doc->GetParametrString(domElement, AttrSuffix); } //--------------------------------------------------------------------------------------------------------------------- @@ -512,10 +515,7 @@ void VToolMove::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrAngle, formulaAngle); doc->SetAttribute(tag, AttrRotationAngle, formulaRotationAngle); doc->SetAttribute(tag, AttrLength, formulaLength); - doc->SetAttribute(tag, AttrSuffix, suffix); doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); - - SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -530,7 +530,7 @@ QString VToolMove::MakeToolTip() const .arg(GetFormulaAngle().getDoubleValue()) // 2 .arg(tr("Length")) // 3 .arg(GetFormulaLength().getDoubleValue()) // 4 - .arg(UnitsToStr(qApp->patternUnits(), true), // 5 + .arg(UnitsToStr(qApp->patternUnits(), true), // 5 tr("Rotation angle")) // 6 .arg(GetFormulaRotationAngle().getDoubleValue()) // 7 .arg(tr("Rotation origin point"), // 8 @@ -540,8 +540,7 @@ QString VToolMove::MakeToolTip() const //--------------------------------------------------------------------------------------------------------------------- VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent) - : VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source, - initData.destination, initData.notes, parent), + : VAbstractOperation(initData, parent), formulaAngle(initData.formulaAngle), formulaRotationAngle(initData.formulaRotationAngle), formulaLength(initData.formulaLength), @@ -552,14 +551,19 @@ VToolMove::VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent) } //--------------------------------------------------------------------------------------------------------------------- -DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal angle, - qreal length, qreal rotationAngle, const QPointF &rotationOrigin, +DestinationItem VToolMove::CreatePoint(quint32 idTool, const SourceItem &sItem, qreal angle, + qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle); moved.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + moved.setName(sItem.alias); + } + DestinationItem item; item.mx = moved.mx(); item.my = moved.my(); @@ -570,47 +574,60 @@ DestinationItem VToolMove::CreatePoint(quint32 idTool, quint32 idItem, qreal ang //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolMove::CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data) +DestinationItem VToolMove::CreateArc(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, + const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddArc(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- -void VToolMove::UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, +void VToolMove::UpdatePoint(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, const DestinationItem &item) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF moved = point->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle); moved.setIdObject(idTool); moved.setMx(item.mx); moved.setMy(item.my); moved.SetShowLabel(item.showLabel); + + if (not sItem.alias.isEmpty()) + { + moved.setName(sItem.alias); + } + data->UpdateGObject(item.id, new VPointF(moved)); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolMove::UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, +void VToolMove::UpdateArc(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); + UpdateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); data->AddArc(data->GeometricObject(id), id); } //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data) +DestinationItem VToolMove::CreateItem(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle); moved.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + moved.SetAliasSuffix(sItem.alias); + } + DestinationItem item; item.mx = INT_MAX; item.my = INT_MAX; @@ -620,10 +637,11 @@ DestinationItem VToolMove::CreateItem(quint32 idTool, quint32 idItem, qreal angl //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data) +DestinationItem VToolMove::CreateCurve(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, + const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddSpline(data->GeometricObject(item.id), item.id); return item; @@ -631,12 +649,12 @@ DestinationItem VToolMove::CreateCurve(quint32 idTool, quint32 idItem, qreal ang //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolMove::CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, +DestinationItem VToolMove::CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, + const DestinationItem item = CreateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data); data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); return item; @@ -644,30 +662,36 @@ DestinationItem VToolMove::CreateCurveWithSegments(quint32 idTool, quint32 idIte //--------------------------------------------------------------------------------------------------------------------- template -void VToolMove::UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, +void VToolMove::UpdateItem(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item moved = i->Move(length, angle, suffix).Rotate(rotationOrigin, rotationAngle); moved.setIdObject(idTool); + + if (not sItem.alias.isEmpty()) + { + moved.SetAliasSuffix(sItem.alias); + } + data->UpdateGObject(id, new Item(moved)); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolMove::UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, +void VToolMove::UpdateCurve(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); + UpdateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); data->AddSpline(data->GeometricObject(id), id); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolMove::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data, - quint32 id) +void VToolMove::UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); + UpdateItem(idTool, sItem, angle, length, rotationAngle, rotationOrigin, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h index 32982e81e..1b27befd8 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.h @@ -104,41 +104,45 @@ private: QString formulaLength; quint32 origPointId; - VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent = nullptr); + explicit VToolMove(const VToolMoveInitData &initData, QGraphicsItem *parent = nullptr); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data); + static DestinationItem CreatePoint(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data); template - static DestinationItem CreateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data); + static DestinationItem CreateItem(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data); template - static DestinationItem CreateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data); + static DestinationItem CreateArc(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data); template - static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin,const QString &suffix, VContainer *data); + static DestinationItem CreateCurve(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin,const QString &suffix, + VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, + static DestinationItem CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data); - static void UpdatePoint(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, + static void UpdatePoint(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, const DestinationItem &item); template - static void UpdateItem(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, + static void UpdateItem(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateArc(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, + static void UpdateArc(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurve(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, + static void UpdateCurve(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, qreal angle, qreal length, qreal rotationAngle, - const QPointF &rotationOrigin, const QString &suffix, VContainer *data, - quint32 id); + static void UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, qreal angle, qreal length, + qreal rotationAngle, const QPointF &rotationOrigin, const QString &suffix, + VContainer *data, quint32 id); }; #endif // VTOOLMOVING_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index 7506c7077..de1829a23 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -80,8 +80,7 @@ const QString VToolRotation::ToolType = QStringLiteral("rotation"); //--------------------------------------------------------------------------------------------------------------------- VToolRotation::VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent) - : VAbstractOperation(initData.doc, initData.data, initData.id, initData.suffix, initData.source, - initData.destination, initData.notes, parent), + : VAbstractOperation(initData, parent), origPointId(initData.origin), formulaAngle(initData.angle) { @@ -99,6 +98,7 @@ void VToolRotation::setDialog() dialogTool->SetAngle(formulaAngle); dialogTool->SetSuffix(suffix); dialogTool->SetNotes(m_notes); + dialogTool->SetSourceObjects(source); SetDialogVisibilityGroupData(dialogTool); } @@ -115,7 +115,7 @@ VToolRotation *VToolRotation::Create(const QPointer &dialog, VMainGr initData.origin = dialogTool->GetOrigPointId(); initData.angle = dialogTool->GetAngle(); initData.suffix = dialogTool->GetSuffix(); - initData.source = dialogTool->GetObjects(); + initData.source = dialogTool->GetSourceObjects(); initData.hasLinkedVisibilityGroup = dialogTool->HasLinkedVisibilityGroup(); initData.visibilityGroupName = dialogTool->GetVisibilityGroupName(); initData.visibilityGroupTags = dialogTool->GetVisibilityGroupTags(); @@ -150,9 +150,9 @@ VToolRotation *VToolRotation::Create(VToolRotationInitData &initData) initData.id = initData.data->getNextId();//Just reserve id for tool - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - const QSharedPointer obj = initData.data->GetGObject(idObject); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -162,32 +162,32 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") switch(static_cast(obj->getType())) { case GOType::Point: - initData.destination.append(CreatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, + initData.destination.append(CreatePoint(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::Arc: - initData.destination.append(CreateArc(initData.id, idObject, oPoint, calcAngle, + initData.destination.append(CreateArc(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::EllipticalArc: - initData.destination.append(CreateArc(initData.id, idObject, oPoint, calcAngle, + initData.destination.append(CreateArc(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::Spline: - initData.destination.append(CreateCurve(initData.id, idObject, oPoint, calcAngle, + initData.destination.append(CreateCurve(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::SplinePath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, oPoint, + initData.destination.append(CreateCurveWithSegments(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::CubicBezier: - initData.destination.append(CreateCurve(initData.id, idObject, oPoint, calcAngle, + initData.destination.append(CreateCurve(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; case GOType::CubicBezierPath: - initData.destination.append(CreateCurveWithSegments(initData.id, idObject, oPoint, + initData.destination.append(CreateCurveWithSegments(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data)); break; @@ -203,8 +203,8 @@ QT_WARNING_POP { for (int i = 0; i < initData.source.size(); ++i) { - const quint32 idObject = initData.source.at(i); - const QSharedPointer obj = initData.data->GetGObject(idObject); + const SourceItem object = initData.source.at(i); + const QSharedPointer obj = initData.data->GetGObject(object.id); // This check helps to find missed objects in the switch Q_STATIC_ASSERT_X(static_cast(GOType::Unknown) == 8, "Not all objects were handled."); @@ -215,32 +215,32 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") { case GOType::Point: { - UpdatePoint(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + UpdatePoint(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i)); break; } case GOType::Arc: - UpdateArc(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + UpdateArc(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::EllipticalArc: - UpdateArc(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + UpdateArc(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::Spline: - UpdateCurve(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + UpdateCurve(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::SplinePath: - UpdateCurveWithSegments(initData.id, idObject, oPoint, calcAngle, initData.suffix, + UpdateCurveWithSegments(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezier: - UpdateCurve(initData.id, idObject, oPoint, calcAngle, initData.suffix, initData.data, + UpdateCurve(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::CubicBezierPath: - UpdateCurveWithSegments(initData.id, idObject, oPoint, calcAngle, initData.suffix, + UpdateCurveWithSegments(initData.id, object, oPoint, calcAngle, initData.suffix, initData.data, initData.destination.at(i).id); break; case GOType::Unknown: @@ -269,9 +269,9 @@ QT_WARNING_POP InitOperationToolConnections(initData.scene, tool); VAbstractPattern::AddTool(initData.id, tool); initData.doc->IncrementReferens(originPoint.getIdTool()); - for (auto idObject : qAsConst(initData.source)) + for (auto object : qAsConst(initData.source)) { - initData.doc->IncrementReferens(initData.data->GetGObject(idObject)->getIdTool()); + initData.doc->IncrementReferens(initData.data->GetGObject(object.id)->getIdTool()); } if (initData.typeCreation == Source::FromGui && initData.hasLinkedVisibilityGroup) @@ -342,7 +342,7 @@ void VToolRotation::SetVisualization() VisToolRotation *visual = qobject_cast(vis); SCASSERT(visual != nullptr) - visual->SetObjects(source); + visual->SetObjects(SourceToObjects(source)); visual->SetOriginPointId(origPointId); visual->SetAngle(qApp->TrVars()->FormulaToUser(formulaAngle, qApp->Settings()->GetOsSeparator())); visual->RefreshGeometry(); @@ -367,6 +367,9 @@ void VToolRotation::SaveDialog(QDomElement &domElement, QList &oldDepen const QString notes = dialogTool->GetNotes(); doc->SetAttributeOrRemoveIf(domElement, AttrNotes, notes, notes.isEmpty()); + source = dialogTool->GetSourceObjects(); + SaveSourceDestination(domElement); + // Save visibility data for later use SaveVisibilityGroupData(dialogTool); } @@ -378,7 +381,6 @@ void VToolRotation::ReadToolAttributes(const QDomElement &domElement) origPointId = doc->GetParametrUInt(domElement, AttrCenter, NULL_ID_STR); formulaAngle = doc->GetParametrString(domElement, AttrAngle, QChar('0')); - suffix = doc->GetParametrString(domElement, AttrSuffix); } //--------------------------------------------------------------------------------------------------------------------- @@ -389,9 +391,6 @@ void VToolRotation::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrCenter, QString().setNum(origPointId)); doc->SetAttribute(tag, AttrAngle, formulaAngle); - doc->SetAttribute(tag, AttrSuffix, suffix); - - SaveSourceDestination(tag); } //--------------------------------------------------------------------------------------------------------------------- @@ -406,13 +405,18 @@ QString VToolRotation::MakeToolTip() const } //--------------------------------------------------------------------------------------------------------------------- -DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +DestinationItem VToolRotation::CreatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF rotated = point->Rotate(origin, angle, suffix); rotated.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + rotated.setName(sItem.alias); + } + DestinationItem item; item.mx = rotated.mx(); item.my = rotated.my(); @@ -423,13 +427,18 @@ DestinationItem VToolRotation::CreatePoint(quint32 idTool, quint32 idItem, const //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolRotation::CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +DestinationItem VToolRotation::CreateItem(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item rotated = i->Rotate(origin, angle, suffix); rotated.setIdObject(idTool); + if (not sItem.alias.isEmpty()) + { + rotated.SetAliasSuffix(sItem.alias); + } + DestinationItem item; item.mx = INT_MAX; item.my = INT_MAX; @@ -439,81 +448,93 @@ DestinationItem VToolRotation::CreateItem(quint32 idTool, quint32 idItem, const //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolRotation::CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +DestinationItem VToolRotation::CreateArc(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, origin, angle, suffix, data); data->AddArc(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolRotation::CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +DestinationItem VToolRotation::CreateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, origin, angle, suffix, data); data->AddSpline(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- template -DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, +DestinationItem VToolRotation::CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data) { - const DestinationItem item = CreateItem(idTool, idItem, origin, angle, suffix, data); + const DestinationItem item = CreateItem(idTool, sItem, origin, angle, suffix, data); data->AddCurveWithSegments(data->GeometricObject(item.id), item.id); return item; } //--------------------------------------------------------------------------------------------------------------------- -void VToolRotation::UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +void VToolRotation::UpdatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, const DestinationItem &item) { - const QSharedPointer point = data->GeometricObject(idItem); + const QSharedPointer point = data->GeometricObject(sItem.id); VPointF rotated = point->Rotate(origin, angle, suffix); rotated.setIdObject(idTool); rotated.setMx(item.mx); rotated.setMy(item.my); rotated.SetShowLabel(item.showLabel); + + if (not sItem.alias.isEmpty()) + { + rotated.setName(sItem.alias); + } + data->UpdateGObject(item.id, new VPointF(rotated)); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolRotation::UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +void VToolRotation::UpdateItem(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id) { - const QSharedPointer i = data->GeometricObject(idItem); + const QSharedPointer i = data->GeometricObject(sItem.id); Item rotated = i->Rotate(origin, angle, suffix); rotated.setIdObject(idTool); + + if (not sItem.alias.isEmpty()) + { + rotated.SetAliasSuffix(sItem.alias); + } + data->UpdateGObject(id, new Item(rotated)); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolRotation::UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +void VToolRotation::UpdateArc(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + UpdateItem(idTool, sItem, origin, angle, suffix, data, id); data->AddArc(data->GeometricObject(id), id); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolRotation::UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +void VToolRotation::UpdateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + UpdateItem(idTool, sItem, origin, angle, suffix, data, id); data->AddSpline(data->GeometricObject(id), id); } //--------------------------------------------------------------------------------------------------------------------- template -void VToolRotation::UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, +void VToolRotation::UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id) { - UpdateItem(idTool, idItem, origin, angle, suffix, data, id); + UpdateItem(idTool, sItem, origin, angle, suffix, data, id); data->AddCurveWithSegments(data->GeometricObject(id), id); } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h index 96bc09e45..354ee2a83 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.h @@ -95,35 +95,35 @@ private: VToolRotation(const VToolRotationInitData &initData, QGraphicsItem *parent = nullptr); - static DestinationItem CreatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); template - static DestinationItem CreateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateItem(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); template - static DestinationItem CreateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateArc(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static DestinationItem CreateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); template - static DestinationItem CreateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, + static DestinationItem CreateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data); - static void UpdatePoint(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdatePoint(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, const DestinationItem &item); template - static void UpdateItem(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateItem(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateArc(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateArc(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurve(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateCurve(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id); template - static void UpdateCurveWithSegments(quint32 idTool, quint32 idItem, const QPointF &origin, qreal angle, + static void UpdateCurveWithSegments(quint32 idTool, const SourceItem &sItem, const QPointF &origin, qreal angle, const QString &suffix, VContainer *data, quint32 id); }; diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 3d3414519..93eec3025 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -2,6 +2,7 @@ # This need for corect working file translations.pro HEADERS += \ + $$PWD/toolsdef.h \ $$PWD/vdatatool.h \ $$PWD/vabstracttool.h \ $$PWD/tools.h \ @@ -64,6 +65,7 @@ HEADERS += \ $$PWD/nodeDetails/vtoolplacelabel.h SOURCES += \ + $$PWD/toolsdef.cpp \ $$PWD/vdatatool.cpp \ $$PWD/vabstracttool.cpp \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtooltriangle.cpp \ diff --git a/src/libs/vtools/tools/toolsdef.cpp b/src/libs/vtools/tools/toolsdef.cpp new file mode 100644 index 000000000..e76d15dc6 --- /dev/null +++ b/src/libs/vtools/tools/toolsdef.cpp @@ -0,0 +1,105 @@ +/************************************************************************ + ** + ** @file toolsdef.cpp + ** @author Roman Telezhynskyi + ** @date 6 11, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "toolsdef.h" + +#include +#include + +#include "../vgeometry/vgobject.h" +#include "../qmuparser/qmudef.h" +#include "../vpatterndb/vcontainer.h" + +//--------------------------------------------------------------------------------------------------------------------- +QVector SourceToObjects(const QVector &source) +{ + QVector ids; + ids.reserve(source.size()); + + for (auto s: source) + { + ids.append(s.id); + } + + return ids; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool SourceAliasValid(const SourceItem &item, const QSharedPointer &obj, const VContainer *data, + const QString &originAlias) +{ + SCASSERT(data != nullptr) + + QRegularExpression rx(NameRegExp()); + + QString alias; + + if (obj->getType() == GOType::Point) + { + alias = item.alias; + } + else + { + const QString oldAlias = obj->GetAliasSuffix(); + obj->SetAliasSuffix(item.alias); + alias = obj->GetAlias(); + obj->SetAliasSuffix(oldAlias); + } + + if (not alias.isEmpty() && originAlias != alias && + (not rx.match(alias).hasMatch() || not data->IsUnique(alias))) + { + return false; + } + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString OriginAlias(quint32 id, const QVector &source, const QSharedPointer &obj) +{ + auto item = std::find_if(source.begin(), source.end(), + [id](const SourceItem &sItem) { return sItem.id == id; }); + if (item != source.end()) + { + if (obj->getType() == GOType::Point) + { + return item->alias; + } + else + { + const QString oldAlias = obj->GetAliasSuffix(); + obj->SetAliasSuffix(item->alias); + QString alias = obj->GetAlias(); + obj->SetAliasSuffix(oldAlias); + return alias; + } + } + + return QString(); +} diff --git a/src/libs/vtools/tools/toolsdef.h b/src/libs/vtools/tools/toolsdef.h new file mode 100644 index 000000000..ce09a70f4 --- /dev/null +++ b/src/libs/vtools/tools/toolsdef.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file toolsdef.h + ** @author Roman Telezhynskyi + ** @date 6 11, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef TOOLSDEF_H +#define TOOLSDEF_H + +#include +#include + +class VGObject; +class VContainer; + +struct SourceItem +{ + quint32 id{0}; + QString alias{}; +}; + +Q_DECLARE_METATYPE(SourceItem) +Q_DECLARE_TYPEINFO(SourceItem, Q_MOVABLE_TYPE); + +QVector SourceToObjects(const QVector &source); + +QString OriginAlias(quint32 id, const QVector &source, const QSharedPointer &obj); + +bool SourceAliasValid(const SourceItem &item, const QSharedPointer &obj, const VContainer *data, + const QString &originAlias); + +#endif // TOOLSDEF_H diff --git a/src/libs/vtools/visualization/line/operation/visoperation.cpp b/src/libs/vtools/visualization/line/operation/visoperation.cpp index 258360e92..7147e14d7 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.cpp +++ b/src/libs/vtools/visualization/line/operation/visoperation.cpp @@ -57,7 +57,7 @@ VisOperation::~VisOperation() } //--------------------------------------------------------------------------------------------------------------------- -void VisOperation::SetObjects(QVector objects) +void VisOperation::SetObjects(const QVector &objects) { this->objects = objects; } diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h index 0599a03fb..e444ddba1 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.h +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -41,7 +41,7 @@ public: explicit VisOperation(const VContainer *data, QGraphicsItem *parent = nullptr); virtual ~VisOperation(); - void SetObjects(QVector objects); + void SetObjects(const QVector &objects); virtual void VisualMode(const quint32 &pointId = NULL_ID) override; From e5a9092e25435b45c6a56f339f983fdeece9cd02 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 15:14:46 +0200 Subject: [PATCH 20/23] Fix potential crash with too big shift for a label. --- .../drawTools/operation/flipping/vabstractflipping.h | 2 -- .../tools/drawTools/operation/vabstractoperation.cpp | 6 +++--- .../vtools/tools/drawTools/operation/vabstractoperation.h | 8 ++++---- src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp | 2 -- .../vtools/tools/drawTools/operation/vtoolrotation.cpp | 2 -- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h index ff662f328..fd2893b6c 100644 --- a/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h +++ b/src/libs/vtools/tools/drawTools/operation/flipping/vabstractflipping.h @@ -94,8 +94,6 @@ DestinationItem VAbstractFlipping::CreateItem(quint32 idTool, const SourceItem & } DestinationItem item; - item.mx = INT_MAX; - item.my = INT_MAX; item.id = data->AddGObject(new Item(rotated)); return item; } diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index 05a987b92..fc4b3bbb7 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -252,8 +252,8 @@ QVector VAbstractOperation::ExtractDestinationData(const QDomEl { DestinationItem d; d.id = VDomDocument::GetParametrUInt(element, AttrIdObject, NULL_ID_STR); - d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QString::number(INT_MAX))); - d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QString::number(INT_MAX))); + d.mx = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMx, QChar('1'))); + d.my = qApp->toPixel(VDomDocument::GetParametrDouble(element, AttrMy, QChar('1'))); d.showLabel = VDomDocument::GetParametrBool(element, AttrShowLabel, trueStr); destination.append(d); } @@ -754,7 +754,7 @@ void VAbstractOperation::SaveSourceDestination(QDomElement &tag) QDomElement item = doc->createElement(TagItem); doc->SetAttribute(item, AttrIdObject, dItem.id); - VAbstractSimple *obj = operatedObjects.value(dItem.id); + VAbstractSimple *obj = operatedObjects.value(dItem.id, nullptr); doc->SetAttributeOrRemoveIf(item, AttrMx, qApp->fromPixel(dItem.mx), obj && obj->GetType() != GOType::Point); diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index d23b88bbc..dc077446d 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -45,10 +45,10 @@ struct DestinationItem { - quint32 id; - qreal mx; - qreal my; - bool showLabel; + quint32 id{NULL_ID}; + qreal mx{1}; + qreal my{1}; + bool showLabel{true}; }; struct VAbstractOperationInitData : VDrawToolInitData diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 8646ad2c4..957d70007 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -629,8 +629,6 @@ DestinationItem VToolMove::CreateItem(quint32 idTool, const SourceItem &sItem, q } DestinationItem item; - item.mx = INT_MAX; - item.my = INT_MAX; item.id = data->AddGObject(new Item(moved)); return item; } diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp index de1829a23..7e9687da0 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolrotation.cpp @@ -440,8 +440,6 @@ DestinationItem VToolRotation::CreateItem(quint32 idTool, const SourceItem &sIte } DestinationItem item; - item.mx = INT_MAX; - item.my = INT_MAX; item.id = data->AddGObject(new Item(rotated)); return item; } From 91da094f2b77975981306fc408116c2c0d5d48ca Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 15:34:50 +0200 Subject: [PATCH 21/23] Alias support for pattern recipe. --- src/libs/vformat/vpatternrecipe.cpp | 43 ++++++++++++++++--- src/libs/vformat/vpatternrecipe.h | 3 ++ .../operation/vabstractoperation.cpp | 20 +-------- .../drawTools/operation/vabstractoperation.h | 2 +- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/libs/vformat/vpatternrecipe.cpp b/src/libs/vformat/vpatternrecipe.cpp index 0d86747e6..f2db3cd7e 100644 --- a/src/libs/vformat/vpatternrecipe.cpp +++ b/src/libs/vformat/vpatternrecipe.cpp @@ -89,7 +89,7 @@ VPatternRecipe::VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObj QDomElement recipeElement = createElement(QStringLiteral("recipe")); recipeElement.appendChild(createComment(FileComment())); - SetAttribute(recipeElement, QStringLiteral("version"), QStringLiteral("1.2.0")); + SetAttribute(recipeElement, QStringLiteral("version"), QStringLiteral("1.3.0")); recipeElement.appendChild(Prerequisite()); recipeElement.appendChild(Content()); @@ -811,6 +811,8 @@ QDomElement VPatternRecipe::CutArc(const VToolRecord &record) Formula(step, tool->GetFormulaLength(), AttrLength, AttrLengthValue); SetAttribute(step, AttrArc, tool->CurveName()); + CutCurveAttributes(step, tool); + return step; } @@ -825,6 +827,8 @@ QDomElement VPatternRecipe::CutSpline(const VToolRecord &record) Formula(step, tool->GetFormulaLength(), AttrLength, AttrLengthValue); SetAttribute(step, VToolCutSpline::AttrSpline, tool->CurveName()); + CutCurveAttributes(step, tool); + return step; } @@ -839,6 +843,8 @@ QDomElement VPatternRecipe::CutSplinePath(const VToolRecord &record) Formula(step, tool->GetFormulaLength(), AttrLength, AttrLengthValue); SetAttribute(step, VToolCutSplinePath::AttrSplinePath, tool->CurveName()); + CutCurveAttributes(step, tool); + return step; } @@ -1097,6 +1103,16 @@ void VPatternRecipe::CurveAttributes(QDomElement &step, T *tool) SetAttribute(step, AttrPenStyle, tool->GetPenStyle()); SetAttribute(step, AttrAScale, tool->GetApproximationScale()); SetAttribute(step, AttrDuplicate, tool->GetDuplicate()); + SetAttribute(step, AttrAlias, tool->GetAliasSuffix()); +} + + +//--------------------------------------------------------------------------------------------------------------------- +template +void VPatternRecipe::CutCurveAttributes(QDomElement &step, T *tool) +{ + SetAttribute(step, AttrAlias1, tool->GetAliasSuffix1()); + SetAttribute(step, AttrAlias2, tool->GetAliasSuffix2()); } //--------------------------------------------------------------------------------------------------------------------- @@ -1114,17 +1130,34 @@ QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint SCASSERT(tool) QDomElement nodes = createElement(QStringLiteral("nodes")); - QVector names = tool->SourceItems(); + QVector items = tool->SourceItems(); - if (names.isEmpty()) + if (items.isEmpty()) { throw VExceptionInvalidHistory(QObject::tr("Empty list of nodes for tool with id '%1'.").arg(id)); } - for (auto &nodeName : names) + for (auto &item : items) { QDomElement node = createElement(QStringLiteral("node")); - SetAttribute(node, AttrItem, nodeName); + + QSharedPointer obj; + + try + { + obj = m_data->GetGObject(item.id); + } + catch (const VExceptionBadId &e) + { + qCritical() << e.ErrorMessage()<name()); + if (not obj->GetAlias().isEmpty()) + { + SetAttribute(node, AttrAlias, obj->GetAlias()); + } nodes.appendChild(node); } diff --git a/src/libs/vformat/vpatternrecipe.h b/src/libs/vformat/vpatternrecipe.h index 4b53304a2..890dfe144 100644 --- a/src/libs/vformat/vpatternrecipe.h +++ b/src/libs/vformat/vpatternrecipe.h @@ -115,6 +115,9 @@ private: template void CurveAttributes(QDomElement &step, T* tool); + template + void CutCurveAttributes(QDomElement &step, T* tool); + QDomElement GroupOperationSource(VAbstractOperation *tool, quint32 id); }; diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp index fc4b3bbb7..ddb2a3125 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.cpp @@ -89,25 +89,9 @@ void VAbstractOperation::SetSuffix(const QString &suffix) } //--------------------------------------------------------------------------------------------------------------------- -QVector VAbstractOperation::SourceItems() const +QVector VAbstractOperation::SourceItems() const { - QVector itemNames; - itemNames.reserve(source.size()); - - try - { - for (auto &item : source) - { - itemNames.append(VAbstractTool::data.GetGObject(item.id)->ObjectName()); - } - } - catch (const VExceptionBadId &e) - { - qCritical() << e.ErrorMessage()<(); - } - - return itemNames; + return source; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index dc077446d..29ff7c12c 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -86,7 +86,7 @@ public: QString Suffix() const; void SetSuffix(const QString &suffix); - QVector SourceItems() const; + QVector SourceItems() const; virtual void GroupVisibility(quint32 object, bool visible) override; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; From adab73320251f546d184c94282df0c1c34d9fa49 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 16:20:35 +0200 Subject: [PATCH 22/23] Use an object name together with alias everywhere where is possible. --- src/libs/vtools/dialogs/tools/dialogtool.cpp | 17 ++-------------- .../dialogs/tools/piece/dialoginsertnode.cpp | 2 +- .../toolcut/vtoolcutsplinepath.cpp | 20 +++++++++++-------- .../toollinepoint/vtoolcurveintersectaxis.cpp | 8 +++++++- .../vtoolpointfromarcandtangent.cpp | 2 +- .../vtoolpointofintersectionarcs.cpp | 2 +- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 79e6aab56..20616e897 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -397,13 +397,10 @@ quint32 DialogTool::DNumber(const QString &baseName) const QString DialogTool::GetNodeName(const VPieceNode &node, bool showPassmarkDetails) const { const QSharedPointer obj = data->GetGObject(node.GetId()); - QString name = obj->name(); + QString name = obj->ObjectName(); if (node.GetTypeTool() != Tool::NodePoint) { - int bias = 0; - qApp->TrVars()->VariablesToUser(name, 0, obj->name(), bias); - if (node.GetReverse()) { name = QStringLiteral("- ") + name; @@ -706,17 +703,7 @@ void DialogTool::PrepareList(QMap &list, quint32 id) const { const auto obj = data->GeometricObject(id); SCASSERT(obj != nullptr) - - QString newName = obj->name(); - int bias = 0; - if (qApp->TrVars()->VariablesToUser(newName, 0, obj->name(), bias)) - { - list[newName] = id; - } - else - { - list[obj->name()] = id; - } + list[obj->ObjectName()] = id; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/piece/dialoginsertnode.cpp b/src/libs/vtools/dialogs/tools/piece/dialoginsertnode.cpp index ec327bdb1..31ad3295b 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialoginsertnode.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialoginsertnode.cpp @@ -109,7 +109,7 @@ void DialogInsertNode::SetNode(const VPieceNode &node) QString name = tr("Uknown"); try { - name = qApp->TrVars()->InternalVarToUser(data->GetGObject(m_node.GetId())->name()); + name = data->GetGObject(m_node.GetId())->ObjectName(); } catch (const VExceptionBadId &) { 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 83144906c..7fbe7fede 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -165,21 +165,25 @@ VToolCutSplinePath* VToolCutSplinePath::Create(VToolCutInitData &initData) { initData.id = initData.data->AddGObject(p); - initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); - initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); + auto path1 = QSharedPointer(splPath1); + initData.data->AddSpline(path1, NULL_ID, initData.id); + initData.data->RegisterUniqueName(path1); - initData.data->RegisterUniqueName(splPath1); - initData.data->RegisterUniqueName(splPath2); + auto path2 = QSharedPointer(splPath2); + initData.data->AddSpline(path2, NULL_ID, initData.id); + initData.data->RegisterUniqueName(path2); } else { initData.data->UpdateGObject(initData.id, p); - initData.data->AddSpline(QSharedPointer(splPath1), NULL_ID, initData.id); - initData.data->AddSpline(QSharedPointer(splPath2), NULL_ID, initData.id); + auto path1 = QSharedPointer(splPath1); + initData.data->AddSpline(path1, NULL_ID, initData.id); + initData.data->RegisterUniqueName(path1); - initData.data->RegisterUniqueName(splPath1); - initData.data->RegisterUniqueName(splPath2); + auto path2 = QSharedPointer(splPath2); + initData.data->AddSpline(path2, NULL_ID, initData.id); + initData.data->RegisterUniqueName(path2); if (initData.parse != Document::FullParse) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp index b8f4b6cb6..cd59ab249 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toollinepoint/vtoolcurveintersectaxis.cpp @@ -143,7 +143,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis { const QString errorMsg = tr("Error calculating point '%1'. There is no intersection with curve '%2' and axis" " through point '%3' with angle %4°") - .arg(initData.name, curve->name(), basePoint->name()).arg(angle); + .arg(initData.name, curve->ObjectName(), basePoint->name()).arg(angle); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } @@ -403,7 +403,10 @@ void VToolCurveIntersectAxis::InitSegments(GOType curveType, qreal segLength, co delete spl2; } + data->RegisterUniqueName(spline1); data->AddSpline(spline1, NULL_ID, p->id()); + + data->RegisterUniqueName(spline2); data->AddSpline(spline2, NULL_ID, p->id()); break; } @@ -448,7 +451,10 @@ void VToolCurveIntersectAxis::InitSegments(GOType curveType, qreal segLength, co delete splPath2; } + data->RegisterUniqueName(splP1); data->AddSpline(splP1, NULL_ID, p->id()); + + data->RegisterUniqueName(splP2); data->AddSpline(splP2, NULL_ID, p->id()); break; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp index e4004777c..ff1b81a74 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointfromarcandtangent.cpp @@ -122,7 +122,7 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA if (not success) { const QString errorMsg = tr("Error calculating point '%1'. Tangent to arc '%2' from point '%3' cannot be found") - .arg(initData.name, arc.name(), tPoint.name()); + .arg(initData.name, arc.ObjectName(), tPoint.name()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp index 36b830b2d..23dc7842e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectionarcs.cpp @@ -121,7 +121,7 @@ VToolPointOfIntersectionArcs *VToolPointOfIntersectionArcs::Create(VToolPointOfI if (not success) { const QString errorMsg = tr("Error calculating point '%1'. Arcs '%2' and '%3' have no point of intersection") - .arg(initData.name, firstArc->name(), secondArc->name()); + .arg(initData.name, firstArc->ObjectName(), secondArc->ObjectName()); qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) : qWarning() << VAbstractValApplication::patternMessageSignature + errorMsg; } From bee09c9e0bd79e89d99ce0119bf0a771177577eb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 7 Nov 2020 16:21:28 +0200 Subject: [PATCH 23/23] Update the change log. --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 29ec26e9e..0d8da1774 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ - Improve editing a spline path through control points for locked angles. - [smart-pattern/valentina#73] Notes for tools. - Fix crash while synchronize measurements. +- Object alias. # Version 0.7.36 October 24, 2020 - [#892] Show tooltip for piece node point.