Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix item snapping while resizing
  • Loading branch information
nyalldawson committed Oct 6, 2017
1 parent 6289367 commit d65a18c
Show file tree
Hide file tree
Showing 5 changed files with 603 additions and 80 deletions.
87 changes: 87 additions & 0 deletions python/core/layout/qgslayoutsnapper.sip
Expand Up @@ -98,9 +98,35 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject
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.

.. seealso:: snapRect()
:rtype: QPointF
%End

QRectF snapRect( const QRectF &rect, double scaleFactor, bool &snapped /Out/, QGraphicsLineItem *horizontalSnapLine = 0,
QGraphicsLineItem *verticalSnapLine = 0,
const QList< QgsLayoutItem * > *ignoreItems = 0 ) const;
%Docstring
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.

.. seealso:: snapPoint()
:rtype: QRectF
%End

QPointF snapPointToGrid( QPointF point, double scaleFactor, bool &snappedX /Out/, bool &snappedY /Out/ ) const;
%Docstring
Snaps a layout coordinate ``point`` to the grid. If ``point``
Expand All @@ -113,6 +139,26 @@ class QgsLayoutSnapper: QgsLayoutSerializableObject

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

.. seealso:: snapPointsToGrid()
:rtype: QPointF
%End

QPointF snapPointsToGrid( const QList< QPointF > &points, double scaleFactor, bool &snappedX /Out/, bool &snappedY /Out/ ) const;
%Docstring
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.

.. seealso:: snapPointToGrid()
:rtype: QPointF
%End

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

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

.. seealso:: snapPointsToGuides()
:rtype: float
%End

double snapPointsToGuides( const QList< double > &points, QgsLayoutGuide::Orientation orientation, double scaleFactor, bool &snapped /Out/ ) const;
%Docstring
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.

.. seealso:: snapPointToGuides()
:rtype: float
%End

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

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.

.. seealso:: snapPointsToItems()
:rtype: float
%End

double snapPointsToItems( const QList< double > &points, Qt::Orientation orientation, double scaleFactor, const QList< QgsLayoutItem * > &ignoreItems, bool &snapped /Out/,
QGraphicsLineItem *snapLine = 0 ) const;
%Docstring
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.

.. seealso:: snapPointToItems()
:rtype: float
%End

Expand Down

0 comments on commit d65a18c

Please sign in to comment.