19#include "moc_qgsmapcanvasannotationitem.cpp" 
   37  , mAnnotation( annotation )
 
   39  setFlag( QGraphicsItem::ItemIsSelectable, 
true );
 
   45  connect( mAnnotation, &
QgsAnnotation::moved, 
this, &QgsMapCanvasAnnotationItem::setFeatureForMapPosition );
 
   54  connect( mAnnotation, &QgsAnnotation::destroyed, 
this, &QgsMapCanvasAnnotationItem::annotationDeleted );
 
   57  setFeatureForMapPosition();
 
 
   93void QgsMapCanvasAnnotationItem::updateBoundingRect()
 
   95  prepareGeometryChange();
 
  100  const double mmToPixelScale = 
mMapCanvas->physicalDpiX() / 25.4;
 
  104    mBoundingRect = QRectF( -fillSymbolBleed, -fillSymbolBleed, mmToPixelScale * mAnnotation->
frameSizeMm().width() + fillSymbolBleed * 2, mmToPixelScale * mAnnotation->
frameSizeMm().height() + fillSymbolBleed * 2 );
 
  108    double halfSymbolSize = 0.0;
 
  111      halfSymbolSize = scaledSymbolSize() / 2.0;
 
  116    const QSizeF frameSize = mAnnotation ? QSizeF( mAnnotation->
frameSizeMm().width() * mmToPixelScale, mAnnotation->
frameSizeMm().height() * mmToPixelScale ) : QSizeF( 0.0, 0.0 );
 
  118    const double xMinPos = std::min( -halfSymbolSize, offset.x() - fillSymbolBleed );
 
  119    const double xMaxPos = std::max( halfSymbolSize, offset.x() + frameSize.width() + fillSymbolBleed );
 
  120    const double yMinPos = std::min( -halfSymbolSize, offset.y() - fillSymbolBleed );
 
  121    const double yMaxPos = std::max( halfSymbolSize, offset.y() + frameSize.height() + fillSymbolBleed );
 
  122    mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
 
  126void QgsMapCanvasAnnotationItem::onCanvasLayersChanged()
 
  134  else if ( !mAnnotation->
mapLayer() )
 
  144void QgsMapCanvasAnnotationItem::setFeatureForMapPosition()
 
  160      mapPosition = ct.transform( mapPosition );
 
  166  QgsRectangle searchRect( mapPosition.
x() - halfIdentifyWidth, mapPosition.
y() - halfIdentifyWidth, mapPosition.
x() + halfIdentifyWidth, mapPosition.
y() + halfIdentifyWidth );
 
  177void QgsMapCanvasAnnotationItem::annotationDeleted()
 
  179  mAnnotation = 
nullptr;
 
  183void QgsMapCanvasAnnotationItem::drawSelectionBoxes( QPainter *p )
 const 
  190  const double handlerSize = 10;
 
  191  p->setPen( Qt::NoPen );
 
  192  p->setBrush( QColor( 200, 200, 210, 120 ) );
 
  193  p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.top(), handlerSize, handlerSize ) );
 
  194  p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.top(), handlerSize, handlerSize ) );
 
  195  p->drawRect( QRectF( mBoundingRect.right() - handlerSize, mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
 
  196  p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
 
  201  const QPointF itemPos = mapFromScene( pos );
 
  203  const int cursorSensitivity = 7;
 
  205  if ( mAnnotation && mAnnotation->
hasFixedMapPosition() && std::fabs( itemPos.x() ) < cursorSensitivity && std::fabs( itemPos.y() ) < cursorSensitivity ) 
 
  210  const double mmToPixelScale = 
mMapCanvas->logicalDpiX() / 25.4;
 
  213  const QSizeF frameSize = mAnnotation ? mAnnotation->
frameSizeMm() * mmToPixelScale : QSizeF( 0, 0 );
 
  215  bool left, right, up, down, inframe;
 
  216  left = std::fabs( itemPos.x() - offset.x() ) < cursorSensitivity;
 
  217  right = std::fabs( itemPos.x() - ( offset.x() + frameSize.width() ) ) < cursorSensitivity;
 
  218  up = std::fabs( itemPos.y() - offset.y() ) < cursorSensitivity;
 
  219  down = std::fabs( itemPos.y() - ( offset.y() + frameSize.height() ) ) < cursorSensitivity;
 
  220  inframe = ( itemPos.x() + cursorSensitivity >= offset.x() && itemPos.x() - cursorSensitivity <= ( offset.x() + frameSize.width() ) && itemPos.y() + cursorSensitivity >= offset.y() && itemPos.y() - cursorSensitivity <= ( offset.y() + frameSize.height() ) );
 
  230    else if ( right && up )
 
  234    else if ( left && down )
 
  238    else if ( right && down )
 
  242    if ( left && inframe )
 
  246    if ( right && inframe )
 
  254    if ( down && inframe )
 
 
  270  switch ( moveAction )
 
  273      return Qt::ArrowCursor;
 
  276      return Qt::SizeAllCursor;
 
  279      return Qt::SizeVerCursor;
 
  282      return Qt::SizeHorCursor;
 
  285      return Qt::SizeFDiagCursor;
 
  288      return Qt::SizeBDiagCursor;
 
  290      return Qt::ArrowCursor;
 
 
  294double QgsMapCanvasAnnotationItem::scaledSymbolSize()
 const 
  306  const double dpmm = 
mMapCanvas->logicalDpiX() / 25.4;
 
  312  if ( !mAnnotation || !mAnnotation->
isVisible() )
 
  319    mAnnotation->
render( rc );
 
  323    drawSelectionBoxes( painter );
 
 
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
 
@ Antialiasing
Use antialiasing while drawing.
 
Abstract base class for annotation items which are drawn over a map.
 
void appearanceChanged()
Emitted whenever the annotation's appearance changes.
 
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.
 
QgsMarkerSymbol * markerSymbol() const
Returns the symbol that is drawn at the annotation's map position.
 
void moved()
Emitted when the annotation's position has changed and items need to be moved to reflect this.
 
QgsMapLayer * mapLayer() const
Returns the map layer associated with the annotation.
 
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)
Fetch next feature and stores in f, returns true on success.
 
This class wraps a request for features to a vector layer (or directly its vector data provider).
 
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(bool expandGroupLayers=false) 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(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
 
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.