Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Exclude selected nodes item when snapping during node move
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 938b239 commit 9a08fad
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 5 deletions.
5 changes: 4 additions & 1 deletion python/gui/layout/qgslayoutviewmouseevent.sip
Expand Up @@ -39,12 +39,15 @@ class QgsLayoutViewMouseEvent : QMouseEvent
\param snap set to true to snap the point using the layout's snapping settings
%End

void snapPoint( QGraphicsLineItem *horizontalSnapLine = 0, QGraphicsLineItem *verticalSnapLine = 0 );
void snapPoint( QGraphicsLineItem *horizontalSnapLine = 0, QGraphicsLineItem *verticalSnapLine = 0,
const QList<QgsLayoutItem *> &ignoreItems = QList< QgsLayoutItem * >() );
%Docstring
Manually triggers a snap for the mouse event position using the layout's snapper.

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.

The ``ignoreItems`` argument can be used to specify a list of items to avoid snapping to.
%End

QPointF layoutPoint() const;
Expand Down
6 changes: 6 additions & 0 deletions python/gui/layout/qgslayoutviewtool.sip
Expand Up @@ -145,6 +145,12 @@ class QgsLayoutViewTool : QObject
:rtype: QgsLayout
%End

virtual QList< QgsLayoutItem * > ignoredSnapItems() const;
%Docstring
Returns a list of items which should be ignored while snapping events
for this tool.
:rtype: list of QgsLayoutItem
%End

signals:

Expand Down
2 changes: 2 additions & 0 deletions python/gui/layout/qgslayoutviewtooleditnodes.sip
Expand Up @@ -45,6 +45,8 @@ class QgsLayoutViewToolEditNodes : QgsLayoutViewTool

virtual void deactivate();

virtual QList< QgsLayoutItem * > ignoredSnapItems() const;


};

Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutview.cpp
Expand Up @@ -769,7 +769,7 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, false ) );
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
{
me->snapPoint( mHorizontalSnapLine.get(), mVerticalSnapLine.get() );
me->snapPoint( mHorizontalSnapLine.get(), mVerticalSnapLine.get(), mTool->ignoredSnapItems() );
}
if ( mTool->flags() & QgsLayoutViewTool::FlagSnaps )
{
Expand Down
4 changes: 2 additions & 2 deletions src/gui/layout/qgslayoutviewmouseevent.cpp
Expand Up @@ -33,11 +33,11 @@ QgsLayoutViewMouseEvent::QgsLayoutViewMouseEvent( QgsLayoutView *view, QMouseEve
}
}

void QgsLayoutViewMouseEvent::snapPoint( QGraphicsLineItem *horizontalSnapLine, QGraphicsLineItem *verticalSnapLine )
void QgsLayoutViewMouseEvent::snapPoint( QGraphicsLineItem *horizontalSnapLine, QGraphicsLineItem *verticalSnapLine, const QList<QgsLayoutItem *> &excludeItems )
{
if ( mView->currentLayout() )
{
mSnappedPoint = mView->currentLayout()->snapper().snapPoint( mLayoutPoint, mView->transform().m11(), mSnapped, horizontalSnapLine, verticalSnapLine );
mSnappedPoint = mView->currentLayout()->snapper().snapPoint( mLayoutPoint, mView->transform().m11(), mSnapped, horizontalSnapLine, verticalSnapLine, &excludeItems );
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/gui/layout/qgslayoutviewmouseevent.h
Expand Up @@ -22,6 +22,7 @@

class QgsLayoutView;
class QGraphicsLineItem;
class QgsLayoutItem;

/**
* \ingroup gui
Expand Down Expand Up @@ -58,8 +59,11 @@ class GUI_EXPORT QgsLayoutViewMouseEvent : public QMouseEvent
*
* If the \a horizontalSnapLine and \a verticalSnapLine arguments are specified, then the snapper
* will automatically display and position these lines to indicate snapping positions to item bounds.
*
* The \a ignoreItems argument can be used to specify a list of items to avoid snapping to.
*/
void snapPoint( QGraphicsLineItem *horizontalSnapLine = nullptr, QGraphicsLineItem *verticalSnapLine = nullptr );
void snapPoint( QGraphicsLineItem *horizontalSnapLine = nullptr, QGraphicsLineItem *verticalSnapLine = nullptr,
const QList<QgsLayoutItem *> &ignoreItems = QList< QgsLayoutItem * >() );

/**
* Returns the event point location in layout coordinates.
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutviewtool.cpp
Expand Up @@ -44,6 +44,11 @@ QgsLayout *QgsLayoutViewTool::layout() const
return mView->currentLayout();
}

QList<QgsLayoutItem *> QgsLayoutViewTool::ignoredSnapItems() const
{
return QList<QgsLayoutItem *>();
}

QgsLayoutViewTool::~QgsLayoutViewTool()
{
mView->unsetTool( this );
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutviewtool.h
Expand Up @@ -166,6 +166,11 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
*/
QgsLayout *layout() const;

/**
* Returns a list of items which should be ignored while snapping events
* for this tool.
*/
virtual QList< QgsLayoutItem * > ignoredSnapItems() const;

signals:

Expand Down
8 changes: 8 additions & 0 deletions src/gui/layout/qgslayoutviewtooleditnodes.cpp
Expand Up @@ -229,6 +229,14 @@ void QgsLayoutViewToolEditNodes::deactivate()
QgsLayoutViewTool::deactivate();
}

QList<QgsLayoutItem *> QgsLayoutViewToolEditNodes::ignoredSnapItems() const
{
QList< QgsLayoutItem * > items;
if ( mNodesItem )
items << mNodesItem;
return items;
}

void QgsLayoutViewToolEditNodes::displayNodes( bool display )
{
QList<QgsLayoutNodesItem *> nodesShapes;
Expand Down
1 change: 1 addition & 0 deletions src/gui/layout/qgslayoutviewtooleditnodes.h
Expand Up @@ -51,6 +51,7 @@ class GUI_EXPORT QgsLayoutViewToolEditNodes : public QgsLayoutViewTool
void layoutDoubleClickEvent( QgsLayoutViewMouseEvent *event ) override;
void keyPressEvent( QKeyEvent *event ) override;
void deactivate() override;
QList< QgsLayoutItem * > ignoredSnapItems() const override;

private:

Expand Down

0 comments on commit 9a08fad

Please sign in to comment.