1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 17:43:59 +02:00

be safer and don't crash. TWK-333

This commit is contained in:
Leo Franchi
2011-08-08 21:07:23 -04:00
parent 6b62265708
commit d7dd3292ff

View File

@@ -328,7 +328,8 @@ SourcesModel::itemUpdated()
return; return;
QModelIndex idx = indexFromItem( item ); QModelIndex idx = indexFromItem( item );
emit dataChanged( idx, idx ); if( idx.isValid() )
emit dataChanged( idx, idx );
} }
@@ -429,7 +430,11 @@ SourcesModel::indexFromItem( SourceTreeItem* item ) const
QList< int > childIndexList; QList< int > childIndexList;
SourceTreeItem* curItem = item; SourceTreeItem* curItem = item;
while( curItem != m_rootItem ) { while( curItem != m_rootItem ) {
childIndexList << rowForItem( curItem ); int row = rowForItem( curItem );
if( row < 0 ) // something went wrong, bail
return QModelIndex();
childIndexList << row;
curItem = curItem->parent(); curItem = curItem->parent();
} }
@@ -448,6 +453,9 @@ SourcesModel::indexFromItem( SourceTreeItem* item ) const
int int
SourcesModel::rowForItem( SourceTreeItem* item ) const SourcesModel::rowForItem( SourceTreeItem* item ) const
{ {
if( !item || !item->parent() || !item->parent()->children().contains( item ) )
return -1;
return item->parent()->children().indexOf( item ); return item->parent()->children().indexOf( item );
} }