Skip to content

Commit 0fa6499

Browse files
authoredJul 26, 2016
Merge pull request #3329 from nyalldawson/annotations
Add an interface class for annotations, remove some hacks
2 parents 68b621a + 1e9274a commit 0fa6499

File tree

9 files changed

+268
-90
lines changed

9 files changed

+268
-90
lines changed
 

‎python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
%Include qgis.sip
2020

21+
%Include qgsannotation.sip
2122
%Include qgsapplication.sip
2223
%Include qgsaction.sip
2324
%Include qgsactionmanager.sip

‎python/core/qgsannotation.sip

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/** \ingroup core
2+
* \class QgsAnnotation
3+
* \note added in QGIS 3.0
4+
*
5+
* \brief An interface for annotation items which are drawn over a map.
6+
*
7+
* QgsAnnotation is an interface class for map annotation items. These annotations can be
8+
* drawn within a map, and have either a fixed map position (retrieved using mapPosition())
9+
* or are placed relative to the map's frame (retrieved using relativePosition()).
10+
* Annotations with a fixed map position also have a corresponding
11+
* QgsCoordinateReferenceSystem, which can be determined by calling mapPositionCrs().
12+
*/
13+
14+
class QgsAnnotation
15+
{
16+
%TypeHeaderCode
17+
#include <qgsannotation.h>
18+
%End
19+
public:
20+
21+
//! Returns true if the annotation should be shown.
22+
virtual bool showItem() const = 0;
23+
24+
/** Returns true if the annotation is attached to a fixed map position, or
25+
* false if the annotation uses a position relative to the current map
26+
* extent.
27+
* @see mapPosition()
28+
* @see relativePositon()
29+
*/
30+
//TODO QGIS 3 - rename to hasFixedMapPosition()
31+
virtual bool mapPositionFixed() const = 0;
32+
33+
/** Returns the map position of the annotation, if it is attached to a fixed map
34+
* position.
35+
* @see mapPositionFixed()
36+
* @see mapPositionCrs()
37+
*/
38+
virtual QgsPoint mapPosition() const;
39+
40+
/** Returns the CRS of the map position, or an invalid CRS if the annotation does
41+
* not have a fixed map position.
42+
*/
43+
virtual QgsCoordinateReferenceSystem mapPositionCrs() const;
44+
45+
/** Returns the relative position of the annotation, if it is not attached to a fixed map
46+
* position. The coordinates in the return point should be between 0 and 1, and represent
47+
* the relative percentage for the position compared to the map width and height.
48+
* @see mapPositionFixed()
49+
*/
50+
virtual QPointF relativePosition() const;
51+
52+
/** Returns a scaling factor which should be applied to painters before rendering
53+
* the item.
54+
*/
55+
virtual double scaleFactor() const = 0;
56+
57+
//! deprecated - do not use
58+
// TODO QGIS 3.0 - remove
59+
virtual void setItemData( int role, const QVariant& value ) = 0;
60+
61+
//! Paint the annotation to a destination painter
62+
virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) = 0;
63+
64+
};

‎python/gui/qgsannotationitem.sip

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "qgstextannotationitem.h"
99
%End
1010

11-
class QgsAnnotationItem: QgsMapCanvasItem
11+
class QgsAnnotationItem: QgsMapCanvasItem, QgsAnnotation
1212
{
1313
%TypeHeaderCode
1414
#include <qgsannotationitem.h>
@@ -66,6 +66,12 @@ class QgsAnnotationItem: QgsMapCanvasItem
6666
virtual void setMapPosition( const QgsPoint& pos );
6767
QgsPoint mapPosition() const;
6868

69+
virtual QPointF relativePosition() const;
70+
71+
virtual double scaleFactor() const;
72+
73+
virtual bool showItem() const;
74+
6975
/** Sets the CRS of the map position.
7076
@param crs the CRS to set */
7177
virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
@@ -97,18 +103,28 @@ class QgsAnnotationItem: QgsMapCanvasItem
97103
void _writeXml( QDomDocument& doc, QDomElement& itemElem ) const;
98104
void _readXml( const QDomDocument& doc, const QDomElement& annotationElem );
99105

106+
virtual void setItemData( int role, const QVariant& value );
107+
virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr );
108+
void paint( QPainter* painter );
109+
100110
protected:
101111
void updateBoundingRect();
102112
/** Check where to attach the balloon connection between frame and map point*/
103113
void updateBalloon();
104114

