Alias support for pattern recipe.

This commit is contained in:
Roman Telezhynskyi 2020-11-07 15:34:50 +02:00
parent e5a9092e25
commit 91da094f2b
4 changed files with 44 additions and 24 deletions

View File

@ -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<typename T>
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<QString> names = tool->SourceItems();
QVector<SourceItem> 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<VGObject> obj;
try
{
obj = m_data->GetGObject(item.id);
}
catch (const VExceptionBadId &e)
{
qCritical() << e.ErrorMessage()<<Q_FUNC_INFO;
continue;
}
SetAttribute(node, AttrItem, obj->name());
if (not obj->GetAlias().isEmpty())
{
SetAttribute(node, AttrAlias, obj->GetAlias());
}
nodes.appendChild(node);
}

View File

@ -115,6 +115,9 @@ private:
template <typename T>
void CurveAttributes(QDomElement &step, T* tool);
template <typename T>
void CutCurveAttributes(QDomElement &step, T* tool);
QDomElement GroupOperationSource(VAbstractOperation *tool, quint32 id);
};

View File

@ -89,25 +89,9 @@ void VAbstractOperation::SetSuffix(const QString &suffix)
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QString> VAbstractOperation::SourceItems() const
QVector<SourceItem> VAbstractOperation::SourceItems() const
{
QVector<QString> 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()<<Q_FUNC_INFO;
return QVector<QString>();
}
return itemNames;
return source;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -86,7 +86,7 @@ public:
QString Suffix() const;
void SetSuffix(const QString &suffix);
QVector<QString> SourceItems() const;
QVector<SourceItem> SourceItems() const;
virtual void GroupVisibility(quint32 object, bool visible) override;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;