28 , mMapPositionFixed( true )
29 , mOffsetFromReferencePoint(
QPointF( 50, -50 ) )
30 , mBalloonSegment( -1 )
32 setFlag( QGraphicsItem::ItemIsSelectable,
true );
109 double halfSymbolSize = 0.0;
138 double minEdgeDist = DBL_MAX;
139 int minEdgeIndex = -1;
144 for (
int i = 0; i < 4; ++i )
146 QLineF currentSegment = segmentList.
at( i );
148 double currentMinDist = origin.
sqrDistToSegment( currentSegment.
x1(), currentSegment.
y1(), currentSegment.
x2(), currentSegment.
y2(), currentMinDistPoint );
149 if ( currentMinDist < minEdgeDist )
152 minEdgePoint = currentMinDistPoint;
153 minEdgeDist = currentMinDist;
154 minEdge = currentSegment;
158 if ( minEdgeIndex < 0 )
164 double segmentPointWidth = 10;
169 if ( sqrt( minEdgePoint.
sqrDist( minEdgeEnd.
x(), minEdgeEnd.
y() ) ) < segmentPointWidth )
188 for (
int i = 0; i < 4; ++i )
191 poly << currentSegment.
p1();
198 poly << currentSegment.
p2();
240 if (
data( 1 ).toString() ==
"composer" )
245 double handlerSize = 10;
277 double dx = directionPoint.
x() - startPoint.
x();
278 double dy = directionPoint.
y() - startPoint.
y();
279 double length = sqrt( dx * dx + dy * dy );
280 double scaleFactor = distance / length;
281 return QPointF( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
288 int cursorSensitivity = 7;
290 if ( qAbs( itemPos.
x() ) < cursorSensitivity && qAbs( itemPos.
y() ) < cursorSensitivity )
295 bool left, right, up, down;
305 else if ( right && up )
309 else if ( left && down )
313 else if ( right && down )
345 switch ( moveAction )
348 return Qt::ArrowCursor;
351 return Qt::SizeAllCursor;
354 return Qt::SizeVerCursor;
357 return Qt::SizeHorCursor;
360 return Qt::SizeFDiagCursor;
363 return Qt::SizeBDiagCursor;
365 return Qt::ArrowCursor;
411 if ( !symbolElem.
isNull() )
422 if ( annotationElem.
isNull() )
448 if ( !symbolElem.isNull() )
450 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)
QgsPoint toMapCoordinates(const QPoint &point) const
transformation from screen coordinates to map coordinates
void _readXML(const QDomDocument &doc, const QDomElement &annotationElem)
double mFrameBorderWidth
Width of the frame.
QDomNode appendChild(const QDomNode &newChild)
QgsAnnotationItem::MouseMoveAction moveActionForPosition(const QPointF &pos) const
Returns the mouse move behaviour for a given position.
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.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
QSizeF expandedTo(const QSizeF &otherSize) const
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)
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)
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
void drawRect(const QRectF &rectangle)
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=0)
void setPen(const QColor &color)
void setAttribute(const QString &name, const QString &value)
void setWidth(qreal width)
void setPos(const QPointF &pos)
int toInt(bool *ok, int base) const
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
QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance) const
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
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)
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
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()
QString qgsDoubleToString(const double &a, const int &precision=17)
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...
QColor mFrameColor
Frame / balloon color.
QVariant data(int key) const
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.
void setOffsetFromReferencePoint(const QPointF &offset)
QgsMapCanvas * mMapCanvas
pointer to map canvas
QDomElement firstChildElement(const QString &tagName) const
void setFrameSize(const QSizeF &size)
void drawFrame(QPainter *p)
void updateBoundingRect()
void setVisible(bool visible)
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)
void setMapPositionFixed(bool fixed)
bool setRenderContextVariables(QPainter *p, QgsRenderContext &context) const
Sets render context parameters.
QLineF segment(int index)
Returns frame width in painter units.