Introducing new method SetAttributeOrRemoveIf.
--HG-- branch : develop
This commit is contained in:
parent
8612f6d0af
commit
7d1c4bc3ba
|
@ -4177,14 +4177,7 @@ void VPattern::SetDefCustomHeight(int value)
|
|||
QDomElement domElement = domNode.toElement();
|
||||
if (domElement.isNull() == false)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
domElement.removeAttribute(AttrDefHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAttribute(domElement, AttrDefHeight, value);
|
||||
}
|
||||
SetAttributeOrRemoveIf(domElement, AttrDefHeight, value, 0);
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
|
@ -4236,14 +4229,7 @@ void VPattern::SetDefCustomSize(int value)
|
|||
QDomElement domElement = domNode.toElement();
|
||||
if (domElement.isNull() == false)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
domElement.removeAttribute(AttrDefSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetAttribute(domElement, AttrDefSize, value);
|
||||
}
|
||||
SetAttributeOrRemoveIf(domElement, AttrDefSize, value, 0);
|
||||
modified = true;
|
||||
}
|
||||
else
|
||||
|
@ -4272,14 +4258,7 @@ void VPattern::SetReadOnly(bool rOnly)
|
|||
|
||||
if (not pattern.isNull())
|
||||
{
|
||||
if (rOnly)
|
||||
{
|
||||
SetAttribute(pattern, AttrReadOnly, rOnly);
|
||||
}
|
||||
else
|
||||
{// For better backward compatibility
|
||||
pattern.removeAttribute(AttrReadOnly);
|
||||
}
|
||||
SetAttributeOrRemoveIf(pattern, AttrReadOnly, rOnly, false);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,9 @@ public:
|
|||
template <typename T>
|
||||
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
|
||||
|
||||
template <typename T>
|
||||
void SetAttributeOrRemoveIf(QDomElement &domElement, const QString &name, const T &value, const T &condition) const;
|
||||
|
||||
static quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue);
|
||||
static bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue);
|
||||
|
||||
|
@ -210,6 +213,14 @@ inline void VDomDocument::SetAttribute<MeasurementsType>(QDomElement &domElement
|
|||
QStringLiteral("individual"));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
inline void VDomDocument::SetAttributeOrRemoveIf(QDomElement &domElement, const QString &name, const T &value,
|
||||
const T &condition) const
|
||||
{
|
||||
value != condition ? domElement.setAttribute(name, value) : domElement.removeAttribute(name);
|
||||
}
|
||||
|
||||
QT_WARNING_POP
|
||||
|
||||
#endif // VDOMDOCUMENT_H
|
||||
|
|
|
@ -523,29 +523,8 @@ QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagNa
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
const bool excluded = node.IsExcluded();
|
||||
if (excluded)
|
||||
{
|
||||
doc->SetAttribute(nod, VAbstractPattern::AttrNodeExcluded, excluded);
|
||||
}
|
||||
else
|
||||
{ // For backward compatebility.
|
||||
nod.removeAttribute(VAbstractPattern::AttrNodeExcluded);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const bool uniqueness = node.IsCheckUniqueness();
|
||||
if (not uniqueness)
|
||||
{
|
||||
doc->SetAttribute(nod, VAbstractPattern::AttrCheckUniqueness, uniqueness);
|
||||
}
|
||||
else
|
||||
{ // For backward compatebility.
|
||||
nod.removeAttribute(VAbstractPattern::AttrCheckUniqueness);
|
||||
}
|
||||
}
|
||||
doc->SetAttributeOrRemoveIf(nod, VAbstractPattern::AttrNodeExcluded, node.IsExcluded(), false);
|
||||
doc->SetAttributeOrRemoveIf(nod, VAbstractPattern::AttrCheckUniqueness, node.IsCheckUniqueness(), true);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
@ -602,17 +581,7 @@ QDomElement VAbstractTool::AddSANode(VAbstractPattern *doc, const QString &tagNa
|
|||
nod.removeAttribute(VAbstractPattern::AttrNodePassmarkAngle);
|
||||
}
|
||||
|
||||
{
|
||||
const bool showSecond = node.IsShowSecondPassmark();
|
||||
if (not showSecond)
|
||||
{
|
||||
doc->SetAttribute(nod, VAbstractPattern::AttrNodeShowSecondPassmark, showSecond);
|
||||
}
|
||||
else
|
||||
{ // For backward compatebility.
|
||||
nod.removeAttribute(VAbstractPattern::AttrNodeShowSecondPassmark);
|
||||
}
|
||||
}
|
||||
doc->SetAttributeOrRemoveIf(nod, VAbstractPattern::AttrNodeShowSecondPassmark, node.IsShowSecondPassmark(), true);
|
||||
|
||||
return nod;
|
||||
}
|
||||
|
|
|
@ -275,17 +275,7 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl
|
|||
doc->SetAttribute(domElement, AttrForceFlipping, piece.IsForceFlipping());
|
||||
doc->SetAttribute(domElement, AttrSeamAllowance, piece.IsSeamAllowance());
|
||||
doc->SetAttribute(domElement, AttrHideMainPath, piece.IsHideMainPath());
|
||||
|
||||
const bool saBuiltIn = piece.IsSeamAllowanceBuiltIn();
|
||||
if (saBuiltIn)
|
||||
{
|
||||
doc->SetAttribute(domElement, AttrSeamAllowanceBuiltIn, saBuiltIn);
|
||||
}
|
||||
else
|
||||
{ // For backward compatebility.
|
||||
domElement.removeAttribute(AttrSeamAllowanceBuiltIn);
|
||||
}
|
||||
|
||||
doc->SetAttributeOrRemoveIf(domElement, AttrSeamAllowanceBuiltIn, piece.IsSeamAllowanceBuiltIn(), false);
|
||||
doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth());
|
||||
doc->SetAttribute(domElement, AttrUnited, piece.IsUnited());
|
||||
}
|
||||
|
@ -368,34 +358,10 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement
|
|||
doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight());
|
||||
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation());
|
||||
|
||||
if (data.CenterPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrCenterPin, data.CenterPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrCenterPin);
|
||||
}
|
||||
|
||||
if (data.TopLeftPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrTopLeftPin, data.TopLeftPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrTopLeftPin);
|
||||
}
|
||||
|
||||
if (data.BottomRightPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrBottomRightPin, data.BottomRightPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrBottomRightPin);
|
||||
}
|
||||
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrCenterPin, data.CenterPin(), not (data.CenterPin() > NULL_ID));
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrTopLeftPin, data.TopLeftPin(), not (data.TopLeftPin() > NULL_ID));
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrBottomRightPin, data.BottomRightPin(),
|
||||
not (data.BottomRightPin() > NULL_ID));
|
||||
doc->SetLabelTemplate(domData, data.GetLabelTemplate());
|
||||
|
||||
domElement.appendChild(domData);
|
||||
|
@ -456,33 +422,9 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle
|
|||
doc->SetAttribute(domData, AttrLength, glGeom.GetLength());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType()));
|
||||
|
||||
if (glGeom.CenterPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrCenterPin, glGeom.CenterPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrCenterPin);
|
||||
}
|
||||
|
||||
if (glGeom.TopPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrTopPin, glGeom.TopPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrTopPin);
|
||||
}
|
||||
|
||||
if (glGeom.BottomPin() > NULL_ID)
|
||||
{
|
||||
doc->SetAttribute(domData, AttrBottomPin, glGeom.BottomPin());
|
||||
}
|
||||
else
|
||||
{
|
||||
domData.removeAttribute(AttrBottomPin);
|
||||
}
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrCenterPin, glGeom.CenterPin(), not (glGeom.CenterPin() > NULL_ID));
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrTopPin, glGeom.TopPin(), not (glGeom.TopPin() > NULL_ID));
|
||||
doc->SetAttributeOrRemoveIf<bool>(domData, AttrBottomPin, glGeom.BottomPin(), not (glGeom.BottomPin() > NULL_ID));
|
||||
|
||||
domElement.appendChild(domData);
|
||||
}
|
||||
|
|
|
@ -75,14 +75,7 @@ void TogglePieceInLayout::Do(bool state)
|
|||
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
||||
if (detail.isElement())
|
||||
{
|
||||
if (state == false)
|
||||
{
|
||||
doc->SetAttribute(detail, AttrInLayout, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
detail.removeAttribute(AttrInLayout);
|
||||
}
|
||||
doc->SetAttributeOrRemoveIf(detail, AttrInLayout, state, true);
|
||||
|
||||
VPiece det = m_data->DataPieces()->value(m_id);
|
||||
det.SetInLayout(state);
|
||||
|
|
Loading…
Reference in New Issue
Block a user