Remove the use of ElementsCollectionItem and ElementDefinition from qetelementeditor class

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4413 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-03-31 17:28:44 +00:00
parent 6d4d1535e5
commit 9a6764ae08
10 changed files with 243 additions and 158 deletions

View File

@@ -22,6 +22,7 @@
#include "elementscollectioncache.h"
#include "elementfactory.h"
#include "element.h"
#include "qetxml.h"
// make this class usable with QVariant
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
@@ -430,6 +431,24 @@ bool ElementsLocation::exist() const
}
}
/**
* @brief ElementsLocation::isWritable
* @return True if this element can be writable (can use set xml)
*/
bool ElementsLocation::isWritable() const
{
if (m_project)
return !m_project->isReadOnly();
else if (isFileSystem())
{
if (fileSystemPath().startsWith(QETApp::commonElementsDirN()))
return false;
else
return true;
}
return false;
}
/**
* @brief ElementsLocation::projectCollection
* @return If this location represente a item in an embedded project collection, return this collection
@@ -492,7 +511,7 @@ QDomElement ElementsLocation::xml() const
QFile file (m_file_system_path);
QDomDocument docu;
if (docu.setContent(&file))
return docu.documentElement().cloneNode().toElement();
return docu.documentElement();
}
else
{
@@ -512,6 +531,51 @@ QDomElement ElementsLocation::xml() const
return QDomElement();
}
/**
* @brief ElementsLocation::setXml
* Replace the current xml description by @xml_element;
* The document element of @xml_document must have tagname "definition" to be written
* This definition must be writable
* @param xml_element
* @return true if success
*/
bool ElementsLocation::setXml(const QDomDocument &xml_document) const
{
if (!isWritable())
return false;
if (xml_document.documentElement().tagName() != "definition")
{
qDebug() << "ElementsLocation::setXml : tag name of document element isn't 'definition'";
return false;
}
if (isFileSystem())
{
QString error;
QETXML::writeXmlFile(xml_document, fileSystemPath(), &error);
if (!error.isEmpty())
{
qDebug() << "ElementsLocation::setXml error : " << error;
return false;
}
else
return true;
}
else if (isProject() && exist())
{
QDomElement dom_element = xml();
QDomNode parent_node = dom_element.parentNode();
parent_node.removeChild(dom_element);
parent_node.appendChild(xml_document.documentElement().cloneNode(true));
return true;
}
return false;
}
/**
* @brief ElementsLocation::uuid
* @return The uuid of the pointed element