QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
Public Member Functions | List of all members
QgsModelSnapper Class Reference

Manages snapping grids and preset snap lines in a layout, and handles snapping points to the nearest grid coordinate/snap line when possible. More...

#include <qgsmodelsnapper.h>

Public Member Functions

 QgsModelSnapper ()
 Constructor for QgsModelSnapper, attached to the specified layout. More...
 
void setSnapToGrid (bool enabled)
 Sets whether snapping to grid is enabled. More...
 
void setSnapTolerance (int snapTolerance)
 Sets the snap tolerance (in pixels) to use when snapping. More...
 
QPointF snapPoint (QPointF point, double scaleFactor, bool &snapped, bool snapHorizontal=true, bool snapVertical=true) const
 Snaps a layout coordinate point. More...
 
QPointF snapPointsToGrid (const QList< QPointF > &points, double scaleFactor, bool &snappedX, bool &snappedY) const
 Snaps a set of points to the grid. More...
 
QPointF snapPointToGrid (QPointF point, double scaleFactor, bool &snappedX, bool &snappedY) const
 Snaps a layout coordinate point to the grid. More...
 
QRectF snapRect (const QRectF &rect, double scaleFactor, bool &snapped, bool snapHorizontal=true, bool snapVertical=true) const
 Snaps a layout coordinate rect. More...
 
QRectF snapRectWithResize (const QRectF &rect, double scaleFactor, bool &snapped, bool snapHorizontal=true, bool snapVertical=true) const
 Snaps a layout coordinate rect. More...
 
bool snapToGrid () const
 Returns true if snapping to grid is enabled. More...
 
int snapTolerance () const
 Returns the snap tolerance (in pixels) to use when snapping. More...
 

Detailed Description

Manages snapping grids and preset snap lines in a layout, and handles snapping points to the nearest grid coordinate/snap line when possible.

Since
QGIS 3.14

Definition at line 33 of file qgsmodelsnapper.h.

Constructor & Destructor Documentation

◆ QgsModelSnapper()

QgsModelSnapper::QgsModelSnapper ( )

Constructor for QgsModelSnapper, attached to the specified layout.

Definition at line 21 of file qgsmodelsnapper.cpp.

Member Function Documentation

◆ setSnapToGrid()

void QgsModelSnapper::setSnapToGrid ( bool  enabled)

Sets whether snapping to grid is enabled.

See also
snapToGrid()

Definition at line 32 of file qgsmodelsnapper.cpp.

◆ setSnapTolerance()

void QgsModelSnapper::setSnapTolerance ( int  snapTolerance)

Sets the snap tolerance (in pixels) to use when snapping.

See also
snapTolerance()

Definition at line 27 of file qgsmodelsnapper.cpp.

◆ snapPoint()

QPointF QgsModelSnapper::snapPoint ( QPointF  point,
double  scaleFactor,
bool &  snapped,
bool  snapHorizontal = true,
bool  snapVertical = true 
) const

Snaps a layout coordinate point.

If point was snapped, snapped will be set to true.

The scaleFactor argument should be set to the transformation from scalar transform from layout coordinates to pixels, i.e. the graphics view transform().m11() value.

This method considers snapping to the grid, snap lines, etc.

If the horizontalSnapLine and verticalSnapLine arguments are specified, then the snapper will automatically display and position these lines to indicate snapping positions to item bounds.

A list of items to ignore during the snapping can be specified via the ignoreItems list.

See also
snapRect()

Definition at line 37 of file qgsmodelsnapper.cpp.

◆ snapPointsToGrid()

QPointF QgsModelSnapper::snapPointsToGrid ( const QList< QPointF > &  points,
double  scaleFactor,
bool &  snappedX,
bool &  snappedY 
) const

Snaps a set of points to the grid.

If the points were snapped, snapped will be set to true.

The scaleFactor argument should be set to the transformation from scalar transform from layout coordinates to pixels, i.e. the graphics view transform().m11() value.

If snapToGrid() is disabled, this method will not attempt to snap the points.

The returned value is the smallest delta which the points need to be shifted by in order to align one of the points to the grid.

See also
snapPointToGrid()

Definition at line 121 of file qgsmodelsnapper.cpp.

◆ snapPointToGrid()

QPointF QgsModelSnapper::snapPointToGrid ( QPointF  point,
double  scaleFactor,
bool &  snappedX,
bool &  snappedY 
) const

Snaps a layout coordinate point to the grid.

If point was snapped horizontally, snappedX will be set to true. If point was snapped vertically, snappedY will be set to true.

The scaleFactor argument should be set to the transformation from scalar transform from layout coordinates to pixels, i.e. the graphics view transform().m11() value.

If snapToGrid() is disabled, this method will return the point unchanged.

See also
snapPointsToGrid()

Definition at line 115 of file qgsmodelsnapper.cpp.

◆ snapRect()

QRectF QgsModelSnapper::snapRect ( const QRectF &  rect,
double  scaleFactor,
bool &  snapped,
bool  snapHorizontal = true,
bool  snapVertical = true 
) const

Snaps a layout coordinate rect.

If rect was snapped, snapped will be set to true.

Snapping occurs by moving the rectangle alone. The rectangle will not be resized as a result of the snap operation.

The scaleFactor argument should be set to the transformation from scalar transform from layout coordinates to pixels, i.e. the graphics view transform().m11() value.

This method considers snapping to the grid, snap lines, etc.

If the horizontalSnapLine and verticalSnapLine arguments are specified, then the snapper will automatically display and position these lines to indicate snapping positions to item bounds.

A list of items to ignore during the snapping can be specified via the ignoreItems list.

See also
snapPoint()

Definition at line 58 of file qgsmodelsnapper.cpp.

◆ snapRectWithResize()

QRectF QgsModelSnapper::snapRectWithResize ( const QRectF &  rect,
double  scaleFactor,
bool &  snapped,
bool  snapHorizontal = true,
bool  snapVertical = true 
) const

Snaps a layout coordinate rect.

If rect was snapped, snapped will be set to true.

The scaleFactor argument should be set to the transformation from scalar transform from layout coordinates to pixels, i.e. the graphics view transform().m11() value.

This method considers snapping to the grid, snap lines, etc.

If the horizontalSnapLine and verticalSnapLine arguments are specified, then the snapper will automatically display and position these lines to indicate snapping positions to item bounds.

A list of items to ignore during the snapping can be specified via the ignoreItems list.

See also
snapPoint()

Definition at line 82 of file qgsmodelsnapper.cpp.

◆ snapToGrid()

bool QgsModelSnapper::snapToGrid ( ) const
inline

Returns true if snapping to grid is enabled.

See also
setSnapToGrid()

Definition at line 59 of file qgsmodelsnapper.h.

◆ snapTolerance()

int QgsModelSnapper::snapTolerance ( ) const
inline

Returns the snap tolerance (in pixels) to use when snapping.

See also
setSnapTolerance()

Definition at line 53 of file qgsmodelsnapper.h.


The documentation for this class was generated from the following files: