Skip to content

Commit 6375f64

Browse files
committed
[composer] Clean up atlas code, move shape and page updating to shape and page items.
1 parent 5186a68 commit 6375f64

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

src/core/composer/qgsatlascomposition.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include "qgsvectordataprovider.h"
2525
#include "qgsexpression.h"
2626
#include "qgsgeometry.h"
27-
#include "qgscomposerlabel.h"
28-
#include "qgscomposershape.h"
29-
#include "qgspaperitem.h"
3027
#include "qgsmaplayerregistry.h"
3128
#include "qgsproject.h"
3229

@@ -268,13 +265,7 @@ void QgsAtlasComposition::endRender()
268265
return;
269266
}
270267

271-
// reset label expression contexts
272-
QList<QgsComposerLabel*> labels;
273-
mComposition->composerItems( labels );
274-
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
275-
{
276-
( *lit )->setExpressionContext( 0, 0 );
277-
}
268+
emit featureChanged( 0 );
278269

279270
updateAtlasMaps();
280271

@@ -367,25 +358,6 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
367358
evalFeatureFilename();
368359

369360
emit featureChanged( &mCurrentFeature );
370-
371-
// TODO - move these updates to shape/page item
372-
373-
// update shapes (in case they use data defined symbology with atlas properties)
374-
QList<QgsComposerShape*> shapes;
375-
mComposition->composerItems( shapes );
376-
for ( QList<QgsComposerShape*>::iterator lit = shapes.begin(); lit != shapes.end(); ++lit )
377-
{
378-
( *lit )->update();
379-
}
380-
381-
// update page background (in case it uses data defined symbology with atlas properties)
382-
QList<QgsPaperItem*> pages;
383-
mComposition->composerItems( pages );
384-
for ( QList<QgsPaperItem*>::iterator pageIt = pages.begin(); pageIt != pages.end(); ++pageIt )
385-
{
386-
( *pageIt )->update();
387-
}
388-
389361
emit statusMsgChanged( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );
390362

391363
//update composer maps

src/core/composer/qgscomposerlabel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ void QgsComposerLabel::refreshExpressionContext()
205205
if ( mComposition->atlasComposition().enabled() )
206206
{
207207
vl = mComposition->atlasComposition().coverageLayer();
208+
}
209+
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
210+
{
208211
feature = mComposition->atlasComposition().currentFeature();
209212
}
210213

src/core/composer/qgscomposershape.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ QgsComposerShape::QgsComposerShape( QgsComposition* composition ): QgsComposerIt
3030
{
3131
setFrameEnabled( true );
3232
createDefaultShapeStyleSymbol();
33+
34+
if ( mComposition )
35+
{
36+
//connect to atlas toggling on/off and coverage layer and feature changes
37+
//to update symbol style (in case of data-defined symbology)
38+
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
39+
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
40+
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
41+
}
3342
}
3443

3544
QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ):
@@ -43,6 +52,15 @@ QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height,
4352
setSceneRect( QRectF( x, y, width, height ) );
4453
setFrameEnabled( true );
4554
createDefaultShapeStyleSymbol();
55+
56+
if ( mComposition )
57+
{
58+
//connect to atlas toggling on/off and coverage layer and feature changes
59+
//to update symbol style (in case of data-defined symbology)
60+
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
61+
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
62+
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
63+
}
4664
}
4765

4866
QgsComposerShape::~QgsComposerShape()

src/core/composer/qgspaperitem.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,16 @@ void QgsPaperItem::initialize()
254254
//(QGraphicsRectItem considers the pen width when calculating an item's scene rect)
255255
setPen( QPen( QBrush( Qt::NoBrush ), 4 ) );
256256

257-
//create a new QgsPaperGrid for this page, and add it to the composition
258-
mPageGrid = new QgsPaperGrid( pos().x(), pos().y(), rect().width(), rect().height(), mComposition );
259-
mComposition->addItem( mPageGrid );
257+
if ( mComposition )
258+
{
259+
//create a new QgsPaperGrid for this page, and add it to the composition
260+
mPageGrid = new QgsPaperGrid( pos().x(), pos().y(), rect().width(), rect().height(), mComposition );
261+
mComposition->addItem( mPageGrid );
262+
263+
//connect to atlas toggling on/off and coverage layer and feature changes
264+
//to update symbol style (in case of data-defined symbology)
265+
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
266+
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
267+
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
268+
}
260269
}

0 commit comments

Comments
 (0)