Skip to content

Commit c8eaeb8

Browse files
committedOct 6, 2017
Port hide pages action from composer
1 parent aa7beaa commit c8eaeb8

File tree

8 files changed

+99
-1
lines changed

8 files changed

+99
-1
lines changed
 

‎python/core/layout/qgslayoutcontext.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ class QgsLayoutContext
151151
.. seealso:: boundingBoxesVisible()
152152
%End
153153

154+
void setPagesVisible( bool visible );
155+
%Docstring
156+
Sets whether the page items should be ``visible`` in the layout. Removing
157+
them will prevent both display of the page boundaries in layout views and
158+
will also prevent them from being rendered in layout exports.
159+
.. seealso:: pagesVisible()
160+
%End
161+
162+
bool pagesVisible() const;
163+
%Docstring
164+
Returns whether the page items are be visible in the layout. This setting
165+
effects both display of the page boundaries in layout views and
166+
whether they will be rendered in layout exports.
167+
.. seealso:: setPagesVisible()
168+
:rtype: bool
169+
%End
170+
154171
};
155172

156173

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
149149
connect( mActionSmartGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToItems );
150150

151151
connect( mActionShowBoxes, &QAction::triggered, this, &QgsLayoutDesignerDialog::showBoxes );
152+
connect( mActionShowPage, &QAction::triggered, this, &QgsLayoutDesignerDialog::showPages );
152153

153154
mView = new QgsLayoutView();
154155
//mView->setMapCanvas( mQgis->mapCanvas() );
@@ -557,6 +558,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
557558
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );
558559
mActionSmartGuides->setChecked( mLayout->snapper().snapToItems() );
559560
mActionShowBoxes->setChecked( mLayout->context().boundingBoxesVisible() );
561+
mActionShowPage->setChecked( mLayout->context().pagesVisible() );
560562

561563
connect( mLayout->undoStack()->stack(), &QUndoStack::canUndoChanged, mActionUndo, &QAction::setEnabled );
562564
connect( mLayout->undoStack()->stack(), &QUndoStack::canRedoChanged, mActionRedo, &QAction::setEnabled );
@@ -671,6 +673,12 @@ void QgsLayoutDesignerDialog::showBoxes( bool visible )
671673
mSelectTool->mouseHandles()->update();
672674
}
673675

676+
void QgsLayoutDesignerDialog::showPages( bool visible )
677+
{
678+
mLayout->context().setPagesVisible( visible );
679+
mLayout->pageCollection()->redraw();
680+
}
681+
674682
void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
675683
{
676684
mLayout->snapper().setSnapToGrid( enabled );

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
130130
*/
131131
void showBoxes( bool visible );
132132

133+
/**
134+
* Toggles whether the layout pages should be \a visible.
135+
*/
136+
void showPages( bool visible );
137+
133138
/**
134139
* Toggles whether snapping to the page grid is \a enabled.
135140
*/

‎src/core/layout/qgslayoutcontext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@ void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
9797
{
9898
mBoundingBoxesVisible = visible;
9999
}
100+
101+
void QgsLayoutContext::setPagesVisible( bool visible )
102+
{
103+
mPagesVisible = visible;
104+
}

‎src/core/layout/qgslayoutcontext.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ class CORE_EXPORT QgsLayoutContext
163163
*/
164164
void setBoundingBoxesVisible( bool visible );
165165

166+
/**
167+
* Sets whether the page items should be \a visible in the layout. Removing
168+
* them will prevent both display of the page boundaries in layout views and
169+
* will also prevent them from being rendered in layout exports.
170+
* \see pagesVisible()
171+
*/
172+
void setPagesVisible( bool visible );
173+
174+
/**
175+
* Returns whether the page items are be visible in the layout. This setting
176+
* effects both display of the page boundaries in layout views and
177+
* whether they will be rendered in layout exports.
178+
* \see setPagesVisible()
179+
*/
180+
bool pagesVisible() const { return mPagesVisible; }
181+
166182
private:
167183

168184
Flags mFlags = 0;
@@ -174,6 +190,7 @@ class CORE_EXPORT QgsLayoutContext
174190

175191
bool mGridVisible = false;
176192
bool mBoundingBoxesVisible = true;
193+
bool mPagesVisible = true;
177194

178195

179196
};

‎src/core/layout/qgslayoutitempage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void QgsLayoutItemPage::redraw()
165165

166166
void QgsLayoutItemPage::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * )
167167
{
168-
if ( !context.painter() || !mLayout /*|| !mLayout->pagesVisible() */ )
168+
if ( !context.painter() || !mLayout || !mLayout->context().pagesVisible() )
169169
{
170170
return;
171171
}

‎src/ui/layout/qgslayoutdesignerbase.ui

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<addaction name="separator"/>
146146
<addaction name="mActionShowRulers"/>
147147
<addaction name="mActionShowBoxes"/>
148+
<addaction name="mActionShowPage"/>
148149
<addaction name="separator"/>
149150
<addaction name="mToolbarMenu"/>
150151
<addaction name="mPanelsMenu"/>
@@ -980,6 +981,17 @@
980981
<string>Simulate Color Blindness (&amp;Deuteranope)</string>
981982
</property>
982983
</action>
984+
<action name="mActionShowPage">
985+
<property name="checkable">
986+
<bool>true</bool>
987+
</property>
988+
<property name="text">
989+
<string>Show Pages</string>
990+
</property>
991+
<property name="toolTip">
992+
<string>Show pages</string>
993+
</property>
994+
</action>
983995
</widget>
984996
<resources>
985997
<include location="../../../images/images.qrc"/>

‎tests/src/core/testqgslayoutpage.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "qgslayoutitemregistry.h"
2121
#include "qgis.h"
2222
#include "qgsproject.h"
23+
#include "qgssymbol.h"
24+
#include "qgssinglesymbolrenderer.h"
25+
#include "qgsfillsymbollayer.h"
26+
#include "qgslinesymbollayer.h"
2327
#include <QObject>
2428
#include "qgstest.h"
2529

@@ -37,6 +41,8 @@ class TestQgsLayoutPage : public QObject
3741
void decodePageOrientation();
3842
void grid();
3943

44+
void hiddenPages(); //test hidden page boundaries
45+
4046
private:
4147
QString mReport;
4248

@@ -159,5 +165,33 @@ void TestQgsLayoutPage::grid()
159165

160166
}
161167

168+
void TestQgsLayoutPage::hiddenPages()
169+
{
170+
QgsProject p;
171+
QgsLayout l( &p );
172+
QgsLayoutItemPage *page = new QgsLayoutItemPage( &l );
173+
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
174+
l.pageCollection()->addPage( page );
175+
176+
#if 0 //TODO
177+
QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
178+
QgsFillSymbol *fillSymbol = new QgsFillSymbol();
179+
fillSymbol->changeSymbolLayer( 0, simpleFill );
180+
simpleFill->setColor( Qt::blue );
181+
simpleFill->setStrokeColor( Qt::transparent );
182+
mComposition->setPageStyleSymbol( fillSymbol );
183+
delete fillSymbol;
184+
#endif
185+
186+
l.context().setPagesVisible( false );
187+
#if 0 //TODO
188+
QgsCompositionChecker checker( QStringLiteral( "composerpaper_hidden" ), mComposition );
189+
checker.setControlPathPrefix( QStringLiteral( "composer_paper" ) );
190+
bool result = checker.testComposition( mReport );
191+
mComposition->setPagesVisible( true );
192+
QVERIFY( result );
193+
#endif
194+
}
195+
162196
QGSTEST_MAIN( TestQgsLayoutPage )
163197
#include "testqgslayoutpage.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.