[FEATURE][composer] Add option to hide pages from view/export

Sponsored by NIWA
This commit is contained in:
Nyall Dawson 2015-09-07 07:55:40 +10:00
parent e9a060c62d
commit 2215d48712
9 changed files with 94 additions and 1 deletions

View File

@ -155,6 +155,23 @@ class QgsComposition : QGraphicsScene
void setSmartGuidesEnabled( const bool b ); void setSmartGuidesEnabled( const bool b );
bool smartGuidesEnabled() const; 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*/ /** Removes all snap lines*/
void clearSnapLines(); void clearSnapLines();

View File

@ -339,6 +339,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addSeparator(); viewMenu->addSeparator();
viewMenu->addAction( mActionShowBoxes ); viewMenu->addAction( mActionShowBoxes );
viewMenu->addAction( mActionShowRulers ); viewMenu->addAction( mActionShowRulers );
viewMenu->addAction( mActionShowPage );
// Panel and toolbar submenus // Panel and toolbar submenus
mPanelMenu = new QMenu( tr( "P&anels" ), this ); mPanelMenu = new QMenu( tr( "P&anels" ), this );
@ -529,6 +530,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) ); connect( mComposition->undoStack(), SIGNAL( canRedoChanged( bool ) ), mActionRedo, SLOT( setEnabled( bool ) ) );
} }
mActionShowPage->setChecked( mComposition->pagesVisible() );
restoreGridSettings(); restoreGridSettings();
connectViewSlots(); connectViewSlots();
connectCompositionSlots(); connectCompositionSlots();
@ -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() void QgsComposer::on_mActionClearGuides_triggered()
{ {
//clear guide lines //clear guide lines
@ -1501,6 +1512,8 @@ void QgsComposer::setComposition( QgsComposition* composition )
restoreGridSettings(); restoreGridSettings();
setupUndoView(); setupUndoView();
mActionShowPage->setChecked( mComposition->pagesVisible() );
//setup atlas composition widget //setup atlas composition widget
QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() ); QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() );
delete oldAtlasWidget; delete oldAtlasWidget;
@ -3320,6 +3333,8 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
//restore grid settings //restore grid settings
restoreGridSettings(); restoreGridSettings();
mActionShowPage->setChecked( mComposition->pagesVisible() );
// look for world file composer map, if needed // look for world file composer map, if needed
// Note: this must be done after maps have been added by addItemsFromXML // Note: this must be done after maps have been added by addItemsFromXML
if ( mComposition->generateWorldFile() ) if ( mComposition->generateWorldFile() )

View File

@ -319,6 +319,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Show/hide bounding boxes //!Show/hide bounding boxes
void on_mActionShowBoxes_triggered( bool checked ); void on_mActionShowBoxes_triggered( bool checked );
//!Show/hide pages
void on_mActionShowPage_triggered( bool checked );
//!Show/hide rulers //!Show/hide rulers
void toggleRulers( bool checked ); void toggleRulers( bool checked );

View File

@ -88,6 +88,7 @@ void QgsComposition::init()
mUseAdvancedEffects = true; mUseAdvancedEffects = true;
mSnapToGrid = false; mSnapToGrid = false;
mGridVisible = false; mGridVisible = false;
mPagesVisible = true;
mSnapGridResolution = 0; mSnapGridResolution = 0;
mSnapGridOffsetX = 0; mSnapGridOffsetX = 0;
mSnapGridOffsetY = 0; mSnapGridOffsetY = 0;
@ -800,6 +801,8 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) ); compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
compositionElem.setAttribute( "snapGridOffsetY", QString::number( mSnapGridOffsetY ) ); compositionElem.setAttribute( "snapGridOffsetY", QString::number( mSnapGridOffsetY ) );
compositionElem.setAttribute( "showPages", mPagesVisible );
//custom snap lines //custom snap lines
QList< QGraphicsLineItem* >::const_iterator snapLineIt = mSnapLines.constBegin(); QList< QGraphicsLineItem* >::const_iterator snapLineIt = mSnapLines.constBegin();
for ( ; snapLineIt != mSnapLines.constEnd(); ++snapLineIt ) for ( ; snapLineIt != mSnapLines.constEnd(); ++snapLineIt )
@ -916,6 +919,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
snapItem->setLine( x1, y1, x2, y2 ); snapItem->setLine( x1, y1, x2, y2 );
} }
mPagesVisible = ( compositionElem.attribute( "showPages", "1" ) != "0" );
mPrintAsRaster = compositionElem.attribute( "printAsRaster" ).toInt(); mPrintAsRaster = compositionElem.attribute( "printAsRaster" ).toInt();
mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt(); mPrintResolution = compositionElem.attribute( "printResolution", "300" ).toInt();
@ -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, QGraphicsLineItem* QgsComposition::nearestSnapLine( const bool horizontal, const double x, const double y, const double tolerance,
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems ) const QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode> >& snappedItems ) const
{ {

View File

@ -219,6 +219,23 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void setSmartGuidesEnabled( const bool b ) { mSmartGuides = b; } void setSmartGuidesEnabled( const bool b ) { mSmartGuides = b; }
bool smartGuidesEnabled() const {return mSmartGuides;} 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*/ /** Removes all snap lines*/
void clearSnapLines(); void clearSnapLines();
@ -802,6 +819,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
QList< QGraphicsLineItem* > mSnapLines; QList< QGraphicsLineItem* > mSnapLines;
bool mBoundingBoxesVisible; bool mBoundingBoxesVisible;
bool mPagesVisible;
QgsComposerMouseHandles* mSelectionHandles; QgsComposerMouseHandles* mSelectionHandles;
QUndoStack* mUndoStack; QUndoStack* mUndoStack;

View File

@ -149,7 +149,7 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
{ {
Q_UNUSED( itemStyle ); Q_UNUSED( itemStyle );
Q_UNUSED( pWidget ); Q_UNUSED( pWidget );
if ( !painter ) if ( !painter || !mComposition || !mComposition->pagesVisible() )
{ {
return; return;
} }

View File

@ -1051,6 +1051,17 @@
<string>F10</string> <string>F10</string>
</property> </property>
</action> </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> </widget>
<resources> <resources>
<include location="../../../images/images.qrc"/> <include location="../../../images/images.qrc"/>

View File

@ -48,6 +48,7 @@ class TestQgsComposerPaper : public QObject
void transparentPaper(); //test totally transparent paper style void transparentPaper(); //test totally transparent paper style
void borderedPaper(); //test page with border void borderedPaper(); //test page with border
void markerLinePaper(); //test page with marker line border void markerLinePaper(); //test page with marker line border
void hiddenPages(); //test hidden page boundaries
private: private:
QgsComposition* mComposition; QgsComposition* mComposition;
@ -147,5 +148,23 @@ void TestQgsComposerPaper::markerLinePaper()
QVERIFY( checker.testComposition( mReport, 0, 0 ) ); 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 ) QTEST_MAIN( TestQgsComposerPaper )
#include "testqgscomposerpaper.moc" #include "testqgscomposerpaper.moc"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB