Skip to content

Commit 21a2929

Browse files
committed
[composer] Move code responsible for updating labels from atlas to QgsComposerLabel, fix potential crash when removing atlas coverage layer.
1 parent 5c8cd77 commit 21a2929

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/core/composer/qgsatlascomposition.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,7 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
413413

414414
emit featureChanged( &mCurrentFeature );
415415

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

426418
// update shapes (in case they use data defined symbology with atlas properties)
427419
QList<QgsComposerShape*> shapes;

src/core/composer/qgscomposerlabel.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ QgsComposerLabel::QgsComposerLabel( QgsComposition *composition ):
5353
//otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
5454
setExpressionContext( mComposition->atlasComposition().currentFeature(), mComposition->atlasComposition().coverageLayer() );
5555
}
56+
57+
//connect to atlas toggling on/off and coverage layer and feature changes
58+
//to update the expression context
59+
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( refreshExpressionContext() ) );
60+
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( refreshExpressionContext() ) );
61+
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
62+
5663
}
5764

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

197+
void QgsComposerLabel::refreshExpressionContext()
198+
{
199+
QgsVectorLayer * vl = 0;
200+
QgsFeature* feature = 0;
201+
202+
if ( mComposition->atlasComposition().enabled() )
203+
{
204+
vl = mComposition->atlasComposition().coverageLayer();
205+
feature = mComposition->atlasComposition().currentFeature();
206+
}
207+
208+
setExpressionContext( feature, vl );
209+
}
210+
190211
QString QgsComposerLabel::displayText() const
191212
{
192213
QString displayText = mText;

src/core/composer/qgscomposerlabel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
9999
*/
100100
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
101101

102+
public slots:
103+
void refreshExpressionContext();
104+
105+
102106
private slots:
103107
void loadingHtmlFinished( bool );
104108

0 commit comments

Comments
 (0)