36   , mAnnotation( annotation )
 
   38   setFlag( QGraphicsItem::ItemIsSelectable, 
true );
 
   44   connect( mAnnotation, &
QgsAnnotation::moved, 
this, &QgsMapCanvasAnnotationItem::setFeatureForMapPosition );
 
   53   connect( mAnnotation, &QgsAnnotation::destroyed, 
this, &QgsMapCanvasAnnotationItem::annotationDeleted );
 
   56   setFeatureForMapPosition();
 
   92 void QgsMapCanvasAnnotationItem::updateBoundingRect()
 
   94   prepareGeometryChange();
 
   97   double fillSymbolBleed = mAnnotation && mAnnotation->
fillSymbol() ?
 
  100   const double mmToPixelScale = 
mMapCanvas->logicalDpiX() / 25.4;
 
  104     mBoundingRect = QRectF( - fillSymbolBleed, -fillSymbolBleed,
 
  105                             mmToPixelScale * mAnnotation->
frameSizeMm().width() + fillSymbolBleed * 2,
 
  106                             mmToPixelScale * mAnnotation->
frameSizeMm().height() + fillSymbolBleed * 2 );
 
  110     double halfSymbolSize = 0.0;
 
  113       halfSymbolSize = scaledSymbolSize() / 2.0;
 
  119     QSizeF frameSize = mAnnotation ? QSizeF( mAnnotation->
frameSizeMm().width() * mmToPixelScale,
 
  120                        mAnnotation->
frameSizeMm().height() * mmToPixelScale ) : QSizeF( 0.0, 0.0 );
 
  122     double xMinPos = std::min( -halfSymbolSize, offset.x() - fillSymbolBleed );
 
  123     double xMaxPos = std::max( halfSymbolSize, offset.x() + frameSize.width() + fillSymbolBleed );
 
  124     double yMinPos = std::min( -halfSymbolSize, offset.y() - fillSymbolBleed );
 
  125     double yMaxPos = std::max( halfSymbolSize, offset.y() + frameSize.height() + fillSymbolBleed );
 
  126     mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
 
  130 void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
 
  138   else if ( !mAnnotation->
mapLayer() )
 
  148 void QgsMapCanvasAnnotationItem::setFeatureForMapPosition()
 
  164       mapPosition = ct.transform( mapPosition );
 
  170   QgsRectangle searchRect( mapPosition.
x() - halfIdentifyWidth, mapPosition.
y() - halfIdentifyWidth,
 
  171                            mapPosition.
x() + halfIdentifyWidth, mapPosition.
y() + halfIdentifyWidth );
 
  182 void QgsMapCanvasAnnotationItem::annotationDeleted()
 
  184   mAnnotation = 
nullptr;
 
  188 void QgsMapCanvasAnnotationItem::drawSelectionBoxes( QPainter *p )
 const 
  195   double handlerSize = 10;
 
  196   p->setPen( Qt::NoPen );
 
  197   p->setBrush( QColor( 200, 200, 210, 120 ) );
 
  198   p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.top(), handlerSize, handlerSize ) );
 
  199   p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.top(), handlerSize, handlerSize ) );
 
  200   p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
 
  201   p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
 
  206   QPointF itemPos = mapFromScene( pos );
 
  208   int cursorSensitivity = 7;
 
  211        std::fabs( itemPos.x() ) < cursorSensitivity && std::fabs( itemPos.y() ) < cursorSensitivity ) 
 
  216   const double mmToPixelScale = 
mMapCanvas->logicalDpiX() / 25.4;
 
  219   QSizeF frameSize = mAnnotation ? mAnnotation->
