QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgslayoutobject.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutobject.cpp
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
18#include "qgslayoutobject.h"
19#include "moc_qgslayoutobject.cpp"
21#include "qgslayout.h"
23
24#include <QPainter>
25
26QgsPropertiesDefinition QgsLayoutObject::sPropertyDefinitions;
27
28void QgsLayoutObject::initPropertyDefinitions()
29{
30 if ( !sPropertyDefinitions.isEmpty() )
31 return;
32
33 sPropertyDefinitions = QgsPropertiesDefinition
34 {
35 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::TestProperty ), QgsPropertyDefinition( "dataDefinedProperty", QgsPropertyDefinition::DataTypeString, "invalid property", QString() ) },
36 {
37 static_cast< int >( QgsLayoutObject::DataDefinedProperty::PresetPaperSize ), QgsPropertyDefinition( "dataDefinedPaperSize", QgsPropertyDefinition::DataTypeString, QObject::tr( "Paper size" ), QObject::tr( "string " ) + QLatin1String( "[<b>A5</b>|<b>A4</b>|<b>A3</b>|<b>A2</b>|<b>A1</b>|<b>A0</b>"
38 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
39 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
40 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
41 ) )
42 },
43 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PaperWidth ), QgsPropertyDefinition( "dataDefinedPaperWidth", QObject::tr( "Page width" ), QgsPropertyDefinition::DoublePositive ) },
44 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PaperHeight ), QgsPropertyDefinition( "dataDefinedPaperHeight", QObject::tr( "Page height" ), QgsPropertyDefinition::DoublePositive ) },
45 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::NumPages ), QgsPropertyDefinition( "dataDefinedNumPages", QObject::tr( "Number of pages" ), QgsPropertyDefinition::IntegerPositive ) },
46 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PaperOrientation ), QgsPropertyDefinition( "dataDefinedPaperOrientation", QgsPropertyDefinition::DataTypeString, QObject::tr( "Symbol size" ), QObject::tr( "string " ) + QLatin1String( "[<b>portrait</b>|<b>landscape</b>]" ) ) },
47 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PageNumber ), QgsPropertyDefinition( "dataDefinedPageNumber", QObject::tr( "Page number" ), QgsPropertyDefinition::IntegerPositive ) },
48 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PositionX ), QgsPropertyDefinition( "dataDefinedPositionX", QObject::tr( "Position (X)" ), QgsPropertyDefinition::Double ) },
49 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PositionY ), QgsPropertyDefinition( "dataDefinedPositionY", QObject::tr( "Position (Y)" ), QgsPropertyDefinition::Double ) },
50 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ItemWidth ), QgsPropertyDefinition( "dataDefinedWidth", QObject::tr( "Width" ), QgsPropertyDefinition::DoublePositive ) },
51 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ItemHeight ), QgsPropertyDefinition( "dataDefinedHeight", QObject::tr( "Height" ), QgsPropertyDefinition::DoublePositive ) },
52 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ItemRotation ), QgsPropertyDefinition( "dataDefinedRotation", QObject::tr( "Rotation angle" ), QgsPropertyDefinition::Rotation ) },
53 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::Transparency ), QgsPropertyDefinition( "dataDefinedTransparency", QObject::tr( "Transparency" ), QgsPropertyDefinition::Opacity ) },
54 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::Opacity ), QgsPropertyDefinition( "dataDefinedOpacity", QObject::tr( "Opacity" ), QgsPropertyDefinition::Opacity ) },
55 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::BlendMode ), QgsPropertyDefinition( "dataDefinedBlendMode", QObject::tr( "Blend mode" ), QgsPropertyDefinition::BlendMode ) },
56 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ExcludeFromExports ), QgsPropertyDefinition( "dataDefinedExcludeExports", QObject::tr( "Exclude item from exports" ), QgsPropertyDefinition::Boolean ) },
57 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::FrameColor ), QgsPropertyDefinition( "dataDefinedFrameColor", QObject::tr( "Frame color" ), QgsPropertyDefinition::ColorWithAlpha ) },
58 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::BackgroundColor ), QgsPropertyDefinition( "dataDefinedBackgroundColor", QObject::tr( "Background color" ), QgsPropertyDefinition::ColorWithAlpha ) },
59 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MarginLeft ), QgsPropertyDefinition( "dataDefinedMarginLeft", QObject::tr( "Left margin" ), QgsPropertyDefinition::DoublePositive ) },
60 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MarginTop ), QgsPropertyDefinition( "dataDefinedMarginTop", QObject::tr( "Top margin" ), QgsPropertyDefinition::DoublePositive ) },
61 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MarginRight ), QgsPropertyDefinition( "dataDefinedMarginRight", QObject::tr( "Right margin" ), QgsPropertyDefinition::DoublePositive ) },
62 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MarginBottom ), QgsPropertyDefinition( "dataDefinedMarginBottom", QObject::tr( "Bottom margin" ), QgsPropertyDefinition::DoublePositive ) },
63 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapRotation ), QgsPropertyDefinition( "dataDefinedMapRotation", QObject::tr( "Map rotation" ), QgsPropertyDefinition::Rotation ) },
64 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapScale ), QgsPropertyDefinition( "dataDefinedMapScale", QObject::tr( "Map scale" ), QgsPropertyDefinition::DoublePositive ) },
65 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapXMin ), QgsPropertyDefinition( "dataDefinedMapXMin", QObject::tr( "Extent minimum X" ), QgsPropertyDefinition::Double ) },
66 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapYMin ), QgsPropertyDefinition( "dataDefinedMapYMin", QObject::tr( "Extent minimum Y" ), QgsPropertyDefinition::Double ) },
67 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapXMax ), QgsPropertyDefinition( "dataDefinedMapXMax", QObject::tr( "Extent maximum X" ), QgsPropertyDefinition::Double ) },
68 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapYMax ), QgsPropertyDefinition( "dataDefinedMapYMax", QObject::tr( "Extent maximum Y" ), QgsPropertyDefinition::Double ) },
69 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapLabelMargin ), QgsPropertyDefinition( "dataDefinedMapLabelMargin", QObject::tr( "Label margin" ), QgsPropertyDefinition::DoublePositive ) },
70 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapAtlasMargin ), QgsPropertyDefinition( "dataDefinedMapAtlasMargin", QObject::tr( "Atlas margin" ), QgsPropertyDefinition::DoublePositive ) },
71 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapLayers ), QgsPropertyDefinition( "dataDefinedMapLayers", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map Layers" ), tr( "list of map layer names separated by | characters" ) ) },
72 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapStylePreset ), QgsPropertyDefinition( "dataDefinedMapStylePreset", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map theme" ), tr( "name of an existing map theme (case-sensitive)" ) ) },
73 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridEnabled ), QgsPropertyDefinition( "dataDefinedMapGridEnabled", QObject::tr( "Grid enabled" ), QgsPropertyDefinition::Boolean ) },
74 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridIntervalX ), QgsPropertyDefinition( "dataDefinedMapGridIntervalX", QObject::tr( "Grid interval X" ), QgsPropertyDefinition::DoublePositive ) },
75 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridIntervalY ), QgsPropertyDefinition( "dataDefinedMapGridIntervalY", QObject::tr( "Grid interval Y" ), QgsPropertyDefinition::DoublePositive ) },
76 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridOffsetX ), QgsPropertyDefinition( "dataDefinedMapGridOffsetX", QObject::tr( "Grid offset X" ), QgsPropertyDefinition::Double ) },
77 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridOffsetY ), QgsPropertyDefinition( "dataDefinedMapGridOffsetY", QObject::tr( "Grid offset Y" ), QgsPropertyDefinition::Double ) },
78 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameSize ), QgsPropertyDefinition( "dataDefinedMapGridFrameSize", QObject::tr( "Grid frame size" ), QgsPropertyDefinition::DoublePositive ) },
79 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameLineThickness ), QgsPropertyDefinition( "dataDefinedMapGridFrameLineThickness", QObject::tr( "Grid frame line thickness" ), QgsPropertyDefinition::DoublePositive ) },
80 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridCrossSize ), QgsPropertyDefinition( "dataDefinedMapGridCrossSize", QObject::tr( "Grid cross size" ), QgsPropertyDefinition::DoublePositive ) },
81 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameMargin ), QgsPropertyDefinition( "dataDefinedMapGridFrameMargin", QObject::tr( "Grid frame margin" ), QgsPropertyDefinition::DoublePositive ) },
82 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridLabelDistance ), QgsPropertyDefinition( "dataDefinedMapGridLabelDistance", QObject::tr( "Grid label distance" ), QgsPropertyDefinition::DoublePositive ) },
83 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridAnnotationDisplayLeft ), QgsPropertyDefinition( "dataDefinedMapGridAnnotationDisplayLeft", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid annotation display left" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
84 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridAnnotationDisplayRight ), QgsPropertyDefinition( "dataDefinedMapGridAnnotationDisplayRight", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid annotation display right" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
85 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridAnnotationDisplayTop ), QgsPropertyDefinition( "dataDefinedMapGridAnnotationDisplayTop", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid annotation display top" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
86 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridAnnotationDisplayBottom ), QgsPropertyDefinition( "dataDefinedMapGridAnnotationDisplayBottom", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid annotation display bottom" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
87 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameDivisionsLeft ), QgsPropertyDefinition( "dataDefinedMapGridFrameDivisionsLeft", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid frame divisions display left" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
88 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameDivisionsRight ), QgsPropertyDefinition( "dataDefinedMapGridFrameDivisionsRight", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid frame divisions display right" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
89 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameDivisionsTop ), QgsPropertyDefinition( "dataDefinedMapGridFrameDivisionsTop", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid frame divisions display top" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
90 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapGridFrameDivisionsBottom ), QgsPropertyDefinition( "dataDefinedMapGridFrameDivisionsBottom", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid frame divisions display bottom" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
91 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapCrs ), QgsPropertyDefinition( "dataDefinedCrs", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map CRS" ), QObject::tr( "string representing a CRS, either an authority/id pair (e.g. 'EPSG:4326'), a proj string prefixes by \"PROJ:\" (e.g. 'PROJ: +proj=...') or a WKT string prefixed by \"WKT:\" (e.g. 'WKT:GEOGCRS[\"WGS 84\"...]')" ) ) },
92 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::StartDateTime ), QgsPropertyDefinition( "dataDefinedStartDateTime", QObject::tr( "Temporal range start date / time" ), QgsPropertyDefinition::DateTime ) },
93 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::EndDateTime ), QgsPropertyDefinition( "dataDefinedEndDateTime", QObject::tr( "Temporal range end date / time" ), QgsPropertyDefinition::DateTime ) },
94 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapZRangeLower ), QgsPropertyDefinition( "dataDefinedZRangeLower", QObject::tr( "Z range lower limit" ), QgsPropertyDefinition::Double ) },
95 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::MapZRangeUpper ), QgsPropertyDefinition( "dataDefinedZRangeUpper", QObject::tr( "Z range upper limit" ), QgsPropertyDefinition::Double ) },
96 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PictureSource ), QgsPropertyDefinition( "dataDefinedSource", QObject::tr( "Picture source (URL)" ), QgsPropertyDefinition::String ) },
97 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::SourceUrl ), QgsPropertyDefinition( "dataDefinedSourceUrl", QObject::tr( "Source URL" ), QgsPropertyDefinition::String ) },
98 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PictureSvgBackgroundColor ), QgsPropertyDefinition( "dataDefinedSvgBackgroundColor", QObject::tr( "SVG background color" ), QgsPropertyDefinition::ColorWithAlpha ) },
99 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PictureSvgStrokeColor ), QgsPropertyDefinition( "dataDefinedSvgStrokeColor", QObject::tr( "SVG stroke color" ), QgsPropertyDefinition::ColorWithAlpha ) },
100 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::PictureSvgStrokeWidth ), QgsPropertyDefinition( "dataDefinedSvgStrokeWidth", QObject::tr( "SVG stroke width" ), QgsPropertyDefinition::StrokeWidth ) },
101 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::LegendTitle ), QgsPropertyDefinition( "dataDefinedLegendTitle", QObject::tr( "Legend title" ), QgsPropertyDefinition::String ) },
102 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::LegendColumnCount ), QgsPropertyDefinition( "dataDefinedLegendColumns", QObject::tr( "Number of columns" ), QgsPropertyDefinition::IntegerPositiveGreaterZero ) },
103 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarFillColor ), QgsPropertyDefinition( "dataDefinedScalebarFill", QObject::tr( "Fill color" ), QgsPropertyDefinition::ColorWithAlpha ) },
104 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarFillColor2 ), QgsPropertyDefinition( "dataDefinedScalebarFill2", QObject::tr( "Secondary fill color" ), QgsPropertyDefinition::ColorWithAlpha ) },
105 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarLineColor ), QgsPropertyDefinition( "dataDefinedScalebarLineColor", QObject::tr( "Line color" ), QgsPropertyDefinition::ColorWithAlpha ) },
106 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarLineWidth ), QgsPropertyDefinition( "dataDefinedScalebarLineWidth", QObject::tr( "Line width" ), QgsPropertyDefinition::StrokeWidth ) },
107 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::AttributeTableSourceLayer ), QgsPropertyDefinition( "dataDefinedAttributeTableSourceLayer", QObject::tr( "Table source layer" ), QgsPropertyDefinition::String ) },
108 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarLeftSegments ), QgsPropertyDefinition( "dataDefinedScaleBarLeftSegments", QObject::tr( "Segments to the left of 0" ), QgsPropertyDefinition::IntegerPositive )},
109 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarRightSegments ), QgsPropertyDefinition( "dataDefinedScaleBarRightSegments", QObject::tr( "Segments to the right of 0" ), QgsPropertyDefinition::IntegerPositive ) },
110 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarSegmentWidth ), QgsPropertyDefinition( "dataDefinedScalebarSegmentWidth", QObject::tr( "Length of a segment in map units" ), QgsPropertyDefinition::DoublePositive ) },
111 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarMinimumWidth ), QgsPropertyDefinition( "dataDefinedScalebarMinWidth", QObject::tr( "Minimum length of a segment in mm" ), QgsPropertyDefinition::DoublePositive ) },
112 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarMaximumWidth ), QgsPropertyDefinition( "dataDefinedScalebarMaxWidth", QObject::tr( "Maximum length of a segment in mm" ), QgsPropertyDefinition::DoublePositive ) },
113 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarHeight ), QgsPropertyDefinition( "dataDefinedScalebarHeight", QObject::tr( "Scalebar height in mm" ), QgsPropertyDefinition::DoublePositive ) },
114 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarSubdivisionHeight ), QgsPropertyDefinition( "dataDefinedScalebarSubdivisionHeight", QObject::tr( "Subdivision height in mm" ), QgsPropertyDefinition::DoublePositive ) },
115 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ScalebarRightSegmentSubdivisions ), QgsPropertyDefinition( "dataDefinedScalebarRightSegmentSubdivisions", QObject::tr( "Number of subdivisions in segments to the right of 0" ), QgsPropertyDefinition::IntegerPositive ) },
116 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileTolerance ), QgsPropertyDefinition( "dataDefinedElevationProfileTolerance", QObject::tr( "Tolerance" ), QgsPropertyDefinition::DoublePositive ) },
117 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileDistanceMajorInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileDistanceMajorInterval", QObject::tr( "Major grid line interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
118 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileDistanceMinorInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileDistanceMinorInterval", QObject::tr( "Minor grid line interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
119 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileDistanceLabelInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileDistanceLabelInterval", QObject::tr( "Label interval for elevation axis" ), QgsPropertyDefinition::DoublePositive ) },
120 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileElevationMajorInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileElevationMajorInterval", QObject::tr( "Major grid line interval for distance axis" ), QgsPropertyDefinition::DoublePositive ) },
121 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileElevationMinorInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileElevationMinorInterval", QObject::tr( "Minor grid line interval for distance axis" ), QgsPropertyDefinition::DoublePositive ) },
122 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileElevationLabelInterval ), QgsPropertyDefinition( "dataDefinedElevationProfileElevationLabelInterval", QObject::tr( "Label interval for distance axis" ), QgsPropertyDefinition::DoublePositive ) },
123 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileMinimumDistance ), QgsPropertyDefinition( "dataDefinedElevationProfileMinimumDistance", QObject::tr( "Minimum distance" ), QgsPropertyDefinition::DoublePositive ) },
124 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileMaximumDistance ), QgsPropertyDefinition( "dataDefinedElevationProfileMaximumDistance", QObject::tr( "Maximum distance" ), QgsPropertyDefinition::DoublePositive ) },
125 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileMinimumElevation ), QgsPropertyDefinition( "dataDefinedElevationProfileMinimumElevation", QObject::tr( "Minimum elevation" ), QgsPropertyDefinition::Double ) },
126 { static_cast< int >( QgsLayoutObject::DataDefinedProperty::ElevationProfileMaximumElevation ), QgsPropertyDefinition( "dataDefinedElevationProfileMaximumElevation", QObject::tr( "Maximum elevation" ), QgsPropertyDefinition::Double ) },
127 };
128}
129
131{
132 QgsLayoutObject::initPropertyDefinitions();
133 return sPropertyDefinitions;
134}
135
137{
138 switch ( property )
139 {
142 return true;
143
230 return false;
231 }
232 return false;
233}
234
236 : QObject( nullptr )
237 , mLayout( layout )
238{
239 initPropertyDefinitions();
240
241 if ( mLayout )
242 {
244 connect( &mLayout->reportContext(), &QgsLayoutReportContext::changed, this, &QgsLayoutObject::refresh );
245 }
246}
247
249{
250 return mLayout.data();
251}
252
254{
255 return mLayout.data();
256}
257
258void QgsLayoutObject::setCustomProperty( const QString &key, const QVariant &value )
259{
260 mCustomProperties.setValue( key, value );
261}
262
263QVariant QgsLayoutObject::customProperty( const QString &key, const QVariant &defaultValue ) const
264{
265 return mCustomProperties.value( key, defaultValue );
266}
267
269{
271}
272
274{
275 return mCustomProperties.keys();
276}
277
279{
280 if ( mLayout )
281 {
282 return mLayout->createExpressionContext();
283 }
284 else
285 {
287 }
288}
289
290bool QgsLayoutObject::writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext & ) const
291{
292 if ( parentElement.isNull() )
293 {
294 return false;
295 }
296
297 //create object element
298 QDomElement objectElement = document.createElement( QStringLiteral( "LayoutObject" ) );
299
300 QDomElement ddPropsElement = document.createElement( QStringLiteral( "dataDefinedProperties" ) );
301 mDataDefinedProperties.writeXml( ddPropsElement, sPropertyDefinitions );
302 objectElement.appendChild( ddPropsElement );
303
304 //custom properties
305 mCustomProperties.writeXml( objectElement, document );
306
307 parentElement.appendChild( objectElement );
308 return true;
309}
310
311bool QgsLayoutObject::readObjectPropertiesFromElement( const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext & )
312{
313 Q_UNUSED( document )
314 if ( parentElement.isNull() )
315 {
316 return false;
317 }
318
319 const QDomNodeList objectNodeList = parentElement.elementsByTagName( QStringLiteral( "LayoutObject" ) );
320 if ( objectNodeList.size() < 1 )
321 {
322 return false;
323 }
324 const QDomElement objectElement = objectNodeList.at( 0 ).toElement();
325
326 const QDomNode propsNode = objectElement.namedItem( QStringLiteral( "dataDefinedProperties" ) );
327 if ( !propsNode.isNull() )
328 {
329 mDataDefinedProperties.readXml( propsNode.toElement(), sPropertyDefinitions );
330 }
331
332 //custom properties
333 mCustomProperties.readXml( objectElement );
334
335 return true;
336}
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QStringList customProperties() const
Returns list of keys stored in custom properties for the object.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the layout object property definitions.
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
QgsPropertyCollection mDataDefinedProperties
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
QPointer< QgsLayout > mLayout
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
void removeCustomProperty(const QString &key)
Remove a custom property from the object.
DataDefinedProperty
Data defined properties for different item types.
@ MapYMin
Map extent y minimum.
@ MapZRangeUpper
Map frame Z-range lower value.
@ ScalebarMinimumWidth
Scalebar segment minimum width.
@ MapGridFrameDivisionsBottom
Map frame division display bottom.
@ MapGridIntervalX
Map grid interval X.
@ MapGridFrameDivisionsTop
Map frame division display top.
@ ExcludeFromExports
Exclude item from exports.
@ PaperWidth
Paper width (deprecated)
@ StartDateTime
Temporal range's start DateTime.
@ PictureSvgStrokeColor
SVG stroke color.
@ MapZRangeLower
Map frame Z-range lower value.
@ MapGridAnnotationDisplayLeft
Map annotation display left.
@ TestProperty
Dummy property with no effect on item.
@ PaperOrientation
Paper orientation.
@ MapXMax
Map extent x maximum.
@ MapGridFrameMargin
Map grid frame margin.
@ MapStylePreset
Layer and style map theme.
@ PageNumber
Page number for item placement.
@ MapYMax
Map extent y maximum.
@ MapGridCrossSize
Map grid cross size.
@ MapGridAnnotationDisplayRight
Map annotation display right.
@ NumPages
Number of pages in composition (deprecated)
@ ElevationProfileMaximumDistance
Maximum distance value for elevation profile.
@ PaperHeight
Paper height (deprecated)
@ ScalebarRightSegments
Number of segments on the right of 0.
@ ScalebarLineColor
Scalebar line color (deprecated, use data defined properties on scalebar line symbol instead)
@ MapGridAnnotationDisplayTop
Map annotation display top.
@ ElevationProfileElevationMinorInterval
Minor grid line interval for elevation profile elevation axis.
@ MapGridAnnotationDisplayBottom
Map annotation display bottom.
@ MapGridFrameDivisionsRight
Map frame division display right.
@ ScalebarRightSegmentSubdivisions
Number of subdivisions per segment on right of 0.
@ ElevationProfileDistanceMinorInterval
Minor grid line interval for elevation profile distance axis.
@ Transparency
Item transparency (deprecated)
@ MapGridLabelDistance
Map grid label distance.
@ ElevationProfileMinimumDistance
Minimum distance value for elevation profile.
@ ElevationProfileMaximumElevation
Maximum elevation value for elevation profile.
@ ScalebarMaximumWidth
Scalebar segment maximum width.
@ ElevationProfileDistanceLabelInterval
Label interval for elevation profile distance axis.
@ MapGridIntervalY
Map grid interval Y.
@ ElevationProfileTolerance
Tolerance distance for elevation profiles.
@ EndDateTime
Temporal range's end DateTime.
@ ScalebarFillColor2
Scalebar secondary fill color (deprecated, use data defined properties on scalebar fill symbol 2 inst...
@ ScalebarSubdivisionHeight
Scalebar subdivision height.
@ ElevationProfileMinimumElevation
Minimum elevation value for elevation profile.
@ BackgroundColor
Item background color.
@ PresetPaperSize
Preset paper size for composition.
@ ScalebarFillColor
Scalebar fill color (deprecated, use data defined properties on scalebar fill symbol 1 instead)
@ MapGridFrameSize
Map grid frame size.
@ ScalebarLineWidth
Scalebar line width (deprecated, use data defined properties on scalebar line symbol instead)
@ PictureSvgBackgroundColor
SVG background color.
@ PictureSource
Picture source url.
@ AttributeTableSourceLayer
Attribute table source layer.
@ ScalebarLeftSegments
Number of segments on the left of 0.
@ ElevationProfileElevationLabelInterval
Label interval for elevation profile elevation axis.
@ MapGridFrameLineThickness
Map grid frame line thickness.
@ ElevationProfileDistanceMajorInterval
Major grid line interval for elevation profile distance axis.
@ ScalebarSegmentWidth
Scalebar width in map units of a single segment.
@ ElevationProfileElevationMajorInterval
Major grid line interval for elevation profile elevation axis.
@ LegendColumnCount
Legend column count.
@ MapGridFrameDivisionsLeft
Map frame division display left.
@ MapXMin
Map extent x minimum.
@ PictureSvgStrokeWidth
SVG stroke width.
@ AllProperties
All properties for item.
QgsLayoutObject(QgsLayout *layout)
Constructor for QgsLayoutObject, with the specified parent layout.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
static bool propertyAssociatesWithParentMultiframe(DataDefinedProperty property)
Returns true if the specified property key is normally associated with the parent QgsLayoutMultiFrame...
void changed()
Emitted certain settings in the context is changed, e.g.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
void refreshed()
Emitted when the layout has been refreshed and items should also be refreshed and updated.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
QStringList keys() const
Returns a list of all stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void remove(const QString &key)
Removes a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
Definition for a property.
Definition qgsproperty.h:45
@ Double
Double value (including negative values)
Definition qgsproperty.h:55
@ StrokeWidth
Line stroke width.
Definition qgsproperty.h:70
@ String
Any string value.
Definition qgsproperty.h:59
@ DateTime
DateTime value.
Definition qgsproperty.h:77
@ BlendMode
Blend mode.
Definition qgsproperty.h:65
@ Boolean
Boolean value.
Definition qgsproperty.h:51
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
Definition qgsproperty.h:54
@ IntegerPositive
Positive integer values (including 0)
Definition qgsproperty.h:53
@ Opacity
Opacity (0-100)
Definition qgsproperty.h:60
@ Rotation
Rotation (value between 0-360 degrees)
Definition qgsproperty.h:58
@ ColorWithAlpha
Color with alpha channel.
Definition qgsproperty.h:62
@ DoublePositive
Positive double value (including 0)
Definition qgsproperty.h:56
@ DataTypeString
Property requires a string value.
Definition qgsproperty.h:90
The class is used as a container of context for various read/write operations on other objects.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.