QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsannotationitem.h
Go to the documentation of this file.
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 "qgscallout.h"
24#include "qgsgeometry.h"
25
26#include <QString>
27
28using namespace Qt::StringLiterals;
29
30class QgsFeedback;
31class QgsMarkerSymbol;
32class QgsLineSymbol;
33class QgsFillSymbol;
40
47class CORE_EXPORT QgsAnnotationItem
48{
49
50#ifdef SIP_RUN
52 if ( sipCpp->type() == "marker"_L1 )
53 {
54 sipType = sipType_QgsAnnotationMarkerItem;
55 }
56 else if ( sipCpp->type() == "linestring"_L1 )
57 {
58 sipType = sipType_QgsAnnotationLineItem;
59 }
60 else if ( sipCpp->type() == "polygon"_L1 )
61 {
62 sipType = sipType_QgsAnnotationPolygonItem;
63 }
64 else if ( sipCpp->type() == "pointtext"_L1 )
65 {
66 sipType = sipType_QgsAnnotationPointTextItem;
67 }
68 else if ( sipCpp->type() == "linetext"_L1 )
69 {
70 sipType = sipType_QgsAnnotationLineTextItem;
71 }
72 else if ( sipCpp->type() == "recttext"_L1 )
73 {
74 sipType = sipType_QgsAnnotationRectangleTextItem;
75 }
76 else if ( sipCpp->type() == "picture"_L1 )
77 {
78 sipType = sipType_QgsAnnotationPictureItem;
79 }
80 else
81 {
82 sipType = 0;
83 }
85#endif
86
87 public:
88
90
91#ifndef SIP_RUN
92 QgsAnnotationItem( const QgsAnnotationItem &other ) = delete;
94#endif
95
97
103 virtual Qgis::AnnotationItemFlags flags() const;
104
112 virtual QgsAnnotationItem *clone() const = 0 SIP_FACTORY;
113
117 virtual QString type() const = 0;
118
122 virtual QgsRectangle boundingBox() const = 0;
123
127 virtual QgsRectangle boundingBox( QgsRenderContext &context ) const { Q_UNUSED( context ) return boundingBox();}
128
135 virtual void render( QgsRenderContext &context, QgsFeedback *feedback ) = 0;
136
145 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
146
155 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
156
163
170
177
184
191 int zIndex() const { return mZIndex; }
192
199 void setZIndex( int index ) { mZIndex = index; }
200
207 bool enabled() const { return mEnabled; }
208
215 void setEnabled( bool enabled ) { mEnabled = enabled; }
216
222 Q_DECL_DEPRECATED virtual QList< QgsAnnotationItemNode > nodes() const SIP_DEPRECATED;
223
229 virtual QList< QgsAnnotationItemNode > nodesV2( const QgsAnnotationItemEditContext &context ) const;
230
237 bool useSymbologyReferenceScale() const { return mUseReferenceScale; }
238
245 void setUseSymbologyReferenceScale( bool enabled ) { mUseReferenceScale = enabled; }
246
262 double symbologyReferenceScale() const { return mReferenceScale; }
263
279 void setSymbologyReferenceScale( double scale ) { mReferenceScale = scale; }
280
296 QgsCallout *callout() const;
297
309 void setCallout( QgsCallout *callout SIP_TRANSFER );
310
324 QgsGeometry calloutAnchor() const;
325
339 void setCalloutAnchor( const QgsGeometry &anchor );
340
353 QSizeF offsetFromCallout() const;
354
367 void setOffsetFromCallout( const QSizeF &offset );
368
377 Qgis::RenderUnit offsetFromCalloutUnit() const;
378
387 void setOffsetFromCalloutUnit( Qgis::RenderUnit unit );
388
389 protected:
390
396 virtual void copyCommonProperties( const QgsAnnotationItem *other );
397
404 virtual bool writeCommonProperties( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
405
412 virtual bool readCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
413
421 void renderCallout( QgsRenderContext &context, const QRectF &rect, double angle, QgsCallout::QgsCalloutContext &calloutContext, QgsFeedback *feedback );
422
423 private:
424
425 int mZIndex = 0;
426 bool mEnabled = true;
427 bool mUseReferenceScale = false;
428 double mReferenceScale = 0;
429
430 std::unique_ptr< QgsCallout > mCallout;
431 QgsGeometry mCalloutAnchor;
432 QSizeF mOffsetFromCallout;
433 Qgis::RenderUnit mOffsetFromCalloutUnit = Qgis::RenderUnit::Millimeters;
434
435#ifdef SIP_RUN
436 QgsAnnotationItem( const QgsAnnotationItem &other );
437#endif
438
439};
440
441#endif // QGSANNOTATIONITEM_H
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2577
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
Definition qgis.h:2528
RenderUnit
Rendering size units.
Definition qgis.h:5255
@ Millimeters
Millimeters.
Definition qgis.h:5256
Abstract base class for annotation item edit operations.
Encapsulates the context for an annotation item edit operation.
Encapsulates the transient results of an in-progress annotation edit operation.
Contains information about a node used for editing an annotation item.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
void setUseSymbologyReferenceScale(bool enabled)
Sets whether the annotation item uses a symbology reference scale.
void setZIndex(int index)
Sets the item's z index, which controls the order in which annotation items are rendered in the layer...
bool useSymbologyReferenceScale() const
Returns true if the annotation item uses a symbology reference scale.
virtual ~QgsAnnotationItem()
virtual bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const =0
Writes the item's state into an XML element.
virtual QgsRectangle boundingBox() const =0
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
void setEnabled(bool enabled)
Sets if the item will be rendered or not in the layer.
virtual QString type() const =0
Returns a unique (untranslated) string identifying the type of item.
virtual void render(QgsRenderContext &context, QgsFeedback *feedback)=0
Renders the item to the specified render context.
bool enabled() const
Returns true if the item is enabled and will be rendered in the layer.
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads the item's state from the given DOM element.
QgsAnnotationItem(const QgsAnnotationItem &other)=delete
virtual Q_DECL_DEPRECATED QgsAnnotationItemEditOperationTransientResults * transientEditResults(QgsAbstractAnnotationItemEditOperation *operation)
Retrieves the results of a transient (in progress) edit operation on the item.
QgsAnnotationItem & operator=(const QgsAnnotationItem &other)=delete
virtual QgsAnnotationItemEditOperationTransientResults * transientEditResultsV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context)
Retrieves the results of a transient (in progress) edit operation on the item.
void setSymbologyReferenceScale(double scale)
Sets the annotation's symbology reference scale.
virtual Qgis::AnnotationItemFlags flags() const
Returns item flags.
virtual Qgis::AnnotationItemEditOperationResult applyEditV2(QgsAbstractAnnotationItemEditOperation *operation, const QgsAnnotationItemEditContext &context)
Applies an edit operation to the item.
int zIndex() const
Returns the item's z index, which controls the order in which annotation items are rendered in the la...
virtual Q_DECL_DEPRECATED Qgis::AnnotationItemEditOperationResult applyEdit(QgsAbstractAnnotationItemEditOperation *operation)
Applies an edit operation to the item.
virtual QgsRectangle boundingBox(QgsRenderContext &context) const
Returns the bounding box of the item's geographic location, in the parent layer's coordinate referenc...
double symbologyReferenceScale() const
Returns the annotation's symbology reference scale.
virtual QgsAnnotationItem * clone() const =0
Returns a clone of the item.
Contains additional contextual information about the context in which a callout is being rendered.
Definition qgscallout.h:250
Abstract base class for callout renderers.
Definition qgscallout.h:55
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
A geometry is the spatial representation of a feature.
A line symbol type, for rendering LineString and MultiLineString geometries.
A marker symbol type, for rendering Point and MultiPoint geometries.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216