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()); SetAttribute(patternElement, AttrLabelPrefix, DefLabelLanguage());
patternElement.appendChild(createComment(FileComment())); patternElement.appendChild(createComment(FileComment()));
patternElement.appendChild(CreateElementWithText(TagVersion, VPatternConverter::PatternMaxVerStr));
QDomElement version = createElement(TagVersion); patternElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(qApp->patternUnit())));
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(createElement(TagDescription)); patternElement.appendChild(createElement(TagDescription));
patternElement.appendChild(createElement(TagNotes)); 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), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FORMAT_VERSION(0, 2, 0),
"Time to refactor the code."); "Time to refactor the code.");
QDomElement unit = createElement(*strUnit);
QDomText newNodeText = createTextNode(MUnitV0_1_4());
unit.appendChild(newNodeText);
QDomElement patternElement = documentElement(); 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(*strType);
ms.removeAttribute(*strPath); ms.removeAttribute(*strPath);
QDomText newNodeText = createTextNode(QFileInfo(m_convertedFileName).absoluteDir().relativeFilePath(path)); ms.appendChild(createTextNode(QFileInfo(m_convertedFileName).absoluteDir().relativeFilePath(path)));
ms.appendChild(newNodeText);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1777,9 +1773,7 @@ void VPatternConverter::SaveChildrenToolUnionToV0_2_4(quint32 id, const QVector<
for (auto child : children) for (auto child : children)
{ {
QDomElement tagChild = createElement(*strChild); tagChildren.appendChild(CreateElementWithText(*strChild, QString().setNum(child)));
tagChild.appendChild(createTextNode(QString().setNum(child)));
tagChildren.appendChild(tagChild);
} }
toolUnion.appendChild(tagChildren); toolUnion.appendChild(tagChildren);

View File

@ -168,18 +168,12 @@ void VVITConverter::AddNewTagsForV0_3_0()
"Time to refactor the code."); "Time to refactor the code.");
QDomElement rootElement = this->documentElement(); 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);
refChild = rootElement.insertAfter(createElement(QStringLiteral("notes")), refChild); refChild = rootElement.insertAfter(createElement(QStringLiteral("notes")), refChild);
QDomElement unit = createElement("unit"); rootElement.insertAfter(CreateElementWithText(QStringLiteral("unit"), MUnitV0_2_0()), refChild);
unit.appendChild(createTextNode(MUnitV0_2_0()));
rootElement.insertAfter(unit, refChild);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -261,12 +255,8 @@ void VVITConverter::GenderV0_3_1()
const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("sex")); const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("sex"));
QDomElement sex = nodeList.at(0).toElement(); QDomElement sex = nodeList.at(0).toElement();
QDomElement gender = createElement(QStringLiteral("gender"));
gender.appendChild(createTextNode(sex.text()));
QDomElement parent = sex.parentNode().toElement(); 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), Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < FORMAT_VERSION(0, 3, 2),
"Time to refactor the code."); "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")); const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("personal"));
QDomElement personal = nodeList.at(0).toElement(); QDomElement personal = nodeList.at(0).toElement();
QDomElement parent = personal.parentNode().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); personal.removeChild(familyNameNode);
} }
QDomElement customer = createElement(*strCustomer);
QString customerName; QString customerName;
if (not givenName.isEmpty() && not familyName.isEmpty()) if (not givenName.isEmpty() && not familyName.isEmpty())
{ {
@ -367,11 +352,8 @@ void VVITConverter::ConverCustomerNameToV0_4_0()
customerName = familyName; customerName = familyName;
} }
if (not customerName.isEmpty()) personal.insertBefore(CreateElementWithText(*strCustomer, not customerName.isEmpty() ? customerName : QString()),
{ personal.firstChild());
customer.appendChild(createTextNode(customerName));
}
personal.insertBefore(customer, personal.firstChild());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -158,21 +158,12 @@ void VVSTConverter::AddNewTagsForV0_4_0()
"Time to refactor the code."); "Time to refactor the code.");
QDomElement rootElement = this->documentElement(); QDomElement rootElement = this->documentElement();
QDomNode refChild = rootElement.firstChildElement("version"); QDomNode refChild = rootElement.firstChildElement(QStringLiteral("version"));
{ refChild = rootElement.insertAfter(CreateElementWithText(QStringLiteral("read-only"), falseStr), refChild);
QDomElement ro = createElement(QStringLiteral("read-only"));
const QDomText roNodeText = createTextNode(falseStr);
ro.appendChild(roNodeText);
refChild = rootElement.insertAfter(ro, refChild);
}
{ rootElement.insertAfter(CreateElementWithText(QStringLiteral("notes"),
QDomElement notes = createElement(QStringLiteral("notes")); UniqueTagText(QStringLiteral("description"))), refChild);
const QDomText nodeText = createTextNode(UniqueTagText(QStringLiteral("description")));
notes.appendChild(nodeText);
rootElement.insertAfter(notes, refChild);
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -277,14 +268,11 @@ void VVSTConverter::PM_SystemV0_4_1()
Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 1), Q_STATIC_ASSERT_X(VVSTConverter::MeasurementMinVer < FORMAT_VERSION(0, 4, 1),
"Time to refactor the code."); "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")); const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("size"));
QDomElement personal = nodeList.at(0).toElement(); QDomElement personal = nodeList.at(0).toElement();
QDomElement parent = personal.parentNode().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(); clear();
QDomElement templateElement = this->createElement(TagTemplate); QDomElement templateElement = this->createElement(TagTemplate);
templateElement.appendChild(CreateElementWithText(TagVersion, VLabelTemplateConverter::LabelTemplateMaxVerStr));
QDomElement version = createElement(TagVersion);
QDomText newNodeText = createTextNode(VLabelTemplateConverter::LabelTemplateMaxVerStr);
version.appendChild(newNodeText);
templateElement.appendChild(version);
templateElement.appendChild(createElement(TagLines)); templateElement.appendChild(createElement(TagLines));
this->appendChild(templateElement); 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); QDomElement mElement = this->createElement(TagVST);
mElement.appendChild(createComment(FileComment())); mElement.appendChild(createComment(FileComment()));
mElement.appendChild(CreateElementWithText(TagVersion, VVSTConverter::MeasurementMaxVerStr));
QDomElement version = createElement(TagVersion); mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
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(createElement(TagNotes)); mElement.appendChild(createElement(TagNotes));
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
QDomElement mUnit = createElement(TagUnit); mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
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);
QDomElement size = createElement(TagSize); QDomElement size = createElement(TagSize);
SetAttribute(size, AttrBase, QString().setNum(baseSize)); SetAttribute(size, AttrBase, QString().setNum(baseSize));
@ -697,7 +681,8 @@ void VMeasurements::CreateEmptyMultisizeFile(Unit unit, int baseSize, int baseHe
mElement.appendChild(createElement(TagBodyMeasurements)); mElement.appendChild(createElement(TagBodyMeasurements));
this->appendChild(mElement); 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); QDomElement mElement = this->createElement(TagVIT);
mElement.appendChild(createComment(FileComment())); mElement.appendChild(createComment(FileComment()));
mElement.appendChild(CreateElementWithText(TagVersion, VVITConverter::MeasurementMaxVerStr));
QDomElement version = createElement(TagVersion); mElement.appendChild(CreateElementWithText(TagReadOnly, falseStr));
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(createElement(TagNotes)); mElement.appendChild(createElement(TagNotes));
mElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(unit)));
QDomElement mUnit = createElement(TagUnit); mElement.appendChild(CreateElementWithText(TagPMSystem, ClearPMCode(p998_S)));
mUnit.appendChild(createTextNode(UnitsToStr(unit)));
mElement.appendChild(mUnit);
QDomElement system = createElement(TagPMSystem);
system.appendChild(createTextNode(ClearPMCode(p998_S)));
mElement.appendChild(system);
QDomElement personal = createElement(TagPersonal); QDomElement personal = createElement(TagPersonal);
personal.appendChild(createElement(TagCustomer)); personal.appendChild(createElement(TagCustomer));
personal.appendChild(CreateElementWithText(TagBirthDate, *defBirthDate));
QDomElement date = createElement(TagBirthDate); personal.appendChild(CreateElementWithText(TagGender, GenderToStr(GenderType::Unknown)));
date.appendChild(createTextNode(*defBirthDate));
personal.appendChild(date);
QDomElement gender = createElement(TagGender);
gender.appendChild(createTextNode(GenderToStr(GenderType::Unknown)));
personal.appendChild(gender);
personal.appendChild(createElement(TagEmail)); personal.appendChild(createElement(TagEmail));
mElement.appendChild(personal); mElement.appendChild(personal);
@ -745,7 +709,8 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit)
mElement.appendChild(createElement(TagBodyMeasurements)); mElement.appendChild(createElement(TagBodyMeasurements));
this->appendChild(mElement); 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); QDomElement pinsElement = doc->createElement(tag);
for (auto record : records) for (auto record : records)
{ {
QDomElement recordNode = doc->createElement(VToolSeamAllowance::TagRecord); pinsElement.appendChild(doc->CreateElementWithText(VToolSeamAllowance::TagRecord,
recordNode.appendChild(doc->createTextNode(QString().setNum(record))); QString().setNum(record)));
pinsElement.appendChild(recordNode);
} }
domElement.appendChild(pinsElement); domElement.appendChild(pinsElement);
} }

View File

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