QGIS API Documentation 3.43.0-Master (32433f7016e)
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 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitem.h" );
41 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemgroup.h" );
42 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmap.h" );
43 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempicture.h" );
44 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemlabel.h" );
45 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemlegend.h" );
46 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempolygon.h" );
47 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempolyline.h" );
48 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemscalebar.h" );
49 //SIP_TYPEHEADER_INCLUDE( "qgslayoutframe.h" );
50 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemshape.h" );
51 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitempage.h" );
52 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemmarker.h" );
53 //SIP_TYPEHEADER_INCLUDE( "qgslayoutitemelevationprofile.h" );
54
55#ifdef SIP_RUN
57 if ( QgsLayoutItem *item = qobject_cast< QgsLayoutItem * >( sipCpp ) )
58 {
59 // the conversions have to be static, because they're using multiple inheritance
60 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
61 switch ( item->type() )
62 {
63 // FREAKKKKIIN IMPORTANT!
64 // IF YOU PUT SOMETHING HERE, PUT IT IN QgsLayoutItem CASTING **ALSO**
65 // (it's not enough for it to be in only one of the places, as sip inconsistently
66 // decides which casting code to perform here)
67
68 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
69 case QGraphicsItem::UserType + 101:
70 sipType = sipType_QgsLayoutItemGroup;
71 *sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
72 break;
73 case QGraphicsItem::UserType + 102:
74 sipType = sipType_QgsLayoutItemPage;
75 *sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
76 break;
77 case QGraphicsItem::UserType + 103:
78 sipType = sipType_QgsLayoutItemMap;
79 *sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
80 break;
81 case QGraphicsItem::UserType + 104:
82 sipType = sipType_QgsLayoutItemPicture;
83 *sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
84 break;
85 case QGraphicsItem::UserType + 105:
86 sipType = sipType_QgsLayoutItemLabel;
87 *sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
88 break;
89 case QGraphicsItem::UserType + 106:
90 sipType = sipType_QgsLayoutItemLegend;
91 *sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
92 break;
93 case QGraphicsItem::UserType + 107:
94 sipType = sipType_QgsLayoutItemShape;
95 *sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
96 break;
97 case QGraphicsItem::UserType + 108:
98 sipType = sipType_QgsLayoutItemPolygon;
99 *sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
100 break;
101 case QGraphicsItem::UserType + 109:
102 sipType = sipType_QgsLayoutItemPolyline;
103 *sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
104 break;
105 case QGraphicsItem::UserType + 110:
106 sipType = sipType_QgsLayoutItemScaleBar;
107 *sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
108 break;
109 case QGraphicsItem::UserType + 111:
110 sipType = sipType_QgsLayoutFrame;
111 *sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
112 break;
113 case QGraphicsItem::UserType + 117:
114 sipType = sipType_QgsLayoutItemMarker;
115 *sipCppRet = static_cast<QgsLayoutItemMarker *>( sipCpp );
116 break;
117 case QGraphicsItem::UserType + 118:
118 sipType = sipType_QgsLayoutItemElevationProfile;
119 *sipCppRet = static_cast<QgsLayoutItemElevationProfile *>( sipCpp );
120 break;
121
122 // did you read that comment above? NO? Go read it now. You're about to break stuff.
123
124 default:
125 sipType = sipType_QgsLayoutItem;
126 }
127 }
128 else
129 sipType = NULL;
130 SIP_END
131#endif
132
133 Q_OBJECT
134 public:
135
136 // *INDENT-OFF*
137
142 {
143 NoProperty = 0,
144 AllProperties,
145 TestProperty,
146 //composer page properties
147 PresetPaperSize,
148 PaperWidth,
149 PaperHeight,
150 NumPages,
151 PaperOrientation,
152 //general composer item properties
153 PageNumber,
154 PositionX,
155 PositionY,
156 ItemWidth,
157 ItemHeight,
158 ItemRotation,
159 Transparency,
160 Opacity,
161 BlendMode,
162 ExcludeFromExports,
163 FrameColor,
164 BackgroundColor,
165 MarginLeft,
166 MarginTop,
167 MarginRight,
168 MarginBottom,
169 //composer map
170 MapRotation,
171 MapScale,
172 MapXMin,
173 MapYMin,
174 MapXMax,
175 MapYMax,
176 MapAtlasMargin,
177 MapLayers,
178 MapStylePreset,
179 MapLabelMargin,
180 MapGridEnabled,
181 MapGridIntervalX,
182 MapGridIntervalY,
183 MapGridOffsetX,
184 MapGridOffsetY,
185 MapGridFrameSize,
186 MapGridFrameMargin,
187 MapGridLabelDistance,
188 MapGridCrossSize,
189 MapGridFrameLineThickness,
190 MapGridAnnotationDisplayLeft,
191 MapGridAnnotationDisplayRight,
192 MapGridAnnotationDisplayTop,
193 MapGridAnnotationDisplayBottom,
194 MapGridFrameDivisionsLeft,
195 MapGridFrameDivisionsRight,
196 MapGridFrameDivisionsTop,
197 MapGridFrameDivisionsBottom,
198 MapCrs,
199 StartDateTime,
200 EndDateTime,
201 MapZRangeLower,
202 MapZRangeUpper,
203 //composer picture
204 PictureSource,
205 PictureSvgBackgroundColor,
206 PictureSvgStrokeColor,
207 PictureSvgStrokeWidth,
208 //html item
209 SourceUrl,
210 //legend item
211 LegendTitle,
212 LegendColumnCount,
213 LegendAutoWrapWidth,
214 //scalebar item
215 ScalebarLeftSegments,
216 ScalebarRightSegments,
217 ScalebarSegmentWidth,
218 ScalebarMinimumWidth,
219 ScalebarMaximumWidth,
220 ScalebarHeight,
221 ScalebarRightSegmentSubdivisions,
222 ScalebarSubdivisionHeight,
223 ScalebarFillColor,
224 ScalebarFillColor2,
225 ScalebarLineColor,
226 ScalebarLineWidth,
227 //table item
228 AttributeTableSourceLayer,
229 ElevationProfileTolerance,
230 ElevationProfileDistanceMajorInterval,
231 ElevationProfileDistanceMinorInterval,
232 ElevationProfileDistanceLabelInterval,
233 ElevationProfileElevationMajorInterval,
234 ElevationProfileElevationMinorInterval,
235 ElevationProfileElevationLabelInterval,
236 ElevationProfileMinimumDistance,
237 ElevationProfileMaximumDistance,
238 ElevationProfileMinimumElevation,
239 ElevationProfileMaximumElevation,
240 };
241
242 // *INDENT-ON*
243
250 {
251 EvaluatedValue = 0,
252 OriginalValue
253 };
254
258 static const QgsPropertiesDefinition &propertyDefinitions();
259
270 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
271
278 explicit QgsLayoutObject( QgsLayout *layout );
279
283 SIP_SKIP const QgsLayout *layout() const;
284
288 QgsLayout *layout();
289
294 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
295
301 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
302
309 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
310
311
320 void setCustomProperty( const QString &key, const QVariant &value );
321
331 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
332
340 void removeCustomProperty( const QString &key );
341
348 QStringList customProperties() const;
349
355
356 public slots:
357
361 virtual void refresh() {}
362
363 signals:
364
368 void changed();
369
370 protected:
371
380 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
381
390 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
391
392 QPointer< QgsLayout > mLayout;
393
395
398
399 private:
400
402 static QgsPropertiesDefinition sPropertyDefinitions;
403
404 static void initPropertyDefinitions();
405
406 friend class TestQgsLayoutObject;
408};
409
410#endif //QGSLAYOUTOBJECT_H
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 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: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.