Skip to content

Commit

Permalink
[composer] Move code responsible for updating labels from atlas to Qg…
Browse files Browse the repository at this point in the history
…sComposerLabel, fix potential crash when removing atlas coverage layer.
  • Loading branch information
nyalldawson committed Apr 28, 2014
1 parent 5c8cd77 commit 21a2929
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/core/composer/qgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/core/composer/qgscomposerlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down

0 comments on commit 21a2929

Please sign in to comment.