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
|
2013-11-15 13:41:26 +01:00
|
|
|
** @author Roman Telezhinsky <dismine@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
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** 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-06 16:49:07 +01:00
|
|
|
#include "../container/vcontainer.h"
|
2013-07-13 12:51:31 +02:00
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
#include <QDomDocument>
|
|
|
|
#include <QDebug>
|
2014-03-14 15:12:53 +01:00
|
|
|
#include "../options.h"
|
2013-11-21 13:05:26 +01:00
|
|
|
|
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-02-25 15:02:09 +01:00
|
|
|
* @brief The VDomDocument class extend QDomDocument class.
|
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-02-25 15:02:09 +01:00
|
|
|
/**
|
|
|
|
* @brief VDomDocument constructor.
|
|
|
|
* @param data container with variables.
|
|
|
|
* @param parent parent object
|
|
|
|
*/
|
|
|
|
VDomDocument(VContainer *data);
|
|
|
|
virtual ~VDomDocument(){}
|
2013-11-19 21:56:49 +01:00
|
|
|
/**
|
2014-01-27 15:05:58 +01:00
|
|
|
* @brief elementById find element by id.
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* @brief removeAllChilds remove all tag childs.
|
|
|
|
* @param element tag.
|
|
|
|
*/
|
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-01-27 15:05:58 +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-01-27 15:05:58 +01:00
|
|
|
* @brief GetParametrLongLong return long long value of attribute.
|
|
|
|
* @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-01-27 15:05:58 +01:00
|
|
|
* @brief GetParametrString return string value of attribute.
|
2014-03-14 16:59:28 +01:00
|
|
|
*
|
|
|
|
* if attribute empty return default value. If default value empty too throw exception.
|
2014-01-27 15:05:58 +01:00
|
|
|
* @param domElement tag in xml tree.
|
|
|
|
* @param name attribute name.
|
2014-03-14 16:59:28 +01:00
|
|
|
* @throw VExceptionEmptyParameter when attribute is empty
|
2014-01-27 15:05:58 +01:00
|
|
|
* @return attribute value.
|
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-01-27 15:05:58 +01:00
|
|
|
* @brief GetParametrDouble return double value of 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-02-25 15:55:02 +01:00
|
|
|
/**
|
|
|
|
* @brief ValidatePattern validate pattern file by xsd schema.
|
|
|
|
* @param schema path to schema file.
|
|
|
|
* @param fileName name of pattern file.
|
|
|
|
* @param errorMsg error message.
|
|
|
|
* @param errorLine number error line.
|
|
|
|
* @param errorColumn number error column.
|
|
|
|
* @return true if validation successful.
|
|
|
|
*/
|
2014-03-14 18:54:20 +01:00
|
|
|
static void ValidatePattern(const QString &schema, const QString &fileName);
|
|
|
|
void setContent(QIODevice * dev);
|
2014-02-25 15:02:09 +01:00
|
|
|
protected:
|
2014-01-27 15:05:58 +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-14 15:12:53 +01:00
|
|
|
Valentina::Units Units(const QString &unit);
|
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-01-27 15:05:58 +01:00
|
|
|
* @brief map use 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-01-27 15:05:58 +01:00
|
|
|
* @brief find 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline void VDomDocument::SetAttribute<Valentina::Units>(QDomElement &domElement, const QString &name,
|
|
|
|
const Valentina::Units &value)
|
|
|
|
{
|
|
|
|
if (value == Valentina::Cm || value == Valentina::Mm)
|
|
|
|
{
|
|
|
|
domElement.setAttribute(name, "cm");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
domElement.setAttribute(name, "in");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|