QGIS API Documentation 4.1.0-Master (60fea48833c)
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#ifdef SIP_RUN
51 if ( sipCpp->type() == "marker"_L1 )
52 {
53 sipType = sipType_QgsAnnotationMarkerItem;
54 }
55 else if ( sipCpp->type() == "linestring"_L1 )
56 {
57 sipType = sipType_QgsAnnotationLineItem;
58 }
59 else if ( sipCpp->type() == "polygon"_L1 )
60 {
61 sipType = sipType_QgsAnnotationPolygonItem;
62 }
63 else if ( sipCpp->type() == "pointtext"_L1 )
64 {
65 sipType = sipType_QgsAnnotationPointTextItem;
66 }
67 else if ( sipCpp->type() == "linetext"_L1 )
68 {
69 sipType = sipType_QgsAnnotationLineTextItem;
70 }
71 else if ( sipCpp->type() == "recttext"_L1 )
72 {
73 sipType = sipType_QgsAnnotationRectangleTextItem;
74 }
75 else if ( sipCpp->type() == "picture"_L1 )
76 {
77 sipType = sipType_QgsAnnotationPictureItem;
78 }
79 else
80 {
81 sipType = 0;
82 }
84#endif
85
86 public:
88
89#ifndef SIP_RUN
90 QgsAnnotationItem( const QgsAnnotationItem &other ) = delete;
92#endif
93
95
101 virtual Qgis::AnnotationItemFlags flags() const;
102
110 virtual QgsAnnotationItem *clone() const = 0 SIP_FACTORY;
111
115 virtual QString type() const = 0;
116
120 virtual QgsRectangle boundingBox() const = 0;
121
125 virtual QgsRectangle boundingBox( QgsRenderContext &context ) const
126 {
127 Q_UNUSED( context )
128 return boundingBox();
129 }
130
137 virtual void render( QgsRenderContext &context, QgsFeedback *feedback ) = 0;
138
147 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
148
157 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
158
165
172
179
186
193 int zIndex() const { return mZIndex; }
194
201 void setZIndex( int index ) { mZIndex = index; }
202
209 bool enabled() const { return mEnabled; }
210
217 void setEnabled( bool enabled ) { mEnabled = enabled; }
218
224 Q_DECL_DEPRECATED virtual QList< QgsAnnotationItemNode > nodes() const SIP_DEPRECATED;
225
231 virtual QList< QgsAnnotationItemNode > nodesV2( const QgsAnnotationItemEditContext &context ) const;
232
239 bool useSymbologyReferenceScale() const { return mUseReferenceScale; }
240
247 void setUseSymbologyReferenceScale( bool enabled ) { mUseReferenceScale = enabled; }
248
264 double symbologyReferenceScale() const { return mReferenceScale; }
265
281 void setSymbologyReferenceScale( double scale ) { mReferenceScale = scale; }
282
298 QgsCallout *callout() const;
299
311 void setCallout( QgsCallout *callout SIP_TRANSFER );
312
326 QgsGeometry calloutAnchor() const;
327
341 void setCalloutAnchor( const QgsGeometry &anchor );
342
355 QSizeF offsetFromCallout() const;
356
369 void setOffsetFromCallout( const QSizeF &offset );
370
379 Qgis::RenderUnit offsetFromCalloutUnit() const;
380
389 void setOffsetFromCalloutUnit( Qgis::RenderUnit unit );
390
391 protected:
397 virtual void copyCommonProperties( const QgsAnnotationItem *other );
398
405 virtual bool writeCommonProperties( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
406
413 virtual bool readCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
414
422 void renderCallout( QgsRenderContext &context, const QRectF &rect, double angle, QgsCallout::QgsCalloutContext &calloutContext, QgsFeedback *feedback );
423
424 private:
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#endif // QGSANNOTATIONITEM_H
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2608
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
Definition qgis.h:2559
RenderUnit
Rendering size units.
Definition qgis.h:5340
@ Millimeters
Millimeters.
Definition qgis.h:5341
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:248
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:198
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215