1 /***************************************************************************
2     qgsannotationitem.h
3     ----------------
4     copyright            : (C) 2019 by Sandro Mani
5     email                : smani at sourcepole dot ch
6  ***************************************************************************/
7 
8 /***************************************************************************
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #ifndef QGSANNOTATIONITEM_H
18 #define QGSANNOTATIONITEM_H
19 
20 #include "qgis_core.h"
21 #include "qgis_sip.h"
22 #include "qgscoordinatereferencesystem.h"
23 #include "qgsrendercontext.h"
24 #include "qgslinestring.h"
25 #include "qgspolygon.h"
26 
27 class QgsFeedback;
28 class QgsMarkerSymbol;
29 class QgsLineSymbol;
30 class QgsFillSymbol;
31 
32 /**
33  * \ingroup core
34  * \brief Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
35  *
36  * \since QGIS 3.16
37  */
38 class CORE_EXPORT QgsAnnotationItem
39 {
40 
41 #ifdef SIP_RUN
42     SIP_CONVERT_TO_SUBCLASS_CODE
43     if ( sipCpp->type() == QLatin1String( "marker" ) )
44     {
45       sipType = sipType_QgsAnnotationMarkerItem;
46     }
47     else if ( sipCpp->type() == QLatin1String( "linestring" ) )
48     {
49       sipType = sipType_QgsAnnotationLineItem;
50     }
51     else if ( sipCpp->type() == QLatin1String( "polygon" ) )
52     {
53       sipType = sipType_QgsAnnotationPolygonItem;
54     }
55     else if ( sipCpp->type() == QLatin1String( "pointtext" ) )
56     {
57       sipType = sipType_QgsAnnotationPointTextItem;
58     }
59     else
60     {
61       sipType = 0;
62     }
63     SIP_END
64 #endif
65 
66   public:
67 
68     /**
69      * Constructor for an annotation item.
70      */
71     QgsAnnotationItem() = default;
72 
73 #ifndef SIP_RUN
74     //! QgsAnnotationItem cannot be copied
75     QgsAnnotationItem( const QgsAnnotationItem &other ) = delete;
76     //! QgsAnnotationItem cannot be copied
77     QgsAnnotationItem &operator=( const QgsAnnotationItem &other ) = delete;
78 #endif
79 
80     virtual ~QgsAnnotationItem() = default;
81 
82     /**
83      * Returns a clone of the item. Ownership is transferred to the caller.
84      */
85     virtual QgsAnnotationItem *clone() = 0 SIP_FACTORY;
86 
87     /**
88      * Returns a unique (untranslated) string identifying the type of item.
89      */
90     virtual QString type() const = 0;
91 
92     /**
93      * Returns the bounding box of the item's geographic location, in the parent layer's coordinate reference system.
94      */
95     virtual QgsRectangle boundingBox() const = 0;
96 
97     /**
98      * Renders the item to the specified render \a context.
99      *
100      * The \a feedback argument can be used to detect render cancellations during expensive
101      * render operations.
102      */
103     virtual void render( QgsRenderContext &context, QgsFeedback *feedback ) = 0;
104 
105     /**
106      * Writes the item's state into an XML \a element.
107      */
108     virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
109 
110     /**
111      * Reads the item's state from the given DOM \a element.
112      */
113     virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
114 
115     /**
116      * Returns the item's z index, which controls the order in which annotation items
117      * are rendered in the layer.
118      *
119      * \see setZIndex()
120      */
zIndex()121     int zIndex() const { return mZIndex; }
122 
123     /**
124      * Sets the item's z \a index, which controls the order in which annotation items
125      * are rendered in the layer.
126      *
127      * \see zIndex()
128      */
setZIndex(int index)129     void setZIndex( int index ) { mZIndex = index; }
130 
131   private:
132 
133     int mZIndex = 0;
134 
135 #ifdef SIP_RUN
136     QgsAnnotationItem( const QgsAnnotationItem &other );
137 #endif
138 
139 };
140 
141 #endif // QGSANNOTATIONITEM_H
142