mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element collection : improve drag and drop behavior
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4325 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -253,71 +253,6 @@ QString XmlProjectElementCollectionItem::collectionName() const {
|
||||
return m_dom_element.attribute("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::lastItemForPath
|
||||
* Return the last existing item in this XmlProjectElementCollectionItem hierarchy according to the given path.
|
||||
* Next_item is the first non existing item in this hierarchy according to the given path.
|
||||
* @param path : The path to find last item. The path must be in form : path/otherPath/myElement.elmt.
|
||||
* @param next_item : The first item that not exist in this hierarchy
|
||||
* @return : The last item that exist in this hierarchy, or nullptr can't find (an error was occurred, or path already exist)
|
||||
*/
|
||||
XmlProjectElementCollectionItem *XmlProjectElementCollectionItem::lastItemForPath(const QString &path, QString &next_item)
|
||||
{
|
||||
QStringList str_list = path.split("/");
|
||||
if (str_list.isEmpty()) return nullptr;
|
||||
|
||||
XmlProjectElementCollectionItem *xpeci = this;
|
||||
foreach (QString str, str_list)
|
||||
{
|
||||
ElementCollectionItem *eci = xpeci->childWithCollectionName(str);
|
||||
if (!eci)
|
||||
{
|
||||
next_item = str;
|
||||
return xpeci;
|
||||
}
|
||||
else
|
||||
xpeci = static_cast<XmlProjectElementCollectionItem *>(eci);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::rowForInsertItem
|
||||
* Return the row for insert a new child item to this item with name @collection_name.
|
||||
* If row can't be found (collection_name is null, or already exist) return -1;
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
int XmlProjectElementCollectionItem::rowForInsertItem(const QString &collection_name)
|
||||
{
|
||||
if (collection_name.isEmpty()) return -1;
|
||||
|
||||
QList <ElementCollectionItem *> child;
|
||||
//The item to insert is an element we search from element child
|
||||
if (collection_name.endsWith(".elmt"))
|
||||
{
|
||||
child = elementsChild();
|
||||
//There isn't element, we insert at last position
|
||||
if (child.isEmpty())
|
||||
return childCount();
|
||||
}
|
||||
//The item is a directory, we search from directory child
|
||||
else
|
||||
{
|
||||
child = directoriesChild();
|
||||
//There isn't directory, we insert at first position
|
||||
if(child.isEmpty())
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach (ElementCollectionItem *eci, child)
|
||||
if (eci->collectionName() > collection_name)
|
||||
return indexOfChild(eci);
|
||||
|
||||
return childCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::insertNewItem
|
||||
* When this XmlProjectElementCollectionItem is already created, we must to use this method for insert a new item.
|
||||
|
||||
Reference in New Issue
Block a user