Skip to content

Commit

Permalink
Don't rely on internal points in QgsMapLayerModel
Browse files Browse the repository at this point in the history
Breaks reorder functionality for subclasses
  • Loading branch information
nyalldawson committed Jun 9, 2020
1 parent 154a499 commit 1158b49
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/qgsmaplayermodel.cpp
Expand Up @@ -115,7 +115,7 @@ QModelIndex QgsMapLayerModel::indexFromLayer( QgsMapLayer *layer ) const

QgsMapLayer *QgsMapLayerModel::layerFromIndex( const QModelIndex &index ) const
{
return static_cast<QgsMapLayer *>( index.internalPointer() );
return mProject->mapLayer( index.data( LayerIdRole ).toString() );
}

void QgsMapLayerModel::setAdditionalItems( const QStringList &items )
Expand Down Expand Up @@ -243,7 +243,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( additionalIndex >= 0 )
return mAdditionalItems.at( additionalIndex );

QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
if ( !layer )
return QVariant();

Expand All @@ -262,7 +262,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( isEmpty || additionalIndex >= 0 )
return QVariant();

QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
return layer ? layer->id() : QVariant();
}

Expand All @@ -271,7 +271,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( isEmpty || additionalIndex >= 0 )
return QVariant();

return QVariant::fromValue<QgsMapLayer *>( static_cast<QgsMapLayer *>( index.internalPointer() ) );
return QVariant::fromValue<QgsMapLayer *>( mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) ) );
}

case EmptyRole:
Expand All @@ -287,7 +287,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( isEmpty || additionalIndex >= 0 )
return QVariant();

QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
return layer ? mLayersChecked[layer->id()] : QVariant();
}

Expand All @@ -296,7 +296,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const

case Qt::ToolTipRole:
{
QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
if ( layer )
{
QStringList parts;
Expand Down Expand Up @@ -326,7 +326,7 @@ QVariant QgsMapLayerModel::data( const QModelIndex &index, int role ) const
if ( isEmpty || additionalIndex >= 0 )
return QVariant();

QgsMapLayer *layer = static_cast<QgsMapLayer *>( index.internalPointer() );
QgsMapLayer *layer = mLayers.value( index.row() - ( mAllowEmpty ? 1 : 0 ) );
if ( !layer )
return QVariant();

Expand Down

0 comments on commit 1158b49

Please sign in to comment.