105-
void drawFrame( QPainter* p );
106-
void drawMarkerSymbol( QPainter* p );
107-
void drawSelectionBoxes( QPainter* p );
115+
//! Draws the annotation frame to a destination painter
116+
void drawFrame( QPainter* p ) const;
117+
118+
//! Draws the map position marker symbol to a destination painter
119+
void drawMarkerSymbol( QPainter* p ) const;
120+
121+
//! Draws selection handles around the item
122+
void drawSelectionBoxes( QPainter* p ) const;
123+
108124
/** Returns frame width in painter units*/
109125
//double scaledFrameWidth( QPainter* p) const;
110126
/** Gets the frame line (0 is the top line, 1 right, 2 bottom, 3 left)*/
111-
QLineF segment( int index );
127+
QLineF segment( int index ) const;
112128
/** Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
113129
QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance ) const;
114130
/** Returns the symbol size scaled in (mapcanvas) pixels. Used for the counding rect calculation*/

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ SET(QGIS_CORE_HDRS
603603
qgis.h
604604
qgsaction.h
605605
qgsaggregatecalculator.h
606+
qgsannotation.h
606607
qgsattributetableconfig.h
607608
qgsattributeaction.h
608609
qgscachedfeatureiterator.h

‎src/core/composer/qgscomposermap.cpp

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "qgspallabeling.h"
3636
#include "qgsexpression.h"
3737
#include "qgsvisibilitypresetcollection.h"
38+
#include "qgsannotation.h"
3839

3940
#include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance
4041

@@ -2365,101 +2366,70 @@ void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraph
23652366
for ( int i = itemList.size() - 1; i >= 0; --i )
23662367
{
23672368
currentItem = itemList.at( i );
2368-
//don't draw mapcanvasmap (has z value -10)
2369-
if ( !currentItem || currentItem->data( 0 ).toString() != "AnnotationItem" )
2369+
2370+
const QgsAnnotation* annotation = dynamic_cast< const QgsAnnotation* >( currentItem );
2371+
if ( !annotation )
23702372
{
23712373
continue;
23722374
}
2373-
drawCanvasItem( currentItem, painter, itemStyle );
2375+
drawCanvasItem( annotation, painter, itemStyle );
23742376
}
23752377
}
23762378

2377-
void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2379+
void QgsComposerMap::drawCanvasItem( const QgsAnnotation* annotation, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
23782380
{
2379-
if ( !item || !mMapCanvas || !item->isVisible() )
2381+
if ( !annotation || !annotation->showItem() )
23802382
{
23812383
return;
23822384
}
23832385

23842386
painter->save();
23852387
painter->setRenderHint( QPainter::Antialiasing );
23862388

2387-
//determine scale factor according to graphics view dpi
2388-
double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
2389+
double scaleFactor = annotation->scaleFactor();
23892390

23902391
double itemX, itemY;
2391-
QGraphicsItem* parent = item->parentItem();
2392-
if ( !parent )
2392+
if ( annotation->mapPositionFixed() )
23932393
{
2394-
// having no parent is a hack to indicate that annotation has a fixed position
2395-
QPointF mapPos = composerMapPosForItem( item );
2394+
QPointF mapPos = composerMapPosForItem( annotation );
23962395
itemX = mapPos.x();
23972396
itemY = mapPos.y();
23982397
}
2399-
else //place item relative to the parent item
2398+
else
24002399
{
2401-
// having a parent is a hack to indicate annotation has relative position
2402-
QPointF itemScenePos = item->scenePos();
2403-
QPointF parentScenePos = parent->scenePos();
2404-
2405-
QPointF mapPos = composerMapPosForItem( parent );
2406-
2407-
itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2408-
itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2400+
itemX = annotation->relativePosition().x() * rect().width();
2401+
itemY = annotation->relativePosition().y() * rect().height();
24092402
}
2410-
painter->translate( itemX, itemY );
24112403

2404+
painter->translate( itemX, itemY );
24122405
painter->scale( scaleFactor, scaleFactor );
24132406

24142407
//a little trick to let the item know that the paint request comes from the composer
2415-
item->setData( 1, "composer" );
2416-
item->paint( painter, itemStyle, nullptr );
2417-
item->setData( 1, "" );
2408+
const_cast< QgsAnnotation* >( annotation )->setItemData( 1, "composer" );
2409+
const_cast< QgsAnnotation* >( annotation )->paint( painter, itemStyle, nullptr );
2410+
const_cast< QgsAnnotation* >( annotation )->setItemData( 1, "" );
2411+
24182412
painter->restore();
24192413
}
24202414

2421-
QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
2415+
QPointF QgsComposerMap::composerMapPosForItem( const QgsAnnotation* annotation ) const
24222416
{
2423-
if ( !item )
2417+
if ( !annotation )
24242418
return QPointF( 0, 0 );
24252419

24262420
double mapX = 0.0;
24272421
double mapY = 0.0;
2428-
if ( item->parentItem() && !mMapCanvas )
2429-
{
2430-
// having a parentItem is a hack used to indicate annotation has relative position
2431-
return QPointF( 0, 0 );
2432-
}
2433-
else if ( item->parentItem() )
2434-
{
2435-
// TODO this is totally broken for rotated maps
2436-
if ( currentMapExtent()->height() <= 0 || currentMapExtent()->width() <= 0 || mMapCanvas->width() <= 0 || mMapCanvas->height() <= 0 )
2437-
{
2438-
return QPointF( 0, 0 );
2439-
}
24402422

2441-
QRectF graphicsSceneRect = mMapCanvas->sceneRect();
2442-
QPointF itemScenePos = item->scenePos();
2443-
QgsRectangle mapRendererExtent = mComposition->mapSettings().visibleExtent();
2423+
mapX = annotation->mapPosition().x();
2424+
mapY = annotation->mapPosition().y();
2425+
QgsCoordinateReferenceSystem crs = annotation->mapPositionCrs();
24442426

2445-
mapX = itemScenePos.x() / graphicsSceneRect.width() * mapRendererExtent.width() + mapRendererExtent.xMinimum();
2446-
mapY = mapRendererExtent.yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.height();
2447-
}
2448-
else
2427+
if ( crs != mComposition->mapSettings().destinationCrs() )
24492428
{
2450-
//fixed position, use a hack where the position is encoded in item's custom data
2451-
//(this whole annotation handling is a hack and needs to be rewritten)
2452-
mapX = item->data( 2 ).toDouble();
2453-
mapY = item->data( 3 ).toDouble();
2454-
long crsid = item->data( 4 ).toLongLong();
2455-
2456-
if ( crsid != mComposition->mapSettings().destinationCrs().srsid() )
2457-
{
2458-
//need to reproject
2459-
QgsCoordinateTransform t( QgsCoordinateReferenceSystem::fromSrsId( crsid ), mComposition->mapSettings().destinationCrs() );
2460-
double z = 0.0;
2461-
t.transformInPlace( mapX, mapY, z );
2462-
}
2429+
//need to reproject
2430+
QgsCoordinateTransform t( crs, mComposition->mapSettings().destinationCrs() );
2431+
double z = 0.0;
2432+
t.transformInPlace( mapX, mapY, z );
24632433
}
24642434

24652435
return mapToItemCoords( QPointF( mapX, mapY ) );

‎src/core/composer/qgscomposermap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class QPainter;
3636
class QgsFillSymbolV2;
3737
class QgsLineSymbolV2;
3838
class QgsVectorLayer;
39+
class QgsAnnotation;
3940

4041
/** \ingroup core
4142
* \class QgsComposerMap
@@ -968,8 +969,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
968969
void transformShift( double& xShift, double& yShift ) const;
969970

970971
void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
971-
void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
972-
QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
972+
void drawCanvasItem( const QgsAnnotation* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
973+
QPointF composerMapPosForItem( const QgsAnnotation* item ) const;
973974

974975
enum PartType
975976
{

‎src/core/qgsannotation.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/***************************************************************************
2+
qgsannotation.h
3+
---------------
4+
begin : July 2016
5+
copyright : (C) 2016 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSANNOTATION_H
19+
#define QGSANNOTATION_H
20+
21+
#include "qgspoint.h"
22+
#include "qgscoordinatereferencesystem.h"
23+
24+
class QPainter;
25+
class QStyleOptionGraphicsItem;
26+
27+
/** \ingroup core
28+
* \class QgsAnnotation
29+
* \note added in QGIS 3.0
30+
*
31+
* \brief An interface for annotation items which are drawn over a map.
32+
*
33+
* QgsAnnotation is an interface class for map annotation items. These annotations can be
34+
* drawn within a map, and have either a fixed map position (retrieved using mapPosition())
35+
* or are placed relative to the map's frame (retrieved using relativePosition()).
36+
* Annotations with a fixed map position also have a corresponding
37+
* QgsCoordinateReferenceSystem, which can be determined by calling mapPositionCrs().
38+
*/
39+
40+
class CORE_EXPORT QgsAnnotation
41+
{
42+
public:
43+
44+
//! Returns true if the annotation should be shown.
45+
virtual bool showItem() const = 0;
46+
47+
/** Returns true if the annotation is attached to a fixed map position, or
48+
* false if the annotation uses a position relative to the current map
49+
* extent.
50+
* @see mapPosition()
51+
* @see relativePositon()
52+
*/
53+
//TODO QGIS 3 - rename to hasFixedMapPosition()
54+
virtual bool mapPositionFixed() const = 0;
55+
56+
/** Returns the map position of the annotation, if it is attached to a fixed map
57+
* position.
58+
* @see mapPositionFixed()
59+
* @see mapPositionCrs()
60+
*/
61+
virtual QgsPoint mapPosition() const { return QgsPoint(); }
62+
63+
/** Returns the CRS of the map position, or an invalid CRS if the annotation does
64+
* not have a fixed map position.
65+
*/
66+
virtual QgsCoordinateReferenceSystem mapPositionCrs() const { return QgsCoordinateReferenceSystem(); }
67+
68+
/** Returns the relative position of the annotation, if it is not attached to a fixed map
69+
* position. The coordinates in the return point should be between 0 and 1, and represent
70+
* the relative percentage for the position compared to the map width and height.
71+
* @see mapPositionFixed()
72+
*/
73+
virtual QPointF relativePosition() const { return QPointF(); }
74+
75+
/** Returns a scaling factor which should be applied to painters before rendering
76+
* the item.
77+
*/
78+
virtual double scaleFactor() const = 0;
79+
80+
//! deprecated - do not use
81+
// TODO QGIS 3.0 - remove
82+
virtual void setItemData( int role, const QVariant& value ) = 0;
83+
84+
//! Paint the annotation to a destination painter
85+
virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) = 0;
86+
87+
88+
};
89+
90+
#endif // QGSANNOTATION_H

‎src/gui/qgsannotationitem.cpp

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,26 @@ void QgsAnnotationItem::setMarkerSymbol( QgsMarkerSymbolV2* symbol )
5353
void QgsAnnotationItem::setMapPosition( const QgsPoint& pos )
5454
{
5555
mMapPosition = pos;
56-
// use a hack to make position accessible to composer (in core, so can't directly access this class)
57-
// TODO - fix this hacky mess with an interface class
58-
setData( 2, mMapPosition.x() );
59-
setData( 3, mMapPosition.y() );
6056

6157
setPos( toCanvasCoordinates( mMapPosition ) );
6258
setMapPositionCrs( mMapCanvas->mapSettings().destinationCrs() );
6359
}
6460

61+
QPointF QgsAnnotationItem::relativePosition() const
62+
{
63+
double x = pos().x() / mMapCanvas->width();
64+
double y = pos().y() / mMapCanvas->height();
65+
return QPointF( x, y );
66+
}
67+
68+
double QgsAnnotationItem::scaleFactor() const
69+
{
70+
return 1.0 / mMapCanvas->logicalDpiX() * 25.4;
71+
}
72+
6573
void QgsAnnotationItem::setMapPositionCrs( const QgsCoordinateReferenceSystem& crs )
6674
{
6775
mMapPositionCrs = crs;
68-
// use a hack to make crs accessible to composer
69-
setData( 4, qlonglong( crs.srsid() ) );
7076
}
7177

7278
void QgsAnnotationItem::setOffsetFromReferencePoint( QPointF offset )
@@ -105,10 +111,6 @@ void QgsAnnotationItem::updatePosition()
105111
else
106112
{
107113
mMapPosition = toMapCoordinates( pos().toPoint() );
108-
// use a hack to make position accessible to composer (in core, so can't directly access this class)
109-
// TODO - fix this hacky mess with an interface class
110-
setData( 2, mMapPosition.x() );
111-
setData( 3, mMapPosition.y() );
112114
}
113115
}
114116

