32 if ( mNodesItem && mNodesItemIndex != -1 )
35 if ( mNodesItem->removeNode( mNodesItemIndex ) )
38 if ( mNodesItem->nodesSize() > 0 )
40 mNodesItemIndex = mNodesItem->selectedNode();
66 if ( event->button() != Qt::LeftButton )
72 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(),
event->pos().y(),
73 mMoveContentSearchRadius,
74 mMoveContentSearchRadius );
75 if ( itemsAtCursorPos.isEmpty() )
82 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
91 mNodesItemIndex = index;
93 mMoveContentStartPos =
event->layoutPoint();
97 if ( mNodesItem && mNodesItemIndex != -1 )
100 setSelectedNode( mNodesItem, mNodesItemIndex );
115 if ( mNodesItem && mNodesItemIndex != -1 && event->
layoutPoint() != mMoveContentStartPos )
117 mNodesItem->moveNode( mNodesItemIndex, event->
snappedPoint() );
123 if ( event->button() != Qt::LeftButton || !isMoving )
130 if ( mNodesItemIndex != -1 )
132 if ( event->
layoutPoint() != mMoveContentStartPos )
145 if ( event->button() != Qt::LeftButton )
152 if ( mNodesItemIndex != -1 )
154 mNodesItem =
nullptr;
155 mNodesItemIndex = -1;
160 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(),
event->pos().y(),
161 mMoveContentSearchRadius,
162 mMoveContentSearchRadius );
164 if ( itemsAtCursorPos.isEmpty() )
168 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
181 mNodesItemIndex = mNodesItem->nodeAtPosition( event->
layoutPoint() );
193 setSelectedNode( mNodesItem, mNodesItemIndex );
194 mNodesItem->update();
200 if ( mNodesItem && mNodesItemIndex != -1 && ( event->key() == Qt::Key_Left
201 ||
event->key() == Qt::Key_Right
202 ||
event->key() == Qt::Key_Up
203 ||
event->key() == Qt::Key_Down ) )
207 if ( mNodesItem->nodePosition( mNodesItemIndex, currentPos ) )
211 currentPos.setX( currentPos.x() + delta.x() );
212 currentPos.setY( currentPos.y() + delta.y() );
215 mNodesItem->moveNode( mNodesItemIndex, currentPos );
228 displayNodes(
false );
235 QList< QgsLayoutItem * > items;
241 void QgsLayoutViewToolEditNodes::displayNodes(
bool display )
243 QList<QgsLayoutNodesItem *> nodesShapes;
248 item->setDisplayNodes( display );
253 void QgsLayoutViewToolEditNodes::deselectNodes()
255 QList<QgsLayoutNodesItem *> nodesShapes;
260 item->deselectNode();
265 void QgsLayoutViewToolEditNodes::setSelectedNode(
QgsLayoutNodesItem *shape,
int index )
267 QList<QgsLayoutNodesItem *> nodesShapes;
274 item->setSelectedNode( index );
280 item->deselectNode();
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
A graphical widget to display and interact with QgsLayouts.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
QPointF deltaForKeyEvent(QKeyEvent *event)
Returns the delta (in layout coordinates) by which to move items for the given key event...
int nodeAtPosition(QPointF point, bool searchInRadius=true, double radius=10) const
Search for the nearest node in the shape within a maximal area.
void layoutItems(QList< T *> &itemList) const
Returns a list of layout items of a specific type.
void endCommand()
Saves final state of an object and pushes the active command to the undo history. ...
void cancelCommand()
Cancels the active command, discarding it without pushing to the undo history.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView...
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
QPointF layoutPoint() const
Returns the event point location in layout coordinates.
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
bool addNode(QPointF point, bool checkArea=true, double radius=10)
Add a node in current shape.
QPointF snappedPoint() const
Returns the snapped event point location in layout coordinates.