QGIS API Documentation 3.41.0-Master (d5b93354e9c)
|
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 <qgslayoutsnapper.h>
Public Member Functions | |
QgsLayoutSnapper (QgsLayout *layout) | |
Constructor for QgsLayoutSnapper, attached to the specified layout. | |
QgsLayout * | layout () override |
Returns the layout the object belongs to. | |
bool | readXml (const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context) override |
Sets the snapper's state from a DOM element. | |
void | setSnapToGrid (bool enabled) |
Sets whether snapping to grid is enabled. | |
void | setSnapToGuides (bool enabled) |
Sets whether snapping to guides is enabled. | |
void | setSnapToItems (bool enabled) |
Sets whether snapping to items is enabled. | |
void | setSnapTolerance (int snapTolerance) |
Sets the snap tolerance (in pixels) to use when snapping. | |
QPointF | snapPoint (QPointF point, double scaleFactor, bool &snapped, QGraphicsLineItem *horizontalSnapLine=nullptr, QGraphicsLineItem *verticalSnapLine=nullptr, const QList< QgsLayoutItem * > *ignoreItems=nullptr) const |
Snaps a layout coordinate point. | |
QPointF | snapPointsToGrid (const QList< QPointF > &points, double scaleFactor, bool &snappedX, bool &snappedY) const |
Snaps a set of points to the grid. | |
double | snapPointsToGuides (const QList< double > &points, Qt::Orientation orientation, double scaleFactor, bool &snapped) const |
Snaps a set of points to the guides. | |
double | snapPointsToItems (const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped, QGraphicsLineItem *snapLine=nullptr) const |
Snaps a set of points to the item bounds. | |
QPointF | snapPointToGrid (QPointF point, double scaleFactor, bool &snappedX, bool &snappedY) const |
Snaps a layout coordinate point to the grid. | |
double | snapPointToGuides (double original, Qt::Orientation orientation, double scaleFactor, bool &snapped) const |
Snaps an original layout coordinate to the guides. | |
double | snapPointToItems (double original, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped, QGraphicsLineItem *snapLine=nullptr) const |
Snaps an original layout coordinate to the item bounds. | |
QRectF | snapRect (const QRectF &rect, double scaleFactor, bool &snapped, QGraphicsLineItem *horizontalSnapLine=nullptr, QGraphicsLineItem *verticalSnapLine=nullptr, const QList< QgsLayoutItem * > *ignoreItems=nullptr) const |
Snaps a layout coordinate rect. | |
bool | snapToGrid () const |
Returns true if snapping to grid is enabled. | |
bool | snapToGuides () const |
Returns true if snapping to guides is enabled. | |
bool | snapToItems () const |
Returns true if snapping to items is enabled. | |
int | snapTolerance () const |
Returns the snap tolerance (in pixels) to use when snapping. | |
QString | stringType () const override |
Returns the object type as a string. | |
bool | writeXml (QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const override |
Stores the snapper's state in a DOM element. | |
Public Member Functions inherited from QgsLayoutSerializableObject | |
QgsAbstractLayoutUndoCommand * | createCommand (const QString &text, int id, QUndoCommand *parent=nullptr) override |
Creates a new layout undo command with the specified text and parent. | |
Public Member Functions inherited from QgsLayoutUndoObjectInterface | |
virtual | ~QgsLayoutUndoObjectInterface ()=default |
Friends | |
class | QgsLayoutSnapperUndoCommand |
Manages snapping grids and preset snap lines in a layout, and handles snapping points to the nearest grid coordinate/snap line when possible.
Definition at line 35 of file qgslayoutsnapper.h.
QgsLayoutSnapper::QgsLayoutSnapper | ( | QgsLayout * | layout | ) |
Constructor for QgsLayoutSnapper, attached to the specified layout.
Definition at line 24 of file qgslayoutsnapper.cpp.
|
overridevirtual |
Returns the layout the object belongs to.
Implements QgsLayoutSerializableObject.
Definition at line 31 of file qgslayoutsnapper.cpp.
|
overridevirtual |
Sets the snapper's state from a DOM element.
snapperElement is the DOM node corresponding to the snapper.
Implements QgsLayoutSerializableObject.
Definition at line 434 of file qgslayoutsnapper.cpp.
void QgsLayoutSnapper::setSnapToGrid | ( | bool | enabled | ) |
Sets whether snapping to grid is enabled.
Definition at line 41 of file qgslayoutsnapper.cpp.
void QgsLayoutSnapper::setSnapToGuides | ( | bool | enabled | ) |
Sets whether snapping to guides is enabled.
Definition at line 46 of file qgslayoutsnapper.cpp.
void QgsLayoutSnapper::setSnapToItems | ( | bool | enabled | ) |
Sets whether snapping to items is enabled.
Definition at line 51 of file qgslayoutsnapper.cpp.
void QgsLayoutSnapper::setSnapTolerance | ( | int | snapTolerance | ) |
Sets the snap tolerance (in pixels) to use when snapping.
Definition at line 36 of file qgslayoutsnapper.cpp.
QPointF QgsLayoutSnapper::snapPoint | ( | QPointF | point, |
double | scaleFactor, | ||
bool & | snapped, | ||
QGraphicsLineItem * | horizontalSnapLine = nullptr , |
||
QGraphicsLineItem * | verticalSnapLine = nullptr , |
||
const QList< QgsLayoutItem * > * | ignoreItems = nullptr |
||
) | 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.
Definition at line 56 of file qgslayoutsnapper.cpp.
QPointF QgsLayoutSnapper::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.
Definition at line 195 of file qgslayoutsnapper.cpp.
double QgsLayoutSnapper::snapPointsToGuides | ( | const QList< double > & | points, |
Qt::Orientation | orientation, | ||
double | scaleFactor, | ||
bool & | snapped | ||
) | const |
Snaps a set of points to the guides.
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 snapToGuides() 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 a guide.
Definition at line 269 of file qgslayoutsnapper.cpp.
double QgsLayoutSnapper::snapPointsToItems | ( | const QList< double > & | points, |
Qt::Orientation | orientation, | ||
double | scaleFactor, | ||
const QList< QgsLayoutItem * > & | ignoreItems, | ||
bool & | snapped, | ||
QGraphicsLineItem * | snapLine = nullptr |
||
) | const |
Snaps a set of points to the item bounds.
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 snapToItems() 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 an item bound.
Definition at line 316 of file qgslayoutsnapper.cpp.
QPointF QgsLayoutSnapper::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.
Definition at line 189 of file qgslayoutsnapper.cpp.
double QgsLayoutSnapper::snapPointToGuides | ( | double | original, |
Qt::Orientation | orientation, | ||
double | scaleFactor, | ||
bool & | snapped | ||
) | const |
Snaps an original layout coordinate to the guides.
If the 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.
If snapToGuides() is disabled, this method will return the point unchanged.
Definition at line 263 of file qgslayoutsnapper.cpp.
double QgsLayoutSnapper::snapPointToItems | ( | double | original, |
Qt::Orientation | orientation, | ||
double | scaleFactor, | ||
const QList< QgsLayoutItem * > & | ignoreItems, | ||
bool & | snapped, | ||
QGraphicsLineItem * | snapLine = nullptr |
||
) | const |
Snaps an original layout coordinate to the item bounds.
If the 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.
If snapToItems() is disabled, this method will return the point unchanged.
A list of items to ignore during the snapping can be specified via the ignoreItems list.
If snapLine is specified, the snapper will automatically show (or hide) the snap line based on the result of the snap, and position it at the correct location for the snap.
Definition at line 309 of file qgslayoutsnapper.cpp.
QRectF QgsLayoutSnapper::snapRect | ( | const QRectF & | rect, |
double | scaleFactor, | ||
bool & | snapped, | ||
QGraphicsLineItem * | horizontalSnapLine = nullptr , |
||
QGraphicsLineItem * | verticalSnapLine = nullptr , |
||
const QList< QgsLayoutItem * > * | ignoreItems = nullptr |
||
) | 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.
Definition at line 119 of file qgslayoutsnapper.cpp.
|
inline |
Returns true
if snapping to grid is enabled.
Definition at line 64 of file qgslayoutsnapper.h.
|
inline |
Returns true
if snapping to guides is enabled.
Definition at line 76 of file qgslayoutsnapper.h.
|
inline |
Returns true
if snapping to items is enabled.
Definition at line 88 of file qgslayoutsnapper.h.
|
inline |
Returns the snap tolerance (in pixels) to use when snapping.
Definition at line 58 of file qgslayoutsnapper.h.
|
inlineoverridevirtual |
Returns the object type as a string.
This string must be a unique, single word, character only representation of the item type, eg "LayoutScaleBar"
Implements QgsLayoutSerializableObject.
Definition at line 45 of file qgslayoutsnapper.h.
|
overridevirtual |
Stores the snapper's state in a DOM element.
The parentElement should refer to the parent layout's DOM element.
Implements QgsLayoutSerializableObject.
Definition at line 421 of file qgslayoutsnapper.cpp.
|
friend |
Definition at line 272 of file qgslayoutsnapper.h.