@@ -196,7 +198,7 @@ void QgsAnnotationItem::updateBalloon()
196198
mBalloonSegmentPoint2 = pointOnLineWithDistance( mBalloonSegmentPoint1, minEdge.p2(), 10 );
197199
}
198200

199-
void QgsAnnotationItem::drawFrame( QPainter* p )
201+
void QgsAnnotationItem::drawFrame( QPainter* p ) const
200202
{
201203
QPen framePen( mFrameColor );
202204
framePen.setWidthF( mFrameBorderWidth );
@@ -230,7 +232,7 @@ void QgsAnnotationItem::setFrameSize( QSizeF size )
230232
updateBalloon();
231233
}
232234

233-
void QgsAnnotationItem::drawMarkerSymbol( QPainter* p )
235+
void QgsAnnotationItem::drawMarkerSymbol( QPainter* p ) const
234236
{
235237
if ( !p )
236238
{
@@ -251,7 +253,7 @@ void QgsAnnotationItem::drawMarkerSymbol( QPainter* p )
251253
}
252254
}
253255

254-
void QgsAnnotationItem::drawSelectionBoxes( QPainter* p )
256+
void QgsAnnotationItem::drawSelectionBoxes( QPainter* p ) const
255257
{
256258
if ( !p )
257259
{
@@ -273,7 +275,7 @@ void QgsAnnotationItem::drawSelectionBoxes( QPainter* p )
273275
p->drawRect( QRectF( mBoundingRect.left(), mBoundingRect.bottom() - handlerSize, handlerSize, handlerSize ) );
274276
}
275277

276-
QLineF QgsAnnotationItem::segment( int index )
278+
QLineF QgsAnnotationItem::segment( int index ) const
277279
{
278280
switch ( index )
279281
{
@@ -455,14 +457,11 @@ void QgsAnnotationItem::_readXml( const QDomDocument& doc, const QDomElement& an
455457
mapPos.setX( annotationElem.attribute( "mapPosX", "0" ).toDouble() );
456458
mapPos.setY( annotationElem.attribute( "mapPosY", "0" ).toDouble() );
457459
mMapPosition = mapPos;
458-
setData( 2, mMapPosition.x() );
459-
setData( 3, mMapPosition.y() );
460460

461461
if ( !mMapPositionCrs.readXml( annotationElem ) )
462462
{
463463
mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
464464
}
465-
setMapPositionCrs( mMapPositionCrs );
466465

467466
mFrameBorderWidth = annotationElem.attribute( "frameBorderWidth", "0.5" ).toDouble();
468467
mFrameColor.setNamedColor( annotationElem.attribute( "frameColor", "#000000" ) );
@@ -491,3 +490,19 @@ void QgsAnnotationItem::_readXml( const QDomDocument& doc, const QDomElement& an
491490
updateBoundingRect();
492491
updateBalloon();
493492
}
493+
494+
void QgsAnnotationItem::setItemData( int role, const QVariant& value )
495+
{
496+
setData( role, value );
497+
}
498+
499+
void QgsAnnotationItem::paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* )
500+
{
501+
// maintain API compatibility, if annotation item subclasses only implement the paint( QPainter* ) override
502+
paint( painter );
503+
}
504+
505+
void QgsAnnotationItem::paint( QPainter* painter )
506+
{
507+
Q_UNUSED( painter );
508+
}

‎src/gui/qgsannotationitem.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "qgsmapcanvasitem.h"
2222
#include "qgscoordinatereferencesystem.h"
23+
#include "qgsannotation.h"
2324

2425
class QDomDocument;
2526
class QDomElement;
@@ -30,7 +31,8 @@ class QgsMarkerSymbolV2;
3031
/** \ingroup gui
3132
* An annotation item can be either placed either on screen corrdinates or on map coordinates.
3233
It may reference a feature and displays that associatiation with a balloon like appearance*/
33-
class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
34+
35+
class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem, public QgsAnnotation
3436
{
3537
public:
3638
enum MouseMoveAction
@@ -65,16 +67,22 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
6567

6668
//setters and getters
6769
void setMapPositionFixed( bool fixed );
68-
bool mapPositionFixed() const { return mMapPositionFixed; }
70+
bool mapPositionFixed() const override { return mMapPositionFixed; }
6971

7072
virtual void setMapPosition( const QgsPoint& pos );
71-
QgsPoint mapPosition() const { return mMapPosition; }
73+
QgsPoint mapPosition() const override { return mMapPosition; }
74+
75+
virtual QPointF relativePosition() const override;
76+
77+
virtual double scaleFactor() const override;
78+
79+
virtual bool showItem() const override { return isVisible(); }
7280

7381
/** Sets the CRS of the map position.
7482
@param crs the CRS to set */
7583
virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
7684
/** Returns the CRS of the map position.*/
77-
QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }
85+
QgsCoordinateReferenceSystem mapPositionCrs() const override { return mMapPositionCrs; }
7886

7987
void setFrameSize( QSizeF size );
8088
QSizeF frameSize() const { return mFrameSize; }
@@ -101,6 +109,12 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
101109
void _writeXml( QDomDocument& doc, QDomElement& itemElem ) const;
102110
void _readXml( const QDomDocument& doc, const QDomElement& annotationElem );
103111

112+
virtual void setItemData( int role, const QVariant& value ) override;
113+
114+
virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override;
115+
116+
void paint( QPainter* painter ) override;
117+
104118
protected:
105119
/** True: the item stays at the same map position, False: the item stays on same screen position*/
106120
bool mMapPositionFixed;
@@ -136,13 +150,19 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
136150
/** Check where to attach the balloon connection between frame and map point*/
137151
void updateBalloon();
138152

139-
void drawFrame( QPainter* p );
140-
void drawMarkerSymbol( QPainter* p );
141-
void drawSelectionBoxes( QPainter* p );
153+
//! Draws the annotation frame to a destination painter
154+
void drawFrame( QPainter* p ) const;
155+
156+
//! Draws the map position marker symbol to a destination painter
157+
void drawMarkerSymbol( QPainter* p ) const;
158+
159+
//! Draws selection handles around the item
160+
void drawSelectionBoxes( QPainter* p ) const;
161+
142162
/** Returns frame width in painter units*/
143163
//double scaledFrameWidth( QPainter* p) const;
144164
/** Gets the frame line (0 is the top line, 1 right, 2 bottom, 3 left)*/
145-
QLineF segment( int index );
165+
QLineF segment( int index ) const;
146166
/** Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point*/
147167
QPointF pointOnLineWithDistance( QPointF startPoint, QPointF directionPoint, double distance ) const;
148168
/** Returns the symbol size scaled in (mapcanvas) pixels. Used for the counding rect calculation*/

0 commit comments

Comments
 (0)
Please sign in to comment.