Skip to content

Commit 2215d48

Browse files
committedSep 25, 2015
[FEATURE][composer] Add option to hide pages from view/export
Sponsored by NIWA
1 parent e9a060c commit 2215d48

File tree

9 files changed

+94
-1
lines changed

9 files changed

+94
-1
lines changed
 

‎python/core/composer/qgscomposition.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ class QgsComposition : QGraphicsScene
155155
void setSmartGuidesEnabled( const bool b );
156156
bool smartGuidesEnabled() const;
157157

158+
/** Sets whether the page items should be visible in the composition. Removing
159+
* them will prevent both display of the page boundaries in composer views and
160+
* will also prevent them from being rendered in composition exports.
161+
* @param visible set to true to show pages, false to hide pages
162+
* @note added in QGIS 2.12
163+
* @see pagesVisible()
164+
*/
165+
void setPagesVisible( bool visible );
166+
167+
/** Returns whether the page items are be visible in the composition. This setting
168+
* effects both display of the page boundaries in composer views and
169+
* whether they will be rendered in composition exports.
170+
* @note added in QGIS 2.12
171+
* @see setPagesVisible()
172+
*/
173+
bool pagesVisible() const;
174+
158175
/** Removes all snap lines*/
159176
void clearSnapLines();
160177

‎src/app/composer/qgscomposer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
339339
viewMenu->addSeparator();
340340
viewMenu->addAction( mActionShowBoxes );
341341
viewMenu->addAction( mActionShowRulers );
342+
viewMenu->addAction( mActionShowPage );
342343

343344
// Panel and toolbar submenus
344345
mPanelMenu = new QMenu( tr( "P&anels" ), this );
@@ -529,6 +530,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
529530
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
530531
}
531532

533+
mActionShowPage->setChecked( mComposition->pagesVisible() );
532534
restoreGridSettings();
533535
connectViewSlots();
534536
connectCompositionSlots();
@@ -1325,6 +1327,15 @@ void QgsComposer::on_mActionShowBoxes_triggered( bool checked )
13251327
}
13261328
}
13271329

1330+
void QgsComposer::on_mActionShowPage_triggered( bool checked )
1331+
{
1332+
//toggle page display
1333+
if ( mComposition )
1334+
{
1335+
mComposition->setPagesVisible( checked );
1336+
}
1337+
}
1338+
13281339
void QgsComposer::on_mActionClearGuides_triggered()
13291340
{
13301341
//clear guide lines
@@ -1501,6 +1512,8 @@ void QgsComposer::setComposition( QgsComposition* composition )
15011512
restoreGridSettings();
15021513
setupUndoView();
15031514

1515+
mActionShowPage->setChecked( mComposition->pagesVisible() );
1516+
15041517
//setup atlas composition widget
15051518
QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() );
15061519
delete oldAtlasWidget;
@@ -3320,6 +3333,8 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
33203333
//restore grid settings
33213334
restoreGridSettings();
33223335

3336+
mActionShowPage->setChecked( mComposition->pagesVisible() );
3337+
33233338
// look for world file composer map, if needed
33243339
// Note: this must be done after maps have been added by addItemsFromXML
33253340
if ( mComposition->generateWorldFile() )

‎src/app/composer/qgscomposer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
319319
//!Show/hide bounding boxes
320320
void on_mActionShowBoxes_triggered( bool checked );
321321

322+
//!Show/hide pages
323+
void on_mActionShowPage_triggered( bool checked );
324+
322325
//!Show/hide rulers
323326
void toggleRulers( bool checked );
324327

‎src/core/composer/qgscomposition.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void QgsComposition::init()
8888
mUseAdvancedEffects = true;
8989
mSnapToGrid = false;
9090
mGridVisible = false;
91+
mPagesVisible = true;
9192
mSnapGridResolution = 0;
9293
mSnapGridOffsetX = 0;
9394
mSnapGridOffsetY = 0;
@@ -800,6 +801,8 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
800801
compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
801802
compositionElem.setAttribute( "snapGridOffsetY", QString::number( mSnapGridOffsetY ) );
802803

804+
compositionElem.setAttribute( "showPages", mPagesVisible );
805+
803806
//custom snap lines
804807
QList< QGraphicsLineItem* >::const_iterator snapLineIt = mSnapLines.constBegin();
805808
for ( ; snapLineIt != mSnapLines.constEnd(); ++snapLineIt )
@@ -916,6 +919,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
916919
snapItem->setLine( x1, y1, x2, y2 );
917920
}
918921

