Skip to content

Commit d65a18c

Browse files
committed
Fix item snapping while resizing
1 parent 6289367 commit d65a18c

File tree

5 files changed

+603
-80
lines changed

5 files changed

+603
-80
lines changed

python/core/layout/qgslayoutsnapper.sip

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,35 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject
9898
will automatically display and position these lines to indicate snapping positions to item bounds.
9999

100100
A list of items to ignore during the snapping can be specified via the ``ignoreItems`` list.
101+
102+
.. seealso:: snapRect()
101103
:rtype: QPointF
102104
%End
103105

106+
QRectF snapRect( const QRectF &rect, double scaleFactor, bool &snapped /Out/, QGraphicsLineItem *horizontalSnapLine = 0,
107+
QGraphicsLineItem *verticalSnapLine = 0,
108+
const QList< QgsLayoutItem * > *ignoreItems = 0 ) const;
109+
%Docstring
110+
Snaps a layout coordinate ``rect``. If ``rect`` was snapped, ``snapped`` will be set to true.
111+
112+
Snapping occurs by moving the rectangle alone. The rectangle will not be resized
113+
as a result of the snap operation.
114+
115+
The ``scaleFactor`` argument should be set to the transformation from
116+
scalar transform from layout coordinates to pixels, i.e. the
117+
graphics view transform().m11() value.
118+
119+
This method considers snapping to the grid, snap lines, etc.
120+
121+
If the ``horizontalSnapLine`` and ``verticalSnapLine`` arguments are specified, then the snapper
122+
will automatically display and position these lines to indicate snapping positions to item bounds.
123+
124+
A list of items to ignore during the snapping can be specified via the ``ignoreItems`` list.
125+
126+
.. seealso:: snapPoint()
127+
:rtype: QRectF
128+
%End
129+
104130
QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX /Out/, bool &snappedY /Out/ ) const;
105131
%Docstring
106132
Snaps a layout coordinate ``point`` to the grid. If ``point``
@@ -113,6 +139,26 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject
113139

114140
If snapToGrid() is disabled, this method will return the point
115141
unchanged.
142+
143+
.. seealso:: snapPointsToGrid()
144+
:rtype: QPointF
145+
%End
146+
147+
QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX /Out/, bool &snappedY /Out/ ) const;
148+
%Docstring
149+
Snaps a set of ``points`` to the grid. If the points
150+
were snapped, ``snapped`` will be set to true.
151+
152+
The ``scaleFactor`` argument should be set to the transformation from
153+
scalar transform from layout coordinates to pixels, i.e. the
154+
graphics view transform().m11() value.
155+
156+
If snapToGrid() is disabled, this method will not attempt to snap the points.
157+
158+
The returned value is the smallest delta which the points need to be shifted by in order to align
159+
one of the points to the grid.
160+
161+
.. seealso:: snapPointToGrid()
116162
:rtype: QPointF
117163
%End
118164

@@ -127,6 +173,26 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject
127173

128174
If snapToGuides() is disabled, this method will return the point
129175
unchanged.
176+
177+
.. seealso:: snapPointsToGuides()
178+
:rtype: float
179+
%End
180+
181+
double snapPointsToGuides( const QList< double > &points, QgsLayoutGuide::Orientation orientation, double scaleFactor, bool &snapped /Out/ ) const;
182+
%Docstring
183+
Snaps a set of ``points`` to the guides. If the points
184+
were snapped, ``snapped`` will be set to true.
185+
186+
The ``scaleFactor`` argument should be set to the transformation from
187+
scalar transform from layout coordinates to pixels, i.e. the
188+
graphics view transform().m11() value.
189+
190+
If snapToGuides() is disabled, this method will not attempt to snap the points.
191+
192+
The returned value is the smallest delta which the points need to be shifted by in order to align
193+
one of the points to a guide.
194+
195+
.. seealso:: snapPointToGuides()
130196
:rtype: float
131197
%End
132198

@@ -147,6 +213,27 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject
147213

148214
If ``snapLine`` is specified, the snapper will automatically show (or hide) the snap line
149215
based on the result of the snap, and position it at the correct location for the snap.
216+
217+
.. seealso:: snapPointsToItems()
218+
:rtype: float
219+
%End
220+
221+
double snapPointsToItems( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped /Out/,
222+
QGraphicsLineItem *snapLine = 0 ) const;
223+
%Docstring
224+
Snaps a set of ``points`` to the item bounds. If the points
225+
were snapped, ``snapped`` will be set to true.
226+
227+
The ``scaleFactor`` argument should be set to the transformation from
228+
scalar transform from layout coordinates to pixels, i.e. the
229+
graphics view transform().m11() value.
230+
231+
If snapToItems() is disabled, this method will not attempt to snap the points.
232+
233+
The returned value is the smallest delta which the points need to be shifted by in order to align
234+
one of the points to an item bound.
235+
236+
.. seealso:: snapPointToItems()
150237
:rtype: float
151238
%End
152239

0 commit comments

Comments
 (0)