Basic structure for new class VPatternRecipe.
--HG-- branch : feature
This commit is contained in:
parent
73e9f2c667
commit
8f961300e6
|
@ -38,6 +38,7 @@
|
||||||
#include "../vmisc/diagnostic.h"
|
#include "../vmisc/diagnostic.h"
|
||||||
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
||||||
#include "../qmuparser/qmuparsererror.h"
|
#include "../qmuparser/qmuparsererror.h"
|
||||||
|
#include "../vpatterndb/variables/vmeasurement.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileOpenEvent>
|
#include <QFileOpenEvent>
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "dialogs/dialognewmeasurements.h"
|
#include "dialogs/dialognewmeasurements.h"
|
||||||
#include "dialogs/dialogmdatabase.h"
|
#include "dialogs/dialogmdatabase.h"
|
||||||
#include "dialogs/dialogtapepreferences.h"
|
#include "dialogs/dialogtapepreferences.h"
|
||||||
|
#include "../vpatterndb/vcontainer.h"
|
||||||
#include "../vpatterndb/calculator.h"
|
#include "../vpatterndb/calculator.h"
|
||||||
#include "../vpatterndb/pmsystems.h"
|
#include "../vpatterndb/pmsystems.h"
|
||||||
#include "../vpatterndb/measurements.h"
|
#include "../vpatterndb/measurements.h"
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "../vmisc/vsettings.h"
|
#include "../vmisc/vsettings.h"
|
||||||
#include "../vmisc/dialogs/dialogexporttocsv.h"
|
#include "../vmisc/dialogs/dialogexporttocsv.h"
|
||||||
#include "../vlayout/vlayoutgenerator.h"
|
#include "../vlayout/vlayoutgenerator.h"
|
||||||
|
#include "../vpatterndb/variables/vmeasurement.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
|
|
|
@ -742,6 +742,14 @@ QString VDomDocument::UnitsHelpString()
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VDomDocument::CreateElementWithText(const QString &tagName, const QString &text)
|
||||||
|
{
|
||||||
|
QDomElement tag = createElement(tagName);
|
||||||
|
tag.appendChild(createTextNode(text));
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
|
bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,6 +123,8 @@ public:
|
||||||
virtual void setXMLContent(const QString &fileName);
|
virtual void setXMLContent(const QString &fileName);
|
||||||
static QString UnitsHelpString();
|
static QString UnitsHelpString();
|
||||||
|
|
||||||
|
QDomElement CreateElementWithText(const QString& tagName, const QString& text);
|
||||||
|
|
||||||
virtual bool SaveDocument(const QString &fileName, QString &error);
|
virtual bool SaveDocument(const QString &fileName, QString &error);
|
||||||
QString Major() const;
|
QString Major() const;
|
||||||
QString Minor() const;
|
QString Minor() const;
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/vmeasurements.cpp \
|
$$PWD/vmeasurements.cpp \
|
||||||
$$PWD/vlabeltemplate.cpp
|
$$PWD/vlabeltemplate.cpp \
|
||||||
|
$$PWD/vpatternrecipe.cpp
|
||||||
|
|
||||||
*msvc*:SOURCES += $$PWD/stable.cpp
|
*msvc*:SOURCES += $$PWD/stable.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/vmeasurements.h \
|
$$PWD/vmeasurements.h \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
$$PWD/vlabeltemplate.h
|
$$PWD/vlabeltemplate.h \
|
||||||
|
$$PWD/vpatternrecipe.h
|
||||||
|
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
#include "../ifc/xml/vdomdocument.h"
|
#include "../ifc/xml/vdomdocument.h"
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vpatterndb/vcontainer.h"
|
|
||||||
|
class VContainer;
|
||||||
|
|
||||||
enum class GenderType : char { Male, Female, Unknown };
|
enum class GenderType : char { Male, Female, Unknown };
|
||||||
|
|
||||||
|
|
226
src/libs/vformat/vpatternrecipe.cpp
Normal file
226
src/libs/vformat/vpatternrecipe.cpp
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpatternrecipe.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 8 7, 2019
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2019 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 "vpatternrecipe.h"
|
||||||
|
#include "../vmisc/projectversion.h"
|
||||||
|
#include "../vmisc/vabstractapplication.h"
|
||||||
|
#include "../ifc/xml/vabstractpattern.h"
|
||||||
|
#include "../vpatterndb/vcontainer.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagRecipe, (QLatin1String("recipe")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagPrerequisite, (QLatin1String("prerequisite")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagValentina, (QLatin1String("valentina")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagDescription, (QLatin1String("description")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagNotes, (QLatin1String("notes")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagMeasurements, (QLatin1String("measurements")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagMeasurement, (QLatin1String("measurement")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagIncrements, (QLatin1String("increments")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagIncrement, (QLatin1String("increment")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagPreviewCalculations, (QLatin1String("previewCalculations")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, TagContent, (QLatin1String("content")))
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrRecipeVersion, (QLatin1String("version")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrDescription, (QLatin1String("description")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrFullName, (QLatin1String("fullName")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrFormula, (QLatin1String("formula")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrValue, (QLatin1String("value")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, AttrIncrementSeparator, (QLatin1String("separator")))
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, RecipeFormatVersion, (QLatin1String("0.1")))
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline QString FileComment()
|
||||||
|
{
|
||||||
|
return QStringLiteral("Recipe created with Valentina v%1 (https://valentinaproject.bitbucket.io/).")
|
||||||
|
.arg(APP_VERSION_STR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPatternRecipe::VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObject *parent)
|
||||||
|
: VDomDocument(parent)
|
||||||
|
{
|
||||||
|
SCASSERT(data != nullptr)
|
||||||
|
SCASSERT(pattern != nullptr)
|
||||||
|
|
||||||
|
QDomElement recipeElement = createElement(*TagRecipe);
|
||||||
|
recipeElement.appendChild(createComment(FileComment()));
|
||||||
|
SetAttribute(recipeElement, *AttrRecipeVersion, *RecipeFormatVersion);
|
||||||
|
|
||||||
|
appendChild(Prerequisite(data, pattern));
|
||||||
|
appendChild(Content(data, pattern));
|
||||||
|
|
||||||
|
appendChild(recipeElement);
|
||||||
|
insertBefore(createProcessingInstruction(QStringLiteral("xml"),
|
||||||
|
QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), firstChild());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Prerequisite(VContainer *data, VAbstractPattern *pattern)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
<prerequisite>
|
||||||
|
<measurements>
|
||||||
|
<m description="" full_name="Обхват талии" name="@От" value="65"/>
|
||||||
|
</measurements>
|
||||||
|
<increments>
|
||||||
|
<increment description="" formula="height/2-15" name="#L_C"/>
|
||||||
|
</increments>
|
||||||
|
<previewCalculations>
|
||||||
|
<increment description="" formula="height/2-15" name="#L_C"/>
|
||||||
|
</previewCalculations>
|
||||||
|
</prerequisite>
|
||||||
|
*/
|
||||||
|
QDomElement prerequisiteElement = createElement(*TagPrerequisite);
|
||||||
|
|
||||||
|
prerequisiteElement.appendChild(CreateElementWithText(*TagValentina, APP_VERSION_STR));
|
||||||
|
prerequisiteElement.appendChild(CreateElementWithText(TagUnit, UnitsToStr(qApp->patternUnit())));
|
||||||
|
prerequisiteElement.appendChild(CreateElementWithText(*TagDescription, pattern->GetDescription()));
|
||||||
|
prerequisiteElement.appendChild(CreateElementWithText(*TagNotes, pattern->GetNotes()));
|
||||||
|
prerequisiteElement.appendChild(Measurements(data));
|
||||||
|
prerequisiteElement.appendChild(Increments(data));
|
||||||
|
prerequisiteElement.appendChild(PreviewCalculations(data));
|
||||||
|
|
||||||
|
return prerequisiteElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Measurements(VContainer *data)
|
||||||
|
{
|
||||||
|
QDomElement measurements = createElement(*TagMeasurements);
|
||||||
|
|
||||||
|
QList<QSharedPointer<VMeasurement>> patternMeasurements = data->DataMeasurements().values();
|
||||||
|
|
||||||
|
// Resore order
|
||||||
|
std::sort(patternMeasurements.begin(), patternMeasurements.end(),
|
||||||
|
[](const QSharedPointer<VMeasurement> &a, const QSharedPointer<VMeasurement> &b)
|
||||||
|
{return a->Index() > b->Index();});
|
||||||
|
|
||||||
|
for(auto &m : patternMeasurements)
|
||||||
|
{
|
||||||
|
measurements.appendChild(Measurement(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
return measurements;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Measurement(const QSharedPointer<VMeasurement> &m)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* <measurements>
|
||||||
|
* <m description="" full_name="Обхват талии" name="@От" value="65"/>
|
||||||
|
* </measurements>
|
||||||
|
*/
|
||||||
|
QDomElement measurement = createElement(*TagMeasurement);
|
||||||
|
|
||||||
|
SetAttribute(measurement, *AttrDescription, m->GetDescription());
|
||||||
|
SetAttribute(measurement, *AttrFullName, m->GetGuiText());
|
||||||
|
SetAttribute(measurement, AttrName, m->GetName());
|
||||||
|
SetAttribute(measurement, *AttrFormula, m->GetFormula()); // TODO: localize
|
||||||
|
SetAttribute(measurement, *AttrValue, *m->GetValue());
|
||||||
|
|
||||||
|
return measurement;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Increments(VContainer *data)
|
||||||
|
{
|
||||||
|
QDomElement increments = createElement(*TagIncrements);
|
||||||
|
|
||||||
|
QList<QSharedPointer<VIncrement>> patternIncrements = data->DataIncrements().values();
|
||||||
|
|
||||||
|
// Resore order
|
||||||
|
std::sort(patternIncrements.begin(), patternIncrements.end(),
|
||||||
|
[](const QSharedPointer<VIncrement> &a, const QSharedPointer<VIncrement> &b)
|
||||||
|
{return a->GetIndex() > b->GetIndex();});
|
||||||
|
|
||||||
|
for(auto &incr : patternIncrements)
|
||||||
|
{
|
||||||
|
if (not incr->IsPreviewCalculation())
|
||||||
|
{
|
||||||
|
increments.appendChild(Increment(incr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return increments;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Increment(const QSharedPointer<VIncrement> &incr)
|
||||||
|
{
|
||||||
|
QDomElement measurement = createElement(*TagIncrement);
|
||||||
|
|
||||||
|
SetAttribute(measurement, *AttrDescription, incr->GetDescription());
|
||||||
|
SetAttribute(measurement, AttrName, incr->GetName());
|
||||||
|
|
||||||
|
if (incr->GetType() != VarType::IncrementSeparator)
|
||||||
|
{
|
||||||
|
SetAttribute(measurement, *AttrFormula, incr->GetFormula()); // TODO: localize
|
||||||
|
SetAttribute(measurement, *AttrValue, *incr->GetValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetAttribute(measurement, *AttrIncrementSeparator, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return measurement;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::Content(VContainer *data, VAbstractPattern *pattern)
|
||||||
|
{
|
||||||
|
QDomElement content = createElement(*TagContent);
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QDomElement VPatternRecipe::PreviewCalculations(VContainer *data)
|
||||||
|
{
|
||||||
|
QDomElement previewCalculations = createElement(*TagPreviewCalculations);
|
||||||
|
|
||||||
|
QList<QSharedPointer<VIncrement>> patternIncrements = data->DataIncrements().values();
|
||||||
|
|
||||||
|
// Resore order
|
||||||
|
std::sort(patternIncrements.begin(), patternIncrements.end(),
|
||||||
|
[](const QSharedPointer<VIncrement> &a, const QSharedPointer<VIncrement> &b)
|
||||||
|
{return a->GetIndex() > b->GetIndex();});
|
||||||
|
|
||||||
|
for(auto &incr : patternIncrements)
|
||||||
|
{
|
||||||
|
if (incr->IsPreviewCalculation())
|
||||||
|
{
|
||||||
|
previewCalculations.appendChild(Increment(incr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return previewCalculations;
|
||||||
|
}
|
63
src/libs/vformat/vpatternrecipe.h
Normal file
63
src/libs/vformat/vpatternrecipe.h
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vpatternrecipe.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 8 7, 2019
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2019 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 VPATTERNRECIPE_H
|
||||||
|
#define VPATTERNRECIPE_H
|
||||||
|
|
||||||
|
#include <QDomElement>
|
||||||
|
|
||||||
|
#include "../ifc/xml/vdomdocument.h"
|
||||||
|
|
||||||
|
class VContainer;
|
||||||
|
class VAbstractPattern;
|
||||||
|
class VMeasurement;
|
||||||
|
class VIncrement;
|
||||||
|
|
||||||
|
class VPatternRecipe : public VDomDocument
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(VPatternRecipe)
|
||||||
|
public:
|
||||||
|
VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObject *parent = nullptr);
|
||||||
|
virtual ~VPatternRecipe() Q_DECL_EQ_DEFAULT;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VPatternRecipe)
|
||||||
|
|
||||||
|
QDomElement Prerequisite(VContainer *data, VAbstractPattern *pattern);
|
||||||
|
|
||||||
|
QDomElement Measurements(VContainer *data);
|
||||||
|
QDomElement Measurement(const QSharedPointer<VMeasurement> &m);
|
||||||
|
|
||||||
|
QDomElement Increments(VContainer *data);
|
||||||
|
QDomElement PreviewCalculations(VContainer *data);
|
||||||
|
QDomElement Increment(const QSharedPointer<VIncrement> &incr);
|
||||||
|
|
||||||
|
QDomElement Content(VContainer *data, VAbstractPattern *pattern);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VPATTERNRECIPE_H
|
|
@ -30,6 +30,7 @@
|
||||||
#include "../vformat/vmeasurements.h"
|
#include "../vformat/vmeasurements.h"
|
||||||
#include "../ifc/xml/vvstconverter.h"
|
#include "../ifc/xml/vvstconverter.h"
|
||||||
#include "../ifc/xml/vvitconverter.h"
|
#include "../ifc/xml/vvitconverter.h"
|
||||||
|
#include "../vpatterndb/vcontainer.h"
|
||||||
#include "../vpatterndb/pmsystems.h"
|
#include "../vpatterndb/pmsystems.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user