Decreases the number of declaring variables

for improve readability
This commit is contained in:
Simon De Backer 2020-08-24 22:10:58 +02:00
parent debca09d5c
commit 995066916b

View File

@ -24,6 +24,7 @@
#include "element.h" #include "element.h"
#include "qetxml.h" #include "qetxml.h"
#include <QPicture> #include <QPicture>
#include <QDebug>
// make this class usable with QVariant // make this class usable with QVariant
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation"); int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
@ -608,6 +609,7 @@ QDomElement ElementsLocation::xml() const
*/ */
pugi::xml_document ElementsLocation::pugiXml() const pugi::xml_document ElementsLocation::pugiXml() const
{ {
pugi::xml_document docu; //empty xml_document();
/* Except for linux OS (because linux keep in cache the file), /* Except for linux OS (because linux keep in cache the file),
* we keep in memory the xml * we keep in memory the xml
* to avoid multiple access to file. * to avoid multiple access to file.
@ -618,49 +620,39 @@ pugi::xml_document ElementsLocation::pugiXml() const
#ifndef Q_OS_LINUX #ifndef Q_OS_LINUX
if (!m_string_stream.str().empty()) if (!m_string_stream.str().empty())
{ {
pugi::xml_document docu;
docu.load_string(m_string_stream.str().c_str()); docu.load_string(m_string_stream.str().c_str());
return docu; return docu;
} }
#endif #endif
if (!m_project) if (!m_project)
{ {
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()))
{ {
#ifndef Q_OS_LINUX #ifndef Q_OS_LINUX
docu.save(m_string_stream); docu.save(m_string_stream);
#endif #endif
return docu;
} }
} }
else else
{ {
QString str = m_collection_path; QString str = m_collection_path;
//Get the xml dom from Qt xml and copie to pugi xml
QDomElement element = m_project
->embeddedElementCollection()
->element(str.remove("embed://"));
QDomDocument qdoc;
if (isElement()) if (isElement())
{ {
//Get the xml dom from Qt xml and copie to pugi xml qdoc.appendChild(qdoc.importNode(
QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://")); element.firstChildElement(
QDomDocument qdoc; "definition"),
qdoc.appendChild(qdoc.importNode(element.firstChildElement("definition"), true)); true));
} else {
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)); qdoc.appendChild(qdoc.importNode(element, true));
pugi::xml_document docu;
docu.load_string(qdoc.toString(4).toStdString().c_str());
return docu;
} }
docu.load_string(qdoc.toString(4).toStdString().c_str());
} }
return docu;
return pugi::xml_document();
} }
/** /**