Skip to content
Permalink
Browse files

Fix crash in vector layer properties when changing renderer type (fixes

  • Loading branch information
wonder-sk committed Jan 25, 2016
1 parent 73bef58 commit 82eabb197623236ab0f8844f537473fd7bcc9b98
@@ -1016,33 +1016,39 @@ void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( const QString& key,

QgsCategorizedSymbolRendererV2* QgsCategorizedSymbolRendererV2::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
QgsCategorizedSymbolRendererV2* r = nullptr;
if ( renderer->type() == "categorizedSymbol" )
{
return dynamic_cast<QgsCategorizedSymbolRendererV2*>( renderer->clone() );
r = dynamic_cast<QgsCategorizedSymbolRendererV2*>( renderer->clone() );
}
if ( renderer->type() == "pointDisplacement" )
else if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
r = convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
else if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
r = convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

// If not one of the specifically handled renderers, then just grab the symbol from the renderer
// Could have applied this to specific renderer types (singleSymbol, graduatedSymbo)

QgsCategorizedSymbolRendererV2* r = new QgsCategorizedSymbolRendererV2( "", QgsCategoryList() );
QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
if ( !r )
{
r->setSourceSymbol( symbols.at( 0 )->clone() );
r = new QgsCategorizedSymbolRendererV2( "", QgsCategoryList() );
QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
{
r->setSourceSymbol( symbols.at( 0 )->clone() );
}
}

r->setOrderBy( renderer->orderBy() );

return r;
}
@@ -1712,34 +1712,40 @@ void QgsGraduatedSymbolRendererV2::sortByLabel( Qt::SortOrder order )

QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
QgsGraduatedSymbolRendererV2* r = nullptr;
if ( renderer->type() == "graduatedSymbol" )
{
return dynamic_cast<QgsGraduatedSymbolRendererV2*>( renderer->clone() );
r = dynamic_cast<QgsGraduatedSymbolRendererV2*>( renderer->clone() );
}
if ( renderer->type() == "pointDisplacement" )
else if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
r = convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
else if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
r = convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

// If not one of the specifically handled renderers, then just grab the symbol from the renderer
// Could have applied this to specific renderer types (singleSymbol, graduatedSymbo)

QgsGraduatedSymbolRendererV2* r = new QgsGraduatedSymbolRendererV2( "", QgsRangeList() );
QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
if ( !r )
{
r->setSourceSymbol( symbols.at( 0 )->clone() );
r = new QgsGraduatedSymbolRendererV2( "", QgsRangeList() );
QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
{
r->setSourceSymbol( symbols.at( 0 )->clone() );
}
}

r->setOrderBy( renderer->orderBy() );

return r;
}

@@ -450,28 +450,38 @@ QSet< QString > QgsSingleSymbolRendererV2::legendKeysForFeature( QgsFeature& fea

QgsSingleSymbolRendererV2* QgsSingleSymbolRendererV2::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
QgsSingleSymbolRendererV2* r = nullptr;
if ( renderer->type() == "singleSymbol" )
{
return dynamic_cast<QgsSingleSymbolRendererV2*>( renderer->clone() );
r = dynamic_cast<QgsSingleSymbolRendererV2*>( renderer->clone() );
}
if ( renderer->type() == "pointDisplacement" )
else if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
if ( pointDisplacementRenderer )
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
r = convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
else if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
if ( invertedPolygonRenderer )
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
r = convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}

QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
if ( !r )
{
return new QgsSingleSymbolRendererV2( symbols.at( 0 )->clone() );
QgsRenderContext context;
QgsSymbolV2List symbols = const_cast<QgsFeatureRendererV2 *>( renderer )->symbols( context );
if ( !symbols.isEmpty() )
{
r = new QgsSingleSymbolRendererV2( symbols.at( 0 )->clone() );
}
}
return nullptr;

if ( r )
{
r->setOrderBy( renderer->orderBy() );
}

return r;
}
@@ -419,7 +419,6 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
if ( renderer )
{
mRenderer = QgsCategorizedSymbolRendererV2::convertFromRenderer( renderer );
mRenderer->setOrderBy( renderer->orderBy() );
}
if ( !mRenderer )
{
@@ -425,7 +425,6 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
if ( renderer )
{
mRenderer = QgsGraduatedSymbolRendererV2::convertFromRenderer( renderer );
mRenderer->setOrderBy( renderer->orderBy() );
}
if ( !mRenderer )
{
@@ -39,7 +39,6 @@ QgsSingleSymbolRendererV2Widget::QgsSingleSymbolRendererV2Widget( QgsVectorLayer
if ( renderer )
{
mRenderer = QgsSingleSymbolRendererV2::convertFromRenderer( renderer );
mRenderer->setOrderBy( renderer->orderBy() );
}
if ( !mRenderer )
{

0 comments on commit 82eabb1

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