QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslayoutobject.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutobject.h
3 -------------------
4 begin : June 2017
5 copyright : (C) 2017 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#ifndef QGSLAYOUTOBJECT_H
18#define QGSLAYOUTOBJECT_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
25
26#include <QDomNode>
27#include <QMap>
28#include <QObject>
29#include <QPointer>
30
31class QgsLayout;
32class QPainter;
34
39class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGenerator
40{
41 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitem.h" );
42 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemgroup.h" );
43 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmap.h" );
44 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempicture.h" );
45 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemlabel.h" );
46 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemlegend.h" );
47 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempolygon.h" );
48 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempolyline.h" );
49 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemscalebar.h" );
50 //SIP_TYPEHEADER_INCLUDE( "qgslayoutframe.h" );
51 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemshape.h" );
52 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempage.h" );
53 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmarker.h" );
54 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemelevationprofile.h" );
55 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemchart.h" );
56
57#ifdef SIP_RUN
59 if ( QgsLayoutItem *item = qobject_cast< QgsLayoutItem * >( sipCpp ) )
60 {
61 // the conversions have to be static, because they're using multiple inheritance
62 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
63 switch ( item->type() )
64 {
65 // FREAKKKKIIN IMPORTANT!
66 // IF YOU PUT SOMETHING HERE, PUT IT IN QgsLayoutItem CASTING **ALSO**
67 // (it's not enough for it to be in only one of the places, as sip inconsistently
68 // decides which casting code to perform here)
69
70 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
71 case QGraphicsItem::UserType + 101:
72 sipType = sipType_QgsLayoutItemGroup;
73 *sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
74 break;
75 case QGraphicsItem::UserType + 102:
76 sipType = sipType_QgsLayoutItemPage;
77 *sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
78 break;
79 case QGraphicsItem::UserType + 103:
80 sipType = sipType_QgsLayoutItemMap;
81 *sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
82 break;
83 case QGraphicsItem::UserType + 104:
84 sipType = sipType_QgsLayoutItemPicture;
85 *sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
86 break;
87 case QGraphicsItem::UserType + 105:
88 sipType = sipType_QgsLayoutItemLabel;
89 *sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
90 break;
91 case QGraphicsItem::UserType + 106:
92 sipType = sipType_QgsLayoutItemLegend;
93 *sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
94 break;
95 case QGraphicsItem::UserType + 107:
96 sipType = sipType_QgsLayoutItemShape;
97 *sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
98 break;
99 case QGraphicsItem::UserType + 108:
100 sipType = sipType_QgsLayoutItemPolygon;
101 *sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
102 break;
103 case QGraphicsItem::UserType + 109:
104 sipType = sipType_QgsLayoutItemPolyline;
105 *sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
106 break;
107 case QGraphicsItem::UserType + 110:
108 sipType = sipType_QgsLayoutItemScaleBar;
109 *sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
110 break;
111 case QGraphicsItem::UserType + 111:
112 sipType = sipType_QgsLayoutFrame;
113 *sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
114 break;
115 case QGraphicsItem::UserType + 117:
116 sipType = sipType_QgsLayoutItemMarker;
117 *sipCppRet = static_cast<QgsLayoutItemMarker *>( sipCpp );
118 break;
119 case QGraphicsItem::UserType + 118:
120 sipType = sipType_QgsLayoutItemElevationProfile;
121 *sipCppRet = static_cast<QgsLayoutItemElevationProfile *>( sipCpp );
122 break;
123 case QGraphicsItem::UserType + 119:
124 sipType = sipType_QgsLayoutItemChart;
125 *sipCppRet = static_cast<QgsLayoutItemChart *>( sipCpp );
126 break;
127
128 // did you read that comment above? NO? Go read it now. You're about to break stuff.
129
130 default:
131 sipType = sipType_QgsLayoutItem;
132 }
133 }
134 else
135 sipType = NULL;
136 SIP_END
137#endif
138
139 Q_OBJECT
140 public:
141
142 // *INDENT-OFF*
143
148 {
149 NoProperty = 0,
150 AllProperties,
151 TestProperty,
152 //composer page properties
153 PresetPaperSize,
154 PaperWidth,
155 PaperHeight,
156 NumPages,
157 PaperOrientation,
158 //general composer item properties
159 PageNumber,
160 PositionX,
161 PositionY,
162 ItemWidth,
163 ItemHeight,
164 ItemRotation,
165 Transparency,
166 Opacity,
167 BlendMode,
168 ExcludeFromExports,
169 FrameColor,
170 BackgroundColor,
171 MarginLeft,
172 MarginTop,
173 MarginRight,
174 MarginBottom,
175 //composer map
176 MapRotation,
177 MapScale,
178 MapXMin,
179 MapYMin,
180 MapXMax,
181 MapYMax,
182 MapAtlasMargin,
183 MapLayers,
184 MapStylePreset,
185 MapLabelMargin,
186 MapGridEnabled,
187 MapGridIntervalX,
188 MapGridIntervalY,
189 MapGridOffsetX,
190 MapGridOffsetY,
191 MapGridFrameSize,
192 MapGridFrameMargin,
193 MapGridLabelDistance,
194 MapGridCrossSize,
195 MapGridFrameLineThickness,
196 MapGridAnnotationDisplayLeft,
197 MapGridAnnotationDisplayRight,
198 MapGridAnnotationDisplayTop,
199 MapGridAnnotationDisplayBottom,
200 MapGridFrameDivisionsLeft,
201 MapGridFrameDivisionsRight,
202 MapGridFrameDivisionsTop,
203 MapGridFrameDivisionsBottom,
204 MapGridDrawAnnotation,
205 MapCrs,
206 StartDateTime,
207 EndDateTime,
208 MapZRangeLower,
209 MapZRangeUpper,
210 //composer picture
211 PictureSource,
212 PictureSvgBackgroundColor,
213 PictureSvgStrokeColor,
214 PictureSvgStrokeWidth,
215 //html item
216 SourceUrl,
217 //legend item
218 LegendTitle,
219 LegendColumnCount,
220 LegendAutoWrapWidth,
221 //scalebar item
222 ScalebarLeftSegments,
223 ScalebarRightSegments,
224 ScalebarSegmentWidth,
225 ScalebarMinimumWidth,
226 ScalebarMaximumWidth,
227 ScalebarHeight,
228 ScalebarRightSegmentSubdivisions,
229 ScalebarSubdivisionHeight,
230 ScalebarFillColor,
231 ScalebarFillColor2,
232 ScalebarLineColor,
233 ScalebarLineWidth,
234 //table item
235 AttributeTableSourceLayer,
236 ElevationProfileTolerance,
237 ElevationProfileDistanceMajorInterval,
238 ElevationProfileDistanceMinorInterval,
239 ElevationProfileDistanceLabelInterval,
240 ElevationProfileElevationMajorInterval,
241 ElevationProfileElevationMinorInterval,
242 ElevationProfileElevationLabelInterval,
243 ElevationProfileMinimumDistance,
244 ElevationProfileMaximumDistance,
245 ElevationProfileMinimumElevation,
246 ElevationProfileMaximumElevation,
247 };
248
249 // *INDENT-ON*
250
261
265 static const QgsPropertiesDefinition &propertyDefinitions();
266
277 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
278
285 explicit QgsLayoutObject( QgsLayout *layout );
286
290 SIP_SKIP const QgsLayout *layout() const;
291
295 QgsLayout *layout();
296
302
309
317
318
327 void setCustomProperty( const QString &key, const QVariant &value );
328
338 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
339
347 void removeCustomProperty( const QString &key );
348
355 QStringList customProperties() const;
356
362
363 public slots:
364
368 virtual void refresh() {}
369
370 signals:
371
375 void changed();
376
377 protected:
378
387 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
388
397 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
398
399 QPointer< QgsLayout > mLayout;
400
402
405
406 private:
407
409 static QgsPropertiesDefinition sPropertyDefinitions;
410
411 static void initPropertyDefinitions();
412
415};
416
417#endif //QGSLAYOUTOBJECT_H
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Base class for frame items, which form a layout multiframe item.
A layout item subclass that renders chart plots.
A layout item subclass for elevation profile plots.
A container for grouping several QgsLayoutItems.
A layout item subclass for text labels.
A layout item subclass for map legends.
Layout graphical items for displaying a map.
A layout item for showing marker symbols.
Item representing the paper in a layout.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
Layout item for node based polygon shapes.
Layout item for node based polyline shapes.
A layout item subclass for scale bars.
Layout item for basic filled shapes (e.g.
Base class for graphical items within a QgsLayout.
A base class for objects which belong to a layout.
friend class TestQgsLayoutObject
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
QgsPropertyCollection mDataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
void changed()
Emitted when the object's properties change.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the objects's property collection, used for data defined overrides.
friend class QgsCompositionConverter
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the object's property collection, used for data defined overrides.
QgsLayoutObject(QgsLayout *layout)
Constructor for QgsLayoutObject, with the specified parent layout.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value,...
@ OriginalValue
Return the original, user set value.
@ EvaluatedValue
Return the current evaluated value for the property.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A container for the context for various read/write operations on objects.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_END
Definition qgis_sip.h:216
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.