Skip to content
Permalink
Browse files

Fix some map item todos

  • Loading branch information
nyalldawson committed Dec 23, 2017
1 parent 49eaebb commit 7c086beb925aeaae08d60f95048306195790d8fc
@@ -28,6 +28,7 @@ class QgsLayoutContext : QObject
FlagAntialiasing,
FlagUseAdvancedEffects,
FlagForceVectorOutput,
FlagHideCoverageLayer,
};
typedef QFlags<QgsLayoutContext::Flag> Flags;

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

@@ -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;
}

@@ -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;
@@ -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.
You can’t perform that action at this time.