Skip to content

Commit

Permalink
[composer] Better method of hiding atlas coverage layer (fix #9506)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 14, 2014
1 parent 7e34bd9 commit 24b0a64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
40 changes: 0 additions & 40 deletions src/core/composer/qgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgsatlascomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 34 additions & 9 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 24b0a64

Please sign in to comment.