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:
dfighter1985 2014-09-24 23:56:11 +02:00
parent c0c5315e57
commit 9f0d4c00ea
2 changed files with 50 additions and 0 deletions

View file

@ -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 )

View file

@ -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();