From 8b49ea68c8679e9324d6d30b7a543c99383b6f6d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Nov 2020 10:58:57 +0200 Subject: [PATCH] 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); } }