QGIS API Documentation 4.1.0-Master (60fea48833c)
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 // clang-format off
140 Q_OBJECT
141
142 public:
143
144 // *INDENT-OFF*
145
150 {
151 NoProperty = 0,
152 AllProperties,
153 TestProperty,
154 //composer page properties
155 PresetPaperSize,
156 PaperWidth,
157 PaperHeight,
158 NumPages,
159 PaperOrientation,
160 //general composer item properties
161 PageNumber,
162 PositionX,
163 PositionY,
164 ItemWidth,
165 ItemHeight,
166 ItemRotation,
167 Transparency,
168 Opacity,
169 BlendMode,
170 ExcludeFromExports,
171 FrameColor,
172 BackgroundColor,
173 MarginLeft,
174 MarginTop,
175 MarginRight,
176 MarginBottom,
177 //composer map
178 MapRotation,
179 MapScale,
180 MapXMin,
181 MapYMin,
182 MapXMax,
183 MapYMax,
184 MapAtlasMargin,
185 MapLayers,
186 MapStylePreset,
187 MapLabelMargin,
188 MapGridEnabled,
189 MapGridIntervalX,
190 MapGridIntervalY,
191 MapGridOffsetX,
192 MapGridOffsetY,
193 MapGridFrameSize,
194 MapGridFrameMargin,
195 MapGridLabelDistance,
196 MapGridCrossSize,
197 MapGridFrameLineThickness,
198 MapGridAnnotationDisplayLeft,
199 MapGridAnnotationDisplayRight,
200 MapGridAnnotationDisplayTop,
201 MapGridAnnotationDisplayBottom,
202 MapGridFrameDivisionsLeft,
203 MapGridFrameDivisionsRight,
204 MapGridFrameDivisionsTop,
205 MapGridFrameDivisionsBottom,
206 MapGridDrawAnnotation,
207 MapCrs,
208 StartDateTime,
209 EndDateTime,
210 MapZRangeLower,
211 MapZRangeUpper,
212 //composer picture
213 PictureSource,
214 PictureSvgBackgroundColor,
215 PictureSvgStrokeColor,
216 PictureSvgStrokeWidth,
217 //html item
218 SourceUrl,
219 //legend item
220 LegendTitle,
221 LegendColumnCount,
222 LegendAutoWrapWidth,
223 //scalebar item
224 ScalebarLeftSegments,
225 ScalebarRightSegments,
226 ScalebarSegmentWidth,
227 ScalebarMinimumWidth,
228 ScalebarMaximumWidth,
229 ScalebarHeight,
230 ScalebarRightSegmentSubdivisions,
231 ScalebarSubdivisionHeight,
232 ScalebarFillColor,
233 ScalebarFillColor2,
234 ScalebarLineColor,
235 ScalebarLineWidth,
236 //table item
237 AttributeTableSourceLayer,
238 ElevationProfileTolerance,
239 ElevationProfileDistanceMajorInterval,
240 ElevationProfileDistanceMinorInterval,
241 ElevationProfileDistanceLabelInterval,
242 ElevationProfileElevationMajorInterval,
243 ElevationProfileElevationMinorInterval,
244 ElevationProfileElevationLabelInterval,
245 ElevationProfileMinimumDistance,
246 ElevationProfileMaximumDistance,
247 ElevationProfileMinimumElevation,
248 ElevationProfileMaximumElevation,
249 };
250 // clang-format on
251
252 // *INDENT-ON*
253
264
268 static const QgsPropertiesDefinition &propertyDefinitions();
269
280 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
281
288 explicit QgsLayoutObject( QgsLayout *layout );
289
293 SIP_SKIP const QgsLayout *layout() const;
294
298 QgsLayout *layout();
299
305
312
320
321
330 void setCustomProperty( const QString &key, const QVariant &value );
331
341 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
342
350 void removeCustomProperty( const QString &key );
351
358 QStringList customProperties() const;
359
365
366 public slots:
367
371 virtual void refresh() {}
372
373 signals:
374
378 void changed();
379
380 protected:
389 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
390
399 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
400
401 QPointer< QgsLayout > mLayout;
402
404
407
408 private:
410 static QgsPropertiesDefinition sPropertyDefinitions;
411
412 static void initPropertyDefinitions();
413
416};
417
418#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:198
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_END
Definition qgis_sip.h:215
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.