Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Allow data defined symbol expressions using atlas feature …
…properties for page background
  • Loading branch information
nyalldawson committed Jan 12, 2014
1 parent 224e340 commit 0c6d9ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -386,7 +386,13 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
return;
}

QgsSymbolV2SelectorDialog d( mComposition->pageStyleSymbol(), QgsStyleV2::defaultStyle(), 0 );
QgsVectorLayer* coverageLayer = 0;
// use the atlas coverage layer, if any
if ( mComposition->atlasComposition().enabled() )
{
coverageLayer = mComposition->atlasComposition().coverageLayer();
}
QgsSymbolV2SelectorDialog d( mComposition->pageStyleSymbol(), QgsStyleV2::defaultStyle(), coverageLayer );

if ( d.exec() == QDialog::Accepted )
{
Expand Down
10 changes: 9 additions & 1 deletion src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -24,6 +24,7 @@
#include "qgsexpression.h"
#include "qgsgeometry.h"
#include "qgscomposerlabel.h"
#include "qgspaperitem.h"
#include "qgsmaplayerregistry.h"

QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
Expand Down Expand Up @@ -369,12 +370,19 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
// evaluate label expressions
QList<QgsComposerLabel*> labels;
mComposition->composerItems( labels );

for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
{
( *lit )->setExpressionContext( &mCurrentFeature, mCoverageLayer );
}

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

// set the new extent (and render)
mComposerMap->setNewAtlasFeatureExtent( new_extent );

Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgsatlascomposition.h
Expand Up @@ -110,6 +110,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
void lastFeature();
void firstFeature();

/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature() { return &mCurrentFeature; }

signals:
/** emitted when one of the parameters changes */
void parameterChanged();
Expand Down
15 changes: 13 additions & 2 deletions src/core/composer/qgspaperitem.cpp
Expand Up @@ -190,10 +190,21 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
calculatePageMargin();
QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) );
QList<QPolygonF> rings; //empty list
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );

//need to render using atlas feature properties?
if ( mComposition->atlasComposition().enabled() && mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//using an atlas, so render using current atlas feature
//since there may be data defined symbols using atlas feature properties
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, mComposition->atlasComposition().currentFeature(), context );
}
else
{
mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );
}

mComposition->pageStyleSymbol()->stopRender( context );
painter->restore();

}

void QgsPaperItem::calculatePageMargin()
Expand Down

0 comments on commit 0c6d9ef

Please sign in to comment.