mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +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,99 +296,122 @@ QDomElement XmlElementCollection::directory(const QString &path) const
|
|||||||
QString XmlElementCollection::addElement(ElementsLocation &location)
|
QString XmlElementCollection::addElement(ElementsLocation &location)
|
||||||
{
|
{
|
||||||
//location must be an element and exist
|
//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
|
//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
|
//First we check if this location exist in this collection if so, we do nothing
|
||||||
if ( exist("import/" + location.collectionPath(false)) )
|
if ( exist("import/" + location.collectionPath(false)) )
|
||||||
return QString();
|
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
|
//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();
|
||||||
|
|
||||||
QString integrated_path = parent_element.attribute("name");
|
QString integrated_path = parent_element.attribute("name");
|
||||||
|
|
||||||
//Split the path
|
//Split the path
|
||||||
QStringList splitted_path = location.collectionPath(false).split("/");
|
QStringList splitted_path = location.collectionPath(false).split("/");
|
||||||
if (splitted_path.isEmpty()) return QString();
|
if (splitted_path.isEmpty())
|
||||||
|
return QString();
|
||||||
|
|
||||||
foreach(QString str, splitted_path)
|
if (location.isFileSystem()) {
|
||||||
{
|
//Get the root dir of the filesystem collection
|
||||||
|
QDir dir(location.fileSystemPath().remove(location.collectionPath(false)));
|
||||||
|
if (!dir.exists())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
foreach(QString str, splitted_path) {
|
||||||
QDomElement child_element = child(parent_element, str);
|
QDomElement child_element = child(parent_element, str);
|
||||||
|
|
||||||
//Child doesn't exist, we create it
|
//Child doesn't exist, we create it
|
||||||
if (child_element.isNull())
|
if (child_element.isNull()) {
|
||||||
{
|
|
||||||
QDomElement created_child;
|
QDomElement created_child;
|
||||||
|
|
||||||
//str is the path of an element, we integrate an element
|
//str is the path of an element, we integrate an element
|
||||||
if (str.endsWith(".elmt"))
|
if (str.endsWith(".elmt")) {
|
||||||
{
|
|
||||||
//The location represent a file system element
|
|
||||||
if (location.isFileSystem())
|
|
||||||
{
|
|
||||||
QFile element_file(dir.filePath(str));
|
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);
|
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.
|
//str is the path of a directory, we integrate a directory.
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
//The location represent a file system directory
|
|
||||||
if (location.isFileSystem())
|
|
||||||
{
|
|
||||||
//Dir doesn't exist.
|
//Dir doesn't exist.
|
||||||
if (!dir.cd(str)) return QString();
|
if (!dir.cd(str))
|
||||||
|
return QString();
|
||||||
|
|
||||||
created_child = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir);
|
created_child = QETXML::fileSystemDirToXmlCollectionDir(m_dom_document, dir);
|
||||||
}
|
}
|
||||||
//The location represent a xml collection directory
|
|
||||||
|
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
|
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 = m_dom_document.createElement("category");
|
||||||
created_child.setAttribute("name", str);
|
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);
|
QDomElement names_element = sub_dir_location.nameList().toXml(m_dom_document);
|
||||||
created_child.appendChild(names_element);
|
created_child.appendChild(names_element);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(created_child.isNull()) return QString();
|
if(created_child.isNull())
|
||||||
|
return QString();
|
||||||
|
|
||||||
parent_element.appendChild(created_child);
|
parent_element.appendChild(created_child);
|
||||||
parent_element = created_child;
|
parent_element = created_child;
|
||||||
}
|
}
|
||||||
//Child exist
|
//Child exist
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (location.isFileSystem())
|
|
||||||
if (!dir.cd(str)) return QString();
|
|
||||||
|
|
||||||
parent_element = child_element;
|
parent_element = child_element;
|
||||||
}
|
|
||||||
|
|
||||||
integrated_path.append("/"+str);
|
integrated_path.append("/"+str);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit elementAdded(integrated_path);
|
emit elementAdded(integrated_path);
|
||||||
return integrated_path;
|
return integrated_path;
|
||||||
|
|||||||
@@ -129,35 +129,29 @@ bool XmlProjectElementCollectionItem::isCollectionRoot() const
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief XmlProjectElementCollectionItem::addChildAtPath
|
* @brief XmlProjectElementCollectionItem::addChildAtPath
|
||||||
* Ask to this item item to add a child with collection name @collection_name
|
* Ask to this item item to add a new child with collection name @collection_name
|
||||||
* @param 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)
|
void XmlProjectElementCollectionItem::addChildAtPath(const QString &collection_name)
|
||||||
{
|
{
|
||||||
if (collection_name.isEmpty())
|
if (collection_name.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QDomNodeList node_list;
|
QString str (collection_name.endsWith(".elmt")? "element" : "category");
|
||||||
if (collection_name.endsWith(".elmt"))
|
QDomElement child_element = m_dom_element.firstChildElement(str);
|
||||||
node_list = m_dom_element.elementsByTagName("element");
|
|
||||||
else
|
|
||||||
node_list = m_dom_element.elementsByTagName("category");
|
|
||||||
|
|
||||||
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 ();
|
XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem ();
|
||||||
insertRow(rowForInsertItem(collection_name), xpeci);
|
insertRow(rowForInsertItem(collection_name), xpeci);
|
||||||
xpeci->setXmlElement(child_element, m_project);
|
xpeci->setXmlElement(child_element, m_project);
|
||||||
xpeci->setUpData();
|
xpeci->setUpData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
child_element = child_element.nextSiblingElement(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user