Skip to content
Permalink
Browse files

Readd menu option to show/hide guides

  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent 98ff702 commit 9267f8676cb6fba3602816b3d9a86551bd1f4b37
@@ -213,6 +213,20 @@ class QgsLayoutGuideCollection : QAbstractTableModel
:rtype: list of QgsLayoutGuide
%End


bool visible() const;
%Docstring
Returns true if the guide lines should be drawn.
.. seealso:: setVisible()
:rtype: bool
%End

void setVisible( bool visible );
%Docstring
Sets whether the guide lines should be ``visible``.
.. seealso:: visible()
%End

};


@@ -133,6 +133,8 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mActionShowGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGrid );
connect( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );

connect( mActionShowGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGuides );

mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
mView->setContentsMargins( 0, 0, 0, 0 );
@@ -309,6 +311,10 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
mLayout->guides().clear();
} );

mActionShowGrid->setChecked( mLayout->context().gridVisible() );
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
mActionShowGuides->setChecked( mLayout->guides().visible() );

createLayoutPropertiesWidget();
}

@@ -393,6 +399,16 @@ void QgsLayoutDesignerDialog::snapToGrid( bool enabled )
mLayout->snapper().setSnapToGrid( enabled );
}

void QgsLayoutDesignerDialog::showGuides( bool visible )
{
mLayout->guides().setVisible( visible );
}

void QgsLayoutDesignerDialog::snapToGuides( bool enabled )
{

}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
{
emit aboutToClose();
@@ -125,6 +125,16 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void snapToGrid( bool enabled );

/**
* Toggles whether the page guides should be \a visible.
*/
void showGuides( bool visible );

/**
* Toggles whether snapping to the page guides is \a enabled.
*/
void snapToGuides( bool enabled );

signals:

/**
@@ -77,6 +77,7 @@ void QgsLayoutGuide::update()
QgsLayoutItemPage *page = mLayout->pageCollection()->page( mPage );
mLineItem->setParentItem( page );
double layoutPos = mLayout->convertToLayoutUnits( mPosition );
bool showGuide = mLayout->guides().visible();
switch ( mOrientation )
{
case Horizontal:
@@ -87,7 +88,7 @@ void QgsLayoutGuide::update()
else
{
mLineItem->setLine( 0, layoutPos, page->rect().width(), layoutPos );
mLineItem->show();
mLineItem->setVisible( showGuide );
}

break;
@@ -100,7 +101,7 @@ void QgsLayoutGuide::update()
else
{
mLineItem->setLine( layoutPos, 0, layoutPos, page->rect().height() );
mLineItem->show();
mLineItem->setVisible( showGuide );
}

break;
@@ -404,6 +405,18 @@ QList<QgsLayoutGuide *> QgsLayoutGuideCollection::guides( QgsLayoutGuide::Orient
return res;
}

bool QgsLayoutGuideCollection::visible() const
{
return mGuidesVisible;
}

void QgsLayoutGuideCollection::setVisible( bool visible )
{
mGuidesVisible = visible;
update();
}



//
// QgsLayoutGuideProxyModel
@@ -236,13 +236,28 @@ class CORE_EXPORT QgsLayoutGuideCollection : public QAbstractTableModel
*/
QList< QgsLayoutGuide * > guides( QgsLayoutGuide::Orientation orientation, int page = -1 );


/**
* Returns true if the guide lines should be drawn.
* \see setVisible()
*/
bool visible() const;

/**
* Sets whether the guide lines should be \a visible.
* \see visible()
*/
void setVisible( bool visible );

private:

QgsLayout *mLayout = nullptr;

QList< QgsLayoutGuide * > mGuides;
int mHeaderSize = 0;

bool mGuidesVisible = true;

};


@@ -83,7 +83,7 @@
<x>0</x>
<y>0</y>
<width>1083</width>
<height>42</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="mLayoutMenu">
@@ -353,6 +353,9 @@
</property>
</action>
<action name="mActionShowGuides">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show G&amp;uides</string>
</property>
@@ -364,6 +367,9 @@
</property>
</action>
<action name="mActionSnapGuides">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Snap to Guides</string>
</property>
@@ -433,6 +439,10 @@
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>
@@ -293,6 +293,25 @@ def testApplyToOtherPages(self):
self.assertEqual(len(guides.guides(QgsLayoutGuide.Vertical, 0)), 1)
self.assertEqual(guides.guides(QgsLayoutGuide.Vertical, 0)[0].position().length(), 6)

def testSetVisible(self):
p = QgsProject()
l = QgsLayout(p)
l.initializeDefaults()
guides = l.guides()

# add some guides
g1 = QgsLayoutGuide(QgsLayoutGuide.Horizontal, QgsLayoutMeasurement(5))
guides.addGuide(g1)
g2 = QgsLayoutGuide(QgsLayoutGuide.Vertical, QgsLayoutMeasurement(6))
guides.addGuide(g2)

guides.setVisible(False)
self.assertFalse(g1.item().isVisible())
self.assertFalse(g2.item().isVisible())
guides.setVisible(True)
self.assertTrue(g1.item().isVisible())
self.assertTrue(g2.item().isVisible())


if __name__ == '__main__':
unittest.main()

0 comments on commit 9267f86

Please sign in to comment.
You can’t perform that action at this time.