mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Enable the drag & drop of an element from the element panel (an embedded element of a project) to the folio of another project.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4388 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -186,12 +186,10 @@ QString ElementsLocation::path() const {
|
|||||||
/**
|
/**
|
||||||
* @brief ElementsLocation::setPath
|
* @brief ElementsLocation::setPath
|
||||||
* Set the path of this item.
|
* Set the path of this item.
|
||||||
* If the path is for a file collection, the path can be in file system or relative to the beginning
|
* The path can be relative to a collection (start by common:// , custom:// or embed://) or not.
|
||||||
* of the colection, in this case the path must start with (common:// or custom://).
|
|
||||||
* @param path
|
* @param path
|
||||||
* @return true if the element pointed by path exist, else false
|
|
||||||
*/
|
*/
|
||||||
bool ElementsLocation::setPath(const QString &path)
|
void ElementsLocation::setPath(const QString &path)
|
||||||
{
|
{
|
||||||
QString tmp_path = path;
|
QString tmp_path = path;
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@@ -203,13 +201,11 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
//There is a project, the path is for an embedded coolection.
|
//There is a project, the path is for an embedded coolection.
|
||||||
if (m_project)
|
if (m_project)
|
||||||
{
|
{
|
||||||
if (path.startsWith("embed://"))
|
m_collection_path = path;
|
||||||
{
|
//Add the protocol to the collection path
|
||||||
m_collection_path = path;
|
if (!path.startsWith("embed://"))
|
||||||
return true;
|
m_collection_path.prepend("embed://");
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//The path start with project, we get the project and the path from the string
|
//The path start with project, we get the project and the path from the string
|
||||||
@@ -227,11 +223,9 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
{
|
{
|
||||||
m_collection_path = rx.capturedTexts().at(2);
|
m_collection_path = rx.capturedTexts().at(2);
|
||||||
m_project = project;
|
m_project = project;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//The path is in file system, the given path is relative to common or custom collection
|
//The path is in file system, the given path is relative to common or custom collection
|
||||||
@@ -257,9 +251,7 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
{
|
{
|
||||||
m_file_system_path = p;
|
m_file_system_path = p;
|
||||||
m_collection_path = path;
|
m_collection_path = path;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
//They must be a directory
|
//They must be a directory
|
||||||
else
|
else
|
||||||
@@ -269,9 +261,7 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
{
|
{
|
||||||
m_file_system_path = p;
|
m_file_system_path = p;
|
||||||
m_collection_path = path;
|
m_collection_path = path;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//In this case, the path is supposed to be relative to the file system.
|
//In this case, the path is supposed to be relative to the file system.
|
||||||
@@ -293,7 +283,6 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
path_.prepend("custom://");
|
path_.prepend("custom://");
|
||||||
m_collection_path = path_;
|
m_collection_path = path_;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -310,11 +299,8 @@ bool ElementsLocation::setPath(const QString &path)
|
|||||||
path_.prepend("custom://");
|
path_.prepend("custom://");
|
||||||
m_collection_path = path_;
|
m_collection_path = path_;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -467,7 +453,9 @@ bool ElementsLocation::isProject() const
|
|||||||
bool ElementsLocation::exist() const
|
bool ElementsLocation::exist() const
|
||||||
{
|
{
|
||||||
if (m_project)
|
if (m_project)
|
||||||
|
{
|
||||||
return m_project->embeddedElementCollection()->exist(collectionPath(false));
|
return m_project->embeddedElementCollection()->exist(collectionPath(false));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fileSystemPath().isEmpty()) return false;
|
if (fileSystemPath().isEmpty()) return false;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ElementsLocation
|
|||||||
QString projectCollectionPath() const;
|
QString projectCollectionPath() const;
|
||||||
QString fileSystemPath() const;
|
QString fileSystemPath() const;
|
||||||
QString path() const;
|
QString path() const;
|
||||||
bool setPath(const QString &path);
|
void setPath(const QString &path);
|
||||||
bool addToPath(const QString &);
|
bool addToPath(const QString &);
|
||||||
|
|
||||||
ElementsLocation parent() const;
|
ElementsLocation parent() const;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ XmlElementCollection::XmlElementCollection(const QDomElement &dom_element, QObje
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XmlElementCollection::root
|
* @brief XmlElementCollection::root
|
||||||
* The root is the beginning of the xml collection, the tag name
|
* The root is the first DOM-Element the xml collection, the tag name
|
||||||
* of the dom element is : collection
|
* of the dom element is : collection
|
||||||
* @return The root QDomElement of the collection
|
* @return The root QDomElement of the collection
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +109,7 @@ QDomNodeList XmlElementCollection::childs(const QDomElement &parent_element) con
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XmlElementCollection::child
|
* @brief XmlElementCollection::child
|
||||||
* If parent_element have child element with name "child_name", return it, else return a null QDomElement.
|
* If parent_element have child element with an attribute name = @child_name, return it, else return a null QDomElement.
|
||||||
* Only search for element with tag-name "category" and "element" (if child_name end with ".elmt")
|
* Only search for element with tag-name "category" and "element" (if child_name end with ".elmt")
|
||||||
* @param parent_element : the parent DomElement where we search for child.
|
* @param parent_element : the parent DomElement where we search for child.
|
||||||
* @parent_element must be a child node of this XmlElementCollection.
|
* @parent_element must be a child node of this XmlElementCollection.
|
||||||
@@ -118,7 +118,7 @@ QDomNodeList XmlElementCollection::childs(const QDomElement &parent_element) con
|
|||||||
*/
|
*/
|
||||||
QDomElement XmlElementCollection::child(const QDomElement &parent_element, const QString &child_name) const
|
QDomElement XmlElementCollection::child(const QDomElement &parent_element, const QString &child_name) const
|
||||||
{
|
{
|
||||||
if (parent_element.ownerDocument() != m_dom_document && parent_element.tagName() != "category") return QDomElement();
|
if (parent_element.ownerDocument() != m_dom_document) return QDomElement();
|
||||||
|
|
||||||
//Get all childs element of parent_element
|
//Get all childs element of parent_element
|
||||||
QDomNodeList child_list = parent_element.childNodes();
|
QDomNodeList child_list = parent_element.childNodes();
|
||||||
@@ -314,75 +314,113 @@ QDomElement XmlElementCollection::directory(const QString &path)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XmlElementCollection::addElement
|
* @brief XmlElementCollection::addElement
|
||||||
* Add the element at path @path to this xml collection.
|
* Add the element at location to this collection.
|
||||||
* The path must be a common or custom collection (a file system element).
|
* The element is copied in this collection in "import" dir with the same path, in other word
|
||||||
* The element is copied in this collection with the same path of @path, in other word,
|
* if the path is dir1/dir2/dir3/myElement.elmt, myElement is copied to this collection at the path : import/dir1/dir2/dir3/myElement.elmt
|
||||||
* if the path is dir1/dir2/dir3/myElement.elmt, myElement is copied to this collection at the path : dir1/dir2/dir3/myElement.elmt
|
|
||||||
* If the path doesn't exist, he was created.
|
* If the path doesn't exist, he was created.
|
||||||
* @param path, path of the element
|
* If the element already exist, do nothing.
|
||||||
* @return the xml collection path of the added item or a null QString if element can't be added.
|
* @param location, location of the element
|
||||||
|
* @return the collection path of the added item or a null QString if element can't be added.
|
||||||
*/
|
*/
|
||||||
QString XmlElementCollection::addElement(const QString &path)
|
QString XmlElementCollection::addElement(ElementsLocation &location)
|
||||||
{
|
{
|
||||||
ElementsLocation location(path);
|
//location must be an element and exist
|
||||||
if (!location.isElement() || location.fileSystemPath().isEmpty()) return QString();
|
if (!(location.exist() && location.isElement())) return QString();
|
||||||
if (exist(QString("import/" + location.collectionPath(false)))) return QString();
|
//Add an element from this collection to this collection have no sense
|
||||||
|
if (location.isProject() && location.projectCollection() == this) return QString();
|
||||||
|
|
||||||
|
//First we check if this location exist in this collection if so, we do nothing
|
||||||
|
if ( exist("import/" + location.collectionPath(false)) )
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
//Get the root dir of the filesystem collection
|
||||||
QDir dir(location.fileSystemPath().remove(location.collectionPath(false)));
|
QDir dir(location.fileSystemPath().remove(location.collectionPath(false)));
|
||||||
if (!dir.exists()) return QString();
|
if (location.isFileSystem() && !dir.exists()) return QString();
|
||||||
|
|
||||||
|
//Get the import dir of this collection
|
||||||
QDomElement parent_element = importCategory();
|
QDomElement parent_element = importCategory();
|
||||||
if (parent_element.isNull()) return QString();
|
if (parent_element.isNull()) return QString();
|
||||||
|
|
||||||
QStringList str_list = location.collectionPath(false).split("/");
|
QString integrated_path = parent_element.attribute("name");
|
||||||
if (str_list.isEmpty()) return QString();
|
|
||||||
|
|
||||||
QString collection_path(parent_element.attribute("name"));
|
//Split the path
|
||||||
|
QStringList splitted_path = location.collectionPath(false).split("/");
|
||||||
|
if (splitted_path.isEmpty()) return QString();
|
||||||
|
|
||||||
foreach(QString str, str_list)
|
foreach(QString str, splitted_path)
|
||||||
{
|
{
|
||||||
QDomElement child_element = child(parent_element, str);
|
QDomElement child_element = child(parent_element, str);
|
||||||
|
|
||||||
//Child doesn't exist
|
//Child doesn't exist, we create it
|
||||||
if (child_element.isNull())
|
if (child_element.isNull())
|
||||||
{
|
{
|
||||||
|
QDomElement created_child;
|
||||||
|
|
||||||
|
//str is the path of an element, we integrate an element
|
||||||
if (str.endsWith(".elmt"))
|
if (str.endsWith(".elmt"))
|
||||||
{
|
{
|
||||||
QFile element_file(dir.filePath(str));
|
//The location represent a file system element
|
||||||
if (!element_file.exists()) return QString();
|
if (location.isFileSystem())
|
||||||
|
{
|
||||||
|
QFile element_file(dir.filePath(str));
|
||||||
|
if (!element_file.exists()) return QString();
|
||||||
|
|
||||||
QDomElement element_dom = QETXML::fileSystemElementToXmlCollectionElement(m_dom_document, element_file);
|
created_child = QETXML::fileSystemElementToXmlCollectionElement(m_dom_document, element_file);
|
||||||
if (element_dom.isNull()) return QString();
|
}
|
||||||
|
//The location represent a xml collection element
|
||||||
|
else
|
||||||
|
{
|
||||||
|
created_child = m_dom_document.createElement("element");
|
||||||
|
created_child.setAttribute("name", str);
|
||||||
|
|
||||||
parent_element.appendChild(element_dom);
|
ElementsLocation element_location(integrated_path + str, location.project());
|
||||||
parent_element = element_dom;
|
QDomElement imported_element = element_location.xml();
|
||||||
|
created_child.appendChild(imported_element.cloneNode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//str is the path of a directory, we integrate a directory.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Dir doesn't exist.
|
//The location represent a file system directory
|
||||||
if (!dir.cd(str)) return QString();
|
if (location.isFileSystem())
|
||||||
QDomElement dir_element = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir);
|
{
|
||||||
//Creation of a xml collection dir failed
|
//Dir doesn't exist.
|
||||||
if (dir_element.isNull()) return QString();
|
if (!dir.cd(str)) return QString();
|
||||||
|
|
||||||
parent_element.appendChild(dir_element);
|
created_child = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir);
|
||||||
parent_element = dir_element;
|
}
|
||||||
|
//The location represent a xml collection directory
|
||||||
|
else
|
||||||
|
{
|
||||||
|
created_child = m_dom_document.createElement("category");
|
||||||
|
created_child.setAttribute("name", str);
|
||||||
|
|
||||||
|
ElementsLocation sub_dir_location(integrated_path + str, location.project());
|
||||||
|
QDomElement names_element = sub_dir_location.nameList().toXml(m_dom_document);
|
||||||
|
created_child.appendChild(names_element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(created_child.isNull()) return QString();
|
||||||
|
|
||||||
|
parent_element.appendChild(created_child);
|
||||||
|
parent_element = created_child;
|
||||||
}
|
}
|
||||||
//Child exist
|
//Child exist
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!dir.cd(str)) return QString();
|
if (location.isFileSystem())
|
||||||
|
if (!dir.cd(str)) return QString();
|
||||||
|
|
||||||
parent_element = child_element;
|
parent_element = child_element;
|
||||||
}
|
}
|
||||||
|
|
||||||
collection_path.append("/"+str);
|
integrated_path.append("/"+str);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit elementAdded(collection_path);
|
emit elementAdded(integrated_path);
|
||||||
return collection_path;
|
return integrated_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -417,14 +455,11 @@ bool XmlElementCollection::exist(const QString &path)
|
|||||||
QStringList str_list = path.split("/");
|
QStringList str_list = path.split("/");
|
||||||
if (str_list.isEmpty()) return false;
|
if (str_list.isEmpty()) return false;
|
||||||
|
|
||||||
//The first category of a XmlElementCollection is always "import"
|
QDomElement parent_element = root();
|
||||||
if (str_list.first() != "import") return false;
|
|
||||||
str_list.removeFirst();
|
|
||||||
|
|
||||||
QDomElement parent_element = importCategory();
|
|
||||||
foreach (QString str, str_list)
|
foreach (QString str, str_list)
|
||||||
{
|
{
|
||||||
QDomElement child_element = child(parent_element, str);
|
QDomElement child_element = child(parent_element, str);
|
||||||
|
|
||||||
if (child_element.isNull())
|
if (child_element.isNull())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class XmlElementCollection : public QObject
|
|||||||
QStringList elementsNames(const QDomElement &parent_element);
|
QStringList elementsNames(const QDomElement &parent_element);
|
||||||
QDomElement element(const QString &path);
|
QDomElement element(const QString &path);
|
||||||
QDomElement directory(const QString &path);
|
QDomElement directory(const QString &path);
|
||||||
QString addElement (const QString &path);
|
QString addElement (ElementsLocation &location);
|
||||||
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||||
bool exist (const QString &path);
|
bool exist (const QString &path);
|
||||||
|
|
||||||
|
|||||||
@@ -789,7 +789,9 @@ QString QETProject::integrateElement(const QString &elmt_path, MoveElementsHandl
|
|||||||
{
|
{
|
||||||
// integre l'element normalement
|
// integre l'element normalement
|
||||||
result = copyElementWithHandler(integ_elmt, target_cat, handler, error_message);
|
result = copyElementWithHandler(integ_elmt, target_cat, handler, error_message);
|
||||||
QString xml_path = m_elements_collection->addElement(elmt_path);
|
|
||||||
|
ElementsLocation location(elmt_path);
|
||||||
|
QString xml_path = m_elements_collection->addElement(location);
|
||||||
if (!xml_path.isNull()) emit elementIntegratedToCollection(this, xml_path);
|
if (!xml_path.isNull()) emit elementIntegratedToCollection(this, xml_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user