Skip to content
Permalink
Browse files

[composer] Move code responsible for updating labels from atlas to Qg…

…sComposerLabel, fix potential crash when removing atlas coverage layer.
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent 5c8cd77 commit 21a2929df7f11902e29113cdf07ca374ea80a311
@@ -413,15 +413,7 @@ void QgsAtlasComposition::prepareForFeature( int featureI )

emit featureChanged( &mCurrentFeature );

// TODO - move these updates to label/shape/page item

// evaluate label expressions
QList<QgsComposerLabel*> labels;
mComposition->composerItems( labels );
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
{
( *lit )->setExpressionContext( &mCurrentFeature, mCoverageLayer );
}
// TODO - move these updates to shape/page item

// update shapes (in case they use data defined symbology with atlas properties)
QList<QgsComposerShape*> shapes;
@@ -53,6 +53,13 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
//otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
setExpressionContext( mComposition->atlasComposition().currentFeature(), mComposition->atlasComposition().coverageLayer() );
}

//connect to atlas toggling on/off and coverage layer and feature changes
//to update the expression context
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( refreshExpressionContext() ) );
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( refreshExpressionContext() ) );
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );

}

QgsComposerLabel::~QgsComposerLabel()
@@ -187,6 +194,20 @@ void QgsComposerLabel::setExpressionContext( QgsFeature* feature, QgsVectorLayer
update();
}

void QgsComposerLabel::refreshExpressionContext()
{
QgsVectorLayer * vl = 0;
QgsFeature* feature = 0;

if ( mComposition->atlasComposition().enabled() )
{
vl = mComposition->atlasComposition().coverageLayer();
feature = mComposition->atlasComposition().currentFeature();
}

setExpressionContext( feature, vl );
}

QString QgsComposerLabel::displayText() const
{
QString displayText = mText;
@@ -99,6 +99,10 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
*/
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

public slots:
void refreshExpressionContext();


private slots:
void loadingHtmlFinished( bool );

0 comments on commit 21a2929

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