Skip to content
Permalink
Browse files

Hook up snap to guides menu option

  • Loading branch information
nyalldawson committed Jul 27, 2017
1 parent 9267f86 commit 66875641a32de08a380bc2805ab0add078fa4552
@@ -50,6 +50,19 @@ class QgsLayoutSnapper
%Docstring
Sets whether snapping to grid is ``enabled``.
.. seealso:: snapToGrid()
%End

bool snapToGuides() const;
%Docstring
Returns true if snapping to guides is enabled.
.. seealso:: setSnapToGuides()
:rtype: bool
%End

void setSnapToGuides( bool enabled );
%Docstring
Sets whether snapping to guides is ``enabled``.
.. seealso:: snapToGuides()
%End

QPointF snapPoint( QPointF point, double scaleFactor, bool &snapped /Out/ ) const;
@@ -134,6 +134,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );

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

mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
@@ -314,6 +315,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
mActionShowGrid->setChecked( mLayout->context().gridVisible() );
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
mActionShowGuides->setChecked( mLayout->guides().visible() );
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );

createLayoutPropertiesWidget();
}
@@ -406,7 +408,7 @@ void QgsLayoutDesignerDialog::showGuides( bool visible )

void QgsLayoutDesignerDialog::snapToGuides( bool enabled )
{

mLayout->snapper().setSnapToGuides( enabled );
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
@@ -107,6 +107,10 @@ QPointF QgsLayoutSnapper::snapPointToGrid( QPointF point, double scaleFactor, bo
double QgsLayoutSnapper::snapPointToGuides( double original, QgsLayoutGuide::Orientation orientation, double scaleFactor, bool &snapped ) const
{
snapped = false;
if ( !mLayout || !mSnapToGuides )
{
return original;
}

//convert snap tolerance from pixels to layout units
double alignThreshold = mTolerance / scaleFactor;
@@ -65,6 +65,18 @@ class CORE_EXPORT QgsLayoutSnapper
*/
void setSnapToGrid( bool enabled ) { mSnapToGrid = enabled; }

/**
* Returns true if snapping to guides is enabled.
* \see setSnapToGuides()
*/
bool snapToGuides() const { return mSnapToGuides; }

/**
* Sets whether snapping to guides is \a enabled.
* \see snapToGuides()
*/
void setSnapToGuides( bool enabled ) { mSnapToGuides = enabled; }

/**
* Snaps a layout coordinate \a point. If \a point was snapped, \a snapped will be set to true.
*
@@ -108,6 +120,7 @@ class CORE_EXPORT QgsLayoutSnapper

int mTolerance = 5;
bool mSnapToGrid = false;
bool mSnapToGuides = true;

};

@@ -43,6 +43,11 @@ def testGettersSetters(self):
s.setSnapToGrid(True)
self.assertTrue(s.snapToGrid())

s.setSnapToGuides(False)
self.assertFalse(s.snapToGuides())
s.setSnapToGuides(True)
self.assertTrue(s.snapToGuides())

s.setSnapTolerance(15)
self.assertEqual(s.snapTolerance(), 15)

0 comments on commit 6687564

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