mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Bug fix : Crash when drag an item from the element panel, which represent an element embedded by a project, and drop it in a folio of another project.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4629 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -296,98 +296,121 @@ QDomElement XmlElementCollection::directory(const QString &path) const
|
||||
QString XmlElementCollection::addElement(ElementsLocation &location)
|
||||
{
|
||||
//location must be an element and exist
|
||||
if (!(location.exist() && location.isElement())) return QString();
|
||||
if (!(location.exist() && location.isElement()))
|
||||
return QString();
|
||||
|
||||
//Add an element from this collection to this collection have no sense
|
||||
if (location.isProject() && location.projectCollection() == this) return QString();
|
||||
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)));
|
||||
if (location.isFileSystem() && !dir.exists()) return QString();
|
||||
|
||||
//Get the import dir of this collection
|
||||
QDomElement parent_element = importCategory();
|
||||
if (parent_element.isNull()) return QString();
|
||||
if (parent_element.isNull())
|
||||
return QString();
|
||||
|
||||
QString integrated_path = parent_element.attribute("name");
|
||||
|
||||
//Split the path
|
||||
QStringList splitted_path = location.collectionPath(false).split("/");
|
||||
if (splitted_path.isEmpty()) return QString();
|
||||
if (splitted_path.isEmpty())
|
||||
return QString();
|
||||
|
||||
foreach(QString str, splitted_path)
|
||||
{
|
||||
QDomElement child_element = child(parent_element, str);
|
||||
if (location.isFileSystem()) {
|
||||
//Get the root dir of the filesystem collection
|
||||
QDir dir(location.fileSystemPath().remove(location.collectionPath(false)));
|
||||
if (!dir.exists())
|
||||
return QString();
|
||||
|
||||
//Child doesn't exist, we create it
|
||||
if (child_element.isNull())
|
||||
{
|
||||
QDomElement created_child;
|
||||
foreach(QString str, splitted_path) {
|
||||
QDomElement child_element = child(parent_element, str);
|
||||
|
||||
//str is the path of an element, we integrate an element
|
||||
if (str.endsWith(".elmt"))
|
||||
{
|
||||
//The location represent a file system element
|
||||
if (location.isFileSystem())
|
||||
{
|
||||
//Child doesn't exist, we create it
|
||||
if (child_element.isNull()) {
|
||||
QDomElement created_child;
|
||||
|
||||
//str is the path of an element, we integrate an element
|
||||
if (str.endsWith(".elmt")) {
|
||||
QFile element_file(dir.filePath(str));
|
||||
if (!element_file.exists()) return QString();
|
||||
if (!element_file.exists())
|
||||
return QString();
|
||||
|
||||
created_child = QETXML::fileSystemElementToXmlCollectionElement(m_dom_document, element_file);
|
||||
}
|
||||
//The location represent a xml collection element
|
||||
else
|
||||
{
|
||||
created_child = m_dom_document.createElement("element");
|
||||
created_child.setAttribute("name", str);
|
||||
|
||||
ElementsLocation element_location(integrated_path + str, location.project());
|
||||
QDomElement imported_element = element_location.xml();
|
||||
created_child.appendChild(imported_element.cloneNode());
|
||||
}
|
||||
}
|
||||
|
||||
//str is the path of a directory, we integrate a directory.
|
||||
else
|
||||
{
|
||||
//The location represent a file system directory
|
||||
if (location.isFileSystem())
|
||||
{
|
||||
//str is the path of a directory, we integrate a directory.
|
||||
else {
|
||||
//Dir doesn't exist.
|
||||
if (!dir.cd(str)) return QString();
|
||||
if (!dir.cd(str))
|
||||
return QString();
|
||||
|
||||
created_child = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir);
|
||||
}
|
||||
//The location represent a xml collection directory
|
||||
else
|
||||
{
|
||||
|
||||
if(created_child.isNull())
|
||||
return QString();
|
||||
|
||||
parent_element.appendChild(created_child);
|
||||
parent_element = created_child;
|
||||
}
|
||||
//Child exist
|
||||
else {
|
||||
if (!dir.cd(str))
|
||||
return QString();
|
||||
|
||||
parent_element = child_element;
|
||||
}
|
||||
|
||||
integrated_path.append("/"+str);
|
||||
}
|
||||
}
|
||||
else if (location.isProject()) {
|
||||
QString path;
|
||||
foreach(QString str, splitted_path) {
|
||||
if (path.isEmpty())
|
||||
path = str;
|
||||
else
|
||||
path = path + "/" + str;
|
||||
|
||||
QDomElement child_element = child(parent_element, str);
|
||||
|
||||
//Child doesn't exist, we create it
|
||||
if (child_element.isNull()) {
|
||||
QDomElement created_child;
|
||||
|
||||
//str is the path of an element, we integrate an element
|
||||
if (str.endsWith(".elmt")) {
|
||||
created_child = m_dom_document.createElement("element");
|
||||
created_child.setAttribute("name", str);
|
||||
|
||||
created_child.appendChild(location.xml().cloneNode(true));
|
||||
}
|
||||
|
||||
//str is the path of a directory, we integrate a directory.
|
||||
else {
|
||||
created_child = m_dom_document.createElement("category");
|
||||
created_child.setAttribute("name", str);
|
||||
|
||||
ElementsLocation sub_dir_location(integrated_path + str, location.project());
|
||||
ElementsLocation sub_dir_location(path, 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
|
||||
else
|
||||
parent_element = child_element;
|
||||
|
||||
if(created_child.isNull()) return QString();
|
||||
|
||||
parent_element.appendChild(created_child);
|
||||
parent_element = created_child;
|
||||
integrated_path.append("/"+str);
|
||||
}
|
||||
//Child exist
|
||||
else
|
||||
{
|
||||
if (location.isFileSystem())
|
||||
if (!dir.cd(str)) return QString();
|
||||
|
||||
parent_element = child_element;
|
||||
}
|
||||
|
||||
integrated_path.append("/"+str);
|
||||
}
|
||||
|
||||
emit elementAdded(integrated_path);
|
||||
|
||||
@@ -129,35 +129,29 @@ bool XmlProjectElementCollectionItem::isCollectionRoot() const
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::addChildAtPath
|
||||
* Ask to this item item to add a child with collection name @collection_name
|
||||
* @param collection_name
|
||||
* Ask to this item item to add a new child with collection name @collection_name
|
||||
* (the child must exist in the xml element collection)
|
||||
* @param collection_name : name of the child item to add.
|
||||
*/
|
||||
void XmlProjectElementCollectionItem::addChildAtPath(const QString &collection_name)
|
||||
{
|
||||
if (collection_name.isEmpty())
|
||||
return;
|
||||
|
||||
QDomNodeList node_list;
|
||||
if (collection_name.endsWith(".elmt"))
|
||||
node_list = m_dom_element.elementsByTagName("element");
|
||||
else
|
||||
node_list = m_dom_element.elementsByTagName("category");
|
||||
QString str (collection_name.endsWith(".elmt")? "element" : "category");
|
||||
QDomElement child_element = m_dom_element.firstChildElement(str);
|
||||
|
||||
QDomElement child_element;
|
||||
for(int i=0 ; i<node_list.count() ; i++)
|
||||
{
|
||||
QDomElement dom_elmt = node_list.at(i).toElement();
|
||||
if (dom_elmt.attribute("name") == collection_name)
|
||||
{
|
||||
child_element = dom_elmt;
|
||||
i = node_list.count();
|
||||
while (!child_element.isNull()) {
|
||||
if (child_element.attribute("name") == collection_name) {
|
||||
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem ();
|
||||
insertRow(rowForInsertItem(collection_name), xpeci);
|
||||
xpeci->setXmlElement(child_element, m_project);
|
||||
xpeci->setUpData();
|
||||
return;
|
||||
}
|
||||
else
|
||||
child_element = child_element.nextSiblingElement(str);
|
||||
}
|
||||
|
||||
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem ();
|
||||
insertRow(rowForInsertItem(collection_name), xpeci);
|
||||
xpeci->setXmlElement(child_element, m_project);
|
||||
xpeci->setUpData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user