From 962f6942eabfcadb90add4652baef695ccbeb148 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 7 Aug 2014 14:17:24 +0300 Subject: [PATCH] Get gradation options. --HG-- branch : feature --- src/app/xml/vdomdocument.cpp | 39 +++++++ src/app/xml/vdomdocument.h | 1 + src/app/xml/vpattern.cpp | 198 +++++++++++++++++++++++++++++++++++ src/app/xml/vpattern.h | 52 +++++++++ 4 files changed, 290 insertions(+) diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index f0c92c3a4..1e062ed98 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -221,6 +221,45 @@ quint32 VDomDocument::GetParametrUInt(const QDomElement &domElement, const QStri return id; } +//--------------------------------------------------------------------------------------------------------------------- +bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString &name, const QString &defValue) const +{ + Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); + + bool ok = false; + QString parametr; + bool val = true; + + QString message = tr("Can't convert toBool parameter"); + try + { + parametr = GetParametrString(domElement, name, defValue); + + QStringList bools {QLatin1String("true"), QLatin1String("false")}; + switch (bools.indexOf(parametr)) + { + case 0: // true + val = true; + break; + case 1: // false + val = false; + break; + default:// others + throw VExceptionConversionError(message, name); + break; + } + } + catch (const VExceptionEmptyParameter &e) + { + VExceptionConversionError excep(message, name); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + return val; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the string value of the given attribute. RENAME: see above diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index a51a2d562..2cfe16785 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -100,6 +100,7 @@ public: domElement.setAttribute(name, val); } quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const; + bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const; QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue = QString()) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 27c3c8114..658231781 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -61,11 +61,53 @@ const QString VPattern::TagLine = QStringLiteral("line"); const QString VPattern::TagSpline = QStringLiteral("spline"); const QString VPattern::TagArc = QStringLiteral("arc"); const QString VPattern::TagTools = QStringLiteral("tools"); +const QString VPattern::TagGradation = QStringLiteral("gradation"); +const QString VPattern::TagHeights = QStringLiteral("heights"); +const QString VPattern::TagSizes = QStringLiteral("sizes"); const QString VPattern::AttrName = QStringLiteral("name"); const QString VPattern::AttrType = QStringLiteral("type"); const QString VPattern::AttrPath = QStringLiteral("path"); +const QString VPattern::AttrAll = QStringLiteral("all"); + +const QString VPattern::AttrH92 = QStringLiteral("h92"); +const QString VPattern::AttrH98 = QStringLiteral("h98"); +const QString VPattern::AttrH104 = QStringLiteral("h104"); +const QString VPattern::AttrH110 = QStringLiteral("h110"); +const QString VPattern::AttrH116 = QStringLiteral("h116"); +const QString VPattern::AttrH122 = QStringLiteral("h122"); +const QString VPattern::AttrH128 = QStringLiteral("h128"); +const QString VPattern::AttrH134 = QStringLiteral("h134"); +const QString VPattern::AttrH140 = QStringLiteral("h140"); +const QString VPattern::AttrH146 = QStringLiteral("h146"); +const QString VPattern::AttrH152 = QStringLiteral("h152"); +const QString VPattern::AttrH158 = QStringLiteral("h158"); +const QString VPattern::AttrH164 = QStringLiteral("h164"); +const QString VPattern::AttrH170 = QStringLiteral("h170"); +const QString VPattern::AttrH176 = QStringLiteral("h176"); +const QString VPattern::AttrH182 = QStringLiteral("h182"); +const QString VPattern::AttrH188 = QStringLiteral("h188"); + +const QString VPattern::AttrS22 = QStringLiteral("s22"); +const QString VPattern::AttrS24 = QStringLiteral("s24"); +const QString VPattern::AttrS26 = QStringLiteral("s26"); +const QString VPattern::AttrS28 = QStringLiteral("s28"); +const QString VPattern::AttrS30 = QStringLiteral("s30"); +const QString VPattern::AttrS32 = QStringLiteral("s32"); +const QString VPattern::AttrS34 = QStringLiteral("s34"); +const QString VPattern::AttrS36 = QStringLiteral("s36"); +const QString VPattern::AttrS38 = QStringLiteral("s38"); +const QString VPattern::AttrS40 = QStringLiteral("s40"); +const QString VPattern::AttrS42 = QStringLiteral("s42"); +const QString VPattern::AttrS44 = QStringLiteral("s44"); +const QString VPattern::AttrS46 = QStringLiteral("s46"); +const QString VPattern::AttrS48 = QStringLiteral("s48"); +const QString VPattern::AttrS50 = QStringLiteral("s50"); +const QString VPattern::AttrS52 = QStringLiteral("s52"); +const QString VPattern::AttrS54 = QStringLiteral("s54"); +const QString VPattern::AttrS56 = QStringLiteral("s56"); + const QString VPattern::IncrementName = QStringLiteral("name"); const QString VPattern::IncrementBase = QStringLiteral("base"); const QString VPattern::IncrementKsize = QStringLiteral("ksize"); @@ -1815,6 +1857,162 @@ quint32 VPattern::GetParametrId(const QDomElement &domElement) const return id; } +//--------------------------------------------------------------------------------------------------------------------- +QMap VPattern::GetGradationHeights() const +{ + QMap map; + map.insert(GHeights::H92, true); + map.insert(GHeights::H98, true); + map.insert(GHeights::H104, true); + map.insert(GHeights::H110, true); + map.insert(GHeights::H116, true); + map.insert(GHeights::H122, true); + map.insert(GHeights::H128, true); + map.insert(GHeights::H134, true); + map.insert(GHeights::H140, true); + map.insert(GHeights::H146, true); + map.insert(GHeights::H152, true); + map.insert(GHeights::H158, true); + map.insert(GHeights::H164, true); + map.insert(GHeights::H170, true); + map.insert(GHeights::H176, true); + map.insert(GHeights::H182, true); + map.insert(GHeights::H188, true); + + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + return map; + } + + QStringList gTags{TagHeights, TagSizes}; + QDomNode domNode = tags.at(0).firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString defValue = QStringLiteral("true"); + switch (gTags.indexOf(domElement.tagName())) + { + case 0: // TagHeights + if (GetParametrBool(domElement, AttrAll, defValue)) + { + return map; + } + + map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue)); + map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue)); + map.insert(GHeights::H104, GetParametrBool(domElement, AttrH104, defValue)); + map.insert(GHeights::H110, GetParametrBool(domElement, AttrH110, defValue)); + map.insert(GHeights::H116, GetParametrBool(domElement, AttrH116, defValue)); + map.insert(GHeights::H122, GetParametrBool(domElement, AttrH122, defValue)); + map.insert(GHeights::H128, GetParametrBool(domElement, AttrH128, defValue)); + map.insert(GHeights::H134, GetParametrBool(domElement, AttrH134, defValue)); + map.insert(GHeights::H140, GetParametrBool(domElement, AttrH140, defValue)); + map.insert(GHeights::H146, GetParametrBool(domElement, AttrH146, defValue)); + map.insert(GHeights::H152, GetParametrBool(domElement, AttrH152, defValue)); + map.insert(GHeights::H158, GetParametrBool(domElement, AttrH158, defValue)); + map.insert(GHeights::H164, GetParametrBool(domElement, AttrH164, defValue)); + map.insert(GHeights::H170, GetParametrBool(domElement, AttrH170, defValue)); + map.insert(GHeights::H176, GetParametrBool(domElement, AttrH176, defValue)); + map.insert(GHeights::H182, GetParametrBool(domElement, AttrH182, defValue)); + map.insert(GHeights::H188, GetParametrBool(domElement, AttrH188, defValue)); + return map; + break; + case 1: // TagSizes + break; + default: + break; + } + } + } + domNode = domNode.nextSibling(); + } + return map; +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap VPattern::GetGradationSizes() const +{ + QMap map; + map.insert(GSizes::S22, true); + map.insert(GSizes::S24, true); + map.insert(GSizes::S26, true); + map.insert(GSizes::S28, true); + map.insert(GSizes::S30, true); + map.insert(GSizes::S32, true); + map.insert(GSizes::S34, true); + map.insert(GSizes::S36, true); + map.insert(GSizes::S38, true); + map.insert(GSizes::S40, true); + map.insert(GSizes::S42, true); + map.insert(GSizes::S44, true); + map.insert(GSizes::S46, true); + map.insert(GSizes::S48, true); + map.insert(GSizes::S50, true); + map.insert(GSizes::S52, true); + map.insert(GSizes::S54, true); + map.insert(GSizes::S56, true); + + QDomNodeList tags = elementsByTagName(TagGradation); + if (tags.size() == 0) + { + return map; + } + + QStringList gTags{TagHeights, TagSizes}; + QDomNode domNode = tags.at(0).firstChild(); + while (domNode.isNull() == false) + { + if (domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + const QString defValue = QStringLiteral("true"); + switch (gTags.indexOf(domElement.tagName())) + { + case 0: // TagHeights + break; + case 1: // TagSizes + if (GetParametrBool(domElement, AttrAll, defValue)) + { + return map; + } + + map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue)); + map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue)); + map.insert(GSizes::S26, GetParametrBool(domElement, AttrS26, defValue)); + map.insert(GSizes::S28, GetParametrBool(domElement, AttrS28, defValue)); + map.insert(GSizes::S30, GetParametrBool(domElement, AttrS30, defValue)); + map.insert(GSizes::S32, GetParametrBool(domElement, AttrS32, defValue)); + map.insert(GSizes::S34, GetParametrBool(domElement, AttrS34, defValue)); + map.insert(GSizes::S36, GetParametrBool(domElement, AttrS36, defValue)); + map.insert(GSizes::S38, GetParametrBool(domElement, AttrS38, defValue)); + map.insert(GSizes::S40, GetParametrBool(domElement, AttrS40, defValue)); + map.insert(GSizes::S42, GetParametrBool(domElement, AttrS42, defValue)); + map.insert(GSizes::S44, GetParametrBool(domElement, AttrS44, defValue)); + map.insert(GSizes::S46, GetParametrBool(domElement, AttrS46, defValue)); + map.insert(GSizes::S48, GetParametrBool(domElement, AttrS48, defValue)); + map.insert(GSizes::S50, GetParametrBool(domElement, AttrS50, defValue)); + map.insert(GSizes::S52, GetParametrBool(domElement, AttrS52, defValue)); + map.insert(GSizes::S54, GetParametrBool(domElement, AttrS54, defValue)); + map.insert(GSizes::S56, GetParametrBool(domElement, AttrS56, defValue)); + return map; + break; + default: + break; + } + } + } + domNode = domNode.nextSibling(); + } + return map; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index de01fbe33..95ecb2873 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -37,6 +37,10 @@ class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse}; +enum class GHeights : char { H92, H98, H104, H110, H116, H122, H128, H134, H140, H146, H152, H158, H164, H170, H176, + H182, H188}; +enum class GSizes : char { S22, S24, S26, S28, S30, S32, S34, S36, S38, S40, S42, S44, S46, S48, S50, S52, S54, S56}; + /* VAL_VERSION is (major << 16) + (minor << 8) + patch. */ @@ -103,18 +107,66 @@ public: static const QString TagSpline; static const QString TagArc; static const QString TagTools; + static const QString TagGradation; + static const QString TagHeights; + static const QString TagSizes; + static const QString AttrName; static const QString AttrType; static const QString AttrPath; + + static const QString AttrAll; + + static const QString AttrH92; + static const QString AttrH98; + static const QString AttrH104; + static const QString AttrH110; + static const QString AttrH116; + static const QString AttrH122; + static const QString AttrH128; + static const QString AttrH134; + static const QString AttrH140; + static const QString AttrH146; + static const QString AttrH152; + static const QString AttrH158; + static const QString AttrH164; + static const QString AttrH170; + static const QString AttrH176; + static const QString AttrH182; + static const QString AttrH188; + + static const QString AttrS22; + static const QString AttrS24; + static const QString AttrS26; + static const QString AttrS28; + static const QString AttrS30; + static const QString AttrS32; + static const QString AttrS34; + static const QString AttrS36; + static const QString AttrS38; + static const QString AttrS40; + static const QString AttrS42; + static const QString AttrS44; + static const QString AttrS46; + static const QString AttrS48; + static const QString AttrS50; + static const QString AttrS52; + static const QString AttrS54; + static const QString AttrS56; + static const QString IncrementName; static const QString IncrementBase; static const QString IncrementKsize; static const QString IncrementKgrowth; static const QString IncrementDescription; + virtual bool SaveDocument(const QString &fileName); QStringList getPatternPieces() const; QRectF ActiveDrawBoundingRect() const; quint32 GetParametrId(const QDomElement& domElement) const; + + QMap GetGradationHeights() const; + QMap GetGradationSizes() const; signals: /** * @brief ChangedActivDraw change active pattern peace.