Refactoring. Use CreateElementWithText to create tag with text.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2019-07-10 13:07:29 +03:00
parent 8f961300e6
commit 6ed74b2dd0
8 changed files with 38 additions and 124 deletions

View File

@ -122,16 +122,8 @@ void VPattern::CreateEmptyFile()
SetAttribute(patternElement, AttrLabelPrefix, DefLabelLanguage());
patternElement.appendChild(createComment(FileComment()));
QDomElement version = createElement(TagVersion);
QDomText newNodeText = createTextNode(VPatternConverter::PatternMaxVerStr);
version.appendChild(newNodeText);
patternElement.appendChild(version);
QDomElement unit = createElement(TagUnit);
newNodeText = createTextNode(UnitsToStr(qApp->patternUnit()));
unit.appendChild(newNodeText);
patternElement.appendChild(unit);
patternElement.appendChild(CreateElementWithText(TagVersion, VPatternConverter::PatternMaxVerStr));
patternElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(qApp->patternUnit())));
patternElement.appendChild(createElement(TagDescription));
patternElement.appendChild(createElement(TagNotes));

View File

@ -1120,12 +1120,9 @@ void VPatternConverter::TagUnitToV0_2_0()
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 0),
"Time to refactor the code.");
QDomElement unit = createElement(*strUnit);
QDomText newNodeText = createTextNode(MUnitV0_1_4());
unit.appendChild(newNodeText);
QDomElement patternElement = documentElement();
patternElement.insertAfter(unit, patternElement.firstChildElement(*strVersion));
patternElement.insertAfter(CreateElementWithText(*strUnit, MUnitV0_1_4()),
patternElement.firstChildElement(*strVersion));
}
//---------------------------------------------------------------------------------------------------------------------
@ -1611,8 +1608,7 @@ void VPatternConverter::TagMeasurementsToV0_2_0()
ms.removeAttribute(*strType);
ms.removeAttribute(*strPath);
QDomText newNodeText = createTextNode(QFileInfo(m_convertedFileName).absoluteDir().relativeFilePath(path));
ms.appendChild(newNodeText);
ms.appendChild(createTextNode(QFileInfo(m_convertedFileName).absoluteDir().relativeFilePath(path)));
}
//---------------------------------------------------------------------------------------------------------------------
@ -1777,9 +1773,7 @@ void VPatternConverter::SaveChildrenToolUnionToV0_2_4(quint32 id, const QVector<
for (auto child : children)
{
QDomElement tagChild = createElement(*strChild);
tagChild.appendChild(createTextNode(QString().setNum(child)));
tagChildren.appendChild(tagChild);
tagChildren.appendChild(CreateElementWithText(*strChild, QString().setNum(child)));
}
toolUnion.appendChild(tagChildren);

View File

@ -168,18 +168,12 @@ void VVITConverter::AddNewTagsForV0_3_0()
"Time to refactor the code.");
QDomElement rootElement = this->documentElement();
QDomNode refChild = rootElement.firstChildElement("version");
QDomElement ro = createElement(QStringLiteral("read-only"));
const QDomText roNodeText = createTextNode(falseStr);
ro.appendChild(roNodeText);
refChild = rootElement.insertAfter(ro, refChild);
QDomNode refChild = rootElement.firstChildElement(QStringLiteral("version"));
refChild = rootElement.insertAfter(CreateElementWithText(QStringLiteral("read-only"), falseStr), refChild);
refChild = rootElement.insertAfter(createElement(QStringLiteral("notes")), refChild);
QDomElement unit = createElement("unit");
unit.appendChild(createTextNode(MUnitV0_2_0()));
rootElement.insertAfter(unit, refChild);
rootElement.insertAfter(CreateElementWithText(QStringLiteral("unit"), MUnitV0_2_0()), refChild);
}
//---------------------------------------------------------------------------------------------------------------------
@ -261,12 +255,8 @@ void VVITConverter::GenderV0_3_1()
const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("sex"));
QDomElement sex = nodeList.at(0).toElement();
QDomElement gender = createElement(QStringLiteral("gender"));
gender.appendChild(createTextNode(sex.text()));
QDomElement parent = sex.parentNode().toElement();
parent.replaceChild(gender, sex);
parent.replaceChild(CreateElementWithText(QStringLiteral("gender"), sex.text()), sex);
}
//---------------------------------------------------------------------------------------------------------------------
@ -276,14 +266,11 @@ void VVITConverter::PM_SystemV0_3_2()
Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 2),
"Time to refactor the code.");
QDomElement pm_system = createElement(QStringLiteral("pm_system"));
pm_system.appendChild(createTextNode(QStringLiteral("998")));
const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("personal"));
QDomElement personal = nodeList.at(0).toElement();
QDomElement parent = personal.parentNode().toElement();
parent.insertBefore(pm_system, personal);
parent.insertBefore(CreateElementWithText(QStringLiteral("pm_system"), QStringLiteral("998")), personal);
}
//---------------------------------------------------------------------------------------------------------------------
@ -351,8 +338,6 @@ void VVITConverter::ConverCustomerNameToV0_4_0()
personal.removeChild(familyNameNode);
}
QDomElement customer = createElement(*strCustomer);
QString customerName;
if (not givenName.isEmpty() && not familyName.isEmpty())
{
@ -367,11 +352,8 @@ void VVITConverter::ConverCustomerNameToV0_4_0()
customerName = familyName;
}
if (not customerName.isEmpty())
{
customer.appendChild(createTextNode(customerName));
}
personal.insertBefore(customer, personal.firstChild());
personal.insertBefore(CreateElementWithText(*strCustomer, not customerName.isEmpty() ? customerName : QString()),
personal.firstChild());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -158,21 +158,12 @@ void VVSTConverter::AddNewTagsForV0_4_0()
"Time to refactor the code.");
QDomElement rootElement = this->documentElement();
QDomNode refChild = rootElement.firstChildElement("version");
QDomNode refChild = rootElement.firstChildElement(QStringLiteral("version"));
{
QDomElement ro = createElement(QStringLiteral("read-only"));
const QDomText roNodeText = createTextNode(falseStr);
ro.appendChild(roNodeText);
refChild = rootElement.insertAfter(ro, refChild);
}
refChild = rootElement.insertAfter(CreateElementWithText(QStringLiteral("read-only"), falseStr), refChild);
{
QDomElement notes = createElement(QStringLiteral("notes"));
const QDomText nodeText = createTextNode(UniqueTagText(QStringLiteral("description")));
notes.appendChild(nodeText);
rootElement.insertAfter(notes, refChild);
}
rootElement.insertAfter(CreateElementWithText(QStringLiteral("notes"),
UniqueTagText(QStringLiteral("description"))), refChild);
}
//---------------------------------------------------------------------------------------------------------------------
@ -277,14 +268,11 @@ void VVSTConverter::PM_SystemV0_4_1()
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 1),
"Time to refactor the code.");
QDomElement pm_system = createElement(QStringLiteral("pm_system"));
pm_system.appendChild(createTextNode(QStringLiteral("998")));
const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("size"));
QDomElement personal = nodeList.at(0).toElement();
QDomElement parent = personal.parentNode().toElement();
parent.insertBefore(pm_system, personal);
parent.insertBefore(CreateElementWithText(QStringLiteral("pm_system"), QStringLiteral("998")), personal);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -42,16 +42,12 @@ void VLabelTemplate::CreateEmptyTemplate()
{
clear();
QDomElement templateElement = this->createElement(TagTemplate);
QDomElement version = createElement(TagVersion);
QDomText newNodeText = createTextNode(VLabelTemplateConverter::LabelTemplateMaxVerStr);
version.appendChild(newNodeText);
templateElement.appendChild(version);
templateElement.appendChild(CreateElementWithText(TagVersion, VLabelTemplateConverter::LabelTemplateMaxVerStr));
templateElement.appendChild(createElement(TagLines));
this->appendChild(templateElement);
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -664,27 +664,11 @@ void VMeasurements::CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHe
QDomElement mElement = this->createElement(TagVST);
mElement.appendChild(createComment(FileComment()));
QDomElement version = createElement(TagVersion);
const QDomText newNodeText = createTextNode(VVSTConverter::MeasurementMaxVerStr);
version.appendChild(newNodeText);
mElement.appendChild(version);
QDomElement ro = createElement(TagReadOnly);
const QDomText roNodeText = createTextNode(falseStr);
ro.appendChild(roNodeText);
mElement.appendChild(ro);
mElement.appendChild(CreateElementWithText(TagVersion, VVSTConverter::MeasurementMaxVerStr));
mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
mElement.appendChild(createElement(TagNotes));
QDomElement mUnit = createElement(TagUnit);
const QDomText unitText = createTextNode(UnitsToStr(unit));
mUnit.appendChild(unitText);
mElement.appendChild(mUnit);
QDomElement system = createElement(TagPMSystem);
system.appendChild(createTextNode(ClearPMCode(p998_S)));
mElement.appendChild(system);
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
QDomElement size = createElement(TagSize);
SetAttribute(size, AttrBase, QString().setNum(baseSize));
@ -697,7 +681,8 @@ void VMeasurements::CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHe
mElement.appendChild(createElement(TagBodyMeasurements));
this->appendChild(mElement);
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
}
//---------------------------------------------------------------------------------------------------------------------
@ -707,37 +692,16 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit)
QDomElement mElement = this->createElement(TagVIT);
mElement.appendChild(createComment(FileComment()));
QDomElement version = createElement(TagVersion);
const QDomText newNodeText = createTextNode(VVITConverter::MeasurementMaxVerStr);
version.appendChild(newNodeText);
mElement.appendChild(version);
QDomElement ro = createElement(TagReadOnly);
const QDomText roNodeText = createTextNode(falseStr);
ro.appendChild(roNodeText);
mElement.appendChild(ro);
mElement.appendChild(CreateElementWithText(TagVersion, VVITConverter::MeasurementMaxVerStr));
mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
mElement.appendChild(createElement(TagNotes));
QDomElement mUnit = createElement(TagUnit);
mUnit.appendChild(createTextNode(UnitsToStr(unit)));
mElement.appendChild(mUnit);
QDomElement system = createElement(TagPMSystem);
system.appendChild(createTextNode(ClearPMCode(p998_S)));
mElement.appendChild(system);
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
QDomElement personal = createElement(TagPersonal);
personal.appendChild(createElement(TagCustomer));
QDomElement date = createElement(TagBirthDate);
date.appendChild(createTextNode(*defBirthDate));
personal.appendChild(date);
QDomElement gender = createElement(TagGender);
gender.appendChild(createTextNode(GenderToStr(GenderType::Unknown)));
personal.appendChild(gender);
personal.appendChild(CreateElementWithText(TagBirthDate, *defBirthDate));
personal.appendChild(CreateElementWithText(TagGender, GenderToStr(GenderType::Unknown)));
personal.appendChild(createElement(TagEmail));
mElement.appendChild(personal);
@ -745,7 +709,8 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit)
mElement.appendChild(createElement(TagBodyMeasurements));
this->appendChild(mElement);
insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild());
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -1930,9 +1930,8 @@ void VToolSeamAllowance::AddPointRecords(VAbstractPattern *doc, QDomElement &dom
QDomElement pinsElement = doc->createElement(tag);
for (auto record : records)
{
QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord);
recordNode.appendChild(doc->createTextNode(QString().setNum(record)));
pinsElement.appendChild(recordNode);
pinsElement.appendChild(doc->CreateElementWithText(VToolSeamAllowance::TagRecord,
QString().setNum(record)));
}
domElement.appendChild(pinsElement);
}

View File

@ -816,9 +816,7 @@ void SaveChildren(VAbstractPattern *doc, quint32 id, QDomElement section, const
{
for (auto child : children)
{
QDomElement tagChild = doc->createElement(VToolUnionDetails::TagChild);
tagChild.appendChild(doc->createTextNode(QString().setNum(child)));
section.appendChild(tagChild);
section.appendChild(doc->CreateElementWithText(VToolUnionDetails::TagChild, QString().setNum(child)));
}
GetTagChildren(doc, id).appendChild(section);