QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 //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 //scalebar item
214 ScalebarLeftSegments,
215 ScalebarRightSegments,
216 ScalebarSegmentWidth,
217 ScalebarMinimumWidth,
218 ScalebarMaximumWidth,
219 ScalebarHeight,
220 ScalebarRightSegmentSubdivisions,
221 ScalebarSubdivisionHeight,
222 ScalebarFillColor,
223 ScalebarFillColor2,
224 ScalebarLineColor,
225 ScalebarLineWidth,
226 //table item
227 AttributeTableSourceLayer,
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 SIP_SKIP { return mDataDefinedProperties; }
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.