Skip to content

Commit

Permalink
vector layer: don't crash on missing labels in invalid layers la(fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 8, 2014
1 parent 915f5c1 commit 4c87b0c
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )

QgsDebugMsg( "Starting draw of labels: " + id() );

if ( mRendererV2 && mLabelOn &&
if ( mRendererV2 && mLabelOn && mLabel &&
( !mLabel->scaleBasedVisibility() ||
( mLabel->minScale() <= rendererContext.rendererScale() &&
rendererContext.rendererScale() <= mLabel->maxScale() ) ) )
Expand Down Expand Up @@ -1878,9 +1878,12 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage

// use scale dependent visibility flag
QDomElement e = node.toElement();
mLabel->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0" ) == "1" );
mLabel->setMinScale( e.attribute( "minLabelScale", "1" ).toFloat() );
mLabel->setMaxScale( e.attribute( "maxLabelScale", "100000000" ).toFloat() );
if ( mLabel )
{
mLabel->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0" ) == "1" );
mLabel->setMinScale( e.attribute( "minLabelScale", "1" ).toFloat() );
mLabel->setMaxScale( e.attribute( "maxLabelScale", "100000000" ).toFloat() );
}

// get the simplification drawing settings
mSimplifyMethod.setSimplifyHints( e.attribute( "simplifyDrawingHints", "1" ).toInt() );
Expand All @@ -1906,7 +1909,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage

QDomNode labelattributesnode = node.namedItem( "labelattributes" );

if ( !labelattributesnode.isNull() )
if ( !labelattributesnode.isNull() && mLabel )
{
QgsDebugMsg( "calling readXML" );
mLabel->readXML( labelattributesnode );
Expand Down Expand Up @@ -2217,9 +2220,12 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
node.appendChild( rendererElement );

// use scale dependent visibility flag
mapLayerNode.setAttribute( "scaleBasedLabelVisibilityFlag", mLabel->scaleBasedVisibility() ? 1 : 0 );
mapLayerNode.setAttribute( "minLabelScale", QString::number( mLabel->minScale() ) );
mapLayerNode.setAttribute( "maxLabelScale", QString::number( mLabel->maxScale() ) );
if ( mLabel )
{
mapLayerNode.setAttribute( "scaleBasedLabelVisibilityFlag", mLabel->scaleBasedVisibility() ? 1 : 0 );
mapLayerNode.setAttribute( "minLabelScale", QString::number( mLabel->minScale() ) );
mapLayerNode.setAttribute( "maxLabelScale", QString::number( mLabel->maxScale() ) );
}

// save the simplification drawing settings
mapLayerNode.setAttribute( "simplifyDrawingHints", QString::number( mSimplifyMethod.simplifyHints() ) );
Expand Down Expand Up @@ -2272,16 +2278,19 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&

// Now we get to do all that all over again for QgsLabel

QString fieldname = mLabel->labelField( QgsLabel::Text );
if ( fieldname != "" )
if ( mLabel )
{
dField = doc.createElement( "labelfield" );
dFieldText = doc.createTextNode( fieldname );
dField.appendChild( dFieldText );
node.appendChild( dField );
}
QString fieldname = mLabel->labelField( QgsLabel::Text );
if ( fieldname != "" )
{
dField = doc.createElement( "labelfield" );
dFieldText = doc.createTextNode( fieldname );
dField.appendChild( dFieldText );
node.appendChild( dField );
}

mLabel->writeXML( node, doc );
mLabel->writeXML( node, doc );
}

if ( mDiagramRenderer )
{
Expand Down

0 comments on commit 4c87b0c

Please sign in to comment.