mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-22 00:48:44 +00:00
When repareting a widget, remove the old item from the hierarchy and add a new one at the right place.
This commit is contained in:
parent
c0c5315e57
commit
9f0d4c00ea
2 changed files with 50 additions and 0 deletions
|
@ -182,6 +182,27 @@ namespace GUIEditor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* WidgetHierarchy::findItem( const std::string &id )
|
||||||
|
{
|
||||||
|
std::map< std::string, QTreeWidgetItem* >::iterator itr
|
||||||
|
= widgetHierarchyMap.find( id );
|
||||||
|
if( itr == widgetHierarchyMap.end() )
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return itr->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* WidgetHierarchy::findParent( const std::string &id )
|
||||||
|
{
|
||||||
|
// Get the parent's name
|
||||||
|
std::string::size_type p = id.find_last_of( ':' );
|
||||||
|
if( p == std::string::npos )
|
||||||
|
return NULL;
|
||||||
|
std::string parentId = id.substr( 0, p );
|
||||||
|
|
||||||
|
return findItem( parentId );
|
||||||
|
}
|
||||||
|
|
||||||
void WidgetHierarchy::onWidgetDeleted( const std::string &id )
|
void WidgetHierarchy::onWidgetDeleted( const std::string &id )
|
||||||
{
|
{
|
||||||
std::map< std::string, QTreeWidgetItem* >::iterator itr
|
std::map< std::string, QTreeWidgetItem* >::iterator itr
|
||||||
|
@ -238,6 +259,33 @@ namespace GUIEditor
|
||||||
|
|
||||||
void WidgetHierarchy::onWidgetMoved( const std::string &oldid, const std::string &newid )
|
void WidgetHierarchy::onWidgetMoved( const std::string &oldid, const std::string &newid )
|
||||||
{
|
{
|
||||||
|
QTreeWidgetItem *newParent = NULL;
|
||||||
|
QTreeWidgetItem *item = NULL;
|
||||||
|
QString id;
|
||||||
|
|
||||||
|
newParent = findParent( newid );
|
||||||
|
item = findItem( oldid );
|
||||||
|
|
||||||
|
if( ( newParent == NULL ) || ( item == NULL ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Remove old item
|
||||||
|
QTreeWidgetItem *p = item->parent();
|
||||||
|
if( p != NULL )
|
||||||
|
p->setExpanded( false );
|
||||||
|
id = item->data( 0, Qt::DisplayRole ).toString();
|
||||||
|
delete item;
|
||||||
|
item = NULL;
|
||||||
|
|
||||||
|
// Remove reference to old item
|
||||||
|
widgetHierarchyMap.erase( oldid );
|
||||||
|
|
||||||
|
// Add new item
|
||||||
|
item = new QTreeWidgetItem();
|
||||||
|
item->setData( 0, Qt::DisplayRole, id );
|
||||||
|
item->setSelected( true );
|
||||||
|
newParent->addChild( item );
|
||||||
|
newParent->setExpanded( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetHierarchy::getCurrentGroup( QString &g )
|
void WidgetHierarchy::getCurrentGroup( QString &g )
|
||||||
|
|
|
@ -50,6 +50,8 @@ namespace GUIEditor
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
|
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
|
||||||
|
QTreeWidgetItem* findItem( const std::string &id );
|
||||||
|
QTreeWidgetItem* findParent( const std::string &id );
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onGUILoaded();
|
void onGUILoaded();
|
||||||
|
|
Loading…
Reference in a new issue