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(), mMoveContentSearchRadius, mMoveContentSearchRadius );
74 if ( itemsAtCursorPos.isEmpty() )
81 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
90 mNodesItemIndex = index;
92 mMoveContentStartPos =
event->layoutPoint();
96 if ( mNodesItem && mNodesItemIndex != -1 )
99 setSelectedNode( mNodesItem, mNodesItemIndex );
114 if ( mNodesItem && mNodesItemIndex != -1 && event->
layoutPoint() != mMoveContentStartPos )
116 mNodesItem->moveNode( mNodesItemIndex, event->
snappedPoint() );
122 if ( event->button() != Qt::LeftButton || !isMoving )
129 if ( mNodesItemIndex != -1 )
131 if ( event->
layoutPoint() != mMoveContentStartPos )
144 if ( event->button() != Qt::LeftButton )
151 if ( mNodesItemIndex != -1 )
153 mNodesItem =
nullptr;
154 mNodesItemIndex = -1;
159 const QList<QGraphicsItem *> itemsAtCursorPos =
view()->items( event->pos().x(), event->pos().y(), mMoveContentSearchRadius, mMoveContentSearchRadius );
161 if ( itemsAtCursorPos.isEmpty() )
165 for ( QGraphicsItem *graphicsItem : itemsAtCursorPos )
178 mNodesItemIndex = mNodesItem->nodeAtPosition( event->
layoutPoint() );
190 setSelectedNode( mNodesItem, mNodesItemIndex );
191 mNodesItem->update();
197 if ( mNodesItem && mNodesItemIndex != -1 && ( event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up || event->key() == Qt::Key_Down ) )
201 if ( mNodesItem->nodePosition( mNodesItemIndex, currentPos ) )
205 currentPos.setX( currentPos.x() + delta.x() );
206 currentPos.setY( currentPos.y() + delta.y() );
209 mNodesItem->moveNode( mNodesItemIndex, currentPos );
222 displayNodes(
false );
229 QList<QgsLayoutItem *> items;
235void QgsLayoutViewToolEditNodes::displayNodes(
bool display )
237 QList<QgsLayoutNodesItem *> nodesShapes;
242 item->setDisplayNodes( display );
247void QgsLayoutViewToolEditNodes::deselectNodes()
249 QList<QgsLayoutNodesItem *> nodesShapes;
254 item->deselectNode();
259void QgsLayoutViewToolEditNodes::setSelectedNode(
QgsLayoutNodesItem *shape,
int index )
261 QList<QgsLayoutNodesItem *> nodesShapes;
268 item->setSelectedNode( index );
274 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 ...