Skip to content
Permalink
Browse files

Port hide pages action from composer

  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent aa7beaa commit c8eaeb8f93b5bfd0be2f6eebc016fd4b569cb7bb
@@ -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

};


@@ -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() );
@@ -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 );
@@ -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 );
@@ -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.
*/
@@ -97,3 +97,8 @@ void QgsLayoutContext::setBoundingBoxesVisible( bool visible )
{
mBoundingBoxesVisible = visible;
}

void QgsLayoutContext::setPagesVisible( bool visible )
{
mPagesVisible = visible;
}
@@ -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;
@@ -174,6 +190,7 @@ class CORE_EXPORT QgsLayoutContext

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


};
@@ -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;
}
@@ -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"/>
@@ -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"/>
@@ -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"

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

void hiddenPages(); //test hidden page boundaries

private:
QString mReport;

@@ -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.
You can’t perform that action at this time.