QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
22 #include "qgspropertycollection.h"
25 #include <QObject>
26 #include <QDomNode>
27 #include <QMap>
28 #include <QPointer>
29 
30 class QgsLayout;
31 class QPainter;
33 
39 class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGenerator
40 {
41 #ifdef SIP_RUN
42 #include <qgslayoutitem.h>
43 #include "qgslayoutitemgroup.h"
44 #include "qgslayoutitemmap.h"
45 #include "qgslayoutitempicture.h"
46 #include "qgslayoutitemlabel.h"
47 #include "qgslayoutitemlegend.h"
48 #include "qgslayoutitempolygon.h"
49 #include "qgslayoutitempolyline.h"
50 #include "qgslayoutitemscalebar.h"
51 #include "qgslayoutframe.h"
52 #include "qgslayoutitemshape.h"
53 #include "qgslayoutitempage.h"
54 #endif
55 
56 #ifdef SIP_RUN
58  if ( QgsLayoutItem *item = qobject_cast< QgsLayoutItem * >( sipCpp ) )
59  {
60  // the conversions have to be static, because they're using multiple inheritance
61  // (seen in PyQt4 .sip files for some QGraphicsItem classes)
62  switch ( item->type() )
63  {
64  // FREAKKKKIIN IMPORTANT!
65  // IF YOU PUT SOMETHING HERE, PUT IT IN QgsLayoutItem CASTING **ALSO**
66  // (it's not enough for it to be in only one of the places, as sip inconsistently
67  // decides which casting code to perform here)
68 
69  // really, these *should* use the constants from QgsLayoutItemRegistry, but sip doesn't like that!
70  case QGraphicsItem::UserType + 101:
71  sipType = sipType_QgsLayoutItemGroup;
72  *sipCppRet = static_cast<QgsLayoutItemGroup *>( sipCpp );
73  break;
74  case QGraphicsItem::UserType + 102:
75  sipType = sipType_QgsLayoutItemPage;
76  *sipCppRet = static_cast<QgsLayoutItemPage *>( sipCpp );
77  break;
78  case QGraphicsItem::UserType + 103:
79  sipType = sipType_QgsLayoutItemMap;
80  *sipCppRet = static_cast<QgsLayoutItemMap *>( sipCpp );
81  break;
82  case QGraphicsItem::UserType + 104:
83  sipType = sipType_QgsLayoutItemPicture;
84  *sipCppRet = static_cast<QgsLayoutItemPicture *>( sipCpp );
85  break;
86  case QGraphicsItem::UserType + 105:
87  sipType = sipType_QgsLayoutItemLabel;
88  *sipCppRet = static_cast<QgsLayoutItemLabel *>( sipCpp );
89  break;
90  case QGraphicsItem::UserType + 106:
91  sipType = sipType_QgsLayoutItemLegend;
92  *sipCppRet = static_cast<QgsLayoutItemLegend *>( sipCpp );
93  break;
94  case QGraphicsItem::UserType + 107:
95  sipType = sipType_QgsLayoutItemShape;
96  *sipCppRet = static_cast<QgsLayoutItemShape *>( sipCpp );
97  break;
98  case QGraphicsItem::UserType + 108:
99  sipType = sipType_QgsLayoutItemPolygon;
100  *sipCppRet = static_cast<QgsLayoutItemPolygon *>( sipCpp );
101  break;
102  case QGraphicsItem::UserType + 109:
103  sipType = sipType_QgsLayoutItemPolyline;
104  *sipCppRet = static_cast<QgsLayoutItemPolyline *>( sipCpp );
105  break;
106  case QGraphicsItem::UserType + 110:
107  sipType = sipType_QgsLayoutItemScaleBar;
108  *sipCppRet = static_cast<QgsLayoutItemScaleBar *>( sipCpp );
109  break;
110  case QGraphicsItem::UserType + 111:
111  sipType = sipType_QgsLayoutFrame;
112  *sipCppRet = static_cast<QgsLayoutFrame *>( sipCpp );
113  break;
114 
115  // did you read that comment above? NO? Go read it now. You're about to break stuff.
116 
117  default:
118  sipType = sipType_QgsLayoutItem;
119  }
120  }
121  else
122  sipType = NULL;
123  SIP_END
124 #endif
125 
126  Q_OBJECT
127  public:
128 
133  {
134  NoProperty = 0,
137  //composer page properties
143  //general composer item properties
156  //composer map
185  //composer picture
190  //html item
192  //legend item
195  //scalebar item
208  //table item
213  };
214 
221  {
222  EvaluatedValue = 0,
223  OriginalValue
224  };
225 
229  static const QgsPropertiesDefinition &propertyDefinitions();
230 
241  static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
242 
249  explicit QgsLayoutObject( QgsLayout *layout );
250 
254  SIP_SKIP const QgsLayout *layout() const;
255 
259  QgsLayout *layout();
260 
265  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
266 
272  const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
273 
280  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
281 
282 
291  void setCustomProperty( const QString &key, const QVariant &value );
292 
302  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
303 
311  void removeCustomProperty( const QString &key );
312 
319  QStringList customProperties() const;
320 
326 
327  public slots:
328 
332  virtual void refresh() {}
333 
334  signals:
335 
339  void changed();
340 
341  protected:
342 
351  bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
352 
361  bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
362 
363  QPointer< QgsLayout > mLayout;
364 
366 
369 
370  private:
371 
373  static QgsPropertiesDefinition sPropertyDefinitions;
374 
375  static void initPropertyDefinitions();
376 
377  friend class TestQgsLayoutObject;
379 };
380 
381 #endif //QGSLAYOUTOBJECT_H
QgsLayoutObject::ScalebarFillColor2
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
Definition: qgslayoutobject.h:205
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLayoutObject::MapGridAnnotationDisplayTop
@ MapGridAnnotationDisplayTop
Map annotation display top.
Definition: qgslayoutobject.h:179
qgslayoutitemgroup.h
qgslayoutitempolygon.h
QgsLayoutObject::MapGridFrameLineThickness
@ MapGridFrameLineThickness
Map grid frame line thickness.
Definition: qgslayoutobject.h:176
QgsLayoutItemShape
Layout item for basic filled shapes (e.g. rectangles, ellipses).
Definition: qgslayoutitemshape.h:31
QgsLayoutObject::ItemRotation
@ ItemRotation
Rotation of item.
Definition: qgslayoutobject.h:149
QgsLayoutObject::StartDateTime
@ StartDateTime
Temporal range's start DateTime.
Definition: qgslayoutobject.h:211
QgsLayoutItemPage
Item representing the paper in a layout.
Definition: qgslayoutitempage.h:58
QgsLayoutObject::refresh
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
Definition: qgslayoutobject.h:332
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayoutObject::ScalebarRightSegments
@ ScalebarRightSegments
Number of segments on the right of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:197
QgsLayoutObject::ScalebarLineColor
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
Definition: qgslayoutobject.h:206
QgsLayoutItemPolyline
Layout item for node based polyline shapes.
Definition: qgslayoutitempolyline.h:33
QgsLayoutObject::mCustomProperties
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
Definition: qgslayoutobject.h:368
QgsLayoutObject::PaperWidth
@ PaperWidth
Paper width (deprecated)
Definition: qgslayoutobject.h:139
QgsLayoutObject::PaperOrientation
@ PaperOrientation
Paper orientation.
Definition: qgslayoutobject.h:142
QgsLayoutObject::MapGridAnnotationDisplayLeft
@ MapGridAnnotationDisplayLeft
Map annotation display left.
Definition: qgslayoutobject.h:177
QgsLayoutObject::LegendColumnCount
@ LegendColumnCount
Legend column count.
Definition: qgslayoutobject.h:194
QgsLayoutObject::ItemHeight
@ ItemHeight
Height of item.
Definition: qgslayoutobject.h:148
QgsLayoutObject::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgslayoutobject.h:365
qgslayoutitemlabel.h
QgsLayoutObject::AttributeTableSourceLayer
@ AttributeTableSourceLayer
Attribute table source layer.
Definition: qgslayoutobject.h:209
QgsLayoutObject::PictureSvgStrokeColor
@ PictureSvgStrokeColor
SVG stroke color.
Definition: qgslayoutobject.h:188
QgsLayoutObject::MapXMin
@ MapXMin
Map extent x minimum.
Definition: qgslayoutobject.h:159
QgsLayoutObject::MapGridOffsetY
@ MapGridOffsetY
Map grid offset Y.
Definition: qgslayoutobject.h:171
QgsLayoutObject::PictureSvgStrokeWidth
@ PictureSvgStrokeWidth
SVG stroke width.
Definition: qgslayoutobject.h:189
QgsLayoutObject::MapCrs
@ MapCrs
Map CRS.
Definition: qgslayoutobject.h:210
QgsLayoutObject::BlendMode
@ BlendMode
Item blend mode.
Definition: qgslayoutobject.h:152
QgsLayoutObject::setDataDefinedProperties
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the objects's property collection, used for data defined overrides.
Definition: qgslayoutobject.h:280
QgsLayoutObject::MapGridFrameDivisionsTop
@ MapGridFrameDivisionsTop
Map frame division display top.
Definition: qgslayoutobject.h:183
qgslayoutframe.h
QgsLayoutItemLegend
A layout item subclass for map legends.
Definition: qgslayoutitemlegend.h:113
QgsLayoutObject::MapYMin
@ MapYMin
Map extent y minimum.
Definition: qgslayoutobject.h:160
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsLayoutObject::PositionX
@ PositionX
X position on page.
Definition: qgslayoutobject.h:145
QgsLayoutObject::AllProperties
@ AllProperties
All properties for item.
Definition: qgslayoutobject.h:135
QgsLayoutObject::MapGridFrameMargin
@ MapGridFrameMargin
Map grid frame margin.
Definition: qgslayoutobject.h:173
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
qgsobjectcustomproperties.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayoutObject::MapGridAnnotationDisplayBottom
@ MapGridAnnotationDisplayBottom
Map annotation display bottom.
Definition: qgslayoutobject.h:180
qgslayoutitem.h
QgsLayoutFrame
Base class for frame items, which form a layout multiframe item.
Definition: qgslayoutframe.h:31
QgsCompositionConverter
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Definition: qgscompositionconverter.h:56
QgsLayoutObject::ScalebarRightSegmentSubdivisions
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:202
QgsLayoutObject::ScalebarMinimumWidth
@ ScalebarMinimumWidth
Scalebar segment minimum width (since QGIS 3.26)
Definition: qgslayoutobject.h:199
QgsLayoutObject::MapRotation
@ MapRotation
Map rotation.
Definition: qgslayoutobject.h:157
QgsLayoutObject::MapGridIntervalX
@ MapGridIntervalX
Map grid interval X.
Definition: qgslayoutobject.h:168
QgsLayoutObject::MapXMax
@ MapXMax
Map extent x maximum.
Definition: qgslayoutobject.h:161
QgsLayoutObject::MapYMax
@ MapYMax
Map extent y maximum.
Definition: qgslayoutobject.h:162
QgsLayoutObject::dataDefinedProperties
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the object's property collection, used for data defined overrides.
Definition: qgslayoutobject.h:272
QgsLayoutObject::ScalebarSegmentWidth
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment (since QGIS 3.26)
Definition: qgslayoutobject.h:198
QgsLayoutObject::ScalebarLeftSegments
@ ScalebarLeftSegments
Number of segments on the left of 0 (since QGIS 3.26)
Definition: qgslayoutobject.h:196
QgsLayoutObject::MapGridCrossSize
@ MapGridCrossSize
Map grid cross size.
Definition: qgslayoutobject.h:175
qgis_sip.h
QgsLayoutObject::ExcludeFromExports
@ ExcludeFromExports
Exclude item from exports.
Definition: qgslayoutobject.h:153
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsLayoutObject::MapGridOffsetX
@ MapGridOffsetX
Map grid offset X.
Definition: qgslayoutobject.h:170
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:112
QgsLayoutObject::ScalebarHeight
@ ScalebarHeight
Scalebar height (since QGIS 3.26)
Definition: qgslayoutobject.h:201
QgsLayoutObject::MapScale
@ MapScale
Map scale.
Definition: qgslayoutobject.h:158
QgsLayoutObject::ScalebarLineWidth
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
Definition: qgslayoutobject.h:207
QgsLayoutObject::MapLabelMargin
@ MapLabelMargin
Map label margin.
Definition: qgslayoutobject.h:166
QgsLayoutItemGroup
A container for grouping several QgsLayoutItems.
Definition: qgslayoutitemgroup.h:28
QgsLayoutObject::PageNumber
@ PageNumber
Page number for item placement.
Definition: qgslayoutobject.h:144
QgsLayoutObject::PaperHeight
@ PaperHeight
Paper height (deprecated)
Definition: qgslayoutobject.h:140
QgsLayoutObject::MapGridEnabled
@ MapGridEnabled
Map grid enabled.
Definition: qgslayoutobject.h:167
qgsexpressioncontextgenerator.h
QgsLayoutItemPicture
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
Definition: qgslayoutitempicture.h:35
QgsLayoutObject::MapAtlasMargin
@ MapAtlasMargin
Map atlas margin.
Definition: qgslayoutobject.h:163
qgslayoutitemlegend.h
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsLayoutObject::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the object's property collection, used for data defined overrides.
Definition: qgslayoutobject.h:265
QgsLayoutObject::LegendTitle
@ LegendTitle
Legend title.
Definition: qgslayoutobject.h:193
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsLayoutObject::BackgroundColor
@ BackgroundColor
Item background color.
Definition: qgslayoutobject.h:155
qgslayoutitempage.h
QgsLayoutObject::TestProperty
@ TestProperty
Dummy property with no effect on item.
Definition: qgslayoutobject.h:136
QgsLayoutObject::PositionY
@ PositionY
Y position on page.
Definition: qgslayoutobject.h:146
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:363
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsObjectCustomProperties
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Definition: qgsobjectcustomproperties.h:35
QgsLayoutObject::MapGridLabelDistance
@ MapGridLabelDistance
Map grid label distance.
Definition: qgslayoutobject.h:174
qgslayoutitempicture.h
qgspropertycollection.h
QgsLayoutObject::PropertyValueType
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value,...
Definition: qgslayoutobject.h:220
qgslayoutitempolyline.h
QgsLayoutObject::MapGridFrameDivisionsRight
@ MapGridFrameDivisionsRight
Map frame division display right.
Definition: qgslayoutobject.h:182
qgslayoutitemshape.h
QgsLayoutItemPolygon
Layout item for node based polygon shapes.
Definition: qgslayoutitempolygon.h:30
QgsLayoutObject::MapGridAnnotationDisplayRight
@ MapGridAnnotationDisplayRight
Map annotation display right.
Definition: qgslayoutobject.h:178
QgsLayoutObject::MapGridIntervalY
@ MapGridIntervalY
Map grid interval Y.
Definition: qgslayoutobject.h:169
QgsLayoutObject::Opacity
@ Opacity
Item opacity.
Definition: qgslayoutobject.h:151
QgsLayoutObject::FrameColor
@ FrameColor
Item frame color.
Definition: qgslayoutobject.h:154
QgsLayoutItemLabel
A layout item subclass for text labels.
Definition: qgslayoutitemlabel.h:36
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:35
QgsLayoutObject::MapGridFrameSize
@ MapGridFrameSize
Map grid frame size.
Definition: qgslayoutobject.h:172
QgsLayoutObject::NumPages
@ NumPages
Number of pages in composition (deprecated)
Definition: qgslayoutobject.h:141
QgsLayoutObject::EndDateTime
@ EndDateTime
Temporal range's end DateTime.
Definition: qgslayoutobject.h:212
QgsLayoutObject::MapGridFrameDivisionsBottom
@ MapGridFrameDivisionsBottom
Map frame division display bottom.
Definition: qgslayoutobject.h:184
QgsLayoutObject::SourceUrl
@ SourceUrl
Html source url.
Definition: qgslayoutobject.h:191
QgsLayoutObject::MapStylePreset
@ MapStylePreset
Layer and style map theme.
Definition: qgslayoutobject.h:165
QgsLayoutObject::MapGridFrameDivisionsLeft
@ MapGridFrameDivisionsLeft
Map frame division display left.
Definition: qgslayoutobject.h:181
QgsLayoutObject::ScalebarFillColor
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
Definition: qgslayoutobject.h:204
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
QgsLayoutObject::PresetPaperSize
@ PresetPaperSize
Preset paper size for composition.
Definition: qgslayoutobject.h:138
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
qgslayoutitemscalebar.h
QgsLayoutObject::PictureSvgBackgroundColor
@ PictureSvgBackgroundColor
SVG background color.
Definition: qgslayoutobject.h:187
QgsLayoutObject::ScalebarSubdivisionHeight
@ ScalebarSubdivisionHeight
Scalebar subdivision height (since QGIS 3.26)
Definition: qgslayoutobject.h:203
QgsLayoutObject::ScalebarMaximumWidth
@ ScalebarMaximumWidth
Scalebar segment maximum width (since QGIS 3.26)
Definition: qgslayoutobject.h:200
QgsLayoutObject::Transparency
@ Transparency
Item transparency (deprecated)
Definition: qgslayoutobject.h:150
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:132
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:39
QgsLayoutObject::PictureSource
@ PictureSource
Picture source url.
Definition: qgslayoutobject.h:186
qgslayoutitemmap.h
QgsLayoutObject::MapLayers
@ MapLayers
Map layer set.
Definition: qgslayoutobject.h:164
QgsLayoutObject::ItemWidth
@ ItemWidth
Width of item.
Definition: qgslayoutobject.h:147