frameSizeMm() * mmToPixelScale : QSizeF( 0, 0 );
 
  221   bool left, right, up, down;
 
  222   left = std::fabs( itemPos.x() - offset.x() ) < cursorSensitivity;
 
  223   right = std::fabs( itemPos.x() - ( offset.x() + frameSize.width() ) ) < cursorSensitivity;
 
  224   up = std::fabs( itemPos.y() - offset.y() ) < cursorSensitivity;
 
  225   down = std::fabs( itemPos.y() - ( offset.y() + frameSize.height() ) ) < cursorSensitivity;
 
  231   else if ( right && up )
 
  235   else if ( left && down )
 
  239   else if ( right && down )
 
  261   if ( itemPos.x() >= offset.x() && itemPos.x() <= ( offset.x() + frameSize.width() )
 
  262        && itemPos.y() >= offset.y() && itemPos.y() <= ( offset.y() + frameSize.height() ) )
 
  271   switch ( moveAction )
 
  274       return Qt::ArrowCursor;
 
  277       return Qt::SizeAllCursor;
 
  280       return Qt::SizeVerCursor;
 
  283       return Qt::SizeHorCursor;
 
  286       return Qt::SizeFDiagCursor;
 
  289       return Qt::SizeBDiagCursor;
 
  291       return Qt::ArrowCursor;
 
  295 double QgsMapCanvasAnnotationItem::scaledSymbolSize()
 const 
  307   double dpmm = 
mMapCanvas->logicalDpiX() / 25.4;
 
  313   if ( !mAnnotation || !mAnnotation->
isVisible() )
 
  320     mAnnotation->
render( rc );
 
  324     drawSelectionBoxes( painter );
 
Abstract base class for annotation items which are drawn over a map.
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
QPointF frameOffsetFromReferencePointMm() const
Returns the annotation's frame's offset (in millimeters) from the mapPosition() reference point.
void moved()
Emitted when the annotation's position has changed and items need to be moved to reflect this.
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
virtual void setAssociatedFeature(const QgsFeature &feature)
Sets the feature associated with the annotation.
void render(QgsRenderContext &context) const
Renders the annotation to a target render context.
bool isVisible() const
Returns true if the annotation is visible and should be rendered.
QgsFillSymbol * fillSymbol() const
Returns the symbol that is used for rendering the annotation frame.
QSizeF frameSizeMm() const
Returns the size (in millimeters) of the annotation's frame (the main area in which the annotation's ...
QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position.
void mapLayerChanged()
Emitted when the map layer associated with the annotation changes.
Custom exception class for Coordinate Reference System related exceptions.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsMapCanvasAnnotationItem(QgsAnnotation *annotation, QgsMapCanvas *mapCanvas)
Constructor for QgsMapCanvasAnnotationItem.
MouseMoveAction moveActionForPosition(QPointF pos) const
Returns the mouse move behavior for a given position in scene coordinates.
Qt::CursorShape cursorShapeForAction(MouseMoveAction moveAction) const
Returns matching cursor shape for a mouse move action.
void paint(QPainter *painter) override
function to be implemented by derived classes
QRectF boundingRect() const override
void updatePosition() override
called on changed extent or resize event to update position of the item
MouseMoveAction
Mouse actions for interacting with item.
@ ResizeFrameRight
Resize frame right.
@ ResizeFrameRightUp
Resize frame right up.
@ MoveFramePosition
Moving position of frame relative to annotation.
@ ResizeFrameUp
Resize frame up.
@ ResizeFrameRightDown
Resize frame right down.
@ MoveMapPosition
Moving annotation map position.
@ ResizeFrameDown
Resize frame down.
@ ResizeFrameLeftUp
Resize frame left up.
@ ResizeFrameLeft
Resize frame left.
@ ResizeFrameLeftDown
Resize frame left down.
An abstract class for items that can be placed on the map canvas.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
Map canvas is a class for displaying all GIS data types on a canvas.
void destinationCrsChanged()
Emitted when map CRS has changed.
void layersChanged()
Emitted when a new set of layers has been received.
bool annotationsVisible() const
Returns true if annotations are visible within the map canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QList< QgsMapLayer * > layers() const
Returns the list of layers which will be rendered in the map.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
A class to represent a 2D point.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
@ Antialiasing
Use antialiasing while drawing.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.