From 71c41d49b774719f36b55dd0c08bed0361057de7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 20 Oct 2017 14:08:03 +1000 Subject: [PATCH] Add export layer settings to QgsLayoutContext --- python/core/layout/qgslayoutcontext.sip | 23 +++++++++++++++++++++++ src/core/layout/qgslayoutcontext.h | 24 ++++++++++++++++++++++++ tests/src/core/testqgslayoutcontext.cpp | 10 ++++++++++ 3 files changed, 57 insertions(+) diff --git a/python/core/layout/qgslayoutcontext.sip b/python/core/layout/qgslayoutcontext.sip index 00d090c974d..99559a6101d 100644 --- a/python/core/layout/qgslayoutcontext.sip +++ b/python/core/layout/qgslayoutcontext.sip @@ -176,6 +176,29 @@ class QgsLayoutContext : QObject :rtype: bool %End + void setCurrentExportLayer( int layer = -1 ); +%Docstring + Sets the current item ``layer`` to draw while exporting. QgsLayoutItem subclasses + which support multi-layer SVG exports must check the currentExportLayer() + and customise their rendering based on the layer. + + If ``layer`` is -1, all item layers will be rendered. + +.. seealso:: currentExportLayer() +%End + + int currentExportLayer() const; +%Docstring + Returns the current item layer to draw while exporting. QgsLayoutItem subclasses + which support multi-layer SVG exports must check this + and customise their rendering based on the layer. + + If ``layer`` is -1, all item layers should be rendered. + +.. seealso:: setCurrentExportLayer() + :rtype: int +%End + signals: void flagsChanged( QgsLayoutContext::Flags flags ); diff --git a/src/core/layout/qgslayoutcontext.h b/src/core/layout/qgslayoutcontext.h index 3691a71a0e8..74f6c3d0d4a 100644 --- a/src/core/layout/qgslayoutcontext.h +++ b/src/core/layout/qgslayoutcontext.h @@ -188,6 +188,28 @@ class CORE_EXPORT QgsLayoutContext : public QObject */ bool pagesVisible() const { return mPagesVisible; } + /** + * Sets the current item \a layer to draw while exporting. QgsLayoutItem subclasses + * which support multi-layer SVG exports must check the currentExportLayer() + * and customise their rendering based on the layer. + * + * If \a layer is -1, all item layers will be rendered. + * + * \see currentExportLayer() + */ + void setCurrentExportLayer( int layer = -1 ) { mCurrentExportLayer = layer; } + + /** + * Returns the current item layer to draw while exporting. QgsLayoutItem subclasses + * which support multi-layer SVG exports must check this + * and customise their rendering based on the layer. + * + * If \a layer is -1, all item layers should be rendered. + * + * \see setCurrentExportLayer() + */ + int currentExportLayer() const { return mCurrentExportLayer; } + signals: /** @@ -200,6 +222,8 @@ class CORE_EXPORT QgsLayoutContext : public QObject Flags mFlags = 0; + int mCurrentExportLayer = -1; + QgsFeature mFeature; QPointer< QgsVectorLayer > mLayer; diff --git a/tests/src/core/testqgslayoutcontext.cpp b/tests/src/core/testqgslayoutcontext.cpp index ca043cfd311..986931a4fa5 100644 --- a/tests/src/core/testqgslayoutcontext.cpp +++ b/tests/src/core/testqgslayoutcontext.cpp @@ -39,6 +39,7 @@ class TestQgsLayoutContext: public QObject void dpi(); void renderContextFlags(); void boundingBoxes(); + void exportLayer(); private: QString mReport; @@ -180,5 +181,14 @@ void TestQgsLayoutContext::boundingBoxes() QVERIFY( context.boundingBoxesVisible() ); } +void TestQgsLayoutContext::exportLayer() +{ + QgsLayoutContext context; + // must default to -1 + QCOMPARE( context.currentExportLayer(), -1 ); + context.setCurrentExportLayer( 1 ); + QCOMPARE( context.currentExportLayer(), 1 ); +} + QGSTEST_MAIN( TestQgsLayoutContext ) #include "testqgslayoutcontext.moc"