Skip to content
Permalink
Browse files

Exclude selected nodes item when snapping during node move

  • Loading branch information
nyalldawson committed Oct 17, 2017
1 parent 938b239 commit 9a08fad506b644521544cd70a9455c3c3bba3ef1
@@ -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;
@@ -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:

@@ -45,6 +45,8 @@ class QgsLayoutViewToolEditNodes : QgsLayoutViewTool

virtual void deactivate();

virtual QList< QgsLayoutItem * > ignoredSnapItems() const;


};

@@ -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 )
{
@@ -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 );
}
}

@@ -22,6 +22,7 @@

class QgsLayoutView;
class QGraphicsLineItem;
class QgsLayoutItem;

/**
* \ingroup gui
@@ -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.
@@ -44,6 +44,11 @@ QgsLayout *QgsLayoutViewTool::layout() const
return mView->currentLayout();
}

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

QgsLayoutViewTool::~QgsLayoutViewTool()
{
mView->unsetTool( this );
@@ -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:

@@ -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;
@@ -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:

0 comments on commit 9a08fad

Please sign in to comment.
You can’t perform that action at this time.