Element dialog : Remove ElementsCategoriesList and use QTreeView with ElementsCollectionModel instead

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4456 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-04-19 09:29:40 +00:00
parent c0a8b60dbb
commit 1d9735d0e3
6 changed files with 343 additions and 391 deletions

View File

@@ -238,26 +238,8 @@ void ElementsLocation::setPath(const QString &path)
p = QETApp::customElementsDirN() + "/" + tmp_path;
}
//This is an element
if (path.endsWith(".elmt"))
{
QFile file(p);
if (file.exists())
{
m_file_system_path = p;
m_collection_path = path;
}
}
//They must be a directory
else
{
QDir dir(p);
if(dir.exists())
{
m_file_system_path = p;
m_collection_path = path;
}
}
m_file_system_path = p;
m_collection_path = path;
}
//In this case, the path is supposed to be relative to the file system.
else
@@ -567,22 +549,39 @@ bool ElementsLocation::setXml(const QDomDocument &xml_document) const
QString error;
QETXML::writeXmlFile(xml_document, fileSystemPath(), &error);
if (!error.isEmpty())
{
if (!error.isEmpty()) {
qDebug() << "ElementsLocation::setXml error : " << error;
return false;
}
else
else {
return true;
}
}
else if (isProject() && exist())
else if (isProject())
{
QDomElement dom_element = xml();
QDomNode parent_node = dom_element.parentNode();
parent_node.removeChild(dom_element);
parent_node.appendChild(xml_document.documentElement().cloneNode(true));
//Element exist, we overwrite the existing element.
if (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;
}
//Element doesn't exist, we create the element
else
{
QString path_ = collectionPath(false);
QRegExp rx ("^(.*)/(.*\\.elmt)$");
return true;
if (rx.exactMatch(path_)) {
return project()->embeddedElementCollection()->addElementDefinition(rx.cap(1), rx.cap(2), xml_document.documentElement());
}
else {
qDebug() << "ElementsLocation::setXml : rx don't match";
}
}
}
return false;

View File

@@ -391,6 +391,44 @@ QString XmlElementCollection::addElement(ElementsLocation &location)
return integrated_path;
}
/**
* @brief XmlElementCollection::addElementDefinition
* Add the élément defintion @xml_definition in the directory at path @dir_path with the name @elmt_name.
* @param dir_path : the path of the directory where we must add the element.
* The path must be an existing directory of this collection.
* @param elmt_name : The name used to store the element (the name must end with .elmt, if not, .elmt will be append to @elmt_name)
* @param xml_definition : The xml definition of the element.
* The tag name of @xml_definition must be "definition".
* @return True if the element is added with success.
*/
bool XmlElementCollection::addElementDefinition(const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition)
{
QDomElement dom_dir = directory(dir_path);
if (dom_dir.isNull()) {
qDebug() << "XmlElementCollection::addElementDefinition : No directory at path : " << dir_path;
return false;
}
if (xml_definition.tagName() != "definition") {
qDebug() << "XmlElementCollection::addElementDefinition : xml_defintion tag name is not \"definition\"";
return false;
}
QString name = elmt_name;
if (!name.endsWith(".elmt")) {
name += ".elmt";
}
QDomElement dom_elmt = m_dom_document.createElement("element");
dom_elmt.setAttribute("name", name);
dom_elmt.appendChild(xml_definition.cloneNode(true));
dom_dir.appendChild(dom_elmt);
emit elementAdded(dir_path + "/" + name);
return true;
}
/**
* @brief XmlElementCollection::copy
* Copy the content represented by source (an element or a directory) to destination.

View File

@@ -47,6 +47,7 @@ class XmlElementCollection : public QObject
QDomElement element(const QString &path);
QDomElement directory(const QString &path);
QString addElement (ElementsLocation &location);
bool addElementDefinition (const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition);
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
bool exist (const QString &path);