28 , mMapPositionFixed( true )
30 , mOffsetFromReferencePoint(
QPointF( 50, -50 ) )
31 , mBalloonSegment( -1 )
33 setFlag( QGraphicsItem::ItemIsSelectable,
true );
117 double halfSymbolSize = 0.0;
149 double minEdgeDist = DBL_MAX;
150 int minEdgeIndex = -1;
155 for (
int i = 0; i < 4; ++i )
157 QLineF currentSegment = segmentList.
at( i );
159 double currentMinDist = origin.
sqrDistToSegment( currentSegment.
x1(), currentSegment.
y1(), currentSegment.
x2(), currentSegment.
y2(), currentMinDistPoint );
160 if ( currentMinDist < minEdgeDist )
163 minEdgePoint = currentMinDistPoint;
164 minEdgeDist = currentMinDist;
165 minEdge = currentSegment;
169 if ( minEdgeIndex < 0 )
175 double segmentPointWidth = 10;
180 if ( sqrt( minEdgePoint.
sqrDist( minEdgeEnd.
x(), minEdgeEnd.
y() ) ) < segmentPointWidth )
199 for (
int i = 0; i < 4; ++i )
202 poly << currentSegment.
p1();
209 poly << currentSegment.
p2();
251 if (
data( 1 ).toString() ==
"composer" )
256 double handlerSize = 10;
288 double dx = directionPoint.
x() - startPoint.
x();
289 double dy = directionPoint.
y() - startPoint.
y();
290 double length = sqrt( dx * dx + dy * dy );
291 double scaleFactor = distance / length;
292 return QPointF( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
299 int cursorSensitivity = 7;
301 if ( qAbs( itemPos.
x() ) < cursorSensitivity && qAbs( itemPos.
y() ) < cursorSensitivity )
306 bool left, right, up, down;
316 else if ( right && up )
320 else if ( left && down )
324 else if ( right && down )
356 switch ( moveAction )
359 return Qt::ArrowCursor;
362 return Qt::SizeAllCursor;
365 return Qt::SizeVerCursor;
368 return Qt::SizeHorCursor;
371 return Qt::SizeFDiagCursor;
374 return Qt::SizeBDiagCursor;
376 return Qt::ArrowCursor;
424 if ( !symbolElem.
isNull() )
435 if ( annotationElem.
isNull() )
463 if ( !symbolElem.isNull() )
465 QgsMarkerSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
virtual QSizeF minimumFrameSize() const
QgsMarkerSymbolV2 * mMarkerSymbol
Point symbol that is to be drawn at the map reference location.
void setRenderHint(RenderHint hint, bool on)
void _readXML(const QDomDocument &doc, const QDomElement &annotationElem)
double mFrameBorderWidth
Width of the frame.
QDomNode appendChild(const QDomNode &newChild)
void setFlag(GraphicsItemFlag flag, bool enabled)
QPointF toCanvasCoordinates(const QgsPoint &point) const
transformation from map coordinates to screen coordinates
QString attribute(const QString &name, const QString &defValue) const
void setData(int key, const QVariant &value)
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
const T & at(int i) const
An abstract class for items that can be placed on the map canvas.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
QSizeF expandedTo(const QSizeF &otherSize) const
virtual void setMapPositionCrs(const QgsCoordinateReferenceSystem &crs)
Sets the CRS of the map position.
void setNamedColor(const QString &name)
double toDouble(bool *ok) const
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
virtual ~QgsAnnotationItem()
Map canvas is a class for displaying all GIS data types on a canvas.
void update(const QRectF &rect)
double x() const
Get the x value of the point.
void setFrameSize(QSizeF size)
void drawSelectionBoxes(QPainter *p)
void updatePosition() override
called on changed extent or resize event to update position of the item
void setMarkerSymbol(QgsMarkerSymbolV2 *symbol)
Set symbol that is drawn on map position.
QRectF mBoundingRect
Bounding rect (including item frame and balloon)
void drawRect(const QRectF &rectangle)
QgsAnnotationItem::MouseMoveAction moveActionForPosition(QPointF pos) const
Returns the mouse move behaviour for a given position.
QString number(int n, int base)
QPointF mBalloonSegmentPoint1
First segment point for drawing the connection (ccw direction)
virtual void setMapPosition(const QgsPoint &pos)
void startRender(QgsRenderContext &context, const QgsFields *fields=nullptr)
bool readXML(const QDomNode &theNode)
Restores state from the given Dom node.
void setPen(const QColor &color)
void setAttribute(const QString &name, const QString &value)
void setWidth(qreal width)
void setPos(const QPointF &pos)
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
QString qgsDoubleToString(double a, int precision=17)
QgsAnnotationItem(QgsMapCanvas *mapCanvas)
double sqrDistToSegment(double x1, double y1, double x2, double y2, QgsPoint &minDistPoint, double epsilon=DEFAULT_SEGMENT_EPSILON) const
Returns the minimum distance between this point and a segment.
QPointF mapFromScene(const QPointF &point) const
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
Qt::CursorShape cursorShapeForAction(MouseMoveAction moveAction) const
Returns suitable cursor shape for mouse move action.
void drawMarkerSymbol(QPainter *p)
int mBalloonSegment
Segment number where the connection to the map point is attached.
QRectF boundingRect() const override
default implementation for canvas items
A class to represent a point.
void prepareGeometryChange()
void setX(double x)
Sets the x value of the point.
void setOffsetFromReferencePoint(QPointF offset)
QgsCoordinateReferenceSystem mMapPositionCrs
CRS of the map position.
void setY(double y)
Sets the y value of the point.
double scaledSymbolSize() const
Returns the symbol size scaled in (mapcanvas) pixels.
bool mMapPositionFixed
True: the item stays at the same map position, False: the item stays on same screen position...
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QColor mFrameColor
Frame / balloon color.
QVariant data(int key) const
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Stores state to the given Dom node in the given document.
Contains information about the context of a rendering operation.
void stopRender(QgsRenderContext &context)
void _writeXML(QDomDocument &doc, QDomElement &itemElem) const
void updateBalloon()
Check where to attach the balloon connection between frame and map point.
QgsMapCanvas * mMapCanvas
pointer to map canvas
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
void drawFrame(QPainter *p)
void updateBoundingRect()
void renderPoint(QPointF point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void setVisible(bool visible)
double y() const
Get the y value of the point.
QColor mFrameBackgroundColor
QPointF mBalloonSegmentPoint2
Second segment point for drawing the balloon connection (ccw direction)
QDomElement createElement(const QString &tagName)
QgsPoint mMapPosition
Map position (in case mMapPositionFixed is true)
void setHeight(qreal height)
QSizeF mFrameSize
Size of the frame (without balloon)
QgsPoint toMapCoordinates(QPoint point) const
transformation from screen coordinates to map coordinates
void setMapPositionFixed(bool fixed)
bool setRenderContextVariables(QPainter *p, QgsRenderContext &context) const
Sets render context parameters.
QPointF pointOnLineWithDistance(QPointF startPoint, QPointF directionPoint, double distance) const
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
QLineF segment(int index)
Returns frame width in painter units.