QGIS API Documentation 4.3.0-Master (6402a64e93b)
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;
40class QPainter;
41
48class CORE_EXPORT QgsAnnotationItem
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:
89
90#ifndef SIP_RUN
91 QgsAnnotationItem( const QgsAnnotationItem &other ) = delete;
93#endif
94
96
102 virtual Qgis::AnnotationItemFlags flags() const;
103
111 virtual QgsAnnotationItem *clone() const = 0 SIP_FACTORY;
112
116 virtual QString type() const = 0;
117
121 virtual QgsRectangle boundingBox() const = 0;
122
126 virtual QgsRectangle boundingBox( QgsRenderContext &context ) const
127 {
128 Q_UNUSED( context )
129 return boundingBox();
130 }
131
138 virtual void render( QgsRenderContext &context, QgsFeedback *feedback ) = 0;
139
148 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const = 0;
149
158 virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
159
166
173
180
187
194 int zIndex() const { return mZIndex; }
195
202 void setZIndex( int index ) { mZIndex = index; }
203
210 bool enabled() const { return mEnabled; }
211
218 void setEnabled( bool enabled ) { mEnabled = enabled; }
219
225 Q_DECL_DEPRECATED virtual QList< QgsAnnotationItemNode > nodes() const SIP_DEPRECATED;
226
232 virtual QList< QgsAnnotationItemNode > nodesV2( const QgsAnnotationItemEditContext &context ) const;
233
240 bool useSymbologyReferenceScale() const { return mUseReferenceScale; }
241
248 void setUseSymbologyReferenceScale( bool enabled ) { mUseReferenceScale = enabled; }
249
265 double symbologyReferenceScale() const { return mReferenceScale; }
266
282 void setSymbologyReferenceScale( double scale ) { mReferenceScale = scale; }
283
299 QgsCallout *callout() const;
300
312 void setCallout( QgsCallout *callout SIP_TRANSFER );
313
327 QgsGeometry calloutAnchor() const;
328
342 void setCalloutAnchor( const QgsGeometry &anchor );
343
356 QSizeF offsetFromCallout() const;
357
370 void setOffsetFromCallout( const QSizeF &offset );
371
380 Qgis::RenderUnit offsetFromCalloutUnit() const;
381
390 void setOffsetFromCalloutUnit( Qgis::RenderUnit unit );
391
392 protected:
398 virtual void copyCommonProperties( const QgsAnnotationItem *other );
399
406 virtual bool writeCommonProperties( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
407
414 virtual bool readCommonProperties( const QDomElement &element, const QgsReadWriteContext &context );
415
423 void renderCallout( QgsRenderContext &context, const QRectF &rect, double angle, QgsCallout::QgsCalloutContext &calloutContext, QgsFeedback *feedback );
424
425 private:
426 int mZIndex = 0;
427 bool mEnabled = true;
428 bool mUseReferenceScale = false;
429 double mReferenceScale = 0;
430
431 std::unique_ptr< QgsCallout > mCallout;
432 QgsGeometry mCalloutAnchor;
433 QSizeF mOffsetFromCallout;
434 Qgis::RenderUnit mOffsetFromCalloutUnit = Qgis::RenderUnit::Millimeters;
435
436#ifdef SIP_RUN
437 QgsAnnotationItem( const QgsAnnotationItem &other );
438#endif
439};
440
441#endif // QGSANNOTATIONITEM_H
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition qgis.h:2706
QFlags< AnnotationItemFlag > AnnotationItemFlags
Annotation item flags.
Definition qgis.h:2657
RenderUnit
Rendering size units.
Definition qgis.h:5655
@ Millimeters
Millimeters.
Definition qgis.h:5656
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