Skip to content

Commit

Permalink
If vector layer renderer cannot be loaded, fallback to default
Browse files Browse the repository at this point in the history
Eg if loading a project which used a plugin based renderer which
is not available, qgis would not renderer the layer and
eventually crash. Now if the saved renderer could not be
restored we fallback to a default renderer for the layer.
  • Loading branch information
nyalldawson committed Sep 4, 2016
1 parent 95c4fa1 commit 96e10eb
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage

bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage )
{
bool result = true;
emit readCustomSymbology( node.toElement(), errorMessage );

if ( hasGeometryType() )
Expand All @@ -1795,18 +1796,28 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage )
if ( !rendererElement.isNull() )
{
QgsFeatureRenderer* r = QgsFeatureRenderer::load( rendererElement );
if ( !r )
return false;

setRenderer( r );
if ( r )
{
setRenderer( r );
}
else
{
result = false;
}
}
else
{
QgsFeatureRenderer* r = QgsSymbologyConversion::readOldRenderer( node, geometryType() );
if ( !r )
r = QgsFeatureRenderer::defaultRenderer( geometryType() );
if ( r )
{
setRenderer( r );
}
}

setRenderer( r );
// make sure layer has a renderer - if none exists, fallback to a default renderer
if ( !renderer() )
{
setRenderer( QgsFeatureRenderer::defaultRenderer( geometryType() ) );
}

QDomElement labelingElement = node.firstChildElement( "labeling" );
Expand Down Expand Up @@ -1879,7 +1890,7 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage )
}
}
}
return true;
return result;
}

bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const
Expand Down

0 comments on commit 96e10eb

Please sign in to comment.