/
qgscompositionconverter.h
226 lines (184 loc) · 8.36 KB
/
qgscompositionconverter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/***************************************************************************
qgscompositionconverter.h - Convert a QGIS 2.x composition to a layout
---------------------
begin : 13.12.2017
copyright : (C) 2017 by Alessandro Pasotti
email : elpaso at itopen dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSCOMPOSITIONCONVERTER_H
#define QGSCOMPOSITIONCONVERTER_H
#include <QDomDocument>
#include <QDomElement>
#include "qgis.h"
#include "qgis_sip.h"
#define SIP_NO_FILE
#include "qgspropertycollection.h"
class QgsPrintLayout;
class QgsLayoutItem;
class QgsLayoutObject;
class QgsReadWriteContext;
class QgsProperty;
class QgsPropertyCollection;
class QgsLayoutItemLabel;
class QgsLayoutItemShape;
class QgsLayoutItemPicture;
class QgsLayoutItemPolygon;
class QgsLayoutItemPolyline;
class QgsLayoutItemMap;
class QgsLayoutItemScaleBar;
class QgsLayoutItemLegend;
class QgsLayoutItemHtml;
/**
* QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout
* \since QGIS 3.0
* \note Not available in Python bindings.
* \ingroup core
*/
class CORE_EXPORT QgsCompositionConverter
{
public:
/**
* Composition data defined properties for different item types
*/
enum DataDefinedProperty
{
NoProperty = 0, //!< No property
AllProperties, //!< All properties for item
TestProperty, //!< Dummy property with no effect on item
//composer page properties
PresetPaperSize, //!< Preset paper size for composition
PaperWidth, //!< Paper width
PaperHeight, //!< Paper height
NumPages, //!< Number of pages in composition
PaperOrientation, //!< Paper orientation
//general composer item properties
PageNumber, //!< Page number for item placement
PositionX, //!< X position on page
PositionY, //!< Y position on page
ItemWidth, //!< Width of item
ItemHeight, //!< Height of item
ItemRotation, //!< Rotation of item
Transparency, //!< Item transparency (deprecated)
Opacity, //!< Item opacity
BlendMode, //!< Item blend mode
ExcludeFromExports, //!< Exclude item from exports
FrameColor, //!< Item frame color
BackgroundColor, //!< Item background color
//composer map
MapRotation, //!< Map rotation
MapScale, //!< Map scale
MapXMin, //!< Map extent x minimum
MapYMin, //!< Map extent y minimum
MapXMax, //!< Map extent x maximum
MapYMax, //!< Map extent y maximum
MapAtlasMargin, //!< Map atlas margin
MapLayers, //!< Map layer set
MapStylePreset, //!< Layer and style map theme
//composer picture
PictureSource, //!< Picture source url
PictureSvgBackgroundColor, //!< SVG background color
PictureSvgStrokeColor, //!< SVG stroke color
PictureSvgStrokeWidth, //!< SVG stroke width
//html item
SourceUrl, //!< Html source url
//legend item
LegendTitle, //!< Legend title
LegendColumnCount, //!< Legend column count
//scalebar item
ScalebarFillColor, //!< Scalebar fill color
ScalebarFillColor2, //!< Scalebar secondary fill color
ScalebarLineColor, //!< Scalebar line color
ScalebarLineWidth, //!< Scalebar line width
};
/**
* The MarkerMode enum is the old QGIS 2.x arrow marker mode
*/
enum MarkerMode
{
DefaultMarker,
NoMarker,
SVGMarker
};
/**
* createLayoutFromCompositionXml is a factory that creates layout instances from a
* QGIS 2.x XML composition \a parentElement and a QGIS \a project
* \return a QgsPrintLayout instance
* \since QGIS 3.0
*/
static std::unique_ptr<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
QgsProject *project );
/**
* addItemsFromCompositionXml parse a QGIS 2.x composition XML in the \a parentElement,
* converts the 2.x items to the new layout elements and add them to the \a layout
* \param position for pasting
* \param pasteInPlace if true element position is translated to \a position
* \return list of layout object items that have been added to the layout
* \since QGIS 3.0
*/
static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
const QDomElement &parentElement,
QPointF *position = nullptr,
bool pasteInPlace = false );
private:
//! Property definitions
static QgsPropertiesDefinition sPropertyDefinitions;
static bool readLabelXml( QgsLayoutItemLabel *layoutItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readShapeXml( QgsLayoutItemShape *layoutItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readPictureXml( QgsLayoutItemPicture *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QgsStringMap &mapId2Uuid );
//! For both polylines and polygons
template <class T, class T2> static bool readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readArrowXml( QgsLayoutItemPolyline *layoutItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readMapXml( QgsLayoutItemMap *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
QgsStringMap &mapId2Uuid );
static bool readScaleBarXml( QgsLayoutItemScaleBar *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QgsStringMap &mapId2Uuid );
static bool readLegendXml( QgsLayoutItemLegend *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QgsStringMap &mapId2Uuid );
static bool readAtlasXml( QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readHtmlXml( QgsLayoutItemHtml *layoutItem,
const QDomElement &itemElem,
const QgsProject *project );
static bool readOldComposerObjectXml( QgsLayoutObject *layoutItem, const QDomElement &itemElem );
static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties );
static QgsProperty readOldDataDefinedProperty( const DataDefinedProperty property, const QDomElement &ddElem );
static void initPropertyDefinitions();
static QgsPropertiesDefinition propertyDefinitions();
//! Reads parameter that are not subclass specific in document. Usually called from readXml methods of subclasses
static bool readXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
//! Make some common import adjustments
static void adjustPos( QgsPrintLayout *layout, QgsLayoutItem *layoutItem, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );
//! Restore general composer item properties
static void restoreGeneralComposeItemProperties( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
//! Get item position
static QRectF itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
//! Calculates the item minimum position from an xml string
static QPointF minPointFromXml( const QDomElement &elem );
};
#endif // QGSCOMPOSITIONCONVERTER_H