33 , mAnnotation( annotation )
35 setFlag( QGraphicsItem::ItemIsSelectable,
true );
41 connect( mAnnotation, &
QgsAnnotation::moved,
this, &QgsMapCanvasAnnotationItem::setFeatureForMapPosition );
50 connect( mAnnotation, &QgsAnnotation::destroyed,
this, &QgsMapCanvasAnnotationItem::deleteLater );
53 setFeatureForMapPosition();
67 coord = t.transform( coord );
89 void QgsMapCanvasAnnotationItem::updateBoundingRect()
91 prepareGeometryChange();
94 double fillSymbolBleed = mAnnotation && mAnnotation->
fillSymbol() ?
99 mBoundingRect = QRectF( - fillSymbolBleed, -fillSymbolBleed, mAnnotation->
frameSize().width() + fillSymbolBleed * 2, mAnnotation->
frameSize().height() + fillSymbolBleed * 2 );
103 double halfSymbolSize = 0.0;
106 halfSymbolSize = scaledSymbolSize() / 2.0;
111 QSizeF frameSize = mAnnotation ? mAnnotation->
frameSize() : QSizeF( 0.0, 0.0 );
113 double xMinPos = std::min( -halfSymbolSize, offset.x() - fillSymbolBleed );
114 double xMaxPos = std::max( halfSymbolSize, offset.x() + frameSize.width() + fillSymbolBleed );
115 double yMinPos = std::min( -halfSymbolSize, offset.y() - fillSymbolBleed );
116 double yMaxPos = std::max( halfSymbolSize, offset.y() + frameSize.height() + fillSymbolBleed );
117 mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
121 void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
127 else if ( !mAnnotation->
mapLayer() )
137 void QgsMapCanvasAnnotationItem::setFeatureForMapPosition()
153 mapPosition = ct.transform( mapPosition );
159 QgsRectangle searchRect( mapPosition.
x() - halfIdentifyWidth, mapPosition.
y() - halfIdentifyWidth,
160 mapPosition.
x() + halfIdentifyWidth, mapPosition.
y() + halfIdentifyWidth );
171 void QgsMapCanvasAnnotationItem::drawSelectionBoxes( QPainter *p )
const 178 double handlerSize = 10;
179 p->setPen( Qt::NoPen );
180 p->setBrush( QColor( 200, 200, 210, 120 ) );
181 p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.top(), handlerSize, handlerSize ) );
182 p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.top(), handlerSize, handlerSize ) );
183 p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
184 p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
189 QPointF itemPos = mapFromScene( pos );
191 int cursorSensitivity = 7;
194 std::fabs( itemPos.x() ) < cursorSensitivity && std::fabs( itemPos.y() ) < cursorSensitivity )
200 QSizeF frameSize = mAnnotation ? mAnnotation->
frameSize() : QSizeF( 0, 0 );
202 bool left, right, up, down;
203 left = std::fabs( itemPos.x() - offset.x() ) < cursorSensitivity;
204 right = std::fabs( itemPos.x() - ( offset.x() + frameSize.width() ) ) < cursorSensitivity;
205 up = std::fabs( itemPos.y() - offset.y() ) < cursorSensitivity;
206 down = std::fabs( itemPos.y() - ( offset.y() + frameSize.height() ) ) < cursorSensitivity;
212 else if ( right && up )
216 else if ( left && down )
220 else if ( right && down )
242 if ( itemPos.x() >= offset.x() && itemPos.x() <= ( offset.x() + frameSize.width() )
243 && itemPos.y() >= offset.y() && itemPos.y() <= ( offset.y() + frameSize.height() ) )
252 switch ( moveAction )
255 return Qt::ArrowCursor;
258 return Qt::SizeAllCursor;
261 return Qt::SizeVerCursor;
264 return Qt::SizeHorCursor;
267 return Qt::SizeFDiagCursor;
270 return Qt::SizeBDiagCursor;
272 return Qt::ArrowCursor;
276 double QgsMapCanvasAnnotationItem::scaledSymbolSize()
const 288 double dpmm =
mMapCanvas->logicalDpiX() / 25.4;
294 if ( !mAnnotation || !mAnnotation->
isVisible() )
301 mAnnotation->
render( rc );
305 drawSelectionBoxes( painter );
void paint(QPainter *painter) override
function to be implemented by derived classes
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Moving annotation map position.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
Use exact geometry intersection (slower) instead of bounding boxes.
Use antialiasing while drawing.
void mapLayerChanged()
Emitted when the map layer associated with the annotation changes.
bool annotationsVisible() const
Returns true if annotations are visible within the map canvas.
A class to represent a 2D point.
An abstract class for items that can be placed on the map canvas.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QRectF boundingRect() const override
Moving position of frame relative to annotation.
MouseMoveAction moveActionForPosition(QPointF pos) const
Returns the mouse move behavior for a given position in scene coordinates.
Map canvas is a class for displaying all GIS data types on a canvas.
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Abstract base class for annotation items which are drawn over a map.
void updatePosition() override
called on changed extent or resize event to update position of the item
void render(QgsRenderContext &context) const
Renders the annotation to a target render context.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void destinationCrsChanged()
Emitted when map CRS has changed.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
void moved()
Emitted when the annotation's position has changed and items need to be moved to reflect this...
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
MouseMoveAction
Mouse actions for interacting with item.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
Contains information about the context of a rendering operation.
QPointF frameOffsetFromReferencePoint() const
Returns the annotation's frame's offset from the mapPosition() reference point.
QgsMapCanvasAnnotationItem(QgsAnnotation *annotation, QgsMapCanvas *mapCanvas)
Constructor for QgsMapCanvasAnnotationItem.
Qt::CursorShape cursorShapeForAction(MouseMoveAction moveAction) const
Returns matching cursor shape for a mouse move action.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
QgsMapCanvas * mMapCanvas
pointer to map canvas
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Query the layer for features specified in request.
Custom exception class for Coordinate Reference System related exceptions.
bool nextFeature(QgsFeature &f)
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Represents a vector layer which manages a vector based data sets.
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
void layersChanged()
Emitted when a new set of layers has been received.