From 6499c73d0cffe089a17bcc01b77b06d389ddc0ac Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 18 Mar 2017 11:04:12 +0200 Subject: [PATCH] Refactoring. Merge identical cases. --HG-- branch : develop --- src/libs/ifc/ifcdef.cpp | 4 +- src/libs/ifc/xml/vabstractpattern.cpp | 15 ++----- src/libs/ifc/xml/vdomdocument.cpp | 57 ++++---------------------- src/libs/ifc/xml/vpatternconverter.cpp | 8 ---- src/test/ParserTest/main.cpp | 2 - 5 files changed, 12 insertions(+), 74 deletions(-) diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp index eb5565f02..2315b2364 100644 --- a/src/libs/ifc/ifcdef.cpp +++ b/src/libs/ifc/ifcdef.cpp @@ -43,15 +43,13 @@ qreal WidthMainLine(Unit patternUnit) qreal _widthMainLine = DefWidth; switch (patternUnit) { - case Unit::Mm: - _widthMainLine = DefWidth; - break; case Unit::Cm: _widthMainLine = DefWidth/10.0; break; case Unit::Inch: _widthMainLine = DefWidth/25.4; break; + case Unit::Mm: default: _widthMainLine = DefWidth; break; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 8e714f415..fc1d3b9c6 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -771,12 +771,10 @@ Unit VAbstractPattern::MUnit() const case 0:// mm return Unit::Mm; break; - case 1:// cm - return Unit::Cm; - break; case 2:// in return Unit::Inch; break; + case 1:// cm default: return Unit::Cm; break; @@ -922,7 +920,6 @@ QMap VAbstractPattern::GetGradationHeights() const return map; break; case 1: // TagSizes - break; default: break; } @@ -1021,7 +1018,6 @@ void VAbstractPattern::SetGradationHeights(const QMap &options) return; break; case 1: // TagSizes - break; default: break; } @@ -1081,8 +1077,6 @@ QMap VAbstractPattern::GetGradationSizes() const const QString defValue = trueStr; switch (gTags.indexOf(domElement.tagName())) { - case 0: // TagHeights - break; case 1: // TagSizes if (GetParametrBool(domElement, AttrAll, defValue)) { @@ -1121,6 +1115,7 @@ QMap VAbstractPattern::GetGradationSizes() const map.insert(GSizes::S72, GetParametrBool(domElement, AttrS72, defValue)); return map; break; + case 0: // TagHeights default: break; } @@ -1153,8 +1148,6 @@ void VAbstractPattern::SetGradationSizes(const QMap &options) { switch (gTags.indexOf(domElement.tagName())) { - case 0: // TagHeights - break; case 1: // TagSizes SetAttribute(domElement, AttrAll, options.value(GSizes::ALL)); if (options.value(GSizes::ALL)) @@ -1220,6 +1213,7 @@ void VAbstractPattern::SetGradationSizes(const QMap &options) emit patternChanged(false); return; break; + case 0: // TagHeights default: break; } @@ -1509,8 +1503,6 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) << TagCustomerName << TagSize << TagShowDate << TagShowMeasurements; switch (tags.indexOf(tag)) { - case 0: //TagUnit - return QDomElement();// Mandatory tag case 1: //TagImage element = createElement(TagImage); break; @@ -1557,6 +1549,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) case 12: // TagShowMeasurements element = createElement(TagShowMeasurements); break; + case 0: //TagUnit (Mandatory tag) default: return QDomElement(); } diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index ebea2dc6e..cd1683307 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -254,14 +254,10 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString switch (bools.indexOf(parametr)) { case 0: // true - val = true; - break; - case 1: // false - val = false; - break; case 2: // 1 val = true; break; + case 1: // false case 3: // 0 val = false; break; @@ -563,15 +559,13 @@ Unit VDomDocument::StrToUnits(const QString &unit) case 0:// mm result = Unit::Mm; break; - case 1:// cm - result = Unit::Cm; - break; case 2:// inch result = Unit::Inch; break; case 3:// px result = Unit::Px; break; + case 1:// cm default: result = Unit::Cm; break; @@ -594,54 +588,17 @@ QString VDomDocument::UnitsToStr(const Unit &unit, const bool translate) switch (unit) { case Unit::Mm: - if (translate) - { - result = QObject::tr("mm"); - } - else - { - result = UnitMM; - } - break; - case Unit::Cm: - if (translate) - { - result = QObject::tr("cm"); - } - else - { - result = UnitCM; - } + translate ? result = QObject::tr("mm") : result = UnitMM; break; case Unit::Inch: - if (translate) - { - result = QObject::tr("inch"); - } - else - { - result = UnitINCH; - } + translate ? result = QObject::tr("inch") : result = UnitINCH; break; case Unit::Px: - if (translate) - { - result = QObject::tr("px"); - } - else - { - result = UnitPX; - } + translate ? result = QObject::tr("px") : result = UnitPX; break; + case Unit::Cm: default: - if (translate) - { - result = QObject::tr("cm"); - } - else - { - result = UnitCM; - } + translate ? result = QObject::tr("cm") : result = UnitCM; break; } return result; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index ff1c45e6d..6906379fb 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -1735,14 +1735,6 @@ void VPatternConverter::FixSubPaths(int i, quint32 id, quint32 baseCurve) switch(splTypes.indexOf(type)) { case 0: //strModelingPath - { - const quint32 spl = element.attribute(strIdObject).toUInt(); - if (spl == id+1 || spl == id+2) - { - element.setAttribute(strIdObject, baseCurve); - } - break; - } case 1: //strModelingSpline { const quint32 spl = element.attribute(strIdObject).toUInt(); diff --git a/src/test/ParserTest/main.cpp b/src/test/ParserTest/main.cpp index a3c1b76a7..0d4a8cf53 100644 --- a/src/test/ParserTest/main.cpp +++ b/src/test/ParserTest/main.cpp @@ -38,8 +38,6 @@ void testMessageOutput(QtMsgType type, const QMessageLogContext &context, const switch (type) { case QtDebugMsg: - fprintf(stderr, "%s\n", localMsg.constData()); - break; case QtWarningMsg: fprintf(stderr, "%s\n", localMsg.constData()); break;