mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Add pugi_xml test branch
This commit is contained in:
@@ -120,10 +120,11 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
|
||||
$$files(sources/autoNum/ui/*.h) \
|
||||
$$files(sources/ui/configpage/*.h) \
|
||||
$$files(sources/SearchAndReplace/*.h) \
|
||||
$$files(sources/SearchAndReplace/ui/*.h) \
|
||||
$$files(sources/NameList/*.h) \
|
||||
$$files(sources/NameList/ui/*.h) \
|
||||
$$files(sources/utils/*.h)
|
||||
$$files(sources/SearchAndReplace/ui/*.h) \
|
||||
$$files(sources/NameList/*.h) \
|
||||
$$files(sources/NameList/ui/*.h) \
|
||||
$$files(sources/utils/*.h) \
|
||||
$$files(sources/pugixml/*.hpp)
|
||||
|
||||
SOURCES += $$files(sources/*.cpp) \
|
||||
$$files(sources/editor/*.cpp) \
|
||||
@@ -144,11 +145,12 @@ SOURCES += $$files(sources/*.cpp) \
|
||||
$$files(sources/autoNum/*.cpp) \
|
||||
$$files(sources/autoNum/ui/*.cpp) \
|
||||
$$files(sources/ui/configpage/*.cpp) \
|
||||
$$files(sources/SearchAndReplace/*.cpp) \
|
||||
$$files(sources/SearchAndReplace/ui/*.cpp) \
|
||||
$$files(sources/NameList/*.cpp) \
|
||||
$$files(sources/NameList/ui/*.cpp) \
|
||||
$$files(sources/utils/*.cpp)
|
||||
$$files(sources/SearchAndReplace/*.cpp) \
|
||||
$$files(sources/SearchAndReplace/ui/*.cpp) \
|
||||
$$files(sources/NameList/*.cpp) \
|
||||
$$files(sources/NameList/ui/*.cpp) \
|
||||
$$files(sources/utils/*.cpp) \
|
||||
$$files(sources/pugixml/*.cpp)
|
||||
|
||||
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
|
||||
RESOURCES += qelectrotech.qrc
|
||||
|
||||
@@ -554,6 +554,49 @@ QDomElement ElementsLocation::xml() const
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::pugiXml
|
||||
* @return the xml document of this element or directory
|
||||
* The definition can be null
|
||||
*/
|
||||
pugi::xml_document ElementsLocation::pugiXml() const
|
||||
{
|
||||
if (!m_project)
|
||||
{
|
||||
QFile file (m_file_system_path);
|
||||
pugi::xml_document docu;
|
||||
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
||||
return docu;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString str = m_collection_path;
|
||||
if (isElement())
|
||||
{
|
||||
//Get the xml dom from Qt xml and copie to pugi xml
|
||||
QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://"));
|
||||
QDomDocument qdoc;
|
||||
qdoc.appendChild(qdoc.importNode(element.firstChildElement("definition"), true));
|
||||
|
||||
pugi::xml_document docu;
|
||||
docu.load_string(qdoc.toString(4).toStdString().c_str());
|
||||
return docu;
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement element = m_project->embeddedElementCollection()->directory(str.remove("embed://"));
|
||||
QDomDocument qdoc;
|
||||
qdoc.appendChild(qdoc.importNode(element, true));
|
||||
|
||||
pugi::xml_document docu;
|
||||
docu.load_string(qdoc.toString(4).toStdString().c_str());
|
||||
return docu;
|
||||
}
|
||||
}
|
||||
|
||||
return pugi::xml_document();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::setXml
|
||||
* Replace the current xml description by @xml_element;
|
||||
@@ -623,13 +666,24 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
|
||||
*/
|
||||
QUuid ElementsLocation::uuid() const
|
||||
{
|
||||
//Get the uuid of element
|
||||
QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
// //Get the uuid of element
|
||||
// QList<QDomElement> list_ = QET::findInDomElement(xml(), "uuid");
|
||||
|
||||
if (!list_.isEmpty())
|
||||
return QUuid(list_.first().attribute("uuid"));
|
||||
// if (!list_.isEmpty())
|
||||
// return QUuid(list_.first().attribute("uuid"));
|
||||
|
||||
return QUuid();
|
||||
// return QUuid();
|
||||
//Get the uuid of element
|
||||
|
||||
if (!isElement()) {
|
||||
return QUuid();
|
||||
}
|
||||
|
||||
pugi::xml_node uuid_node = pugiXml().document_element().child("uuid");
|
||||
if (uuid_node.empty()) {
|
||||
return QUuid();
|
||||
}
|
||||
return QUuid(uuid_node.attribute("uuid").as_string());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -660,7 +714,8 @@ QIcon ElementsLocation::icon() const
|
||||
QString ElementsLocation::name() const
|
||||
{
|
||||
NamesList nl;
|
||||
nl.fromXml(xml());
|
||||
// nl.fromXml(xml());
|
||||
nl.fromXml(pugiXml().document_element());
|
||||
return nl.name(fileName());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "nameslist.h"
|
||||
#include "diagramcontext.h"
|
||||
#include "pugixml.hpp"
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
|
||||
@@ -73,6 +74,7 @@ class ElementsLocation
|
||||
NamesList nameList();
|
||||
|
||||
QDomElement xml() const;
|
||||
pugi::xml_document pugiXml() const;
|
||||
bool setXml(const QDomDocument &xml_document) const;
|
||||
QUuid uuid() const;
|
||||
QIcon icon() const;
|
||||
|
||||
@@ -132,6 +132,39 @@ void NamesList::fromXml(const QDomElement &xml_element, const QHash<QString, QSt
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NamesList::fromXml
|
||||
* Load the list of lang <-> name from an xml description.
|
||||
* @xml_element must be the parent of a child element tagged "names"
|
||||
* If a couple lang <-> name already exist, they will overwrited, else
|
||||
* they will be appened.
|
||||
* @param xml_element : xml element to analyze
|
||||
* @param xml_options : A set of options related to XML parsing.
|
||||
* @see getXmlOptions()
|
||||
*/
|
||||
void NamesList::fromXml(const pugi::xml_node &xml_element, const QHash<QString, QString> &xml_options)
|
||||
{
|
||||
QHash<QString, QString> xml_opt = getXmlOptions(xml_options);
|
||||
|
||||
//Walk the childs "names" of the xml element
|
||||
for (auto names = xml_element.first_child() ; names ; names = names.next_sibling())
|
||||
{
|
||||
if (names.type() != pugi::node_element ||
|
||||
QString(names.name()) != xml_opt["ParentTagName"]) {
|
||||
continue;
|
||||
}
|
||||
for (auto name = names.first_child(); name; name = name.next_sibling()) {
|
||||
if (name.type() != pugi::node_element ||
|
||||
QString(name.name()) != xml_opt["TagName"]) {
|
||||
continue;
|
||||
}
|
||||
QString lang_str(name.attribute(xml_opt["LanguageAttribute"].toStdString().c_str()).as_string());
|
||||
QString name_str(name.text().get());
|
||||
addName(lang_str, name_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Exporte la liste des noms vers un element XML. Veillez a verifier que la
|
||||
liste de noms n'est pas vide avant de l'exporter.
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef NAMES_LIST_H
|
||||
#define NAMES_LIST_H
|
||||
#include <QtXml>
|
||||
#include "pugixml.hpp"
|
||||
/**
|
||||
Cette classe represente une liste de noms, utilisee
|
||||
par les elements et categories pour embarquer un meme nom en plusieurs
|
||||
@@ -57,6 +58,7 @@ class NamesList {
|
||||
|
||||
// methods relatives a XML
|
||||
void fromXml(const QDomElement &, const QHash<QString, QString> & = QHash<QString, QString>());
|
||||
void fromXml(const pugi::xml_node &xml_element, const QHash<QString, QString> &xml_options = QHash<QString, QString>());
|
||||
QDomElement toXml(QDomDocument &, const QHash<QString, QString> & = QHash<QString, QString>()) const;
|
||||
|
||||
protected:
|
||||
|
||||
75
sources/pugixml/pugiconfig.hpp
Normal file
75
sources/pugixml/pugiconfig.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* pugixml parser - version 1.10
|
||||
* --------------------------------------------------------
|
||||
* Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||
* Report bugs and download new versions at https://pugixml.org/
|
||||
*
|
||||
* This library is distributed under the MIT License. See notice at the end
|
||||
* of this file.
|
||||
*
|
||||
* This work is based on the pugxml parser, which is:
|
||||
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
|
||||
*/
|
||||
|
||||
#ifndef HEADER_PUGICONFIG_HPP
|
||||
#define HEADER_PUGICONFIG_HPP
|
||||
|
||||
// Uncomment this to enable wchar_t mode
|
||||
// #define PUGIXML_WCHAR_MODE
|
||||
|
||||
// Uncomment this to enable compact mode
|
||||
// #define PUGIXML_COMPACT
|
||||
|
||||
// Uncomment this to disable XPath
|
||||
// #define PUGIXML_NO_XPATH
|
||||
|
||||
// Uncomment this to disable STL
|
||||
// #define PUGIXML_NO_STL
|
||||
|
||||
// Uncomment this to disable exceptions
|
||||
// #define PUGIXML_NO_EXCEPTIONS
|
||||
|
||||
// Set this to control attributes for public classes/functions, i.e.:
|
||||
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
|
||||
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
|
||||
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
|
||||
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
|
||||
|
||||
// Tune these constants to adjust memory-related behavior
|
||||
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
|
||||
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
||||
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
||||
|
||||
// Uncomment this to switch to header-only version
|
||||
// #define PUGIXML_HEADER_ONLY
|
||||
|
||||
// Uncomment this to enable long long support
|
||||
// #define PUGIXML_HAS_LONG_LONG
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2019 Arseny Kapoulkine
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
12929
sources/pugixml/pugixml.cpp
Normal file
12929
sources/pugixml/pugixml.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1491
sources/pugixml/pugixml.hpp
Normal file
1491
sources/pugixml/pugixml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user