Skip to content

Commit

Permalink
Port hide pages action from composer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent aa7beaa commit c8eaeb8
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 1 deletion.
17 changes: 17 additions & 0 deletions python/core/layout/qgslayoutcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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

};


Expand Down
8 changes: 8 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
{
mBoundingBoxesVisible = visible;
}

void QgsLayoutContext::setPagesVisible( bool visible )
{
mPagesVisible = visible;
}
17 changes: 17 additions & 0 deletions src/core/layout/qgslayoutcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -174,6 +190,7 @@ class CORE_EXPORT QgsLayoutContext

bool mGridVisible = false;
bool mBoundingBoxesVisible = true;
bool mPagesVisible = true;


};
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitempage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/ui/layout/qgslayoutdesignerbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<addaction name="separator"/>
<addaction name="mActionShowRulers"/>
<addaction name="mActionShowBoxes"/>
<addaction name="mActionShowPage"/>
<addaction name="separator"/>
<addaction name="mToolbarMenu"/>
<addaction name="mPanelsMenu"/>
Expand Down Expand Up @@ -980,6 +981,17 @@
<string>Simulate Color Blindness (&amp;Deuteranope)</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
34 changes: 34 additions & 0 deletions tests/src/core/testqgslayoutpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QObject>
#include "qgstest.h"

Expand All @@ -37,6 +41,8 @@ class TestQgsLayoutPage : public QObject
void decodePageOrientation();
void grid();

void hiddenPages(); //test hidden page boundaries

private:
QString mReport;

Expand Down Expand Up @@ -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"

0 comments on commit c8eaeb8

Please sign in to comment.