Creation empty file.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-16 12:38:54 +03:00
parent 58d1cf5fdd
commit a9edee47e5
16 changed files with 819 additions and 68 deletions

View File

@ -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)

View File

@ -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.
*/

View File

@ -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
}

View File

@ -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

View File

@ -32,7 +32,7 @@
<string>Remove measurement</string>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabMeasurements">
<attribute name="icon">
@ -340,7 +340,9 @@
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="go-up"/>
<iconset theme="go-up">
<normaloff/>
</iconset>
</property>
</widget>
</item>
@ -356,7 +358,9 @@
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="go-down"/>
<iconset theme="go-down">
<normaloff/>
</iconset>
</property>
</widget>
</item>
@ -373,7 +377,9 @@
<string notr="true">...</string>
</property>
<property name="icon">
<iconset theme="list-remove"/>
<iconset theme="list-remove">
<normaloff/>
</iconset>
</property>
</widget>
</item>

View File

@ -1,11 +1,11 @@
<RCC>
<qresource prefix="/">
<file>schema/individual_measurements.xsd</file>
<file>schema/standard_measurements.xsd</file>
<file>schema/pattern/v0.1.0.xsd</file>
<file>schema/pattern/v0.1.1.xsd</file>
<file>schema/pattern/v0.1.2.xsd</file>
<file>schema/pattern/v0.1.3.xsd</file>
<file>schema/pattern/v0.1.4.xsd</file>
<file>schema/standard_measurements/v0.3.0.xsd</file>
<file>schema/individual_measurements/v0.2.0.xsd</file>
</qresource>
</RCC>

View File

@ -0,0 +1,148 @@
/************************************************************************
**
** @file vvitconverter.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vvitconverter.h"
#include "exception/vexception.h"
#include <QFile>
/*
* 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();
}

View File

@ -0,0 +1,61 @@
/************************************************************************
**
** @file vvitconverter.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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

View File

@ -0,0 +1,148 @@
/************************************************************************
**
** @file VVSTConverter.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vvstconverter.h"
#include "exception/vexception.h"
#include <QFile>
/*
* 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();
}

View File

@ -0,0 +1,61 @@
/************************************************************************
**
** @file vmeasurementconverter.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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

View File

@ -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

View File

@ -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<int>(UniqueTagAttr(TagSize, AttrBase, 50));
}
else
{
return 0;
}
}
//---------------------------------------------------------------------------------------------------------------------
int VMeasurements::BaseHeight() const
{
if (type == MeasurementsType::Standard)
{
return static_cast<int>(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;
}

View File

@ -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

View File

@ -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 };