Refactoring method MUnit(). All formats have the same syntax.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2017-04-18 11:46:53 +03:00
parent 124fd657e3
commit bab0adfebc
6 changed files with 24 additions and 37 deletions

View File

@ -79,7 +79,6 @@ const QString VAbstractPattern::TagOperation = QStringLiteral("operation"
const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); const QString VAbstractPattern::TagGradation = QStringLiteral("gradation");
const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagHeights = QStringLiteral("heights");
const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes");
const QString VAbstractPattern::TagUnit = QStringLiteral("unit");
const QString VAbstractPattern::TagData = QStringLiteral("data"); const QString VAbstractPattern::TagData = QStringLiteral("data");
const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo"); const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo");
const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); const QString VAbstractPattern::TagMCP = QStringLiteral("mcp");
@ -774,23 +773,6 @@ void VAbstractPattern::SetPath(const QString &path)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
Unit VAbstractPattern::MUnit() const
{
const QStringList units = QStringList() << "mm" << "cm" << "inch";
const QString unit = UniqueTagText(TagUnit);
switch (units.indexOf(unit))
{
case 0:// mm
return Unit::Mm;
case 2:// in
return Unit::Inch;
case 1:// cm
default:
return Unit::Cm;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VAbstractPattern::SiblingNodeId(const quint32 &nodeId) const quint32 VAbstractPattern::SiblingNodeId(const quint32 &nodeId) const
{ {

View File

@ -108,7 +108,6 @@ public:
QString MPath() const; QString MPath() const;
void SetPath(const QString &path); void SetPath(const QString &path);
Unit MUnit() const;
quint32 SiblingNodeId(const quint32 &nodeId) const; quint32 SiblingNodeId(const quint32 &nodeId) const;
@ -189,7 +188,6 @@ public:
static const QString TagGradation; static const QString TagGradation;
static const QString TagHeights; static const QString TagHeights;
static const QString TagSizes; static const QString TagSizes;
static const QString TagUnit;
static const QString TagData; static const QString TagData;
static const QString TagPatternInfo; static const QString TagPatternInfo;
static const QString TagMCP; static const QString TagMCP;

View File

@ -129,6 +129,7 @@ const QString VDomDocument::UnitCM = QStringLiteral("cm");
const QString VDomDocument::UnitINCH = QStringLiteral("inch"); const QString VDomDocument::UnitINCH = QStringLiteral("inch");
const QString VDomDocument::UnitPX = QStringLiteral("px"); const QString VDomDocument::UnitPX = QStringLiteral("px");
const QString VDomDocument::TagVersion = QStringLiteral("version"); const QString VDomDocument::TagVersion = QStringLiteral("version");
const QString VDomDocument::TagUnit = QStringLiteral("unit");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VDomDocument::VDomDocument() VDomDocument::VDomDocument()
@ -398,6 +399,19 @@ quint32 VDomDocument::GetParametrId(const QDomElement &domElement)
return id; return id;
} }
//---------------------------------------------------------------------------------------------------------------------
Unit VDomDocument::MUnit() const
{
Unit unit = VDomDocument::StrToUnits(UniqueTagText(TagUnit, UnitCM));
if (unit == Unit::Px)
{
unit = Unit::Cm;
}
return unit;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal) const QString VDomDocument::UniqueTagText(const QString &tagName, const QString &defVal) const
{ {
@ -555,7 +569,7 @@ void VDomDocument::setXMLContent(const QString &fileName)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
Unit VDomDocument::StrToUnits(const QString &unit) Unit VDomDocument::StrToUnits(const QString &unit)
{ {
QStringList units = QStringList() << UnitMM << UnitCM << UnitINCH << UnitPX; const QStringList units = QStringList() << UnitMM << UnitCM << UnitINCH << UnitPX;
Unit result = Unit::Cm; Unit result = Unit::Cm;
switch (units.indexOf(unit)) switch (units.indexOf(unit))
{ {

View File

@ -81,12 +81,13 @@ class VDomDocument : public QDomDocument
{ {
Q_DECLARE_TR_FUNCTIONS(VDomDocument) Q_DECLARE_TR_FUNCTIONS(VDomDocument)
public: public:
static const QString AttrId; static const QString AttrId;
static const QString UnitMM; static const QString UnitMM;
static const QString UnitCM; static const QString UnitCM;
static const QString UnitINCH; static const QString UnitINCH;
static const QString UnitPX; static const QString UnitPX;
static const QString TagVersion; static const QString TagVersion;
static const QString TagUnit;
VDomDocument(); VDomDocument();
virtual ~VDomDocument() Q_DECL_EQ_DEFAULT; virtual ~VDomDocument() Q_DECL_EQ_DEFAULT;
@ -107,6 +108,8 @@ public:
static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue); static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue);
static quint32 GetParametrId(const QDomElement& domElement); static quint32 GetParametrId(const QDomElement& domElement);
Unit MUnit() const;
static void ValidateXML(const QString &schema, const QString &fileName); static void ValidateXML(const QString &schema, const QString &fileName);
virtual void setXMLContent(const QString &fileName); virtual void setXMLContent(const QString &fileName);
static Unit StrToUnits(const QString &unit); static Unit StrToUnits(const QString &unit);

View File

@ -56,7 +56,6 @@
const QString VMeasurements::TagVST = QStringLiteral("vst"); const QString VMeasurements::TagVST = QStringLiteral("vst");
const QString VMeasurements::TagVIT = QStringLiteral("vit"); const QString VMeasurements::TagVIT = QStringLiteral("vit");
const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements"); const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements");
const QString VMeasurements::TagUnit = QStringLiteral("unit");
const QString VMeasurements::TagNotes = QStringLiteral("notes"); const QString VMeasurements::TagNotes = QStringLiteral("notes");
const QString VMeasurements::TagSize = QStringLiteral("size"); const QString VMeasurements::TagSize = QStringLiteral("size");
const QString VMeasurements::TagHeight = QStringLiteral("height"); const QString VMeasurements::TagHeight = QStringLiteral("height");
@ -323,13 +322,6 @@ MeasurementsType VMeasurements::Type() const
return type; return type;
} }
//---------------------------------------------------------------------------------------------------------------------
Unit VMeasurements::MUnit() const
{
const QString unit = UniqueTagText(TagUnit, UnitCM);
return VDomDocument::StrToUnits(unit);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VMeasurements::BaseSize() const int VMeasurements::BaseSize() const
{ {

View File

@ -65,7 +65,6 @@ public:
void ClearForExport(); void ClearForExport();
MeasurementsType Type() const; MeasurementsType Type() const;
Unit MUnit() const;
int BaseSize() const; int BaseSize() const;
int BaseHeight() const; int BaseHeight() const;
@ -104,7 +103,6 @@ public:
static const QString TagVST; static const QString TagVST;
static const QString TagVIT; static const QString TagVIT;
static const QString TagBodyMeasurements; static const QString TagBodyMeasurements;
static const QString TagUnit;
static const QString TagNotes; static const QString TagNotes;
static const QString TagSize; static const QString TagSize;
static const QString TagHeight; static const QString TagHeight;