QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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
200  //table item
205  };
206 
213  {
214  EvaluatedValue = 0,
215  OriginalValue
216  };
217 
221  static const QgsPropertiesDefinition &propertyDefinitions();
222 
233  static bool propertyAssociatesWithParentMultiframe( DataDefinedProperty property );
234 
241  explicit QgsLayoutObject( QgsLayout *layout );
242 
246  SIP_SKIP const QgsLayout *layout() const;
247 
251  QgsLayout *layout();
252 
257  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
258 
264  const QgsPropertyCollection &dataDefinedProperties() const { return mDataDefinedProperties; } SIP_SKIP
265 
272  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
273 
274 
283  void setCustomProperty( const QString &key, const QVariant &value );
284 
294  QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
295 
303  void removeCustomProperty( const QString &key );
304 
311  QStringList customProperties() const;
312 
318 
319  public slots:
320 
324  virtual void refresh() {}
325 
326  signals:
327 
331  void changed();
332 
333  protected:
334 
343  bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
344 
353  bool readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context );
354 
355  QPointer< QgsLayout > mLayout;
356 
358 
361 
362  private:
363 
365  static QgsPropertiesDefinition sPropertyDefinitions;
366 
367  static void initPropertyDefinitions();
368 
369  friend class TestQgsLayoutObject;
371 };
372 
373 #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 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.
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
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.
@ MapGridIntervalY
Map grid interval Y.
@ MapYMin
Map extent y minimum.
@ PictureSvgStrokeColor
SVG stroke color.
@ PaperOrientation
Paper orientation.
@ MapGridFrameSize
Map grid frame size.
@ LegendTitle
Legend title.
@ Opacity
Item opacity.
@ MapStylePreset
Layer and style map theme.
@ AttributeTableSourceLayer
Attribute table source layer.
@ ItemWidth
Width of item.
@ PaperHeight
Paper height (deprecated)
@ ItemHeight
Height of item.
@ MapXMax
Map extent x maximum.
@ 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.
@ AllProperties
All properties for item.
@ PositionY
Y position on page.
@ MapGridFrameDivisionsBottom
Map frame division display bottom.
@ 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.
@ PictureSvgStrokeWidth
SVG stroke width.
@ MapGridFrameDivisionsLeft
Map frame division display left.
@ MapGridEnabled
Map grid enabled.
@ BackgroundColor
Item background color.
@ MapScale
Map scale.
@ LegendColumnCount
Legend column count.
@ 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)
@ MapGridFrameLineThickness
Map grid frame line thickness.
@ PictureSvgBackgroundColor
SVG background color.
@ MapGridFrameDivisionsRight
Map frame division display right.
@ PictureSource
Picture source url.
@ MapGridFrameDivisionsTop
Map frame division display top.
@ PaperWidth
Paper width (deprecated)
@ PresetPaperSize
Preset paper size for composition.
@ PositionX
X position on page.
@ 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.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the objects's property collection, used for data defined overrides.
QgsPropertyCollection & dataDefinedProperties()
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,...
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the object's property collection, used for data defined overrides.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
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:177
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_END
Definition: qgis_sip.h:194
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.