diff --git a/python/core/layout/qgslayoutcontext.sip b/python/core/layout/qgslayoutcontext.sip
index 09d930b9018..fdac9823653 100644
--- a/python/core/layout/qgslayoutcontext.sip
+++ b/python/core/layout/qgslayoutcontext.sip
@@ -151,6 +151,23 @@ class QgsLayoutContext
.. seealso:: boundingBoxesVisible()
%End
+ void setPagesVisible( bool visible );
+%Docstring
+ Sets whether the page items should be ``visible`` in the layout. Removing
+ them will prevent both display of the page boundaries in layout views and
+ will also prevent them from being rendered in layout exports.
+.. seealso:: pagesVisible()
+%End
+
+ bool pagesVisible() const;
+%Docstring
+ Returns whether the page items are be visible in the layout. This setting
+ effects both display of the page boundaries in layout views and
+ whether they will be rendered in layout exports.
+.. seealso:: setPagesVisible()
+ :rtype: bool
+%End
+
};
diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp
index beea8b98401..89e2a1fb3f8 100644
--- a/src/app/layout/qgslayoutdesignerdialog.cpp
+++ b/src/app/layout/qgslayoutdesignerdialog.cpp
@@ -149,6 +149,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mActionSmartGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToItems );
connect( mActionShowBoxes, &QAction::triggered, this, &QgsLayoutDesignerDialog::showBoxes );
+ connect( mActionShowPage, &QAction::triggered, this, &QgsLayoutDesignerDialog::showPages );
mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
@@ -557,6 +558,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );
mActionSmartGuides->setChecked( mLayout->snapper().snapToItems() );
mActionShowBoxes->setChecked( mLayout->context().boundingBoxesVisible() );
+ mActionShowPage->setChecked( mLayout->context().pagesVisible() );
connect( mLayout->undoStack()->stack(), &QUndoStack::canUndoChanged, mActionUndo, &QAction::setEnabled );
connect( mLayout->undoStack()->stack(), &QUndoStack::canRedoChanged, mActionRedo, &QAction::setEnabled );
@@ -671,6 +673,12 @@ void QgsLayoutDesignerDialog::showBoxes( bool visible )
mSelectTool->mouseHandles()->update();
}
+void QgsLayoutDesignerDialog::showPages( bool visible )
+{
+ mLayout->context().setPagesVisible( visible );
+ mLayout->pageCollection()->redraw();
+}
+
void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
{
mLayout->snapper().setSnapToGrid( enabled );
diff --git a/src/app/layout/qgslayoutdesignerdialog.h b/src/app/layout/qgslayoutdesignerdialog.h
index efaa56a4abe..b1b3766a3c5 100644
--- a/src/app/layout/qgslayoutdesignerdialog.h
+++ b/src/app/layout/qgslayoutdesignerdialog.h
@@ -130,6 +130,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void showBoxes( bool visible );
+ /**
+ * Toggles whether the layout pages should be \a visible.
+ */
+ void showPages( bool visible );
+
/**
* Toggles whether snapping to the page grid is \a enabled.
*/
diff --git a/src/core/layout/qgslayoutcontext.cpp b/src/core/layout/qgslayoutcontext.cpp
index 8568c55f21a..d6b0f6eb6dd 100644
--- a/src/core/layout/qgslayoutcontext.cpp
+++ b/src/core/layout/qgslayoutcontext.cpp
@@ -97,3 +97,8 @@ void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
{
mBoundingBoxesVisible = visible;
}
+
+void QgsLayoutContext::setPagesVisible( bool visible )
+{
+ mPagesVisible = visible;
+}
diff --git a/src/core/layout/qgslayoutcontext.h b/src/core/layout/qgslayoutcontext.h
index 5b5f505bd7d..72d0ce7e0af 100644
--- a/src/core/layout/qgslayoutcontext.h
+++ b/src/core/layout/qgslayoutcontext.h
@@ -163,6 +163,22 @@ class CORE_EXPORT QgsLayoutContext
*/
void setBoundingBoxesVisible( bool visible );
+ /**
+ * Sets whether the page items should be \a visible in the layout. Removing
+ * them will prevent both display of the page boundaries in layout views and
+ * will also prevent them from being rendered in layout exports.
+ * \see pagesVisible()
+ */
+ void setPagesVisible( bool visible );
+
+ /**
+ * Returns whether the page items are be visible in the layout. This setting
+ * effects both display of the page boundaries in layout views and
+ * whether they will be rendered in layout exports.
+ * \see setPagesVisible()
+ */
+ bool pagesVisible() const { return mPagesVisible; }
+
private:
Flags mFlags = 0;
@@ -174,6 +190,7 @@ class CORE_EXPORT QgsLayoutContext
bool mGridVisible = false;
bool mBoundingBoxesVisible = true;
+ bool mPagesVisible = true;
};
diff --git a/src/core/layout/qgslayoutitempage.cpp b/src/core/layout/qgslayoutitempage.cpp
index d06593fa1a4..013367753b5 100644
--- a/src/core/layout/qgslayoutitempage.cpp
+++ b/src/core/layout/qgslayoutitempage.cpp
@@ -165,7 +165,7 @@ void QgsLayoutItemPage::redraw()
void QgsLayoutItemPage::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * )
{
- if ( !context.painter() || !mLayout /*|| !mLayout->pagesVisible() */ )
+ if ( !context.painter() || !mLayout || !mLayout->context().pagesVisible() )
{
return;
}
diff --git a/src/ui/layout/qgslayoutdesignerbase.ui b/src/ui/layout/qgslayoutdesignerbase.ui
index 58f84e5d4bf..bf6fde386ba 100644
--- a/src/ui/layout/qgslayoutdesignerbase.ui
+++ b/src/ui/layout/qgslayoutdesignerbase.ui
@@ -145,6 +145,7 @@
+
@@ -980,6 +981,17 @@
Simulate Color Blindness (&Deuteranope)
+
+
+ true
+
+
+ Show Pages
+
+
+ Show pages
+
+
diff --git a/tests/src/core/testqgslayoutpage.cpp b/tests/src/core/testqgslayoutpage.cpp
index d6142cb452f..782642da827 100644
--- a/tests/src/core/testqgslayoutpage.cpp
+++ b/tests/src/core/testqgslayoutpage.cpp
@@ -20,6 +20,10 @@
#include "qgslayoutitemregistry.h"
#include "qgis.h"
#include "qgsproject.h"
+#include "qgssymbol.h"
+#include "qgssinglesymbolrenderer.h"
+#include "qgsfillsymbollayer.h"
+#include "qgslinesymbollayer.h"
#include
#include "qgstest.h"
@@ -37,6 +41,8 @@ class TestQgsLayoutPage : public QObject
void decodePageOrientation();
void grid();
+ void hiddenPages(); //test hidden page boundaries
+
private:
QString mReport;
@@ -159,5 +165,33 @@ void TestQgsLayoutPage::grid()
}
+void TestQgsLayoutPage::hiddenPages()
+{
+ QgsProject p;
+ QgsLayout l( &p );
+ QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
+ page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
+ l.pageCollection()->addPage( page );
+
+#if 0 //TODO
+ QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
+ QgsFillSymbol *fillSymbol = new QgsFillSymbol();
+ fillSymbol->changeSymbolLayer( 0, simpleFill );
+ simpleFill->setColor( Qt::blue );
+ simpleFill->setStrokeColor( Qt::transparent );
+ mComposition->setPageStyleSymbol( fillSymbol );
+ delete fillSymbol;
+#endif
+
+ l.context().setPagesVisible( false );
+#if 0 //TODO
+ QgsCompositionChecker checker( QStringLiteral( "composerpaper_hidden" ), mComposition );
+ checker.setControlPathPrefix( QStringLiteral( "composer_paper" ) );
+ bool result = checker.testComposition( mReport );
+ mComposition->setPagesVisible( true );
+ QVERIFY( result );
+#endif
+}
+
QGSTEST_MAIN( TestQgsLayoutPage )
#include "testqgslayoutpage.moc"