mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Hook up snap to guides menu option
This commit is contained in:
parent
9267f8676c
commit
66875641a3
@ -50,6 +50,19 @@ class QgsLayoutSnapper
|
|||||||
%Docstring
|
%Docstring
|
||||||
Sets whether snapping to grid is ``enabled``.
|
Sets whether snapping to grid is ``enabled``.
|
||||||
.. seealso:: snapToGrid()
|
.. 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
|
%End
|
||||||
|
|
||||||
QPointF snapPoint( QPointF point, double scaleFactor, bool &snapped /Out/ ) const;
|
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( mActionSnapGrid, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGrid );
|
||||||
|
|
||||||
connect( mActionShowGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGuides );
|
connect( mActionShowGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::showGuides );
|
||||||
|
connect( mActionSnapGuides, &QAction::triggered, this, &QgsLayoutDesignerDialog::snapToGuides );
|
||||||
|
|
||||||
mView = new QgsLayoutView();
|
mView = new QgsLayoutView();
|
||||||
//mView->setMapCanvas( mQgis->mapCanvas() );
|
//mView->setMapCanvas( mQgis->mapCanvas() );
|
||||||
@ -314,6 +315,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
|
|||||||
mActionShowGrid->setChecked( mLayout->context().gridVisible() );
|
mActionShowGrid->setChecked( mLayout->context().gridVisible() );
|
||||||
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
|
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );
|
||||||
mActionShowGuides->setChecked( mLayout->guides().visible() );
|
mActionShowGuides->setChecked( mLayout->guides().visible() );
|
||||||
|
mActionSnapGuides->setChecked( mLayout->snapper().snapToGuides() );
|
||||||
|
|
||||||
createLayoutPropertiesWidget();
|
createLayoutPropertiesWidget();
|
||||||
}
|
}
|
||||||
@ -406,7 +408,7 @@ void QgsLayoutDesignerDialog::showGuides( bool visible )
|
|||||||
|
|
||||||
void QgsLayoutDesignerDialog::snapToGuides( bool enabled )
|
void QgsLayoutDesignerDialog::snapToGuides( bool enabled )
|
||||||
{
|
{
|
||||||
|
mLayout->snapper().setSnapToGuides( enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
|
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
|
double QgsLayoutSnapper::snapPointToGuides( double original, QgsLayoutGuide::Orientation orientation, double scaleFactor, bool &snapped ) const
|
||||||
{
|
{
|
||||||
snapped = false;
|
snapped = false;
|
||||||
|
if ( !mLayout || !mSnapToGuides )
|
||||||
|
{
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
|
||||||
//convert snap tolerance from pixels to layout units
|
//convert snap tolerance from pixels to layout units
|
||||||
double alignThreshold = mTolerance / scaleFactor;
|
double alignThreshold = mTolerance / scaleFactor;
|
||||||
|
@ -65,6 +65,18 @@ class CORE_EXPORT QgsLayoutSnapper
|
|||||||
*/
|
*/
|
||||||
void setSnapToGrid( bool enabled ) { mSnapToGrid = enabled; }
|
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.
|
* 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;
|
int mTolerance = 5;
|
||||||
bool mSnapToGrid = false;
|
bool mSnapToGrid = false;
|
||||||
|
bool mSnapToGuides = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,6 +43,11 @@ class TestQgsLayoutSnapper(unittest.TestCase):
|
|||||||
s.setSnapToGrid(True)
|
s.setSnapToGrid(True)
|
||||||
self.assertTrue(s.snapToGrid())
|
self.assertTrue(s.snapToGrid())
|
||||||
|
|
||||||
|
s.setSnapToGuides(False)
|
||||||
|
self.assertFalse(s.snapToGuides())
|
||||||
|
s.setSnapToGuides(True)
|
||||||
|
self.assertTrue(s.snapToGuides())
|
||||||
|
|
||||||
s.setSnapTolerance(15)
|
s.setSnapTolerance(15)
|
||||||
self.assertEqual(s.snapTolerance(), 15)
|
self.assertEqual(s.snapTolerance(), 15)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user