28 setFlag( QGraphicsItem::ItemIsSelectable,
true );
33 setData( 0,
"AnnotationItem" );
99 return QSizeF( 0, 0 );
104 prepareGeometryChange();
105 double halfSymbolSize = 0.0;
115 mBoundingRect = QRectF( xMinPos, yMinPos, xMaxPos - xMinPos, yMaxPos - yMinPos );
130 QList<QLineF> segmentList;
134 double minEdgeDist = DBL_MAX;
135 int minEdgeIndex = -1;
140 for (
int i = 0; i < 4; ++i )
142 QLineF currentSegment = segmentList.at( i );
144 double currentMinDist = origin.
sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
145 if ( currentMinDist < minEdgeDist )
148 minEdgePoint = currentMinDistPoint;
149 minEdgeDist = currentMinDist;
150 minEdge = currentSegment;
154 if ( minEdgeIndex < 0 )
160 double segmentPointWidth = 10;
163 QPointF minEdgeEnd = minEdge.p2();
165 if ( sqrt( minEdgePoint.
sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth )
178 p->setPen( framePen );
180 p->setBrush( frameBrush );
181 p->setRenderHint( QPainter::Antialiasing,
true );
184 for (
int i = 0; i < 4; ++i )
186 QLineF currentSegment =
segment( i );
187 poly << currentSegment.p1();
191 poly << QPointF( 0, 0 );
194 poly << currentSegment.p2();
196 p->drawPolygon( poly );
236 if ( data( 1 ).toString() ==
"composer" )
241 double handlerSize = 10;
242 p->setPen( Qt::NoPen );
243 p->setBrush( QColor( 200, 200, 210, 120 ) );
273 double dx = directionPoint.x() - startPoint.x();
274 double dy = directionPoint.y() - startPoint.y();
275 double length = sqrt( dx * dx + dy * dy );
276 double scaleFactor = distance / length;
277 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
282 QPointF itemPos = mapFromScene( pos );
284 int cursorSensitivity = 7;
286 if ( qAbs( itemPos.x() ) < cursorSensitivity && qAbs( itemPos.y() ) < cursorSensitivity )
291 bool left, right, up, down;
301 else if ( right && up )
305 else if ( left && down )
309 else if ( right && down )
341 switch ( moveAction )
344 return Qt::ArrowCursor;
347 return Qt::SizeAllCursor;
350 return Qt::SizeVerCursor;
353 return Qt::SizeHorCursor;
356 return Qt::SizeFDiagCursor;
359 return Qt::SizeBDiagCursor;
361 return Qt::ArrowCursor;
377 double dpmm =
mMapCanvas->logicalDpiX() / 25.4;
383 if ( itemElem.isNull() )
387 QDomElement annotationElem = doc.createElement(
"AnnotationItem" );
389 annotationElem.setAttribute(
"mapPosX", QString::number(
mMapPosition.
x() ) );
390 annotationElem.setAttribute(
"mapPosY", QString::number(
mMapPosition.
y() ) );
393 annotationElem.setAttribute(
"frameWidth", QString::number(
mFrameSize.width() ) );
394 annotationElem.setAttribute(
"frameHeight", QString::number(
mFrameSize.height() ) );
395 QPointF canvasPos = pos();
396 annotationElem.setAttribute(
"canvasPosX", QString::number( canvasPos.x() ) );
397 annotationElem.setAttribute(
"canvasPosY", QString::number( canvasPos.y() ) );
398 annotationElem.setAttribute(
"frameBorderWidth", QString::number(
mFrameBorderWidth ) );
399 annotationElem.setAttribute(
"frameColor",
mFrameColor.name() );
400 annotationElem.setAttribute(
"frameColorAlpha",
mFrameColor.alpha() );
403 annotationElem.setAttribute(
"visible", isVisible() );
407 if ( !symbolElem.isNull() )
409 annotationElem.appendChild( symbolElem );
412 itemElem.appendChild( annotationElem );
418 if ( annotationElem.isNull() )
423 pos.setX( annotationElem.attribute(
"canvasPosX",
"0" ).toDouble() );
424 pos.setY( annotationElem.attribute(
"canvasPosY",
"0" ).toDouble() );
427 mapPos.
setX( annotationElem.attribute(
"mapPosX",
"0" ).toDouble() );
428 mapPos.
setY( annotationElem.attribute(
"mapPosY",
"0" ).toDouble() );
430 mFrameBorderWidth = annotationElem.attribute(
"frameBorderWidth",
"0.5" ).toDouble();
431 mFrameColor.setNamedColor( annotationElem.attribute(
"frameColor",
"#000000" ) );
432 mFrameColor.setAlpha( annotationElem.attribute(
"frameColorAlpha",
"255" ).toInt() );
434 mFrameBackgroundColor.setAlpha( annotationElem.attribute(
"frameBackgroundColorAlpha",
"255" ).toInt() );
435 mFrameSize.setWidth( annotationElem.attribute(
"frameWidth",
"50" ).toDouble() );
436 mFrameSize.setHeight( annotationElem.attribute(
"frameHeight",
"50" ).toDouble() );
440 setVisible( annotationElem.attribute(
"visible",
"1" ).toInt() );
443 QDomElement symbolElem = annotationElem.firstChildElement(
"symbol" );
444 if ( !symbolElem.isNull() )
virtual QSizeF minimumFrameSize() const
QgsMarkerSymbolV2 * mMarkerSymbol
Point symbol that is to be drawn at the map reference location.
void _readXML(const QDomDocument &doc, const QDomElement &annotationElem)
double mFrameBorderWidth
Width of the frame.
QgsAnnotationItem::MouseMoveAction moveActionForPosition(const QPointF &pos) const
Returns the mouse move behaviour for a given position.
QPointF mOffsetFromReferencePoint
Describes the shift of the item content box to the reference point.
An abstract class for items that can be placed on the map canvas.
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 drawSelectionBoxes(QPainter *p)
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)
QPointF mBalloonSegmentPoint1
First segment point for drawing the connection (ccw direction)
QRectF boundingRect() const
default implementation for canvas items
virtual void setMapPosition(const QgsPoint &pos)
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
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 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...
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.
A class to represent a point geometry.
QPointF toCanvasCoordinates(const QgsPoint &point)
transformation from map coordinates to screen coordinates
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.
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
void setFrameSize(const QSizeF &size)
void drawFrame(QPainter *p)
void updateBoundingRect()
QColor mFrameBackgroundColor
static QgsSymbolV2 * loadSymbol(QDomElement &element)
QgsPoint toMapCoordinates(const QPoint &point)
transformation from screen coordinates to map coordinates
QPointF mBalloonSegmentPoint2
Second segment point for drawing the balloon connection (ccw direction)
QgsPoint mMapPosition
Map position (in case mMapPositionFixed is true)
QSizeF mFrameSize
Size of the frame (without balloon)
void updatePosition()
called on changed extent or resize event to update position of the item
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.