From fe044b85927bbf2e83962db8a96398bade63ba6d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 26 Jul 2014 02:05:21 +0200 Subject: [PATCH] Reindex tile item nodes after deleting a node. --- .../src/plugins/tile_editor/tile_item.cpp | 26 +++++++++++++++++++ .../src/plugins/tile_editor/tile_item.h | 6 +++++ 2 files changed, 32 insertions(+) diff --git a/code/studio/src/plugins/tile_editor/tile_item.cpp b/code/studio/src/plugins/tile_editor/tile_item.cpp index 230776fbd..e228a6745 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.cpp +++ b/code/studio/src/plugins/tile_editor/tile_item.cpp @@ -224,7 +224,33 @@ TileModel::TNodeTileType TileTypeNode::getTileType() return m_nodeTileType; } +bool TileTypeNode::removeChildren( int position, int count ) +{ + bool ok = Node::removeChildren( position, count ); + if( !ok ) + return false; + reindex(); + + return true; +} + +void TileTypeNode::reindex() +{ + int i = 0; + + QListIterator< Node* > itr( m_childItems ); + while( itr.hasNext() ) + { + TileItemNode *n = dynamic_cast< TileItemNode* >( itr.next() ); + if( n == NULL ) + continue; + + n->setId( i ); + + i++; + } +} /////////////////////////////////////////////////// diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index 5331ef081..f232acb4b 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -90,7 +90,11 @@ public: int columnCount() const; TileModel::TNodeTileType getTileType(); + + bool removeChildren( int position, int count ); + private: + void reindex(); TileModel::TNodeTileType m_nodeTileType; }; @@ -102,6 +106,8 @@ public: QVariant data(int column, int role) const; int columnCount() const; void setTileFilename(TileModel::TTileChannel channel, QString filename); + void setId( int id ){ m_tileId = id; } + int id() const{ return m_tileId; } private: int m_tileId; QMap m_tileFilename;