Fix regression with embedded element collection

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4420 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-04-03 17:01:44 +00:00
parent 28bc603828
commit eb7ff07feb

View File

@@ -72,9 +72,10 @@ XmlElementCollection::XmlElementCollection(QObject *parent) :
XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QObject *parent) : XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QObject *parent) :
QObject(parent) QObject(parent)
{ {
QDomElement collection = m_dom_document.createElement("collection"); if (dom_element.tagName() == "collection")
m_dom_document.appendChild(collection); m_dom_document.appendChild(m_dom_document.importNode(dom_element, true));
collection.appendChild(dom_element.firstChildElement("category").cloneNode(true)); else
qDebug() << "XmlElementCollection : tagName of dom_element is not collection";
} }
/** /**
@@ -142,20 +143,25 @@ QDomElement XmlElementCollection::child(const QDomElement &parent_element, const
/** /**
* @brief XmlElementCollection::child * @brief XmlElementCollection::child
* @param path * @param path
* @return the DomElement at path if exist. Else return a null QDomElement * @return the DomElement at path if exist, else return a null QDomElement
*/ */
QDomElement XmlElementCollection::child(const QString &path) const QDomElement XmlElementCollection::child(const QString &path) const
{ {
QStringList path_list = path.split("/"); QStringList path_list = path.split("/");
if (path_list.first() != "import") return QDomElement(); if (path_list.isEmpty()) return QDomElement();
path_list.removeFirst();
QDomElement dom_element = importCategory(); QDomElement parent_element = root();
foreach (QString str, path_list)
{
QDomElement child_element = child(parent_element, str);
for (int i=0 ; i<path_list.size() ; i++) if (child_element.isNull())
dom_element = child(dom_element, path_list.at(i)); return QDomElement();
else
parent_element = child_element;
}
return dom_element; return parent_element;
} }
/** /**
@@ -242,8 +248,7 @@ QStringList XmlElementCollection::elementsNames(const QDomElement &parent_elemen
/** /**
* @brief XmlElementCollection::element * @brief XmlElementCollection::element
* @param path : path of element : the path must start by "import/", * @param path : path of the element in this collection
* because import is the first directory of an xml collection
* @return the QDomElement that represent the element at path @path * @return the QDomElement that represent the element at path @path
* or a null QDomElement if not found or doesn't represent an element * or a null QDomElement if not found or doesn't represent an element
*/ */
@@ -251,50 +256,28 @@ QDomElement XmlElementCollection::element(const QString &path)
{ {
if (!path.endsWith(".elmt")) return QDomElement(); if (!path.endsWith(".elmt")) return QDomElement();
QStringList path_list = path.split("/"); QDomElement element = child(path);
QString element_name = path_list.last();
path_list.removeLast();
QDomElement dom_element = directory(path_list.join("/"));
if (dom_element.isNull()) return QDomElement();
QDomNodeList node_list = dom_element.elementsByTagName("element");
if (node_list.isEmpty()) return QDomElement();
for (int i=0 ; i <node_list.size() ; i++)
{
QDomNode node = node_list.at(i);
if (node.isElement())
{
QDomElement qde = node.toElement();
if (qde.attribute("name") == element_name)
return qde;
}
}
if (element.tagName() == "element")
return element;
else
return QDomElement(); return QDomElement();
} }
/** /**
* @brief XmlElementCollection::directory * @brief XmlElementCollection::directory
* @param path : path of directory : the path must start by "import/", * @param path : path of the directory in this collection
* because import is the first directory of an xml collection
* @return the QDomElement that represent the directory at path @path * @return the QDomElement that represent the directory at path @path
* or a null QDomElement if not found. * or a null QDomElement if not found.
*/ */
QDomElement XmlElementCollection::directory(const QString &path) QDomElement XmlElementCollection::directory(const QString &path)
{ {
QStringList path_list = path.split("/"); QDomElement directory = child(path);
QDomElement parent_dom = m_dom_document.documentElement();
for (int i=0 ; i<path_list.size() ; i++) if (directory.tagName() == "category")
{ return directory;
QDomElement child_dom = child(parent_dom, path_list.at(i)); else
if (child_dom.isNull()) return QDomElement(); return QDomElement();
else parent_dom = child_dom;
}
return parent_dom;
} }
/** /**
@@ -437,20 +420,9 @@ ElementsLocation XmlElementCollection::copy(ElementsLocation &source, ElementsLo
*/ */
bool XmlElementCollection::exist(const QString &path) bool XmlElementCollection::exist(const QString &path)
{ {
QStringList str_list = path.split("/"); if (child(path).isNull())
if (str_list.isEmpty()) return false;
QDomElement parent_element = root();
foreach (QString str, str_list)
{
QDomElement child_element = child(parent_element, str);
if (child_element.isNull())
return false; return false;
else else
parent_element = child_element;
}
return true; return true;
} }