QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
55 class CORE_EXPORT QgsCompositionConverter
56 {
57  public:
58 
63  {
64  NoProperty = 0,
67  //composer page properties
73  //general composer item properties
86  //composer map
96  //composer picture
101  //html item
103  //legend item
106  //scalebar item
111  };
112 
117  {
120  SVGMarker
121  };
122 
123 
129  static std::unique_ptr<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
130  QgsProject *project );
131 
132 
142  static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
143  const QDomElement &parentElement,
144  QPointF *position = nullptr,
145  bool pasteInPlace = false );
146 
152  static bool isCompositionTemplate( const QDomDocument &document );
153 
161  static QDomDocument convertCompositionTemplate( const QDomDocument
162  &document, QgsProject *project );
163 
164 
165  private:
166 
167 
169  static QgsPropertiesDefinition sPropertyDefinitions;
170 
171 
172  static bool readLabelXml( QgsLayoutItemLabel *layoutItem,
173  const QDomElement &itemElem,
174  const QgsProject *project );
175 
176  static bool readShapeXml( QgsLayoutItemShape *layoutItem,
177  const QDomElement &itemElem,
178  const QgsProject *project );
179 
180  static bool readPictureXml( QgsLayoutItemPicture *layoutItem,
181  const QDomElement &itemElem,
182  const QgsProject *project,
183  const QgsStringMap &mapId2Uuid );
184 
186  template <class T, class T2> static bool readPolyXml( T *layoutItem,
187  const QDomElement &itemElem,
188  const QgsProject *project );
189 
190  static bool readArrowXml( QgsLayoutItemPolyline *layoutItem,
191  const QDomElement &itemElem,
192  const QgsProject *project );
193 
194  static bool readMapXml( QgsLayoutItemMap *layoutItem,
195  const QDomElement &itemElem,
196  const QgsProject *project,
197  QgsStringMap &mapId2Uuid );
198 
199  static bool readScaleBarXml( QgsLayoutItemScaleBar *layoutItem,
200  const QDomElement &itemElem,
201  const QgsProject *project,
202  const QgsStringMap &mapId2Uuid );
203 
204  static bool readLegendXml( QgsLayoutItemLegend *layoutItem,
205  const QDomElement &itemElem,
206  const QgsProject *project,
207  const QgsStringMap &mapId2Uuid );
208 
209  static bool readAtlasXml( QgsLayoutAtlas *atlasItem,
210  const QDomElement &itemElem,
211  const QgsProject *project );
212 
213  static bool readHtmlXml( QgsLayoutItemHtml *layoutItem,
214  const QDomElement &itemElem,
215  const QgsProject *project );
216 
217  static bool readTableXml( QgsLayoutItemAttributeTable *layoutItem,
218  const QDomElement &itemElem,
219  const QgsProject *project );
220 
221  static bool readGroupXml( QgsLayoutItemGroup *layoutItem,
222  const QDomElement &itemElem,
223  const QgsProject *project,
224  const QList<QgsLayoutObject *> &items );
225 
226  static bool readOldComposerObjectXml( QgsLayoutObject *layoutItem, const QDomElement &itemElem );
227 
228  static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
229  QgsPropertyCollection &dataDefinedProperties );
230 
231  static QgsProperty readOldDataDefinedProperty( DataDefinedProperty property, const QDomElement &ddElem );
232 
233  static void initPropertyDefinitions();
234 
235  static QgsPropertiesDefinition propertyDefinitions();
236 
238  static bool readXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
239 
241  static void adjustPos( QgsPrintLayout *layout, QgsLayoutItem *layoutItem, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );
242 
244  static void restoreGeneralComposeItemProperties( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
245 
247  static QRectF itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
248 
250  static QPointF minPointFromXml( const QDomElement &elem );
251 
252 };
253 
254 #endif // QGSCOMPOSITIONCONVERTER_H
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
DataDefinedProperty
Composition data defined properties for different item types.
@ PaperOrientation
Paper orientation.
@ MapYMax
Map extent y maximum.
@ MapStylePreset
Layer and style map theme.
@ MapAtlasMargin
Map atlas margin.
@ MapYMin
Map extent y minimum.
@ MapXMin
Map extent x minimum.
@ ScalebarFillColor2
Scalebar secondary fill color.
@ ExcludeFromExports
Exclude item from exports.
@ NumPages
Number of pages in composition.
@ PictureSvgBackgroundColor
SVG background color.
@ LegendColumnCount
Legend column count.
@ PictureSvgStrokeWidth
SVG stroke width.
@ ScalebarFillColor
Scalebar fill color.
@ PictureSvgStrokeColor
SVG stroke color.
@ PageNumber
Page number for item placement.
@ ScalebarLineColor
Scalebar line color.
@ Transparency
Item transparency (deprecated)
@ MapXMax
Map extent x maximum.
@ TestProperty
Dummy property with no effect on item.
@ AllProperties
All properties for item.
@ PresetPaperSize
Preset paper size for composition.
@ BackgroundColor
Item background color.
@ PositionY
Y position on page.
@ PositionX
X position on page.
@ ScalebarLineWidth
Scalebar line width.
@ PictureSource
Picture source url.
MarkerMode
The MarkerMode enum is the old QGIS 2.x arrow marker mode.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
A layout table subclass that displays attributes from a vector layer.
A container for grouping several QgsLayoutItems.
A layout multiframe subclass for HTML content.
A layout item subclass for text labels.
A layout item subclass for map legends.
Layout graphical items for displaying a map.
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.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A store for object properties.
Definition: qgsproperty.h:232
The class is used as a container of context for various read/write operations on other objects.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:1041
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.