922+
mPagesVisible = ( compositionElem.attribute( "showPages", "1" ) != "0" );
919923
mPrintAsRaster = compositionElem.attribute( "printAsRaster" ).toInt();
920924
mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt();
921925

@@ -1985,6 +1989,12 @@ void QgsComposition::setSnapLinesVisible( const bool visible )
19851989
}
19861990
}
19871991

1992+
void QgsComposition::setPagesVisible( bool visible )
1993+
{
1994+
mPagesVisible = visible;
1995+
update();
1996+
}
1997+
19881998
QGraphicsLineItem* QgsComposition::nearestSnapLine( const bool horizontal, const double x, const double y, const double tolerance,
19891999
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems ) const
19902000
{

‎src/core/composer/qgscomposition.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
219219
void setSmartGuidesEnabled( const bool b ) { mSmartGuides = b; }
220220
bool smartGuidesEnabled() const {return mSmartGuides;}
221221

222+
/** Sets whether the page items should be visible in the composition. Removing
223+
* them will prevent both display of the page boundaries in composer views and
224+
* will also prevent them from being rendered in composition exports.
225+
* @param visible set to true to show pages, false to hide pages
226+
* @note added in QGIS 2.12
227+
* @see pagesVisible()
228+
*/
229+
void setPagesVisible( bool visible );
230+
231+
/** Returns whether the page items are be visible in the composition. This setting
232+
* effects both display of the page boundaries in composer views and
233+
* whether they will be rendered in composition exports.
234+
* @note added in QGIS 2.12
235+
* @see setPagesVisible()
236+
*/
237+
bool pagesVisible() const { return mPagesVisible; }
238+
222239
/** Removes all snap lines*/
223240
void clearSnapLines();
224241

@@ -802,6 +819,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
802819
QList< QGraphicsLineItem* > mSnapLines;
803820

804821
bool mBoundingBoxesVisible;
822+
bool mPagesVisible;
805823
QgsComposerMouseHandles* mSelectionHandles;
806824

807825
QUndoStack* mUndoStack;

‎src/core/composer/qgspaperitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
149149
{
150150
Q_UNUSED( itemStyle );
151151
Q_UNUSED( pWidget );
152-
if ( !painter )
152+
if ( !painter || !mComposition || !mComposition->pagesVisible() )
153153
{
154154
return;
155155
}

‎src/ui/composer/qgscomposerbase.ui

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,17 @@
10511051
<string>F10</string>
10521052
</property>
10531053
</action>
1054+
<action name="mActionShowPage">
1055+
<property name="checkable">
1056+
<bool>true</bool>
1057+
</property>
1058+
<property name="text">
1059+
<string>Show Pages</string>
1060+
</property>
1061+
<property name="toolTip">
1062+
<string>Show pages</string>
1063+
</property>
1064+
</action>
10541065
</widget>
10551066
<resources>
10561067
<include location="../../../images/images.qrc"/>

‎tests/src/core/testqgscomposerpaper.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TestQgsComposerPaper : public QObject
4848
void transparentPaper(); //test totally transparent paper style
4949
void borderedPaper(); //test page with border
5050
void markerLinePaper(); //test page with marker line border
51+
void hiddenPages(); //test hidden page boundaries
5152

5253
private:
5354
QgsComposition* mComposition;
@@ -147,5 +148,23 @@ void TestQgsComposerPaper::markerLinePaper()
147148
QVERIFY( checker.testComposition( mReport, 0, 0 ) );
148149
}
149150

151+
void TestQgsComposerPaper::hiddenPages()
152+
{
153+
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
154+
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
155+
fillSymbol->changeSymbolLayer( 0, simpleFill );
156+
simpleFill->setColor( Qt::blue );
157+
simpleFill->setBorderColor( Qt::transparent );
158+
mComposition->setPageStyleSymbol( fillSymbol );
159+
delete fillSymbol;
160+
161+
mComposition->setPagesVisible( false );
162+
QgsCompositionChecker checker( "composerpaper_hidden", mComposition );
163+
checker.setControlPathPrefix( "composer_paper" );
164+
bool result = checker.testComposition( mReport );
165+
mComposition->setPagesVisible( true );
166+
QVERIFY( result );
167+
}
168+
150169
QTEST_MAIN( TestQgsComposerPaper )
151170
#include "testqgscomposerpaper.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.