mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
Use pugixml for parse local name of directory and element informations
This commit is contained in:
@@ -570,7 +570,6 @@ pugi::xml_document ElementsLocation::pugiXml() const
|
|||||||
{
|
{
|
||||||
if (!m_project)
|
if (!m_project)
|
||||||
{
|
{
|
||||||
QFile file (m_file_system_path);
|
|
||||||
pugi::xml_document docu;
|
pugi::xml_document docu;
|
||||||
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
if (docu.load_file(m_file_system_path.toStdString().c_str()))
|
||||||
return docu;
|
return docu;
|
||||||
@@ -680,7 +679,8 @@ QUuid ElementsLocation::uuid() const
|
|||||||
QSettings set;
|
QSettings set;
|
||||||
if(set.value("use_pugixml").toBool())
|
if(set.value("use_pugixml").toBool())
|
||||||
{
|
{
|
||||||
pugi::xml_node uuid_node = pugiXml().document_element().child("uuid");
|
auto document = pugiXml();
|
||||||
|
auto uuid_node = document.document_element().child("uuid");
|
||||||
if (uuid_node.empty()) {
|
if (uuid_node.empty()) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
}
|
}
|
||||||
@@ -765,8 +765,16 @@ DiagramContext ElementsLocation::elementInformations() const
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomElement dom = this->xml().firstChildElement("elementInformations");
|
QSettings set;
|
||||||
context.fromXml(dom, "elementInformation");
|
if (set.value("use_pugixml").toBool())
|
||||||
|
{
|
||||||
|
context.fromXml(pugiXml().document_element().child("elementInformations"), "elementInformation");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QDomElement dom = this->xml().firstChildElement("elementInformations");
|
||||||
|
context.fromXml(dom, "elementInformation");
|
||||||
|
}
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,20 +120,39 @@ QString FileElementCollectionItem::localName()
|
|||||||
else
|
else
|
||||||
setText(QObject::tr("Collection inconnue"));
|
setText(QObject::tr("Collection inconnue"));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
QSettings set;
|
||||||
|
if (set.value("use_pugixml").toBool())
|
||||||
|
{
|
||||||
|
QString str(fileSystemPath() + "/qet_directory");
|
||||||
|
pugi::xml_document docu;
|
||||||
|
if(docu.load_file(str.toStdString().c_str()))
|
||||||
|
{
|
||||||
|
if (QString(docu.document_element().name()) == "qet-directory")
|
||||||
|
{
|
||||||
|
NamesList nl;
|
||||||
|
nl.fromXml(docu.document_element());
|
||||||
|
setText(nl.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//Open the qet_directory file, to get the traductions name of this dir
|
//Open the qet_directory file, to get the traductions name of this dir
|
||||||
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
QFile dir_conf(fileSystemPath() + "/qet_directory");
|
||||||
|
|
||||||
if (dir_conf.exists() && dir_conf.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (dir_conf.exists() && dir_conf.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
|
||||||
//Get the content of the file
|
//Get the content of the file
|
||||||
QDomDocument document;
|
QDomDocument document;
|
||||||
if (document.setContent(&dir_conf)) {
|
if (document.setContent(&dir_conf)) {
|
||||||
QDomElement root = document.documentElement();
|
QDomElement root = document.documentElement();
|
||||||
if (root.tagName() == "qet-directory") {
|
if (root.tagName() == "qet-directory") {
|
||||||
NamesList nl;
|
NamesList nl;
|
||||||
nl.fromXml(root);
|
nl.fromXml(root);
|
||||||
setText(nl.name());
|
setText(nl.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,21 @@ void DiagramContext::fromXml(const QDomElement &e, const QString &tag_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DiagramContext::fromXml
|
||||||
|
* Read this context properties from the @dom_element, looking for tags named @tag_name
|
||||||
|
* @param dom_element : dom element to parse
|
||||||
|
* @param tag_name : tag name to find, by default "property"
|
||||||
|
*/
|
||||||
|
void DiagramContext::fromXml(const pugi::xml_node &dom_element, const QString &tag_name)
|
||||||
|
{
|
||||||
|
for(auto node = dom_element.child(tag_name.toStdString().c_str()) ; node ; node = node.next_sibling(tag_name.toStdString().c_str()))
|
||||||
|
{
|
||||||
|
addValue(node.attribute("name").as_string(), QVariant(node.text().as_string()));
|
||||||
|
m_content_show.insert(node.attribute("name").as_string(), node.attribute("show").empty()? 1 : node.attribute("show").as_int());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Export this context properties to \a settings by creating an array named \a
|
Export this context properties to \a settings by creating an array named \a
|
||||||
array_name.
|
array_name.
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include "pugixml.hpp"
|
||||||
/**
|
/**
|
||||||
This class represents a diagram context, i.e. the data (a list of key/value
|
This class represents a diagram context, i.e. the data (a list of key/value
|
||||||
pairs) of a diagram at a given time. It is notably used by titleblock templates
|
pairs) of a diagram at a given time. It is notably used by titleblock templates
|
||||||
@@ -74,6 +76,7 @@ class DiagramContext
|
|||||||
|
|
||||||
void toXml(QDomElement &, const QString & = "property") const;
|
void toXml(QDomElement &, const QString & = "property") const;
|
||||||
void fromXml(const QDomElement &, const QString & = "property");
|
void fromXml(const QDomElement &, const QString & = "property");
|
||||||
|
void fromXml(const pugi::xml_node &dom_element, const QString &tag_name = "property");
|
||||||
void toSettings(QSettings &, const QString &) const;
|
void toSettings(QSettings &, const QString &) const;
|
||||||
void fromSettings(QSettings &, const QString &);
|
void fromSettings(QSettings &, const QString &);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user