Skip to content
Permalink
Browse files
[composer] Better method of hiding atlas coverage layer (fix #9506)
  • Loading branch information
nyalldawson committed Feb 14, 2014
1 parent 7e34bd9 commit 24b0a6468937d195e87f1f2528c4d0f3f328eaf7
@@ -270,19 +270,6 @@ bool QgsAtlasComposition::beginRender()
return false;
}

mRestoreLayer = false;
QStringList& layerSet = mComposition->mapRenderer()->layerSet();
if ( mHideCoverage )
{
// look for the layer in the renderer's set
int removeAt = layerSet.indexOf( mCoverageLayer->id() );
if ( removeAt != -1 )
{
mRestoreLayer = true;
layerSet.removeAt( removeAt );
}
}

// special columns for expressions
QgsExpression::setSpecialColumn( "$numpages", QVariant( mComposition->numPages() ) );
QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
@@ -305,14 +292,6 @@ void QgsAtlasComposition::endRender()
( *lit )->setExpressionContext( 0, 0 );
}

// restore the coverage visibility
if ( mRestoreLayer )
{
QStringList& layerSet = mComposition->mapRenderer()->layerSet();

layerSet.push_back( mCoverageLayer->id() );
}

updateAtlasMaps();
}

@@ -669,25 +648,6 @@ void QgsAtlasComposition::setHideCoverage( bool hide )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//an atlas preview is enabled, so reflect changes in coverage layer visibility immediately
QStringList& layerSet = mComposition->mapRenderer()->layerSet();
if ( hide )
{
// look for the layer in the renderer's set
int removeAt = layerSet.indexOf( mCoverageLayer->id() );
if ( removeAt != -1 )
{
mRestoreLayer = true;
layerSet.removeAt( removeAt );
}
}
else
{
if ( mRestoreLayer )
{
layerSet.push_back( mCoverageLayer->id() );
mRestoreLayer = false;
}
}
updateAtlasMaps();
mComposition->update();
}
@@ -193,7 +193,7 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
QVector<QgsFeatureId> mFeatureIds;

QgsFeature mCurrentFeature;
bool mRestoreLayer;

std::auto_ptr<QgsExpression> mFilenameExpr;

// bounding box of the current feature transformed into map crs
@@ -184,15 +184,9 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
if ( mMapRenderer->labelingEngine() )
theMapRenderer.setLabelingEngine( mMapRenderer->labelingEngine()->clone() );

//use stored layer set or read current set from main canvas
if ( mKeepLayerSet )
{
theMapRenderer.setLayerSet( mLayerSet );
}
else
{
theMapRenderer.setLayerSet( mMapRenderer->layerSet() );
}
//set layers to render
theMapRenderer.setLayerSet( layersToRender() );

theMapRenderer.setDestinationCrs( mMapRenderer->destinationCrs() );
theMapRenderer.setProjectionsEnabled( mMapRenderer->hasCrsTransformEnabled() );

@@ -470,6 +464,37 @@ void QgsComposerMap::setCacheUpdated( bool u )
mCacheUpdated = u;
}

QStringList QgsComposerMap::layersToRender()
{
//use stored layer set or read current set from main canvas
QStringList renderLayerSet;
if ( mKeepLayerSet )
{
renderLayerSet = mLayerSet;
}
else
{
renderLayerSet = mMapRenderer->layerSet();
}

//remove atlas coverage layer if required
//TODO - move setting for hiding coverage layer to map item properties
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
{
if ( mComposition->atlasComposition().hideCoverage() )
{
//hiding coverage layer
int removeAt = renderLayerSet.indexOf( mComposition->atlasComposition().coverageLayer()->id() );
if ( removeAt != -1 )
{
renderLayerSet.removeAt( removeAt );
}
}
}

return renderLayerSet;
}

double QgsComposerMap::scale() const
{
QgsScaleCalculator calculator;
@@ -596,6 +596,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**Margin size for atlas driven extents (percentage of feature size)*/
double mAtlasMargin;

/**Returns a list of the layers to render for this map item*/
QStringList layersToRender();

/**Draws the map grid*/
void drawGrid( QPainter* p );
void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );

0 comments on commit 24b0a64

Please sign in to comment.