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
  • Loading branch information
nyalldawson committed Jan 14, 2019
1 parent d5cedfe commit 4b154a4
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/core/symbology/qgsstylemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,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 @@ -144,14 +147,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 4b154a4

Please sign in to comment.