diff --git a/include/resources_tree_model.h b/include/resources_tree_model.h index 6b5d8b4c1..5ecabff33 100644 --- a/include/resources_tree_model.h +++ b/include/resources_tree_model.h @@ -62,6 +62,19 @@ public: void setFilter( const QString & _s ); + // return ResourcesTreeItem belonging to a certain index + static inline ResourcesTreeItem * treeItem( const QModelIndex & _idx ) + { + return static_cast( + _idx.internalPointer() ); + } + + // return ResourcesItem belonging to a certain index + static inline ResourcesItem * item( const QModelIndex & _idx ) + { + return treeItem( _idx )->item(); + } + private: bool filterItems( ResourcesTreeItem * _item, diff --git a/src/core/resources_tree_model.cpp b/src/core/resources_tree_model.cpp index d31fb43bd..0ac1381e5 100644 --- a/src/core/resources_tree_model.cpp +++ b/src/core/resources_tree_model.cpp @@ -42,9 +42,7 @@ QVariant ResourcesTreeModel::data( const QModelIndex & _idx, int _role ) const { if( _idx.isValid() ) { - ResourcesTreeItem * item = - static_cast( - _idx.internalPointer() ); + ResourcesTreeItem * item = treeItem( _idx ); if( _role == Qt::DisplayRole ) { if( item->parent() == m_db->topLevelNode() ) @@ -121,8 +119,7 @@ int ResourcesTreeModel::rowCount( const QModelIndex & _parent ) const } else { - parentItem = static_cast( - _parent.internalPointer() ); + parentItem = treeItem( _parent ); } return parentItem->rowCount(); } @@ -146,8 +143,7 @@ QModelIndex ResourcesTreeModel::index( int _row, int _col, } else { - parentItem = static_cast( - _parent.internalPointer() ); + parentItem = treeItem( _parent ); } if( _row < parentItem->rowCount() ) @@ -167,9 +163,7 @@ QModelIndex ResourcesTreeModel::parent( const QModelIndex & _idx ) const return QModelIndex(); } - ResourcesTreeItem * childItem = - static_cast( - _idx.internalPointer() ); + ResourcesTreeItem * childItem = treeItem( _idx ); ResourcesTreeItem * parentItem = childItem->parent(); if( parentItem == m_db->topLevelNode() ) {