27 #include "qgssettings.h"
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 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;
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.
QgsLayoutItem * createItem(int metadataId, QgsLayout *layout) const
Creates a new instance of a layout item given the item metadata metadataId, target layout.
Base class for graphical items within a QgsLayout.
An abstract layout item that provides generic methods for node based shapes such as polygon or polyli...
static double snappedAngle(double angle)
Snaps an angle (in degrees) to its closest 45 degree angle.
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.
A graphical widget to display and interact with QgsLayouts.
void setSelectedItem(QgsLayoutItem *item)
Clears any selected items and sets item as the current selection.
void addLayoutItem(QgsLayoutItem *item)
Adds an item to the layout.
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)