Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Clean up atlas code, move shape and page updating to shape…
… and page items.
  • Loading branch information
nyalldawson committed May 24, 2014
1 parent 5186a68 commit 6375f64
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
30 changes: 1 addition & 29 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -24,9 +24,6 @@
#include "qgsvectordataprovider.h"
#include "qgsexpression.h"
#include "qgsgeometry.h"
#include "qgscomposerlabel.h"
#include "qgscomposershape.h"
#include "qgspaperitem.h"
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"

Expand Down Expand Up @@ -268,13 +265,7 @@ void QgsAtlasComposition::endRender()
return;
}

// reset label expression contexts
QList<QgsComposerLabel*> labels;
mComposition->composerItems( labels );
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
{
( *lit )->setExpressionContext( 0, 0 );
}
emit featureChanged( 0 );

updateAtlasMaps();

Expand Down Expand Up @@ -367,25 +358,6 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
evalFeatureFilename();

emit featureChanged( &mCurrentFeature );

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

// update shapes (in case they use data defined symbology with atlas properties)
QList<QgsComposerShape*> shapes;
mComposition->composerItems( shapes );
for ( QList<QgsComposerShape*>::iterator lit = shapes.begin(); lit != shapes.end(); ++lit )
{
( *lit )->update();
}

// update page background (in case it uses data defined symbology with atlas properties)
QList<QgsPaperItem*> pages;
mComposition->composerItems( pages );
for ( QList<QgsPaperItem*>::iterator pageIt = pages.begin(); pageIt != pages.end(); ++pageIt )
{
( *pageIt )->update();
}

emit statusMsgChanged( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );

//update composer maps
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -205,6 +205,9 @@ void QgsComposerLabel::refreshExpressionContext()
if ( mComposition->atlasComposition().enabled() )
{
vl = mComposition->atlasComposition().coverageLayer();
}
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
{
feature = mComposition->atlasComposition().currentFeature();
}

Expand Down
18 changes: 18 additions & 0 deletions src/core/composer/qgscomposershape.cpp
Expand Up @@ -30,6 +30,15 @@ QgsComposerShape::QgsComposerShape( QgsComposition* composition ): QgsComposerIt
{
setFrameEnabled( true );
createDefaultShapeStyleSymbol();

if ( mComposition )
{
//connect to atlas toggling on/off and coverage layer and feature changes
//to update symbol style (in case of data-defined symbology)
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
}
}

QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition ):
Expand All @@ -43,6 +52,15 @@ QgsComposerShape::QgsComposerShape( qreal x, qreal y, qreal width, qreal height,
setSceneRect( QRectF( x, y, width, height ) );
setFrameEnabled( true );
createDefaultShapeStyleSymbol();

if ( mComposition )
{
//connect to atlas toggling on/off and coverage layer and feature changes
//to update symbol style (in case of data-defined symbology)
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
}
}

QgsComposerShape::~QgsComposerShape()
Expand Down
15 changes: 12 additions & 3 deletions src/core/composer/qgspaperitem.cpp
Expand Up @@ -254,7 +254,16 @@ void QgsPaperItem::initialize()
//(QGraphicsRectItem considers the pen width when calculating an item's scene rect)
setPen( QPen( QBrush( Qt::NoBrush ), 4 ) );

//create a new QgsPaperGrid for this page, and add it to the composition
mPageGrid = new QgsPaperGrid( pos().x(), pos().y(), rect().width(), rect().height(), mComposition );
mComposition->addItem( mPageGrid );
if ( mComposition )
{
//create a new QgsPaperGrid for this page, and add it to the composition
mPageGrid = new QgsPaperGrid( pos().x(), pos().y(), rect().width(), rect().height(), mComposition );
mComposition->addItem( mPageGrid );

//connect to atlas toggling on/off and coverage layer and feature changes
//to update symbol style (in case of data-defined symbology)
connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( repaint() ) );
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( repaint() ) );
}
}

0 comments on commit 6375f64

Please sign in to comment.