24#include "moc_qgslayoutviewtooleditnodes.cpp"
35 if ( mNodesItem && mNodesItemIndex != -1 )
38 if ( mNodesItem->removeNode( mNodesItemIndex ) )
41 if ( mNodesItem->nodesSize() > 0 )
43 mNodesItemIndex = mNodesItem->selectedNode();
69 if ( event->button() != Qt::LeftButton )
75 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(), event->pos().y(), mMoveContentSearchRadius, 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(), mMoveContentSearchRadius, mMoveContentSearchRadius );
163 if ( itemsAtCursorPos.isEmpty() )
167 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
192 setSelectedNode( mNodesItem, mNodesItemIndex );
193 mNodesItem->update();
199 if ( mNodesItem && mNodesItemIndex != -1 && ( event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up || event->key() == Qt::Key_Down ) )
203 if ( mNodesItem->nodePosition( mNodesItemIndex, currentPos ) )
207 currentPos.setX( currentPos.x() + delta.x() );
208 currentPos.setY( currentPos.y() + delta.y() );
211 mNodesItem->moveNode( mNodesItemIndex, currentPos );
224 displayNodes(
false );
231 QList<QgsLayoutItem *> items;
237void QgsLayoutViewToolEditNodes::displayNodes(
bool display )
239 QList<QgsLayoutNodesItem *> nodesShapes;
244 item->setDisplayNodes( display );
249void QgsLayoutViewToolEditNodes::deselectNodes()
251 QList<QgsLayoutNodesItem *> nodesShapes;
254 for ( QgsLayoutNodesItem *item : std::as_const( nodesShapes ) )
256 item->deselectNode();
261void QgsLayoutViewToolEditNodes::setSelectedNode(
QgsLayoutNodesItem *shape,
int index )
263 QList<QgsLayoutNodesItem *> nodesShapes;
266 for ( QgsLayoutNodesItem *item : std::as_const( nodesShapes ) )
270 item->setSelectedNode( index );
276 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 mouse event which is the result of a user interaction with 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 ...