QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 QgsLayoutAtlas;
47 
54 class CORE_EXPORT QgsCompositionConverter
55 {
56  public:
57 
62  {
63  NoProperty = 0,
66  //composer page properties
72  //general composer item properties
85  //composer map
95  //composer picture
100  //html item
102  //legend item
105  //scalebar item
110  };
111 
116  {
119  SVGMarker
120  };
121 
122 
128  static std::unique_ptr<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
129  QgsProject *project );
130 
131 
141  static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
142  const QDomElement &parentElement,
143  QPointF *position = nullptr,
144  bool pasteInPlace = false );
145 
151  static bool isCompositionTemplate( const QDomDocument &document );
152 
160  static QDomDocument convertCompositionTemplate( const QDomDocument
161  &document, QgsProject *project );
162 
163 
164  private:
165 
166 
168  static QgsPropertiesDefinition sPropertyDefinitions;
169 
170 
171  static bool readLabelXml( QgsLayoutItemLabel *layoutItem,
172  const QDomElement &itemElem,
173  const QgsProject *project );
174 
175  static bool readShapeXml( QgsLayoutItemShape *layoutItem,
176  const QDomElement &itemElem,
177  const QgsProject *project );
178 
179  static bool readPictureXml( QgsLayoutItemPicture *layoutItem,
180  const QDomElement &itemElem,
181  const QgsProject *project,
182  const QgsStringMap &mapId2Uuid );
183 
185  template <class T, class T2> static bool readPolyXml( T *layoutItem,
186  const QDomElement &itemElem,
187  const QgsProject *project );
188 
189  static bool readArrowXml( QgsLayoutItemPolyline *layoutItem,
190  const QDomElement &itemElem,
191  const QgsProject *project );
192 
193  static bool readMapXml( QgsLayoutItemMap *layoutItem,
194  const QDomElement &itemElem,
195  const QgsProject *project,
196  QgsStringMap &mapId2Uuid );
197 
198  static bool readScaleBarXml( QgsLayoutItemScaleBar *layoutItem,
199  const QDomElement &itemElem,
200  const QgsProject *project,
201  const QgsStringMap &mapId2Uuid );
202 
203  static bool readLegendXml( QgsLayoutItemLegend *layoutItem,
204  const QDomElement &itemElem,
205  const QgsProject *project,
206  const QgsStringMap &mapId2Uuid );
207 
208  static bool readAtlasXml( QgsLayoutAtlas *atlasItem,
209  const QDomElement &itemElem,
210  const QgsProject *project );
211 
212  static bool readHtmlXml( QgsLayoutItemHtml *layoutItem,
213  const QDomElement &itemElem,
214  const QgsProject *project );
215 
216  static bool readTableXml( QgsLayoutItemAttributeTable *layoutItem,
217  const QDomElement &itemElem,
218  const QgsProject *project );
219 
220  static bool readOldComposerObjectXml( QgsLayoutObject *layoutItem, const QDomElement &itemElem );
221 
222  static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
223  QgsPropertyCollection &dataDefinedProperties );
224 
225  static QgsProperty readOldDataDefinedProperty( DataDefinedProperty property, const QDomElement &ddElem );
226 
227  static void initPropertyDefinitions();
228 
229  static QgsPropertiesDefinition propertyDefinitions();
230 
232  static bool readXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
233 
235  static void adjustPos( QgsPrintLayout *layout, QgsLayoutItem *layoutItem, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );
236 
238  static void restoreGeneralComposeItemProperties( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
239 
241  static QRectF itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
242 
244  static QPointF minPointFromXml( const QDomElement &elem );
245 
246 };
247 
248 #endif // QGSCOMPOSITIONCONVERTER_H
QgsCompositionConverter::ItemHeight
@ ItemHeight
Height of item.
Definition: qgscompositionconverter.h:77
QgsLayoutItemShape
Layout item for basic filled shapes (e.g.
Definition: qgslayoutitemshape.h:33
QgsCompositionConverter::MapXMin
@ MapXMin
Map extent x minimum.
Definition: qgscompositionconverter.h:88
QgsCompositionConverter::MapScale
@ MapScale
Map scale.
Definition: qgscompositionconverter.h:87
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsCompositionConverter::PositionY
@ PositionY
Y position on page.
Definition: qgscompositionconverter.h:75
QgsCompositionConverter::BlendMode
@ BlendMode
Item blend mode.
Definition: qgscompositionconverter.h:81
QgsCompositionConverter::PaperWidth
@ PaperWidth
Paper width.
Definition: qgscompositionconverter.h:68
QgsCompositionConverter::BackgroundColor
@ BackgroundColor
Item background color.
Definition: qgscompositionconverter.h:84
QgsCompositionConverter::MapXMax
@ MapXMax
Map extent x maximum.
Definition: qgscompositionconverter.h:90
QgsLayoutItemPolyline
Layout item for node based polyline shapes.
Definition: qgslayoutitempolyline.h:33
QgsCompositionConverter::MapStylePreset
@ MapStylePreset
Layer and style map theme.
Definition: qgscompositionconverter.h:94
QgsCompositionConverter::TestProperty
@ TestProperty
Dummy property with no effect on item.
Definition: qgscompositionconverter.h:65
QgsCompositionConverter::MapRotation
@ MapRotation
Map rotation.
Definition: qgscompositionconverter.h:86
QgsLayoutItemHtml
A layout multiframe subclass for HTML content.
Definition: qgslayoutitemhtml.h:37
QgsCompositionConverter::ItemRotation
@ ItemRotation
Rotation of item.
Definition: qgscompositionconverter.h:78
QgsCompositionConverter::PageNumber
@ PageNumber
Page number for item placement.
Definition: qgscompositionconverter.h:73
QgsCompositionConverter::Transparency
@ Transparency
Item transparency (deprecated)
Definition: qgscompositionconverter.h:79
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
QgsLayoutItemLegend
A layout item subclass for map legends.
Definition: qgslayoutitemlegend.h:114
QgsCompositionConverter::MapYMax
@ MapYMax
Map extent y maximum.
Definition: qgscompositionconverter.h:91
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsCompositionConverter::MapAtlasMargin
@ MapAtlasMargin
Map atlas margin.
Definition: qgscompositionconverter.h:92
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:31
QgsCompositionConverter::LegendColumnCount
@ LegendColumnCount
Legend column count.
Definition: qgscompositionconverter.h:104
QgsCompositionConverter
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Definition: qgscompositionconverter.h:55
qgis_sip.h
QgsCompositionConverter::PictureSvgStrokeWidth
@ PictureSvgStrokeWidth
SVG stroke width.
Definition: qgscompositionconverter.h:99
QgsCompositionConverter::PaperOrientation
@ PaperOrientation
Paper orientation.
Definition: qgscompositionconverter.h:71
QgsCompositionConverter::ScalebarLineColor
@ ScalebarLineColor
Scalebar line color.
Definition: qgscompositionconverter.h:108
QgsCompositionConverter::ExcludeFromExports
@ ExcludeFromExports
Exclude item from exports.
Definition: qgscompositionconverter.h:82
QgsCompositionConverter::PictureSvgBackgroundColor
@ PictureSvgBackgroundColor
SVG background color.
Definition: qgscompositionconverter.h:97
QgsCompositionConverter::AllProperties
@ AllProperties
All properties for item.
Definition: qgscompositionconverter.h:64
QgsLayoutItemAttributeTable
A layout table subclass that displays attributes from a vector layer.
Definition: qgslayoutitemattributetable.h:35
QgsCompositionConverter::PictureSvgStrokeColor
@ PictureSvgStrokeColor
SVG stroke color.
Definition: qgscompositionconverter.h:98
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsCompositionConverter::ScalebarLineWidth
@ ScalebarLineWidth
Scalebar line width.
Definition: qgscompositionconverter.h:109
QgsCompositionConverter::PaperHeight
@ PaperHeight
Paper height.
Definition: qgscompositionconverter.h:69
QgsCompositionConverter::Opacity
@ Opacity
Item opacity.
Definition: qgscompositionconverter.h:80
QgsCompositionConverter::DefaultMarker
@ DefaultMarker
Definition: qgscompositionconverter.h:117
QgsLayoutItemPicture
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
Definition: qgslayoutitempicture.h:36
QgsCompositionConverter::MapLayers
@ MapLayers
Map layer set.
Definition: qgscompositionconverter.h:93
QgsCompositionConverter::MarkerMode
MarkerMode
The MarkerMode enum is the old QGIS 2.x arrow marker mode.
Definition: qgscompositionconverter.h:116
QgsCompositionConverter::ScalebarFillColor
@ ScalebarFillColor
Scalebar fill color.
Definition: qgscompositionconverter.h:106
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:319
QgsCompositionConverter::DataDefinedProperty
DataDefinedProperty
Composition data defined properties for different item types.
Definition: qgscompositionconverter.h:62
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsCompositionConverter::SourceUrl
@ SourceUrl
Html source url.
Definition: qgscompositionconverter.h:101
qgspropertycollection.h
QgsCompositionConverter::NoMarker
@ NoMarker
Definition: qgscompositionconverter.h:118
QgsLayoutItemPolygon
Layout item for node based polygon shapes.
Definition: qgslayoutitempolygon.h:30
QgsCompositionConverter::LegendTitle
@ LegendTitle
Legend title.
Definition: qgscompositionconverter.h:103
QgsCompositionConverter::FrameColor
@ FrameColor
Item frame color.
Definition: qgscompositionconverter.h:83
QgsCompositionConverter::ItemWidth
@ ItemWidth
Width of item.
Definition: qgscompositionconverter.h:76
QgsLayoutItemLabel
A layout item subclass for text labels.
Definition: qgslayoutitemlabel.h:35
QgsLayoutItemScaleBar
A layout item subclass for scale bars.
Definition: qgslayoutitemscalebar.h:36
QgsCompositionConverter::PictureSource
@ PictureSource
Picture source url.
Definition: qgscompositionconverter.h:96
QgsLayoutAtlas
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
Definition: qgslayoutatlas.h:42
QgsCompositionConverter::NumPages
@ NumPages
Number of pages in composition.
Definition: qgscompositionconverter.h:70
QgsCompositionConverter::MapYMin
@ MapYMin
Map extent y minimum.
Definition: qgscompositionconverter.h:89
QgsCompositionConverter::PresetPaperSize
@ PresetPaperSize
Preset paper size for composition.
Definition: qgscompositionconverter.h:67
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:40
QgsCompositionConverter::ScalebarFillColor2
@ ScalebarFillColor2
Scalebar secondary fill color.
Definition: qgscompositionconverter.h:107
QgsCompositionConverter::PositionX
@ PositionX
X position on page.
Definition: qgscompositionconverter.h:74