17#include "moc_qgslayoutviewtooleditnodes.cpp"
33 if ( mNodesItem && mNodesItemIndex != -1 )
36 if ( mNodesItem->removeNode( mNodesItemIndex ) )
39 if ( mNodesItem->nodesSize() > 0 )
41 mNodesItemIndex = mNodesItem->selectedNode();
67 if ( event->button() != Qt::LeftButton )
73 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(), event->pos().y(),
74 mMoveContentSearchRadius,
75 mMoveContentSearchRadius );
76 if ( itemsAtCursorPos.isEmpty() )
83 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
92 mNodesItemIndex = index;
94 mMoveContentStartPos =
event->layoutPoint();
98 if ( mNodesItem && mNodesItemIndex != -1 )
101 setSelectedNode( mNodesItem, mNodesItemIndex );
116 if ( mNodesItem && mNodesItemIndex != -1 && event->
layoutPoint() != mMoveContentStartPos )
118 mNodesItem->moveNode( mNodesItemIndex, event->
snappedPoint() );
124 if ( event->button() != Qt::LeftButton || !isMoving )
131 if ( mNodesItemIndex != -1 )
133 if ( event->
layoutPoint() != mMoveContentStartPos )
146 if ( event->button() != Qt::LeftButton )
153 if ( mNodesItemIndex != -1 )
155 mNodesItem =
nullptr;
156 mNodesItemIndex = -1;
161 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(), event->pos().y(),
162 mMoveContentSearchRadius,
163 mMoveContentSearchRadius );
165 if ( itemsAtCursorPos.isEmpty() )
169 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
182 mNodesItemIndex = mNodesItem->nodeAtPosition( event->
layoutPoint() );
194 setSelectedNode( mNodesItem, mNodesItemIndex );
195 mNodesItem->update();
201 if ( mNodesItem && mNodesItemIndex != -1 && ( event->key() == Qt::Key_Left
202 || event->key() == Qt::Key_Right
203 || event->key() == Qt::Key_Up
204 || event->key() == Qt::Key_Down ) )
208 if ( mNodesItem->nodePosition( mNodesItemIndex, currentPos ) )
212 currentPos.setX( currentPos.x() + delta.x() );
213 currentPos.setY( currentPos.y() + delta.y() );
216 mNodesItem->moveNode( mNodesItemIndex, currentPos );
229 displayNodes(
false );
236 QList< QgsLayoutItem * > items;
242void QgsLayoutViewToolEditNodes::displayNodes(
bool display )
244 QList<QgsLayoutNodesItem *> nodesShapes;
249 item->setDisplayNodes( display );
254void QgsLayoutViewToolEditNodes::deselectNodes()
256 QList<QgsLayoutNodesItem *> nodesShapes;
261 item->deselectNode();
266void QgsLayoutViewToolEditNodes::setSelectedNode(
QgsLayoutNodesItem *shape,
int index )
268 QList<QgsLayoutNodesItem *> nodesShapes;
275 item->setSelectedNode( index );
281 item->deselectNode();
bool isLocked() const
Returns true if the item is locked, and cannot be interacted with using the mouse.
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
bool addNode(QPointF point, bool checkArea=true, double radius=10)
Add a node in current shape.
int nodeAtPosition(QPointF point, bool searchInRadius=true, double radius=10) const
Search for the nearest node in the shape within a maximal area.
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.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView.
QPointF snappedPoint() const
Returns the snapped event point location in layout coordinates.
QPointF layoutPoint() const
Returns the event point location in layout coordinates.
A graphical widget to display and interact with QgsLayouts.
QPointF deltaForKeyEvent(QKeyEvent *event)
Returns the delta (in layout coordinates) by which to move items for the given key event.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...