mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
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.
This commit is contained in:
parent
19b062c304
commit
31c79da523
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user