Skip to content
Permalink
Browse files
[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 6375f64de824e8a7896f7e7dfd9950adb131ff79
Showing with 34 additions and 32 deletions.
  1. +1 −29 src/core/composer/qgsatlascomposition.cpp
  2. +3 −0 src/core/composer/qgscomposerlabel.cpp
  3. +18 −0 src/core/composer/qgscomposershape.cpp
  4. +12 −3 src/core/composer/qgspaperitem.cpp
@@ -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"

@@ -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();

@@ -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
@@ -205,6 +205,9 @@ void QgsComposerLabel::refreshExpressionContext()
if ( mComposition->atlasComposition().enabled() )
{
vl = mComposition->atlasComposition().coverageLayer();
}
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
{
feature = mComposition->atlasComposition().currentFeature();
}

@@ -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 ):
@@ -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()
@@ -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.