Skip to content
Permalink
Browse files

[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 0c6d9ef90c614f456e07aff5497f08e001dae933
@@ -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 )
{
@@ -24,6 +24,7 @@
#include "qgsexpression.h"
#include "qgsgeometry.h"
#include "qgscomposerlabel.h"
#include "qgspaperitem.h"
#include "qgsmaplayerregistry.h"

QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
@@ -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 );

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

0 comments on commit 0c6d9ef

Please sign in to comment.
You can’t perform that action at this time.