[composer] Clean up atlas code, move shape and page updating to shape and page items.

This commit is contained in:
Nyall Dawson 2014-05-18 22:57:48 +10:00
parent 5186a68350
commit 6375f64de8
4 changed files with 34 additions and 32 deletions

View File

@ -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

View File

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

View File

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

View File

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