Skip to content
Permalink
Browse files

Don't crash when project has no layers

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 31c79da5232307b7c0cb817726f79f12d133e034
Showing with 12 additions and 9 deletions.
  1. +12 −9 src/core/qgsmaplayermodel.cpp
@@ -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

0 comments on commit 31c79da

Please sign in to comment.
You can’t perform that action at this time.