QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
39class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGenerator
40{
41#ifdef SIP_RUN
42#include <qgslayoutitem.h>
43#include "qgslayoutitemgroup.h"
44#include "qgslayoutitemmap.h"
46#include "qgslayoutitemlabel.h"
47#include "qgslayoutitemlegend.h"
51#include "qgslayoutframe.h"
52#include "qgslayoutitemshape.h"
53#include "qgslayoutitempage.h"
54#include "qgslayoutitemmarker.h"
56#endif
57
58#ifdef SIP_RUN
60 if ( QgsLayoutItem *item = qobject_cast< QgsLayoutItem * >( sipCpp ) )
61 {
62 // the conversions have to be static, because they're using multiple inheritance
63 // (seen in PyQt4 .sip files for some QGraphicsItem classes)
64 switch ( item->type() )
65 {
66 // FREAKKKKIIN IMPORTANT!
67 // IF YOU PUT SOMETHING HERE, PUT IT IN QgsLayoutItem CASTING **ALSO**
68 // (it's not enough for it to be in only one of the places, as sip inconsistently
69 // decides which casting code to perform here)
70
71 // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
72 case QGraphicsItem::UserType + 101:
73 sipType = sipType_QgsLayoutItemGroup;
74 *sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
75 break;
76 case QGraphicsItem::UserType + 102:
77 sipType = sipType_QgsLayoutItemPage;
78 *sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
79 break;
80 case QGraphicsItem::UserType + 103:
81 sipType = sipType_QgsLayoutItemMap;
82 *sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
83 break;
84 case QGraphicsItem::UserType + 104:
85 sipType = sipType_QgsLayoutItemPicture;
86 *sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
87 break;
88 case QGraphicsItem::UserType + 105:
89 sipType = sipType_QgsLayoutItemLabel;
90 *sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
91 break;
92 case QGraphicsItem::UserType + 106:
93 sipType = sipType_QgsLayoutItemLegend;
94 *sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
95 break;
96 case QGraphicsItem::UserType + 107:
97 sipType = sipType_QgsLayoutItemShape;
98 *sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
99 break;
100 case QGraphicsItem::UserType + 108:
101 sipType = sipType_QgsLayoutItemPolygon;
102 *sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
103 break;
104 case QGraphicsItem::UserType + 109:
105 sipType = sipType_QgsLayoutItemPolyline;
106 *sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
107 break;
108 case QGraphicsItem::UserType + 110:
109 sipType = sipType_QgsLayoutItemScaleBar;
110 *sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
111 break;
112 case QGraphicsItem::UserType + 111:
113 sipType = sipType_QgsLayoutFrame;
114 *sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
115 break;
116 case QGraphicsItem::UserType + 117:
117 sipType = sipType_QgsLayoutItemMarker;
118 *sipCppRet = static_cast<QgsLayoutItemMarker *>( sipCpp );
119 break;
120 case QGraphicsItem::UserType + 118:
121 sipType = sipType_QgsLayoutItemElevationProfile;
122 *sipCppRet = static_cast<QgsLayoutItemElevationProfile *>( sipCpp );
123 break;
124
125 // did you read that comment above? NO? Go read it now. You're about to break stuff.
126
127 default:
128 sipType = sipType_QgsLayoutItem;
129 }
130 }
131 else
132 sipType = NULL;
133 SIP_END
134#endif
135
136 Q_OBJECT
137 public:
138
143 {
144 NoProperty = 0,
147 //composer page properties
153 //general composer item properties
170 //composer map
199 //composer picture
204 //html item
206 //legend item
209 //scalebar item
222 //table item
238 };
239
246 {
247 EvaluatedValue = 0,
248 OriginalValue
249 };
250
254 static const QgsPropertiesDefinition &propertyDefinitions();
255
266 static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
267
274 explicit QgsLayoutObject( QgsLayout *layout );
275
279 SIP_SKIP const QgsLayout *layout() const;
280
284 QgsLayout *layout();
285
290 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
291
297 const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
298
305 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
306
307
316 void setCustomProperty( const QString &key, const QVariant &value );
317
327 QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
328
336 void removeCustomProperty( const QString &key );
337
344 QStringList customProperties() const;
345
351
352 public slots:
353
357 virtual void refresh() {}
358
359 signals:
360
364 void changed();
365
366 protected:
367
376 bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
377
386 bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
387
388 QPointer< QgsLayout > mLayout;
389
391
394
395 private:
396
398 static QgsPropertiesDefinition sPropertyDefinitions;
399
400 static void initPropertyDefinitions();
401
402 friend class TestQgsLayoutObject;
404};
405
406#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.
@ TestProperty
Dummy property with no effect on item.
@ MapGridIntervalX
Map grid interval X.
@ MapGridAnnotationDisplayBottom
Map annotation display bottom.
@ ElevationProfileTolerance
Tolerance distance for elevation profiles (since QGIS 3.30)
@ MapGridIntervalY
Map grid interval Y.
@ MapYMin
Map extent y minimum.
@ PictureSvgStrokeColor
SVG stroke color.
@ PaperOrientation
Paper orientation.
@ MapGridFrameSize
Map grid frame size.
@ ElevationProfileElevationLabelInterval
Label interval for elevation profile elevation axis (since QGIS 3.30)
@ LegendTitle
Legend title.
@ Opacity
Item opacity.
@ MapStylePreset
Layer and style map theme.
@ AttributeTableSourceLayer
Attribute table source layer.
@ ItemWidth
Width of item.
@ ScalebarMinimumWidth
Scalebar segment minimum width (since QGIS 3.26)
@ PaperHeight
Paper height (deprecated)
@ ItemHeight
Height of item.
@ ElevationProfileDistanceMajorInterval
Major grid line interval for elevation profile distance axis (since QGIS 3.30)
@ MarginTop
Top margin (since QGIS 3.30)
@ ElevationProfileDistanceLabelInterval
Label interval for elevation profile distance axis (since QGIS 3.30)
@ MapXMax
Map extent x maximum.
@ ElevationProfileElevationMinorInterval
Minor grid line interval for elevation profile elevation axis (since QGIS 3.30)
@ BlendMode
Item blend mode.
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
@ StartDateTime
Temporal range's start DateTime.
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment (since QGIS 3.26)
@ AllProperties
All properties for item.
@ MarginLeft
Left margin (since QGIS 3.30)
@ PositionY
Y position on page.
@ MapGridFrameDivisionsBottom
Map frame division display bottom.
@ ElevationProfileMaximumDistance
Maximum distance value for elevation profile (since QGIS 3.30)
@ MapGridAnnotationDisplayRight
Map annotation display right.
@ SourceUrl
Html source url.
@ EndDateTime
Temporal range's end DateTime.
@ Transparency
Item transparency (deprecated)
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
@ MapGridFrameMargin
Map grid frame margin.
@ MapGridOffsetX
Map grid offset X.
@ MapGridLabelDistance
Map grid label distance.
@ MapAtlasMargin
Map atlas margin.
@ MapGridAnnotationDisplayLeft
Map annotation display left.
@ MapYMax
Map extent y maximum.
@ PageNumber
Page number for item placement.
@ MapXMin
Map extent x minimum.
@ ExcludeFromExports
Exclude item from exports.
@ MarginRight
Right margin (since QGIS 3.30)
@ PictureSvgStrokeWidth
SVG stroke width.
@ MapGridFrameDivisionsLeft
Map frame division display left.
@ ElevationProfileMinimumElevation
Minimum elevation value for elevation profile (since QGIS 3.30)
@ MapGridEnabled
Map grid enabled.
@ BackgroundColor
Item background color.
@ MapScale
Map scale.
@ ElevationProfileElevationMajorInterval
Major grid line interval for elevation profile elevation axis (since QGIS 3.30)
@ LegendColumnCount
Legend column count.
@ ScalebarMaximumWidth
Scalebar segment maximum width (since QGIS 3.26)
@ MapLabelMargin
Map label margin.
@ ItemRotation
Rotation of item.
@ MapLayers
Map layer set.
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
@ ScalebarHeight
Scalebar height (since QGIS 3.26)
@ ScalebarRightSegments
Number of segments on the right of 0 (since QGIS 3.26)
@ MapGridFrameLineThickness
Map grid frame line thickness.
@ PictureSvgBackgroundColor
SVG background color.
@ MapGridFrameDivisionsRight
Map frame division display right.
@ ElevationProfileMinimumDistance
Minimum distance value for elevation profile (since QGIS 3.30)
@ PictureSource
Picture source url.
@ MapGridFrameDivisionsTop
Map frame division display top.
@ PaperWidth
Paper width (deprecated)
@ MarginBottom
Bottom margin (since QGIS 3.30)
@ ElevationProfileDistanceMinorInterval
Minor grid line interval for elevation profile distance axis (since QGIS 3.30)
@ PresetPaperSize
Preset paper size for composition.
@ PositionX
X position on page.
@ ElevationProfileMaximumElevation
Maximum elevation value for elevation profile (since QGIS 3.30)
@ FrameColor
Item frame color.
@ MapGridCrossSize
Map grid cross size.
@ NumPages
Number of pages in composition (deprecated)
@ MapGridOffsetY
Map grid offset Y.
@ MapGridAnnotationDisplayTop
Map annotation display top.
@ MapRotation
Map rotation.
@ ScalebarSubdivisionHeight
Scalebar subdivision height (since QGIS 3.26)
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0 (since QGIS 3.26)
@ ScalebarLeftSegments
Number of segments on the left of 0 (since QGIS 3.26)
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: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 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:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_END
Definition: qgis_sip.h:203
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.