Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some map item todos
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 49eaebb commit 7c086be
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
1 change: 1 addition & 0 deletions python/core/layout/qgslayoutcontext.sip
Expand Up @@ -28,6 +28,7 @@ class QgsLayoutContext : QObject
FlagAntialiasing,
FlagUseAdvancedEffects,
FlagForceVectorOutput,
FlagHideCoverageLayer,
};
typedef QFlags<QgsLayoutContext::Flag> Flags;

Expand Down
16 changes: 4 additions & 12 deletions src/core/layout/qgslayoutatlas.cpp
Expand Up @@ -384,14 +384,8 @@ void QgsLayoutAtlas::setHideCoverage( bool hide )
{
mHideCoverage = hide;

#if 0 //TODO
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//an atlas preview is enabled, so reflect changes in coverage layer visibility immediately
updateAtlasMaps();
mComposition->update();
}
#endif
mLayout->context().setFlag( QgsLayoutContext::FlagHideCoverageLayer, hide );
mLayout->refresh();
}

bool QgsLayoutAtlas::setFilenameExpression( const QString &pattern, QString &errorString )
Expand All @@ -410,12 +404,10 @@ QgsExpressionContext QgsLayoutAtlas::createExpressionContext()
QgsExpressionContext expressionContext;
expressionContext << QgsExpressionContextUtils::globalScope();
if ( mLayout )
expressionContext << QgsExpressionContextUtils::projectScope( mLayout->project() );
#if 0 //TODO
<< QgsExpressionContextUtils::compositionScope( mLayout );
expressionContext << QgsExpressionContextUtils::projectScope( mLayout->project() )
<< QgsExpressionContextUtils::layoutScope( mLayout );

expressionContext.appendScope( QgsExpressionContextUtils::atlasScope( this ) );
#endif

if ( mCoverageLayer )
expressionContext.lastScope()->setFields( mCoverageLayer->fields() );
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutcontext.h
Expand Up @@ -46,6 +46,7 @@ class CORE_EXPORT QgsLayoutContext : public QObject
FlagAntialiasing = 1 << 3, //!< Use antialiasing when drawing items.
FlagUseAdvancedEffects = 1 << 4, //!< Enable advanced effects such as blend modes.
FlagForceVectorOutput = 1 << 5, //!< Force output in vector format where possible, even if items require rasterization to keep their correct appearance.
FlagHideCoverageLayer = 1 << 6, //!< Hide coverage layer in outputs
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down
17 changes: 6 additions & 11 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1400,22 +1400,17 @@ QList<QgsMapLayer *> QgsLayoutItemMap::layersToRender( const QgsExpressionContex
}
}

#if 0 //TODO
//remove atlas coverage layer if required
//TODO - move setting for hiding coverage layer to map item properties
if ( mLayout->atlasMode() != QgsComposition::AtlasOff )
if ( mLayout->context().flags() & QgsLayoutContext::FlagHideCoverageLayer )
{
if ( mComposition->atlasComposition().hideCoverage() )
//hiding coverage layer
int removeAt = renderLayers.indexOf( mLayout->context().layer() );
if ( removeAt != -1 )
{
//hiding coverage layer
int removeAt = renderLayers.indexOf( mComposition->atlasComposition().coverageLayer() );
if ( removeAt != -1 )
{
renderLayers.removeAt( removeAt );
}
renderLayers.removeAt( removeAt );
}
}
#endif

return renderLayers;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/src/core/testqgslayoutmap.cpp
Expand Up @@ -55,6 +55,7 @@ class TestQgsLayoutMap : public QObject
void dataDefinedLayers(); //test data defined layer string
void dataDefinedStyles(); //test data defined styles
void rasterized();
void layersToRender();

private:
QgsRasterLayer *mRasterLayer = nullptr;
Expand Down Expand Up @@ -503,5 +504,27 @@ void TestQgsLayoutMap::rasterized()
QVERIFY( checker.testLayout( mReport, 0, 0 ) );
}

void TestQgsLayoutMap::layersToRender()
{
QList<QgsMapLayer *> layers = QList<QgsMapLayer *>() << mRasterLayer << mPolysLayer << mPointsLayer << mLinesLayer;
QList<QgsMapLayer *> layers2 = QList<QgsMapLayer *>() << mRasterLayer << mPolysLayer << mLinesLayer;

QgsLayout l( QgsProject::instance() );

QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->setLayers( layers );
l.addLayoutItem( map );

QCOMPARE( map->layersToRender(), layers );

// hide coverage layer
l.context().setLayer( mPointsLayer );
l.context().setFlag( QgsLayoutContext::FlagHideCoverageLayer, true );
QCOMPARE( map->layersToRender(), layers2 );

l.context().setFlag( QgsLayoutContext::FlagHideCoverageLayer, false );
QCOMPARE( map->layersToRender(), layers );
}

QGSTEST_MAIN( TestQgsLayoutMap )
#include "testqgslayoutmap.moc"

0 comments on commit 7c086be

Please sign in to comment.