Skip to content

Commit

Permalink
[FEATURE][composer] Add option to hide pages from view/export
Browse files Browse the repository at this point in the history
Sponsored by NIWA
  • Loading branch information
nyalldawson committed Sep 25, 2015
1 parent e9a060c commit 2215d48
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
17 changes: 17 additions & 0 deletions python/core/composer/qgscomposition.sip
Expand Up @@ -155,6 +155,23 @@ class QgsComposition : QGraphicsScene
void setSmartGuidesEnabled( const bool b );
bool smartGuidesEnabled() const;

/** Sets whether the page items should be visible in the composition. Removing
* them will prevent both display of the page boundaries in composer views and
* will also prevent them from being rendered in composition exports.
* @param visible set to true to show pages, false to hide pages
* @note added in QGIS 2.12
* @see pagesVisible()
*/
void setPagesVisible( bool visible );

/** Returns whether the page items are be visible in the composition. This setting
* effects both display of the page boundaries in composer views and
* whether they will be rendered in composition exports.
* @note added in QGIS 2.12
* @see setPagesVisible()
*/
bool pagesVisible() const;

/** Removes all snap lines*/
void clearSnapLines();

Expand Down
15 changes: 15 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -339,6 +339,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addSeparator();
viewMenu->addAction( mActionShowBoxes );
viewMenu->addAction( mActionShowRulers );
viewMenu->addAction( mActionShowPage );

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

mActionShowPage->setChecked( mComposition->pagesVisible() );
restoreGridSettings();
connectViewSlots();
connectCompositionSlots();
Expand Down Expand Up @@ -1325,6 +1327,15 @@ void QgsComposer::on_mActionShowBoxes_triggered( bool checked )
}
}

void QgsComposer::on_mActionShowPage_triggered( bool checked )
{
//toggle page display
if ( mComposition )
{
mComposition->setPagesVisible( checked );
}
}

void QgsComposer::on_mActionClearGuides_triggered()
{
//clear guide lines
Expand Down Expand Up @@ -1501,6 +1512,8 @@ void QgsComposer::setComposition( QgsComposition* composition )
restoreGridSettings();
setupUndoView();

mActionShowPage->setChecked( mComposition->pagesVisible() );

//setup atlas composition widget
QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() );
delete oldAtlasWidget;
Expand Down Expand Up @@ -3320,6 +3333,8 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
//restore grid settings
restoreGridSettings();

mActionShowPage->setChecked( mComposition->pagesVisible() );

// look for world file composer map, if needed
// Note: this must be done after maps have been added by addItemsFromXML
if ( mComposition->generateWorldFile() )
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -319,6 +319,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Show/hide bounding boxes
void on_mActionShowBoxes_triggered( bool checked );

//!Show/hide pages
void on_mActionShowPage_triggered( bool checked );

//!Show/hide rulers
void toggleRulers( bool checked );

Expand Down
10 changes: 10 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -88,6 +88,7 @@ void QgsComposition::init()
mUseAdvancedEffects = true;
mSnapToGrid = false;
mGridVisible = false;
mPagesVisible = true;
mSnapGridResolution = 0;
mSnapGridOffsetX = 0;
mSnapGridOffsetY = 0;
Expand Down Expand Up @@ -800,6 +801,8 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
compositionElem.setAttribute( "snapGridOffsetY", QString::number( mSnapGridOffsetY ) );

compositionElem.setAttribute( "showPages", mPagesVisible );

//custom snap lines
QList< QGraphicsLineItem* >::const_iterator snapLineIt = mSnapLines.constBegin();
for ( ; snapLineIt != mSnapLines.constEnd(); ++snapLineIt )
Expand Down Expand Up @@ -916,6 +919,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
snapItem->setLine( x1, y1, x2, y2 );
}

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

Expand Down Expand Up @@ -1985,6 +1989,12 @@ void QgsComposition::setSnapLinesVisible( const bool visible )
}
}

void QgsComposition::setPagesVisible( bool visible )
{
mPagesVisible = visible;
update();
}

QGraphicsLineItem* QgsComposition::nearestSnapLine( const bool horizontal, const double x, const double y, const double tolerance,
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems ) const
{
Expand Down
18 changes: 18 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -219,6 +219,23 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void setSmartGuidesEnabled( const bool b ) { mSmartGuides = b; }
bool smartGuidesEnabled() const {return mSmartGuides;}

/** Sets whether the page items should be visible in the composition. Removing
* them will prevent both display of the page boundaries in composer views and
* will also prevent them from being rendered in composition exports.
* @param visible set to true to show pages, false to hide pages
* @note added in QGIS 2.12
* @see pagesVisible()
*/
void setPagesVisible( bool visible );

/** Returns whether the page items are be visible in the composition. This setting
* effects both display of the page boundaries in composer views and
* whether they will be rendered in composition exports.
* @note added in QGIS 2.12
* @see setPagesVisible()
*/
bool pagesVisible() const { return mPagesVisible; }

/** Removes all snap lines*/
void clearSnapLines();

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

bool mBoundingBoxesVisible;
bool mPagesVisible;
QgsComposerMouseHandles* mSelectionHandles;

QUndoStack* mUndoStack;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgspaperitem.cpp
Expand Up @@ -149,7 +149,7 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
{
Q_UNUSED( itemStyle );
Q_UNUSED( pWidget );
if ( !painter )
if ( !painter || !mComposition || !mComposition->pagesVisible() )
{
return;
}
Expand Down
11 changes: 11 additions & 0 deletions src/ui/composer/qgscomposerbase.ui
Expand Up @@ -1051,6 +1051,17 @@
<string>F10</string>
</property>
</action>
<action name="mActionShowPage">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Pages</string>
</property>
<property name="toolTip">
<string>Show pages</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down
19 changes: 19 additions & 0 deletions tests/src/core/testqgscomposerpaper.cpp
Expand Up @@ -48,6 +48,7 @@ class TestQgsComposerPaper : public QObject
void transparentPaper(); //test totally transparent paper style
void borderedPaper(); //test page with border
void markerLinePaper(); //test page with marker line border
void hiddenPages(); //test hidden page boundaries

private:
QgsComposition* mComposition;
Expand Down Expand Up @@ -147,5 +148,23 @@ void TestQgsComposerPaper::markerLinePaper()
QVERIFY( checker.testComposition( mReport, 0, 0 ) );
}

void TestQgsComposerPaper::hiddenPages()
{
QgsSimpleFillSymbolLayerV2* simpleFill = new QgsSimpleFillSymbolLayerV2();
QgsFillSymbolV2* fillSymbol = new QgsFillSymbolV2();
fillSymbol->changeSymbolLayer( 0, simpleFill );
simpleFill->setColor( Qt::blue );
simpleFill->setBorderColor( Qt::transparent );
mComposition->setPageStyleSymbol( fillSymbol );
delete fillSymbol;

mComposition->setPagesVisible( false );
QgsCompositionChecker checker( "composerpaper_hidden", mComposition );
checker.setControlPathPrefix( "composer_paper" );
bool result = checker.testComposition( mReport );
mComposition->setPagesVisible( true );
QVERIFY( result );
}

QTEST_MAIN( TestQgsComposerPaper )
#include "testqgscomposerpaper.moc"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2215d48

Please sign in to comment.