Skip to content

Commit

Permalink
Fix potential crash when removing entities from a style
Browse files Browse the repository at this point in the history
(cherry picked from commit 4b154a4)
  • Loading branch information
nyalldawson committed Jan 15, 2019
1 parent 5c24b4e commit 59485f3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/core/symbology/qgsstylemodel.cpp
Expand Up @@ -117,15 +117,18 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
return icon;

std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
if ( mAdditionalSizes.isEmpty() )
icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( 24, 24 ), 1 ) );

for ( const QVariant &size : mAdditionalSizes )
if ( symbol )
{
QSize s = size.toSize();
icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
}
if ( mAdditionalSizes.isEmpty() )
icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( 24, 24 ), 1 ) );

for ( const QVariant &size : mAdditionalSizes )
{
QSize s = size.toSize();
icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
}

}
mSymbolIconCache.insert( name, icon );
return icon;
}
Expand All @@ -137,14 +140,17 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
return icon;

std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
if ( mAdditionalSizes.isEmpty() )
icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), QSize( 24, 24 ), 1 ) );
for ( const QVariant &size : mAdditionalSizes )
if ( ramp )
{
QSize s = size.toSize();
icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
}
if ( mAdditionalSizes.isEmpty() )
icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), QSize( 24, 24 ), 1 ) );
for ( const QVariant &size : mAdditionalSizes )
{
QSize s = size.toSize();
icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
}

}
mColorRampIconCache.insert( name, icon );
return icon;
}
Expand Down

0 comments on commit 59485f3

Please sign in to comment.