QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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#include <QObject>
26#include <QDomNode>
27#include <QMap>
28#include <QPointer>
29
30class QgsLayout;
31class QPainter;
33
38class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGenerator
39{
40#ifdef SIP_RUN
41#include <qgslayoutitem.h>
42#include "qgslayoutitemgroup.h"
43#include "qgslayoutitemmap.h"
45#include "qgslayoutitemlabel.h"
46#include "qgslayoutitemlegend.h"
50#include "qgslayoutframe.h"
51#include "qgslayoutitemshape.h"
52#include "qgslayoutitempage.h"
53#include "qgslayoutitemmarker.h"
55#endif
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
124 // did you read that comment above? NO? Go read it now. You're about to break stuff.
125
126 default:
127 sipType = sipType_QgsLayoutItem;
128 }
129 }
130 else
131 sipType = NULL;
132 SIP_END
133#endif
134
135 Q_OBJECT
136 public:
137
138 // *INDENT-OFF*
139
144 {
145 NoProperty = 0,
146 AllProperties,
147 TestProperty,
148 //composer page properties
149 PresetPaperSize,
150 PaperWidth,
151 PaperHeight,
152 NumPages,
153 PaperOrientation,
154 //general composer item properties
155 PageNumber,
156 PositionX,
157 PositionY,
158 ItemWidth,
159 ItemHeight,
160 ItemRotation,
161 Transparency,
162 Opacity,
163 BlendMode,
164 ExcludeFromExports,
165 FrameColor,
166 BackgroundColor,
167 MarginLeft,
168 MarginTop,
169 MarginRight,
170 MarginBottom,
171 //composer map
172 MapRotation,
173 MapScale,
174 MapXMin,
175 MapYMin,
176 MapXMax,
177 MapYMax,
178 MapAtlasMargin,
179 MapLayers,
180 MapStylePreset,
181 MapLabelMargin,
182 MapGridEnabled,
183 MapGridIntervalX,
184 MapGridIntervalY,
185 MapGridOffsetX,
186 MapGridOffsetY,
187 MapGridFrameSize,
188 MapGridFrameMargin,
189 MapGridLabelDistance,
190 MapGridCrossSize,
191 MapGridFrameLineThickness,
192 MapGridAnnotationDisplayLeft,
193 MapGridAnnotationDisplayRight,
194 MapGridAnnotationDisplayTop,
195 MapGridAnnotationDisplayBottom,
196 MapGridFrameDivisionsLeft,
197 MapGridFrameDivisionsRight,
198 MapGridFrameDivisionsTop,
199 MapGridFrameDivisionsBottom,
200 //composer picture
201 PictureSource,
202 PictureSvgBackgroundColor,
203 PictureSvgStrokeColor,
204 PictureSvgStrokeWidth,
205 //html item
206 SourceUrl,
207 //legend item
208 LegendTitle,
209 LegendColumnCount,
210 //scalebar item
211 ScalebarLeftSegments,
212 ScalebarRightSegments,
213 ScalebarSegmentWidth,
214 ScalebarMinimumWidth,
215 ScalebarMaximumWidth,
216 ScalebarHeight,
217 ScalebarRightSegmentSubdivisions,
218 ScalebarSubdivisionHeight,
219 ScalebarFillColor,
220 ScalebarFillColor2,
221 ScalebarLineColor,
222 ScalebarLineWidth,
223 //table item
224 AttributeTableSourceLayer,
225 MapCrs,
226 StartDateTime,
227 EndDateTime,
228 ElevationProfileTolerance,
229 ElevationProfileDistanceMajorInterval,
230 ElevationProfileDistanceMinorInterval,
231 ElevationProfileDistanceLabelInterval,
232 ElevationProfileElevationMajorInterval,
233 ElevationProfileElevationMinorInterval,
234 ElevationProfileElevationLabelInterval,
235 ElevationProfileMinimumDistance,
236 ElevationProfileMaximumDistance,
237 ElevationProfileMinimumElevation,
238 ElevationProfileMaximumElevation,
239 };
240
241 // *INDENT-ON*
242
249 {
250 EvaluatedValue = 0,
251 OriginalValue
252 };
253
257 static const QgsPropertiesDefinition &propertyDefinitions();
258
269 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
270
277 explicit QgsLayoutObject( QgsLayout *layout );
278
282 SIP_SKIP const QgsLayout *layout() const;
283
287 QgsLayout *layout();
288
293 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
294
300 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
301
308 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
309
310
319 void setCustomProperty( const QString &key, const QVariant &value );
320
330 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
331
339 void removeCustomProperty( const QString &key );
340
347 QStringList customProperties() const;
348
354
355 public slots:
356
360 virtual void refresh() {}
361
362 signals:
363
367 void changed();
368
369 protected:
370
379 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
380
389 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
390
391 QPointer< QgsLayout > mLayout;
392
394
397
398 private:
399
401 static QgsPropertiesDefinition sPropertyDefinitions;
402
403 static void initPropertyDefinitions();
404
405 friend class TestQgsLayoutObject;
407};
408
409#endif //QGSLAYOUTOBJECT_H
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
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 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.
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
QgsPropertyCollection mDataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
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.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the object's property collection, used for data defined overrides.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value,...
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
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 a integer key value.
The class is used as a container of context for various read/write operations on other objects.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_END
Definition qgis_sip.h:208
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.