QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgscompositionconverter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscompositionconverter.h - Convert a QGIS 2.x composition to a layout
3 
4  ---------------------
5  begin : 13.12.2017
6  copyright : (C) 2017 by Alessandro Pasotti
7  email : elpaso at itopen dot it
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSCOMPOSITIONCONVERTER_H
17 #define QGSCOMPOSITIONCONVERTER_H
18 
19 
20 #include <QDomDocument>
21 #include <QDomElement>
22 
23 #include "qgis_sip.h"
24 
25 #define SIP_NO_FILE
26 
27 #include "qgspropertycollection.h"
28 
29 class QgsPrintLayout;
30 class QgsLayoutItem;
31 class QgsLayoutObject;
33 class QgsProperty;
35 
36 class QgsLayoutItemLabel;
37 class QgsLayoutItemShape;
41 class QgsLayoutItemMap;
44 class QgsLayoutItemHtml;
46 class QgsLayoutItemGroup;
47 class QgsLayoutAtlas;
48 class QgsProject;
49 
56 class CORE_EXPORT QgsCompositionConverter
57 {
58  public:
59 
64  {
65  NoProperty = 0,
68  //composer page properties
74  //general composer item properties
87  //composer map
97  //composer picture
102  //html item
104  //legend item
107  //scalebar item
112  };
113 
118  {
121  SVGMarker
122  };
123 
124 
130  static std::unique_ptr<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
131  QgsProject *project );
132 
133 
143  static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
144  const QDomElement &parentElement,
145  QPointF *position = nullptr,
146  bool pasteInPlace = false );
147 
153  static bool isCompositionTemplate( const QDomDocument &document );
154 
162  static QDomDocument convertCompositionTemplate( const QDomDocument
163  &document, QgsProject *project );
164 
165 
166  private:
167 
168 
170  static QgsPropertiesDefinition sPropertyDefinitions;
171 
172 
173  static bool readLabelXml( QgsLayoutItemLabel *layoutItem,
174  const QDomElement &itemElem,
175  const QgsProject *project );
176 
177  static bool readShapeXml( QgsLayoutItemShape *layoutItem,
178  const QDomElement &itemElem,
179  const QgsProject *project );
180 
181  static bool readPictureXml( QgsLayoutItemPicture *layoutItem,
182  const QDomElement &itemElem,
183  const QgsProject *project,
184  const QgsStringMap &mapId2Uuid );
185 
187  template <class T, class T2> static bool readPolyXml( T *layoutItem,
188  const QDomElement &itemElem,
189  const QgsProject *project );
190 
191  static bool readArrowXml( QgsLayoutItemPolyline *layoutItem,
192  const QDomElement &itemElem,
193  const QgsProject *project );
194 
195  static bool readMapXml( QgsLayoutItemMap *layoutItem,
196  const QDomElement &itemElem,
197  const QgsProject *project,
198  QgsStringMap &mapId2Uuid );
199 
200  static bool readScaleBarXml( QgsLayoutItemScaleBar *layoutItem,
201  const QDomElement &itemElem,
202  const QgsProject *project,
203  const QgsStringMap &mapId2Uuid );
204 
205  static bool readLegendXml( QgsLayoutItemLegend *layoutItem,
206  const QDomElement &itemElem,
207  const QgsProject *project,
208  const QgsStringMap &mapId2Uuid );
209 
210  static bool readAtlasXml( QgsLayoutAtlas *atlasItem,
211  const QDomElement &itemElem,
212  const QgsProject *project );
213 
214  static bool readHtmlXml( QgsLayoutItemHtml *layoutItem,
215  const QDomElement &itemElem,
216  const QgsProject *project );
217 
218  static bool readTableXml( QgsLayoutItemAttributeTable *layoutItem,
219  const QDomElement &itemElem,
220  const QgsProject *project );
221 
222  static bool readGroupXml( QgsLayoutItemGroup *layoutItem,
223  const QDomElement &itemElem,
224  const QgsProject *project,
225  const QList<QgsLayoutObject *> &items );
226 
227  static bool readOldComposerObjectXml( QgsLayoutObject *layoutItem, const QDomElement &itemElem );
228 
229  static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
230  QgsPropertyCollection &dataDefinedProperties );
231 
232  static QgsProperty readOldDataDefinedProperty( DataDefinedProperty property, const QDomElement &ddElem );
233 
234  static void initPropertyDefinitions();
235 
236  static QgsPropertiesDefinition propertyDefinitions();
237 
239  static bool readXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
240 
242  static void adjustPos( QgsPrintLayout *layout, QgsLayoutItem *layoutItem, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );
243 
245  static void restoreGeneralComposeItemProperties( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
246 
248  static QRectF itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
249 
251  static QPointF minPointFromXml( const QDomElement &elem );
252 
253 };
254 
255 #endif // QGSCOMPOSITIONCONVERTER_H
QgsCompositionConverter::ItemHeight
@ ItemHeight
Height of item.
Definition: qgscompositionconverter.h:79
QgsLayoutItemShape
Layout item for basic filled shapes (e.g. rectangles, ellipses).
Definition: qgslayoutitemshape.h:31
QgsCompositionConverter::MapXMin
@ MapXMin
Map extent x minimum.
Definition: qgscompositionconverter.h:90
QgsCompositionConverter::MapScale
@ MapScale
Map scale.
Definition: qgscompositionconverter.h:89
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsCompositionConverter::PositionY
@ PositionY
Y position on page.
Definition: qgscompositionconverter.h:77
QgsCompositionConverter::BlendMode
@ BlendMode
Item blend mode.
Definition: qgscompositionconverter.h:83
QgsCompositionConverter::PaperWidth
@ PaperWidth
Paper width.
Definition: qgscompositionconverter.h:70
QgsCompositionConverter::BackgroundColor
@ BackgroundColor
Item background color.
Definition: qgscompositionconverter.h:86
QgsCompositionConverter::MapXMax
@ MapXMax
Map extent x maximum.
Definition: qgscompositionconverter.h:92
QgsLayoutItemPolyline
Layout item for node based polyline shapes.
Definition: qgslayoutitempolyline.h:33
QgsCompositionConverter::MapStylePreset
@ MapStylePreset
Layer and style map theme.
Definition: qgscompositionconverter.h:96
QgsCompositionConverter::TestProperty
@ TestProperty
Dummy property with no effect on item.
Definition: qgscompositionconverter.h:67
QgsCompositionConverter::MapRotation
@ MapRotation
Map rotation.
Definition: qgscompositionconverter.h:88
QgsLayoutItemHtml
A layout multiframe subclass for HTML content.
Definition: qgslayoutitemhtml.h:36
QgsCompositionConverter::ItemRotation
@ ItemRotation
Rotation of item.
Definition: qgscompositionconverter.h:80
QgsCompositionConverter::PageNumber
@ PageNumber
Page number for item placement.
Definition: qgscompositionconverter.h:75
QgsCompositionConverter::Transparency
@ Transparency
Item transparency (deprecated)
Definition: qgscompositionconverter.h:81
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsLayoutItemLegend
A layout item subclass for map legends.
Definition: qgslayoutitemlegend.h:113
QgsCompositionConverter::MapYMax
@ MapYMax
Map extent y maximum.
Definition: qgscompositionconverter.h:93
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsCompositionConverter::MapAtlasMargin
@ MapAtlasMargin
Map atlas margin.
Definition: qgscompositionconverter.h:94
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:30
QgsCompositionConverter::LegendColumnCount
@ LegendColumnCount
Legend column count.
Definition: qgscompositionconverter.h:106
QgsCompositionConverter
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Definition: qgscompositionconverter.h:56
qgis_sip.h
QgsCompositionConverter::PictureSvgStrokeWidth
@ PictureSvgStrokeWidth
SVG stroke width.
Definition: qgscompositionconverter.h:101
QgsCompositionConverter::PaperOrientation
@ PaperOrientation
Paper orientation.
Definition: qgscompositionconverter.h:73
QgsCompositionConverter::ScalebarLineColor
@ ScalebarLineColor
Scalebar line color.
Definition: qgscompositionconverter.h:110
QgsCompositionConverter::ExcludeFromExports
@ ExcludeFromExports
Exclude item from exports.
Definition: qgscompositionconverter.h:84
QgsCompositionConverter::PictureSvgBackgroundColor
@ PictureSvgBackgroundColor
SVG background color.
Definition: qgscompositionconverter.h:99
QgsCompositionConverter::AllProperties
@ AllProperties
All properties for item.
Definition: qgscompositionconverter.h:66
QgsLayoutItemAttributeTable
A layout table subclass that displays attributes from a vector layer.
Definition: qgslayoutitemattributetable.h:34
QgsCompositionConverter::PictureSvgStrokeColor
@ PictureSvgStrokeColor
SVG stroke color.
Definition: qgscompositionconverter.h:100
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:112
QgsCompositionConverter::ScalebarLineWidth
@ ScalebarLineWidth
Scalebar line width.
Definition: qgscompositionconverter.h:111
QgsCompositionConverter::PaperHeight
@ PaperHeight
Paper height.
Definition: qgscompositionconverter.h:71
QgsLayoutItemGroup
A container for grouping several QgsLayoutItems.
Definition: qgslayoutitemgroup.h:28
QgsCompositionConverter::Opacity
@ Opacity
Item opacity.
Definition: qgscompositionconverter.h:82
QgsCompositionConverter::DefaultMarker
@ DefaultMarker
Definition: qgscompositionconverter.h:119
QgsLayoutItemPicture
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
Definition: qgslayoutitempicture.h:35
QgsCompositionConverter::MapLayers
@ MapLayers
Map layer set.
Definition: qgscompositionconverter.h:95
QgsCompositionConverter::MarkerMode
MarkerMode
The MarkerMode enum is the old QGIS 2.x arrow marker mode.
Definition: qgscompositionconverter.h:117
QgsCompositionConverter::ScalebarFillColor
@ ScalebarFillColor
Scalebar fill color.
Definition: qgscompositionconverter.h:108
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:317
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsCompositionConverter::DataDefinedProperty
DataDefinedProperty
Composition data defined properties for different item types.
Definition: qgscompositionconverter.h:63
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:2781
QgsCompositionConverter::SourceUrl
@ SourceUrl
Html source url.
Definition: qgscompositionconverter.h:103
qgspropertycollection.h
QgsCompositionConverter::NoMarker
@ NoMarker
Definition: qgscompositionconverter.h:120
QgsLayoutItemPolygon
Layout item for node based polygon shapes.
Definition: qgslayoutitempolygon.h:30
QgsCompositionConverter::LegendTitle
@ LegendTitle
Legend title.
Definition: qgscompositionconverter.h:105
QgsCompositionConverter::FrameColor
@ FrameColor
Item frame color.
Definition: qgscompositionconverter.h:85
QgsCompositionConverter::ItemWidth
@ ItemWidth
Width of item.
Definition: qgscompositionconverter.h:78
QgsLayoutItemLabel
A layout item subclass for text labels.
Definition: qgslayoutitemlabel.h:36
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:35
QgsCompositionConverter::PictureSource
@ PictureSource
Picture source url.
Definition: qgscompositionconverter.h:98
QgsLayoutAtlas
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
Definition: qgslayoutatlas.h:41
QgsCompositionConverter::NumPages
@ NumPages
Number of pages in composition.
Definition: qgscompositionconverter.h:72
QgsCompositionConverter::MapYMin
@ MapYMin
Map extent y minimum.
Definition: qgscompositionconverter.h:91
QgsCompositionConverter::PresetPaperSize
@ PresetPaperSize
Preset paper size for composition.
Definition: qgscompositionconverter.h:69
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:39
QgsCompositionConverter::ScalebarFillColor2
@ ScalebarFillColor2
Scalebar secondary fill color.
Definition: qgscompositionconverter.h:109
QgsCompositionConverter::PositionX
@ PositionX
X position on page.
Definition: qgscompositionconverter.h:76