From a9edee47e5e1745ce1d8e2d49c16a866206a0b5d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 16 Jul 2015 12:38:54 +0300 Subject: [PATCH] Creation empty file. --HG-- branch : feature --- src/app/tape/mapplication.cpp | 32 -- src/app/tape/mapplication.h | 10 - src/app/tape/tmainwindow.cpp | 50 +++- src/app/tape/tmainwindow.h | 10 +- src/app/tape/tmainwindow.ui | 14 +- src/libs/ifc/schema.qrc | 4 +- .../v0.2.0.xsd} | 0 .../v0.3.0.xsd} | 0 src/libs/ifc/xml/vvitconverter.cpp | 148 +++++++++ src/libs/ifc/xml/vvitconverter.h | 61 ++++ src/libs/ifc/xml/vvstconverter.cpp | 148 +++++++++ src/libs/ifc/xml/vvstconverter.h | 61 ++++ src/libs/ifc/xml/xml.pri | 8 +- src/libs/vformat/vmeasurements.cpp | 283 +++++++++++++++++- src/libs/vformat/vmeasurements.h | 56 ++++ src/libs/vmisc/def.h | 2 +- 16 files changed, 819 insertions(+), 68 deletions(-) rename src/libs/ifc/schema/{individual_measurements.xsd => individual_measurements/v0.2.0.xsd} (100%) rename src/libs/ifc/schema/{standard_measurements.xsd => standard_measurements/v0.3.0.xsd} (100%) create mode 100644 src/libs/ifc/xml/vvitconverter.cpp create mode 100644 src/libs/ifc/xml/vvitconverter.h create mode 100644 src/libs/ifc/xml/vvstconverter.cpp create mode 100644 src/libs/ifc/xml/vvstconverter.h diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 146e9cce6..039450eaa 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -42,8 +42,6 @@ MApplication::MApplication(int &argc, char **argv) mainWindows(), localServer(nullptr), trVars(nullptr), - _mUnit(Unit::Cm), - _mType(MeasurementsType::Individual), settings(nullptr) { setApplicationDisplayName(VER_PRODUCTNAME_STR); @@ -247,36 +245,6 @@ QString MApplication::translationsPath() const #endif } -//--------------------------------------------------------------------------------------------------------------------- -Unit MApplication::mUnit() const -{ - return _mUnit; -} - -//--------------------------------------------------------------------------------------------------------------------- -const Unit *MApplication::mUnitP() const -{ - return &_mUnit; -} - -//--------------------------------------------------------------------------------------------------------------------- -void MApplication::setMUnit(const Unit &mUnit) -{ - _mUnit = mUnit; -} - -//--------------------------------------------------------------------------------------------------------------------- -MeasurementsType MApplication::mType() const -{ - return mType(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MApplication::setMType(const MeasurementsType &mType) -{ - _mType = mType; -} - //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_WS_MAC) bool MApplication::event(QEvent* event) diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index 9a4c8abec..fe0a9912c 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -70,13 +70,6 @@ public: QString translationsPath() const; - Unit mUnit() const; - const Unit *mUnitP() const; - void setMUnit(const Unit &mUnit); - - MeasurementsType mType() const; - void setMType(const MeasurementsType &mType); - public slots: TMainWindow *NewMainWindow(); @@ -90,9 +83,6 @@ private: QLocalServer *localServer; VTranslateVars *trVars; - Unit _mUnit; - MeasurementsType _mType; - /** * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. */ diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index eb44ad3ee..4a0ced890 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -37,7 +37,9 @@ TMainWindow::TMainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::TMainWindow), m(nullptr), - data(nullptr) + data(nullptr), + mUnit(Unit::Cm), + mType(MeasurementsType::Individual) { ui->setupUi(this); ui->tabWidget->setVisible(false); @@ -71,7 +73,21 @@ void TMainWindow::FileNew() return; } - InitNew(measurements.Type(), measurements.MUnit()); + mUnit = measurements.MUnit(); + mType = measurements.Type(); + + data = new VContainer(qApp->TrVars(), &mUnit); + + if (mType == MeasurementsType::Standard) + { + m = new VMeasurements(mUnit, measurements.BaseSize(), measurements.BaseHeight(), data); + } + else + { + m = new VMeasurements(mUnit, data); + } + + InitWindow(); } else { @@ -184,20 +200,20 @@ void TMainWindow::SetupMenu() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::InitNew(MeasurementsType type, Unit unit) +void TMainWindow::InitWindow() { + SCASSERT(m != nullptr); ui->labelToolTip->setVisible(false); ui->tabWidget->setVisible(true); - qApp->setMType(type); - qApp->setMUnit(unit); + ui->plainTextEditNotes->setEnabled(true); - data = new VContainer(qApp->TrVars(), qApp->mUnitP()); - m = new VMeasurements(data); - - if (type == MeasurementsType::Standard) + if (mType == MeasurementsType::Standard) { ui->labelMType->setText(tr("Standard measurements")); + ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + VDomDocument::UnitsToStr(m->MUnit(), true)); + ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + + VDomDocument::UnitsToStr(m->MUnit(), true)); // Tab Measurements delete ui->labelValue; @@ -219,6 +235,12 @@ void TMainWindow::InitNew(MeasurementsType type, Unit unit) { ui->labelMType->setText(tr("Individual measurements")); + ui->lineEditGivenName->setEnabled(true); + ui->lineEditFamilyName->setEnabled(true); + ui->dateEditBirthDate->setEnabled(true); + ui->comboBoxSex->setEnabled(true); + ui->lineEditEmail->setEnabled(true); + // Tab Measurements delete ui->labelBaseValue; delete ui->doubleSpinBoxBaseValue; @@ -234,13 +256,17 @@ void TMainWindow::InitNew(MeasurementsType type, Unit unit) delete ui->labelBaseHeightValue; } - InitTable(type); + ui->actionAddCustom->setEnabled(true); + ui->actionAddKnown->setEnabled(true); + ui->actionReadOnly->setEnabled(true); + + InitTable(); } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::InitTable(MeasurementsType type) +void TMainWindow::InitTable() { - if (type == MeasurementsType::Standard) + if (mType == MeasurementsType::Standard) { ui->tableWidget->setColumnHidden( 1, true );// value } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 540d4e819..cae0c79e6 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -62,12 +62,14 @@ private slots: private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; - VMeasurements *m; - VContainer *data; + VMeasurements *m; + VContainer *data; + Unit mUnit; + MeasurementsType mType; void SetupMenu(); - void InitNew(MeasurementsType type, Unit unit); - void InitTable(MeasurementsType type); + void InitWindow(); + void InitTable(); }; #endif // TMAINWINDOW_H diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 0346fc15b..18bc668bb 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -32,7 +32,7 @@ Remove measurement - 0 + 1 @@ -340,7 +340,9 @@ ... - + + + @@ -356,7 +358,9 @@ ... - + + + @@ -373,7 +377,9 @@ ... - + + + diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index d1285d947..aa5dc9e80 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -1,11 +1,11 @@ - schema/individual_measurements.xsd - schema/standard_measurements.xsd schema/pattern/v0.1.0.xsd schema/pattern/v0.1.1.xsd schema/pattern/v0.1.2.xsd schema/pattern/v0.1.3.xsd schema/pattern/v0.1.4.xsd + schema/standard_measurements/v0.3.0.xsd + schema/individual_measurements/v0.2.0.xsd diff --git a/src/libs/ifc/schema/individual_measurements.xsd b/src/libs/ifc/schema/individual_measurements/v0.2.0.xsd similarity index 100% rename from src/libs/ifc/schema/individual_measurements.xsd rename to src/libs/ifc/schema/individual_measurements/v0.2.0.xsd diff --git a/src/libs/ifc/schema/standard_measurements.xsd b/src/libs/ifc/schema/standard_measurements/v0.3.0.xsd similarity index 100% rename from src/libs/ifc/schema/standard_measurements.xsd rename to src/libs/ifc/schema/standard_measurements/v0.3.0.xsd diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp new file mode 100644 index 000000000..8bfcb40f1 --- /dev/null +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -0,0 +1,148 @@ +/************************************************************************ + ** + ** @file vvitconverter.cpp + ** @author Roman Telezhynskyi + ** @date 15 7, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vvitconverter.h" +#include "exception/vexception.h" + +#include + +/* + * Version rules: + * 1. Version have three parts "major.minor.patch"; + * 2. major part only for stable releases; + * 3. minor - 10 or more patch changes, or one big change; + * 4. patch - little change. + */ + +const QString VVITConverter::MeasurementMinVerStr = QStringLiteral("0.2.0"); +const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.3.0"); +const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.3.0.xsd"); + +//--------------------------------------------------------------------------------------------------------------------- +VVITConverter::VVITConverter(const QString &fileName) + :VAbstractConverter(fileName) +{ + const QString schema = XSDSchema(ver); + ValidateXML(schema, fileName); +} + +//--------------------------------------------------------------------------------------------------------------------- +VVITConverter::~VVITConverter() +{} + +//--------------------------------------------------------------------------------------------------------------------- +int VVITConverter::MinVer() const +{ + return GetVersion(MeasurementMinVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VVITConverter::MaxVer() const +{ + return GetVersion(MeasurementMaxVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVITConverter::MinVerStr() const +{ + return MeasurementMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVITConverter::MaxVerStr() const +{ + return MeasurementMaxVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVITConverter::XSDSchema(int ver) const +{ + CheckVersion(ver); + + switch (ver) + { + case (0x000200): + return QStringLiteral("://schema/individual_measurements/v0.2.0.xsd"); + case (0x000300): + return CurrentSchema; + default: + { + const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16)); + throw VException(errorMsg); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ApplyPatches() +{ + try + { + switch (ver) + { + case (0x000200): + { + ToV0_3_0(); + const QString schema = XSDSchema(0x000300); + ValidateXML(schema, fileName); + // continue conversion + #ifdef Q_CC_CLANG + [[clang::fallthrough]]; + #endif + } + case (0x000300): + break; + default: + break; + } + } + catch (VException &e) + { + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(backupFileName, fileName, error) == false) + { + const QString errorMsg(tr("Error restoring backup file: %1.").arg(error)); + VException excep(errorMsg); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + QFile file(backupFileName); + file.remove(); + + throw; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ToV0_3_0() +{ + SetVersion(QStringLiteral("0.3.0")); + Save(); +} diff --git a/src/libs/ifc/xml/vvitconverter.h b/src/libs/ifc/xml/vvitconverter.h new file mode 100644 index 000000000..d1d1947bc --- /dev/null +++ b/src/libs/ifc/xml/vvitconverter.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file vvitconverter.h + ** @author Roman Telezhynskyi + ** @date 15 7, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VVITCONVERTER_H +#define VVITCONVERTER_H + +#include "vabstractconverter.h" + +class VVITConverter : public VAbstractConverter +{ + Q_DECLARE_TR_FUNCTIONS(VVITConverter) +public: + VVITConverter(const QString &fileName); + virtual ~VVITConverter() Q_DECL_OVERRIDE; + + static const QString MeasurementMaxVerStr; + static const QString CurrentSchema; + +protected: + virtual int MinVer() const Q_DECL_OVERRIDE; + virtual int MaxVer() const Q_DECL_OVERRIDE; + + virtual QString MinVerStr() const Q_DECL_OVERRIDE; + virtual QString MaxVerStr() const Q_DECL_OVERRIDE; + + QString XSDSchema(int ver) const; + virtual void ApplyPatches() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(VVITConverter) + static const QString MeasurementMinVerStr; + + void ToV0_3_0(); +}; + +#endif // VVITCONVERTER_H diff --git a/src/libs/ifc/xml/vvstconverter.cpp b/src/libs/ifc/xml/vvstconverter.cpp new file mode 100644 index 000000000..faedbe163 --- /dev/null +++ b/src/libs/ifc/xml/vvstconverter.cpp @@ -0,0 +1,148 @@ +/************************************************************************ + ** + ** @file VVSTConverter.cpp + ** @author Roman Telezhynskyi + ** @date 15 7, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vvstconverter.h" +#include "exception/vexception.h" + +#include + +/* + * Version rules: + * 1. Version have three parts "major.minor.patch"; + * 2. major part only for stable releases; + * 3. minor - 10 or more patch changes, or one big change; + * 4. patch - little change. + */ + +const QString VVSTConverter::MeasurementMinVerStr = QStringLiteral("0.3.0"); +const QString VVSTConverter::MeasurementMaxVerStr = QStringLiteral("0.4.0"); +const QString VVSTConverter::CurrentSchema = QStringLiteral("://schema/standard_measurements/v0.4.0.xsd"); + +//--------------------------------------------------------------------------------------------------------------------- +VVSTConverter::VVSTConverter(const QString &fileName) + :VAbstractConverter(fileName) +{ + const QString schema = XSDSchema(ver); + ValidateXML(schema, fileName); +} + +//--------------------------------------------------------------------------------------------------------------------- +VVSTConverter::~VVSTConverter() +{} + +//--------------------------------------------------------------------------------------------------------------------- +int VVSTConverter::MinVer() const +{ + return GetVersion(MeasurementMinVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VVSTConverter::MaxVer() const +{ + return GetVersion(MeasurementMaxVerStr); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVSTConverter::MinVerStr() const +{ + return MeasurementMinVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVSTConverter::MaxVerStr() const +{ + return MeasurementMaxVerStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VVSTConverter::XSDSchema(int ver) const +{ + CheckVersion(ver); + + switch (ver) + { + case (0x000300): + return QStringLiteral("://schema/standard_measurements/v0.3.0.xsd"); + case (0x000400): + return CurrentSchema; + default: + { + const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16)); + throw VException(errorMsg); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::ApplyPatches() +{ + try + { + switch (ver) + { + case (0x000300): + { + ToV0_4_0(); + const QString schema = XSDSchema(0x000400); + ValidateXML(schema, fileName); + // continue conversion + #ifdef Q_CC_CLANG + [[clang::fallthrough]]; + #endif + } + case (0x000400): + break; + default: + break; + } + } + catch (VException &e) + { + QString error; + const QString backupFileName = fileName +".backup"; + if (SafeCopy(backupFileName, fileName, error) == false) + { + const QString errorMsg(tr("Error restoring backup file: %1.").arg(error)); + VException excep(errorMsg); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + + QFile file(backupFileName); + file.remove(); + + throw; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VVSTConverter::ToV0_4_0() +{ + SetVersion(QStringLiteral("0.4.0")); + Save(); +} diff --git a/src/libs/ifc/xml/vvstconverter.h b/src/libs/ifc/xml/vvstconverter.h new file mode 100644 index 000000000..d58ee6d4e --- /dev/null +++ b/src/libs/ifc/xml/vvstconverter.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file vmeasurementconverter.h + ** @author Roman Telezhynskyi + ** @date 15 7, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VMEASUREMENTCONVERTER_H +#define VMEASUREMENTCONVERTER_H + +#include "vabstractconverter.h" + +class VVSTConverter : public VAbstractConverter +{ + Q_DECLARE_TR_FUNCTIONS(VVSTConverter) +public: + VVSTConverter(const QString &fileName); + virtual ~VVSTConverter() Q_DECL_OVERRIDE; + + static const QString MeasurementMaxVerStr; + static const QString CurrentSchema; + +protected: + virtual int MinVer() const Q_DECL_OVERRIDE; + virtual int MaxVer() const Q_DECL_OVERRIDE; + + virtual QString MinVerStr() const Q_DECL_OVERRIDE; + virtual QString MaxVerStr() const Q_DECL_OVERRIDE; + + QString XSDSchema(int ver) const; + virtual void ApplyPatches() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(VVSTConverter) + static const QString MeasurementMinVerStr; + + void ToV0_4_0(); +}; + +#endif // VMEASUREMENTCONVERTER_H diff --git a/src/libs/ifc/xml/xml.pri b/src/libs/ifc/xml/xml.pri index 65b44e814..123beff3c 100644 --- a/src/libs/ifc/xml/xml.pri +++ b/src/libs/ifc/xml/xml.pri @@ -6,11 +6,15 @@ HEADERS += \ $$PWD/vdomdocument.h \ $$PWD/vpatternconverter.h \ $$PWD/vtoolrecord.h \ - xml/vabstractpattern.h + $$PWD/vabstractpattern.h \ + $$PWD/vvstconverter.h \ + xml/vvitconverter.h SOURCES += \ $$PWD/vabstractconverter.cpp \ $$PWD/vdomdocument.cpp \ $$PWD/vpatternconverter.cpp \ $$PWD/vtoolrecord.cpp \ - xml/vabstractpattern.cpp + $$PWD/vabstractpattern.cpp \ + $$PWD/vvstconverter.cpp \ + xml/vvitconverter.cpp diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 6cf9c57cd..cd451abad 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -27,16 +27,297 @@ *************************************************************************/ #include "vmeasurements.h" +#include "../ifc/xml/vvstconverter.h" +#include "../ifc/xml/vvitconverter.h" + +const QString VMeasurements::TagVST = QStringLiteral("vst"); +const QString VMeasurements::TagVIT = QStringLiteral("vit"); +const QString VMeasurements::TagBodyMeasurements = QStringLiteral("body-measurements"); +const QString VMeasurements::TagUnit = QStringLiteral("unit"); +const QString VMeasurements::TagNotes = QStringLiteral("notes"); +const QString VMeasurements::TagSize = QStringLiteral("size"); +const QString VMeasurements::TagHeight = QStringLiteral("height"); +const QString VMeasurements::TagPersonal = QStringLiteral("personal"); +const QString VMeasurements::TagFamilyName = QStringLiteral("family-name"); +const QString VMeasurements::TagGivenName = QStringLiteral("given-name"); +const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date"); +const QString VMeasurements::TagSex = QStringLiteral("sex"); +const QString VMeasurements::TagEmail = QStringLiteral("email"); + +const QString VMeasurements::AttrBase = QStringLiteral("base"); + +const QString VMeasurements::SexMale = QStringLiteral("male"); +const QString VMeasurements::SexFemale = QStringLiteral("female"); +const QString VMeasurements::SexUnknown = QStringLiteral("unknown"); //--------------------------------------------------------------------------------------------------------------------- VMeasurements::VMeasurements(VContainer *data) :VDomDocument(), - data(data) + data(data), + type(MeasurementsType::Unknown) { SCASSERT(data != nullptr) } +//--------------------------------------------------------------------------------------------------------------------- +VMeasurements::VMeasurements(Unit unit, VContainer *data) + :VDomDocument(), + data(data), + type(MeasurementsType::Individual) +{ + SCASSERT(data != nullptr); + + CreateEmptyIndividualFile(unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +VMeasurements::VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data) + :VDomDocument(), + data(data), + type(MeasurementsType::Standard) +{ + SCASSERT(data != nullptr); + + CreateEmptyStandardFile(unit, baseSize, baseHeight); +} + //--------------------------------------------------------------------------------------------------------------------- VMeasurements::~VMeasurements() { } + +//--------------------------------------------------------------------------------------------------------------------- +MeasurementsType VMeasurements::Type() const +{ + return type; +} + +//--------------------------------------------------------------------------------------------------------------------- +Unit VMeasurements::MUnit() const +{ + const QString unit = UniqueTagText(TagUnit, UnitCM); + return VDomDocument::StrToUnits(unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::BaseSize() const +{ + if (type == MeasurementsType::Standard) + { + return static_cast(UniqueTagAttr(TagSize, AttrBase, 50)); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::BaseHeight() const +{ + if (type == MeasurementsType::Standard) + { + return static_cast(UniqueTagAttr(TagHeight, AttrBase, 176)); + } + else + { + return 0; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::Notes() const +{ + return UniqueTagText(TagNotes, ""); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetNotes(const QString &text) +{ + setTagText(TagNotes, text); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::FamilyName() const +{ + return UniqueTagText(TagFamilyName, ""); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetFamilyName(const QString &text) +{ + setTagText(TagFamilyName, text); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::GivenName() const +{ + return UniqueTagText(TagGivenName, ""); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetGivenName(const QString &text) +{ + setTagText(TagGivenName, text); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDate VMeasurements::BirthDate() const +{ + const QString date = UniqueTagText(TagBirthDate, "1900-01-01"); + return QDate::fromString(date, "yyyy-MM-dd"); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetBirthDate(const QDate &date) +{ + setTagText(TagBirthDate, date.toString("yyyy-MM-dd")); +} + +//--------------------------------------------------------------------------------------------------------------------- +SexType VMeasurements::Sex() const +{ + return StrToGender(UniqueTagText(TagSex, "")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetSex(const SexType &sex) +{ + setTagText(TagSex, GenderToStr(sex)); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::Email() const +{ + return UniqueTagText(TagEmail, ""); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::SetEmail(const QString &text) +{ + setTagText(TagEmail, text); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VMeasurements::GenderToStr(const SexType &sex) +{ + switch (sex) + { + case SexType::Male: + return SexMale; + case SexType::Female: + return SexFemale; + case SexType::Unknown: + return SexUnknown; + default: + return SexUnknown; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +SexType VMeasurements::StrToGender(const QString &sex) +{ + QStringList genders = QStringList() << SexMale << SexFemale << SexUnknown; + switch (genders.indexOf(sex)) + { + case 0: // SexMale + return SexType::Male; + case 1: // SexFemale + return SexType::Female; + case 2: // SexUnknown + return SexType::Unknown; + default: + return SexType::Unknown; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::CreateEmptyStandardFile(Unit unit, int baseSize, int baseHeight) +{ + this->clear(); + QDomElement mElement = this->createElement(TagVST); + + mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/).")); + + QDomElement version = createElement(TagVersion); + const QDomText newNodeText = createTextNode(VVSTConverter::MeasurementMaxVerStr); + version.appendChild(newNodeText); + mElement.appendChild(version); + + mElement.appendChild(createElement(TagNotes)); + + QDomElement mUnit = createElement(TagUnit); + const QDomText unitText = createTextNode(UnitsToStr(unit)); + mUnit.appendChild(unitText); + mElement.appendChild(mUnit); + + QDomElement size = createElement(TagSize); + SetAttribute(size, AttrBase, QString().setNum(baseSize)); + mElement.appendChild(size); + + QDomElement height = createElement(TagHeight); + SetAttribute(height, AttrBase, QString().setNum(baseHeight)); + mElement.appendChild(height); + + mElement.appendChild(createElement(TagBodyMeasurements)); + + this->appendChild(mElement); + insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::CreateEmptyIndividualFile(Unit unit) +{ + this->clear(); + QDomElement mElement = this->createElement(TagVIT); + + mElement.appendChild(createComment("Measurements created with Valentina (http://www.valentina-project.org/).")); + + QDomElement version = createElement(TagVersion); + const QDomText newNodeText = createTextNode(VVITConverter::MeasurementMaxVerStr); + version.appendChild(newNodeText); + mElement.appendChild(version); + + mElement.appendChild(createElement(TagNotes)); + + QDomElement mUnit = createElement(TagUnit); + mUnit.appendChild(createTextNode(UnitsToStr(unit))); + mElement.appendChild(mUnit); + + QDomElement personal = createElement(TagPersonal); + personal.appendChild(createElement(TagGivenName)); + personal.appendChild(createElement(TagBirthDate)); + personal.appendChild(createElement(TagSex)); + personal.appendChild(createElement(TagEmail)); + mElement.appendChild(personal); + + mElement.appendChild(createElement(TagBodyMeasurements)); + + this->appendChild(mElement); + insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const +{ + const qreal defVal = UnitConvertor(defValue, Unit::Cm, MUnit()); + + const QDomNodeList nodeList = this->elementsByTagName(tag); + if (nodeList.isEmpty()) + { + return defVal; + } + else + { + const QDomNode domNode = nodeList.at(0); + if (domNode.isNull() == false && domNode.isElement()) + { + const QDomElement domElement = domNode.toElement(); + if (domElement.isNull() == false) + { + return GetParametrDouble(domElement, attr, QString("%1").arg(defVal)); + } + } + } + return defVal; +} diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 3f65d3f12..64ebc9af8 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -32,18 +32,74 @@ #include "../ifc/xml/vdomdocument.h" #include "../vpatterndb/vcontainer.h" +enum class SexType : char { Male, Female, Unknown }; + class VMeasurements : public VDomDocument { public: VMeasurements(VContainer *data); + VMeasurements(Unit unit, VContainer *data); + VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data); virtual ~VMeasurements() Q_DECL_OVERRIDE; + MeasurementsType Type() const; + Unit MUnit() const; + int BaseSize() const; + int BaseHeight() const; + + QString Notes() const; + void SetNotes(const QString &text); + + QString FamilyName() const; + void SetFamilyName(const QString &text); + + QString GivenName() const; + void SetGivenName(const QString &text); + + QDate BirthDate() const; + void SetBirthDate(const QDate &date); + + SexType Sex() const; + void SetSex(const SexType &sex); + + QString Email() const; + void SetEmail(const QString &text); + + static const QString TagVST; + static const QString TagVIT; + static const QString TagBodyMeasurements; + static const QString TagUnit; + static const QString TagNotes; + static const QString TagSize; + static const QString TagHeight; + static const QString TagPersonal; + static const QString TagFamilyName; + static const QString TagGivenName; + static const QString TagBirthDate; + static const QString TagSex; + static const QString TagEmail; + + static const QString AttrBase; + + static const QString SexMale; + static const QString SexFemale; + static const QString SexUnknown; + + static QString GenderToStr(const SexType &sex); + static SexType StrToGender(const QString &sex); + private: Q_DISABLE_COPY(VMeasurements) /** @brief data container with data. */ VContainer *data; + MeasurementsType type; + + void CreateEmptyStandardFile(Unit unit, int baseSize, int baseHeight); + void CreateEmptyIndividualFile(Unit unit); + + qreal UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const; }; #endif // VMEASUREMENTS_H diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 22f3026c7..f5d034b74 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -38,7 +38,7 @@ enum class NodeDetail : char { Contour, Modeling }; enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; -enum class MeasurementsType : char { Standard, Individual }; +enum class MeasurementsType : char { Standard, Individual, Unknown }; enum class Unit : char { Mm, Cm, Inch, Px }; enum class Source : char { FromGui, FromFile, FromTool };