QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
30 #include <QGraphicsRectItem>
33 #include <QMouseEvent>
44 mItemMetadataId = metadataId;
49 if ( event->button() == Qt::LeftButton )
56 layout()->addItem( mRubberBand.get() );
65 else if ( event->button() == Qt::RightButton && mRubberBand )
70 mPolygon.remove( mPolygon.count() - 1 );
77 nodesItem->setNodes( mPolygon );
95 moveTemporaryNode( event->
snappedPoint(), event->modifiers() );
114 if ( !mRubberBand || event->isAutoRepeat() )
120 if ( event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace )
122 if ( mPolygon.size() > 2 )
126 setRubberBandNodes();
134 else if ( event->key() == Qt::Key_Escape )
154 void QgsLayoutViewToolAddNodeItem::addNode( QPointF scenePoint )
156 mPolygon.append( scenePoint );
158 if ( mPolygon.size() == 1 )
159 mPolygon.append( scenePoint );
161 setRubberBandNodes();
164 void QgsLayoutViewToolAddNodeItem::moveTemporaryNode( QPointF scenePoint, Qt::KeyboardModifiers modifiers )
166 if ( mPolygon.isEmpty() )
169 if ( mPolygon.size() > 1 && ( modifiers & Qt::ShiftModifier ) )
171 const QPointF start = mPolygon.at( mPolygon.size() - 2 );
172 QLineF newLine = QLineF( start, scenePoint );
176 newLine.setAngle(
angle );
177 scenePoint = newLine.p2();
180 mPolygon.replace( mPolygon.size() - 1, scenePoint );
181 setRubberBandNodes();
184 void QgsLayoutViewToolAddNodeItem::setRubberBandNodes()
186 if ( QGraphicsPolygonItem *polygonItem =
dynamic_cast< QGraphicsPolygonItem *
>( mRubberBand.get() ) )
188 polygonItem->setPolygon( mPolygon );
190 else if ( QGraphicsPathItem *polylineItem =
dynamic_cast< QGraphicsPathItem *
>( mRubberBand.get() ) )
194 path.addPolygon( mPolygon );
195 polylineItem->setPath( path );
201 return mItemMetadataId;
void addLayoutItem(QgsLayoutItem *item)
Adds an item to the layout.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
static double snappedAngle(double angle)
Snaps an angle (in degrees) to its closest 45 degree angle.
Base class for graphical items within a QgsLayout.
QPointF snappedPoint() const
Returns the snapped event point location in layout coordinates.
QgsLayoutItem * createItem(int metadataId, QgsLayout *layout) const
Creates a new instance of a layout item given the item metadata metadataId, target layout.
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
A graphical widget to display and interact with QgsLayouts.
A QgsLayoutViewMouseEvent is the result of a user interaction with the mouse on a QgsLayoutView.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.