QGIS API Documentation 3.39.0-Master (be2050b798e)
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 MapCrs,
201 StartDateTime,
202 EndDateTime,
203 MapZRangeLower,
204 MapZRangeUpper,
205 //composer picture
206 PictureSource,
207 PictureSvgBackgroundColor,
208 PictureSvgStrokeColor,
209 PictureSvgStrokeWidth,
210 //html item
211 SourceUrl,
212 //legend item
213 LegendTitle,
214 LegendColumnCount,
215 //scalebar item
216 ScalebarLeftSegments,
217 ScalebarRightSegments,
218 ScalebarSegmentWidth,
219 ScalebarMinimumWidth,
220 ScalebarMaximumWidth,
221 ScalebarHeight,
222 ScalebarRightSegmentSubdivisions,
223 ScalebarSubdivisionHeight,
224 ScalebarFillColor,
225 ScalebarFillColor2,
226 ScalebarLineColor,
227 ScalebarLineWidth,
228 //table item
229 AttributeTableSourceLayer,
230 ElevationProfileTolerance,
231 ElevationProfileDistanceMajorInterval,
232 ElevationProfileDistanceMinorInterval,
233 ElevationProfileDistanceLabelInterval,
234 ElevationProfileElevationMajorInterval,
235 ElevationProfileElevationMinorInterval,
236 ElevationProfileElevationLabelInterval,
237 ElevationProfileMinimumDistance,
238 ElevationProfileMaximumDistance,
239 ElevationProfileMinimumElevation,
240 ElevationProfileMaximumElevation,
241 };
242
243 // *INDENT-ON*
244
251 {
252 EvaluatedValue = 0,
253 OriginalValue
254 };
255
259 static const QgsPropertiesDefinition &propertyDefinitions();
260
271 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
272
279 explicit QgsLayoutObject( QgsLayout *layout );
280
284 SIP_SKIP const QgsLayout *layout() const;
285
289 QgsLayout *layout();
290
295 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
296
302 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
303
310 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
311
312
321 void setCustomProperty( const QString &key, const QVariant &value );
322
332 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
333
341 void removeCustomProperty( const QString &key );
342
349 QStringList customProperties() const;
350
356
357 public slots:
358
362 virtual void refresh() {}
363
364 signals:
365
369 void changed();
370
371 protected:
372
381 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
382
391 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
392
393 QPointer< QgsLayout > mLayout;
394
396
399
400 private:
401
403 static QgsPropertiesDefinition sPropertyDefinitions;
404
405 static void initPropertyDefinitions();
406
407 friend class TestQgsLayoutObject;
409};
410
411#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.