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.
|
2013-11-15 13:41:26 +01:00
|
|
|
** Copyright (C) 2013 Valentina project
|
|
|
|
** <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
|
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QDomDocument>
|
|
|
|
#include <QDebug>
|
2014-06-08 20:10:57 +02:00
|
|
|
#include "../container/vcontainer.h"
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2014-05-16 16:11:31 +02:00
|
|
|
/*
|
|
|
|
can be used like #if (V_FORMAT_VERSION >= V_FORMAT_VERSION_CHECK(4, 4, 0))
|
|
|
|
*/
|
|
|
|
#define V_FORMAT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
|
|
|
|
|
2013-11-06 18:59:20 +01:00
|
|
|
#ifdef Q_CC_GNU
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Weffc++"
|
|
|
|
#endif
|
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:
|
2014-03-21 11:08:29 +01:00
|
|
|
static const QString AttrId;
|
|
|
|
static const QString AttrUnit;
|
|
|
|
static const QString UnitMM;
|
|
|
|
static const QString UnitCM;
|
2014-03-24 16:02:57 +01:00
|
|
|
static const QString UnitINCH;
|
2014-05-16 16:11:31 +02:00
|
|
|
static const QString TagVersion;
|
2014-03-18 23:36:32 +01:00
|
|
|
/**
|
2014-06-02 09:43:27 +02:00
|
|
|
* @param data container with variables
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
VDomDocument(VContainer *data);
|
2014-06-02 09:43:27 +02:00
|
|
|
virtual ~VDomDocument();
|
2014-03-18 23:36:32 +01:00
|
|
|
/**
|
|
|
|
* @brief Finds an element by id.
|
2014-01-27 15:05:58 +01:00
|
|
|
* @param id value id attribute.
|
|
|
|
* @return dom element.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-27 08:47:01 +01:00
|
|
|
QDomElement elementById(const QString& id);
|
2014-01-27 15:05:58 +01:00
|
|
|
/**
|
2014-03-19 13:11:45 +01:00
|
|
|
* @brief Removes all children of a given element tag. RENAME: removeAllChildren
|
2014-03-18 23:36:32 +01:00
|
|
|
* @param element tag
|
2014-01-27 15:05:58 +01:00
|
|
|
*/
|
2014-01-02 16:50:01 +01:00
|
|
|
void removeAllChilds(QDomElement &element);
|
2014-02-25 15:02:09 +01:00
|
|
|
template <typename T>
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-02-25 15:02:09 +01:00
|
|
|
* @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.
|
2014-03-18 23:36:32 +01:00
|
|
|
* @param parse parsing mode
|
|
|
|
* @return list of tool pointers
|
|
|
|
* @return list of history record lists
|
|
|
|
* @return cursor
|
2014-03-19 13:11:45 +01:00
|
|
|
* @throw VExceptionUniqueId
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
void SetAttribute(QDomElement &domElement, const QString &name, const T &value)
|
|
|
|
{
|
|
|
|
QString val = QString().setNum(value);
|
|
|
|
val = val.replace(",", ".");
|
|
|
|
domElement.setAttribute(name, val);
|
|
|
|
}
|
2013-12-23 21:14:45 +01:00
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief Returns the long long value of the given attribute. RENAME: GetParameterLongLong?
|
|
|
|
* @param domElement tag in xml tree
|
|
|
|
* @param name attribute name
|
|
|
|
* @return long long value
|
2013-12-23 21:14:45 +01:00
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
quint32 GetParametrUInt(const QDomElement& domElement, const QString &name,
|
2013-12-23 21:14:45 +01:00
|
|
|
const QString &defValue) const;
|
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief Returns the string value of the given attribute. RENAME: see above
|
2014-03-14 16:59:28 +01:00
|
|
|
*
|
|
|
|
* if attribute empty return default value. If default value empty too throw exception.
|
2014-03-18 23:36:32 +01:00
|
|
|
* @return attribute value
|
2014-03-14 16:59:28 +01:00
|
|
|
* @throw VExceptionEmptyParameter when attribute is empty
|
2013-12-23 21:14:45 +01:00
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
QString GetParametrString(const QDomElement& domElement, const QString &name,
|
|
|
|
const QString &defValue = QString()) const;
|
2013-12-23 21:14:45 +01:00
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief Returns the double value of the given attribute.
|
|
|
|
* @param domElement tag in xml tree
|
|
|
|
* @param name attribute name
|
|
|
|
* @return double value
|
2013-12-23 21:14:45 +01:00
|
|
|
*/
|
|
|
|
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
|
2014-02-25 15:02:09 +01:00
|
|
|
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
|
2014-01-27 15:05:58 +01:00
|
|
|
/**
|
2014-03-24 16:02:57 +01:00
|
|
|
* @brief ValidateXML validate xml file by xsd schema.
|
2014-02-25 15:55:02 +01:00
|
|
|
* @param schema path to schema file.
|
2014-03-24 16:02:57 +01:00
|
|
|
* @param fileName name of xml file.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-03-28 14:11:46 +01:00
|
|
|
static void ValidateXML(const QString &schema, const QString &fileName);
|
|
|
|
void setContent(const QString &fileName);
|
2014-03-24 16:02:57 +01:00
|
|
|
static Valentina::Units StrToUnits(const QString &unit);
|
|
|
|
static QString UnitsToStr(const Valentina::Units &unit);
|
2014-05-16 16:11:31 +02:00
|
|
|
virtual bool SaveDocument(const QString &fileName);
|
|
|
|
QString Major() const;
|
|
|
|
QString Minor() const;
|
|
|
|
QString Patch() const;
|
2014-02-25 15:02:09 +01:00
|
|
|
protected:
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-02-25 15:02:09 +01:00
|
|
|
* @brief data container with data.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
VContainer *data;
|
2014-03-28 14:11:46 +01:00
|
|
|
void setTagText(const QString &tag, const QString &text);
|
2014-03-24 16:02:57 +01:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
private:
|
2013-09-26 20:50:52 +02:00
|
|
|
Q_DISABLE_COPY(VDomDocument)
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief Map used for finding element by id.
|
2013-11-19 21:56:49 +01:00
|
|
|
*/
|
2013-10-04 13:32:42 +02:00
|
|
|
QHash<QString, QDomElement> map;
|
2014-02-25 15:02:09 +01:00
|
|
|
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-03-18 23:36:32 +01:00
|
|
|
* @brief Find element by id.
|
|
|
|
* @param node node
|
|
|
|
* @param id id value
|
|
|
|
* @return true if found
|
2013-11-19 21:56:49 +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
|
|
|
};
|
|
|
|
|
2014-02-25 15:02:09 +01:00
|
|
|
template <>
|
|
|
|
inline void VDomDocument::SetAttribute<QString>(QDomElement &domElement, const QString &name, const QString &value)
|
|
|
|
{
|
|
|
|
domElement.setAttribute(name, value);
|
|
|
|
}
|
|
|
|
|
2014-03-16 07:32:52 +01:00
|
|
|
template <>
|
|
|
|
inline void VDomDocument::SetAttribute<Pattern::Measurements>(QDomElement &domElement, const QString &name,
|
|
|
|
const Pattern::Measurements &value)
|
|
|
|
{
|
|
|
|
if (value == Pattern::Standard)
|
|
|
|
{
|
|
|
|
domElement.setAttribute(name, "standard");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domElement.setAttribute(name, "individual");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-06 18:59:20 +01:00
|
|
|
#ifdef Q_CC_GNU
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
2013-08-20 12:26:02 +02:00
|
|
|
|
2013-07-13 12:51:31 +02:00
|
|
|
#endif // VDOMDOCUMENT_H
|