2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vdomdocument.h
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2014-03-18 23:36:32 +01:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program that allows creating and modelling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#ifndef VDOMDOCUMENT_H
|
|
|
|
#define VDOMDOCUMENT_H
|
|
|
|
|
2014-12-10 19:33:20 +01:00
|
|
|
#include <QCoreApplication>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDomDocument>
|
|
|
|
#include <QDomElement>
|
|
|
|
#include <QDomNode>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QLatin1String>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QtGlobal>
|
2016-10-23 11:11:00 +02:00
|
|
|
#include <QLocale>
|
2014-12-10 19:33:20 +01:00
|
|
|
|
2015-06-18 19:23:24 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2015-06-18 10:45:38 +02:00
|
|
|
#include "../vmisc/def.h"
|
2016-08-06 20:42:40 +02:00
|
|
|
#include "../vmisc/diagnostic.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/logging.h"
|
|
|
|
|
|
|
|
class QDomElement;
|
|
|
|
class QDomNode;
|
|
|
|
template <typename T> class QVector;
|
2014-11-24 14:03:34 +01:00
|
|
|
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(vXML)
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
2013-11-19 21:56:49 +01:00
|
|
|
|
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief The VDomDocument class represents a Valentina document (.val file).
|
2014-05-01 13:33:40 +02:00
|
|
|
*
|
|
|
|
* A Valentina document describes the construction of a sewing pattern. The
|
2014-03-18 23:36:32 +01:00
|
|
|
* information is stored in XML format. By parsing a VDomDocument, the contained
|
|
|
|
* pattern is rendered to a Valentina graphics scene (VMainGraphicsScene).
|
|
|
|
*
|
2014-05-01 13:33:40 +02:00
|
|
|
* A sewing pattern consists of zero or more increments and one
|
2014-03-18 23:36:32 +01:00
|
|
|
* or more pattern pieces.
|
|
|
|
*
|
|
|
|
* An increment is an auxiliary variable that is calculated from regular measurement
|
|
|
|
* variables (that belong to the standard measurements table). Increments are used to
|
|
|
|
* create a graduation schema for the sewing pattern.
|
|
|
|
*
|
2014-05-01 13:33:40 +02:00
|
|
|
* A pattern piece contains
|
2014-03-18 23:36:32 +01:00
|
|
|
* 1) auxiliary pattern construction elements (calculation),
|
2014-05-01 13:33:40 +02:00
|
|
|
* 2) pattern construction elements (modeling), and
|
2014-03-18 23:36:32 +01:00
|
|
|
* 3) special markers, e.g. seam allowances (details).
|
|
|
|
* Of these, 2) and 3) are visible in the final pattern (draw mode 'Modeling'),
|
|
|
|
* 1) is only displayed when editing (draw mode 'Calculation') the pattern.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
class VDomDocument : public QDomDocument
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-02-25 15:02:09 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(VDomDocument)
|
2013-07-13 12:51:31 +02:00
|
|
|
public:
|
2017-04-18 10:46:53 +02:00
|
|
|
static const QString AttrId;
|
|
|
|
static const QString UnitMM;
|
|
|
|
static const QString UnitCM;
|
|
|
|
static const QString UnitINCH;
|
|
|
|
static const QString UnitPX;
|
|
|
|
static const QString TagVersion;
|
|
|
|
static const QString TagUnit;
|
2015-03-16 13:23:02 +01:00
|
|
|
|
2014-12-10 19:33:20 +01:00
|
|
|
VDomDocument();
|
2017-04-01 16:27:55 +02:00
|
|
|
virtual ~VDomDocument() Q_DECL_EQ_DEFAULT;
|
2013-10-27 08:47:01 +01:00
|
|
|
QDomElement elementById(const QString& id);
|
2015-02-11 11:43:50 +01:00
|
|
|
QDomElement elementById(quint32 id);
|
2015-07-03 16:03:19 +02:00
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
template <typename T>
|
2015-07-03 16:03:19 +02:00
|
|
|
void SetAttribute(QDomElement &domElement, const QString &name, const T &value) const;
|
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
static quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue);
|
|
|
|
static bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue);
|
2015-12-26 14:08:41 +01:00
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
static NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name);
|
|
|
|
static void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value);
|
2015-12-26 14:08:41 +01:00
|
|
|
|
2017-01-16 10:59:02 +01:00
|
|
|
static QString GetParametrString(const QDomElement& domElement, const QString &name,
|
|
|
|
const QString &defValue = QString());
|
|
|
|
static qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue);
|
|
|
|
static quint32 GetParametrId(const QDomElement& domElement);
|
2014-08-08 18:07:44 +02:00
|
|
|
|
2017-04-18 10:46:53 +02:00
|
|
|
Unit MUnit() const;
|
|
|
|
|
2014-03-28 14:11:46 +01:00
|
|
|
static void ValidateXML(const QString &schema, const QString &fileName);
|
2015-12-26 14:08:41 +01:00
|
|
|
virtual void setXMLContent(const QString &fileName);
|
2014-06-12 15:38:28 +02:00
|
|
|
static Unit StrToUnits(const QString &unit);
|
2014-06-12 09:49:45 +02:00
|
|
|
static QString UnitsToStr(const Unit &unit, const bool translate = false);
|
2015-08-25 19:53:03 +02:00
|
|
|
static QString UnitsHelpString();
|
|
|
|
|
2014-12-16 08:42:24 +01:00
|
|
|
virtual bool SaveDocument(const QString &fileName, QString &error) const;
|
2014-05-16 16:11:31 +02:00
|
|
|
QString Major() const;
|
|
|
|
QString Minor() const;
|
|
|
|
QString Patch() const;
|
2016-03-04 17:08:29 +01:00
|
|
|
static void RemoveAllChildren(QDomElement &domElement);
|
2014-11-10 15:49:39 +01:00
|
|
|
|
|
|
|
QDomNode ParentNodeById(const quint32 &nodeId);
|
|
|
|
QDomElement CloneNodeById(const quint32 &nodeId);
|
|
|
|
QDomElement NodeById(const quint32 &nodeId);
|
2014-12-16 08:42:24 +01:00
|
|
|
|
2014-12-10 19:33:20 +01:00
|
|
|
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
|
2014-06-13 19:02:41 +02:00
|
|
|
|
2014-12-10 19:33:20 +01:00
|
|
|
protected:
|
2014-12-16 08:42:24 +01:00
|
|
|
bool setTagText(const QString &tag, const QString &text);
|
2016-04-06 04:34:08 +02:00
|
|
|
bool setTagText(const QDomElement &domElement, const QString &text);
|
2014-08-08 18:07:44 +02:00
|
|
|
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
2014-12-10 19:33:20 +01:00
|
|
|
|
2014-12-16 08:42:24 +01:00
|
|
|
void TestUniqueId() const;
|
|
|
|
void CollectId(const QDomElement &node, QVector<quint32> &vector)const;
|
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
private:
|
2013-09-26 20:50:52 +02:00
|
|
|
Q_DISABLE_COPY(VDomDocument)
|
2014-06-13 19:02:41 +02:00
|
|
|
/** @brief Map used for finding element by id. */
|
2013-10-04 13:32:42 +02:00
|
|
|
QHash<QString, QDomElement> map;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
2013-11-06 22:11:12 +01:00
|
|
|
bool find(const QDomElement &node, const QString& id);
|
2013-07-13 12:51:31 +02:00
|
|
|
};
|
|
|
|
|
2015-07-03 16:03:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
/**
|
|
|
|
* @brief SetAttribute set attribute in pattern file. Replace "," by ".".
|
|
|
|
* @param domElement element in xml tree.
|
|
|
|
* @param name name of attribute.
|
|
|
|
* @param value value of attribute.
|
|
|
|
*/
|
|
|
|
inline void VDomDocument::SetAttribute(QDomElement &domElement, const QString &name, const T &value) const
|
|
|
|
{
|
2016-10-04 15:43:06 +02:00
|
|
|
// See specification for xs:decimal
|
|
|
|
const QLocale locale = QLocale::c();
|
|
|
|
domElement.setAttribute(name, locale.toString(value).remove(locale.groupSeparator()));
|
2015-07-03 16:03:19 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-02-25 15:02:09 +01:00
|
|
|
template <>
|
2014-06-11 16:18:50 +02:00
|
|
|
inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const QString &name,
|
|
|
|
const QString &value) const
|
2014-02-25 15:02:09 +01:00
|
|
|
{
|
|
|
|
domElement.setAttribute(name, value);
|
|
|
|
}
|
|
|
|
|
2014-08-08 18:07:44 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
inline void VDomDocument::SetAttribute<bool>(QDomElement &domElement, const QString &name, const bool &value) const
|
|
|
|
{
|
2016-10-04 15:44:11 +02:00
|
|
|
domElement.setAttribute(name, value ? trueStr : falseStr);
|
2014-08-08 18:07:44 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 19:02:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-03-16 07:32:52 +01:00
|
|
|
template <>
|
2014-06-12 09:22:29 +02:00
|
|
|
inline void VDomDocument::SetAttribute<MeasurementsType>(QDomElement &domElement, const QString &name,
|
|
|
|
const MeasurementsType &value) const
|
2014-03-16 07:32:52 +01:00
|
|
|
{
|
2016-07-20 17:59:35 +02:00
|
|
|
domElement.setAttribute(name, value == MeasurementsType::Standard ? QStringLiteral("standard") :
|
|
|
|
QStringLiteral("individual"));
|
2014-03-16 07:32:52 +01:00
|
|
|
}
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2013-08-20 12:26:02 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#endif // VDOMDOCUMENT_H
|