Skip to content

Commit

Permalink
Don't crash when project has no layers
Browse files Browse the repository at this point in the history
This only crashes when Qt is built in
debug mode because there is an assert
in the item model class that checks for
index range validity.
  • Loading branch information
elpaso committed Dec 1, 2017
1 parent 19b062c commit 31c79da
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/core/qgsmaplayermodel.cpp
Expand Up @@ -154,17 +154,20 @@ void QgsMapLayerModel::removeLayers( const QStringList &layerIds )

void QgsMapLayerModel::addLayers( const QList<QgsMapLayer *> &layers )
{
int offset = 0;
if ( mAllowEmpty )
offset++;

beginInsertRows( QModelIndex(), mLayers.count() + offset, mLayers.count() + layers.count() - 1 + offset );
Q_FOREACH ( QgsMapLayer *layer, layers )
if ( layers.count( ) )
{
mLayers.append( layer );
mLayersChecked.insert( layer->id(), Qt::Unchecked );
int offset = 0;
if ( mAllowEmpty )
offset++;

beginInsertRows( QModelIndex(), mLayers.count() + offset, mLayers.count() + layers.count() - 1 + offset );
Q_FOREACH ( QgsMapLayer *layer, layers )
{
mLayers.append( layer );
mLayersChecked.insert( layer->id(), Qt::Unchecked );
}
endInsertRows();
}
endInsertRows();
}

QModelIndex QgsMapLayerModel::index( int row, int column, const QModelIndex &parent ) const
Expand Down

0 comments on commit 31c79da

Please sign in to comment.