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)
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));

View File

@ -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());
}
}

View File

@ -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));
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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;

View File

@ -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)

View File

@ -227,6 +227,9 @@ private:
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>
uint qHash( const QSharedPointer<T> &p );
@ -334,25 +337,42 @@ template <typename T>
void VContainer::AddVariable(const QSharedPointer<T> &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 <typename T>
void VContainer::AddVariable(const QSharedPointer<T> &var, const QString &name)
{
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(var->GetName()));
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(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);
}
}