Add alias support for internal variables.

This commit is contained in:
Roman Telezhynskyi 2020-11-04 10:58:57 +02:00
parent 788aa92d44
commit 8b49ea68c8
8 changed files with 88 additions and 17 deletions

View File

@ -49,7 +49,12 @@ VArcRadius::VArcRadius(const quint32 &id, const quint32 &parentId, const VArc *a
SCASSERT(arc != nullptr) SCASSERT(arc != nullptr)
SetType(VarType::ArcRadius); 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)); SetValue(FromPixel(arc->GetRadius(), patternUnit));
} }
@ -62,6 +67,12 @@ VArcRadius::VArcRadius(const quint32 &id, const quint32 &parentId, const VEllipt
SetType(VarType::ArcRadius); SetType(VarType::ArcRadius);
SetName(radius_V + QString("%1%2").arg(numberRadius).arg(elArc->name())); SetName(radius_V + QString("%1%2").arg(numberRadius).arg(elArc->name()));
if (not elArc->GetAlias().isEmpty())
{
SetAlias(radius_V + elArc->GetAlias());
}
if (numberRadius == 1) if (numberRadius == 1)
{ {
SetValue(FromPixel(elArc->GetRadius1(), patternUnit)); SetValue(FromPixel(elArc->GetRadius1(), patternUnit));

View File

@ -62,11 +62,21 @@ VCurveAngle::VCurveAngle(const quint32 &id, const quint32 &parentId, const VAbst
{ {
SetValue(curve->GetStartAngle()); SetValue(curve->GetStartAngle());
SetName(angle1_V + curve->name()); SetName(angle1_V + curve->name());
if (not curve->GetAlias().isEmpty())
{
SetAlias(angle1_V + curve->GetAlias());
}
} }
else else
{ {
SetValue(curve->GetEndAngle()); SetValue(curve->GetEndAngle());
SetName(angle2_V + curve->name()); 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) SCASSERT(elArc != nullptr)
SetValue(elArc->GetRotationAngle()); SetValue(elArc->GetRotationAngle());
SetName(rotation_V + elArc->name()); SetName(rotation_V + elArc->name());
if (not elArc->GetAlias().isEmpty())
{
SetAlias(rotation_V + elArc->GetAlias());
}
} }

View File

@ -50,6 +50,12 @@ VCurveLength::VCurveLength(const quint32 &id, const quint32 &parentId, const VAb
SetType(VarType::CurveLength); SetType(VarType::CurveLength);
SCASSERT(curve != nullptr) SCASSERT(curve != nullptr)
SetName(curve->name()); SetName(curve->name());
if (not curve->GetAlias().isEmpty())
{
SetAlias(curve->GetAlias());
}
SetValue(FromPixel(curve->GetLength(), patternUnit)); SetValue(FromPixel(curve->GetLength(), patternUnit));
} }

View File

@ -45,7 +45,6 @@ class VCurveVariableData : public QSharedData
public: public:
VCurveVariableData() VCurveVariableData()
:id(NULL_ID), parentId(NULL_ID)
{} {}
VCurveVariableData(const quint32 &id, const quint32 &parentId) VCurveVariableData(const quint32 &id, const quint32 &parentId)
@ -53,13 +52,15 @@ public:
{} {}
VCurveVariableData(const VCurveVariableData &var) VCurveVariableData(const VCurveVariableData &var)
:QSharedData(var), id(var.id), parentId(var.parentId) :QSharedData(var),
id(var.id),
parentId(var.parentId)
{} {}
virtual ~VCurveVariableData(); virtual ~VCurveVariableData();
quint32 id; quint32 id{NULL_ID};
quint32 parentId; quint32 parentId{NULL_ID};
private: private:
Q_DISABLE_ASSIGN(VCurveVariableData) Q_DISABLE_ASSIGN(VCurveVariableData)

View File

@ -123,3 +123,15 @@ void VInternalVariable::SetType(const VarType &type)
{ {
d->type = type; d->type = type;
} }
//---------------------------------------------------------------------------------------------------------------------
void VInternalVariable::SetAlias(const QString &alias)
{
d->alias = alias;
}
//---------------------------------------------------------------------------------------------------------------------
QString VInternalVariable::GetAlias() const
{
return d->alias;
}

View File

@ -61,6 +61,9 @@ public:
VarType GetType() const; VarType GetType() const;
void SetType(const VarType &type); void SetType(const VarType &type);
void SetAlias(const QString &alias);
QString GetAlias() const;
virtual bool Filter(quint32 id); virtual bool Filter(quint32 id);
virtual bool IsNotUsed() const; virtual bool IsNotUsed() const;

View File

@ -42,23 +42,26 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
class VInternalVariableData : public QSharedData class VInternalVariableData : public QSharedData
{ {
public: public:
VInternalVariableData() VInternalVariableData()
:type(VarType::Unknown), value(0), name(QString())
{} {}
VInternalVariableData(const VInternalVariableData &var) 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(); virtual ~VInternalVariableData();
VarType type; VarType type{VarType::Unknown};
/** @brief value variable's value */ /** @brief value variable's value */
qreal value; qreal value{0};
QString name; QString name{};
QString alias{};
private: private:
Q_DISABLE_ASSIGN(VInternalVariableData) Q_DISABLE_ASSIGN(VInternalVariableData)

View File

@ -227,6 +227,9 @@ private:
void AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId = NULL_ID); void AddCurve(const QSharedPointer<VAbstractCurve> &curve, const quint32 &id, quint32 parentId = NULL_ID);
template <typename T>
void AddVariable(const QSharedPointer<T> &var, const QString &name);
template <class T> template <class T>
uint qHash( const QSharedPointer<T> &p ); uint qHash( const QSharedPointer<T> &p );
@ -334,25 +337,42 @@ template <typename T>
void VContainer::AddVariable(const QSharedPointer<T> &var) void VContainer::AddVariable(const QSharedPointer<T> &var)
{ {
SCASSERT(not var->GetName().isEmpty()) 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 <typename T>
void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
{
if (name.isEmpty())
{
return;
}
if (d->variables.contains(name))
{
if (d->variables.value(name)->GetType() == var->GetType())
{ {
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(var->GetName())); QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
if (v.isNull()) if (v.isNull())
{ {
throw VExceptionBadId(tr("Can't cast object."), var->GetName()); throw VExceptionBadId(tr("Can't cast object."), name);
} }
*v = *var; *v = *var;
} }
else else
{ {
throw VExceptionBadId(tr("Can't find object. Type mismatch."), var->GetName()); throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
} }
} }
else else
{ {
d->variables.insert(var->GetName(), var); d->variables.insert(name, var);
} }
} }