Skip to content

Commit da3636e

Browse files
committed
[layout] Converter: initial implementation
1 parent 97c005a commit da3636e

18 files changed

+3360
-2
lines changed

python/core/layout/qgslayoutitemlabel.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Returns the required item size (in layout units) for the label's text to fill th
6161
.. seealso:: :py:func:`adjustSizeToText()`
6262
%End
6363

64-
QString text();
64+
QString text() const;
6565
%Docstring
6666
Returns the label's preset text.
6767

python/core/layout/qgslayoutitemshape.sip

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ class QgsLayoutItemShape : QgsLayoutItem
3434
Constructor for QgsLayoutItemShape, with the specified parent ``layout``.
3535
%End
3636

37+
static QgsLayoutItemShape *create( QgsLayout *layout ) /Factory/;
38+
%Docstring
39+
Returns a new shape item for the specified ``layout``.
40+
41+
The caller takes responsibility for deleting the returned object.
42+
43+
:rtype: QgsLayoutItemShape
44+
%End
45+
46+
3747
virtual int type() const;
3848

3949
virtual QIcon icon() const;

src/core/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ SET(QGIS_CORE_SRCS
418418
layout/qgsreport.cpp
419419
layout/qgsreportsectionfieldgroup.cpp
420420
layout/qgsreportsectionlayout.cpp
421+
layout/qgscompositionconverter.cpp
421422

422423
pal/costcalculator.cpp
423424
pal/feature.cpp
@@ -1050,8 +1051,12 @@ SET(QGIS_CORE_HDRS
10501051
layout/qgslayoutsnapper.h
10511052
layout/qgslayoutundocommand.h
10521053
layout/qgslayoututils.h
1054+
<<<<<<< 2b8143a20674b8598fad5ee489def7ebd539cb5b
10531055
layout/qgsreportsectionfieldgroup.h
10541056
layout/qgsreportsectionlayout.h
1057+
=======
1058+
layout/qgscompositionconverter.h
1059+
>>>>>>> [layout] Converter: initial implementation
10551060

10561061
metadata/qgslayermetadata.h
10571062
metadata/qgslayermetadatavalidator.h

src/core/layout/qgscompositionconverter.cpp

+657
Large diffs are not rendered by default.
+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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 : apasotti at boundlessgeo dot com
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+
#include <QDomDocument>
20+
#include <QDomElement>
21+
22+
23+
#include "qgis.h"
24+
#include "qgspropertycollection.h"
25+
26+
class QgsLayout;
27+
class QgsLayoutItem;
28+
class QgsLayoutItemLabel;
29+
class QgsLayoutItemShape;
30+
class QgsReadWriteContext;
31+
class QgsProperty;
32+
class QgsPropertyCollection;
33+
34+
class CORE_EXPORT QgsCompositionConverter
35+
{
36+
public:
37+
38+
/**
39+
* Composition data defined properties for different item types
40+
*/
41+
enum DataDefinedProperty
42+
{
43+
NoProperty = 0, //!< No property
44+
AllProperties, //!< All properties for item
45+
TestProperty, //!< Dummy property with no effect on item
46+
//composer page properties
47+
PresetPaperSize, //!< Preset paper size for composition
48+
PaperWidth, //!< Paper width
49+
PaperHeight, //!< Paper height
50+
NumPages, //!< Number of pages in composition
51+
PaperOrientation, //!< Paper orientation
52+
//general composer item properties
53+
PageNumber, //!< Page number for item placement
54+
PositionX, //!< X position on page
55+
PositionY, //!< Y position on page
56+
ItemWidth, //!< Width of item
57+
ItemHeight, //!< Height of item
58+
ItemRotation, //!< Rotation of item
59+
Transparency, //!< Item transparency (deprecated)
60+
Opacity, //!< Item opacity
61+
BlendMode, //!< Item blend mode
62+
ExcludeFromExports, //!< Exclude item from exports
63+
FrameColor, //!< Item frame color
64+
BackgroundColor, //!< Item background color
65+
//composer map
66+
MapRotation, //!< Map rotation
67+
MapScale, //!< Map scale
68+
MapXMin, //!< Map extent x minimum
69+
MapYMin, //!< Map extent y minimum
70+
MapXMax, //!< Map extent x maximum
71+
MapYMax, //!< Map extent y maximum
72+
MapAtlasMargin, //!< Map atlas margin
73+
MapLayers, //!< Map layer set
74+
MapStylePreset, //!< Layer and style map theme
75+
//composer picture
76+
PictureSource, //!< Picture source url
77+
PictureSvgBackgroundColor, //!< SVG background color
78+
PictureSvgStrokeColor, //!< SVG stroke color
79+
PictureSvgStrokeWidth, //!< SVG stroke width
80+
//html item
81+
SourceUrl, //!< Html source url
82+
//legend item
83+
LegendTitle, //!< Legend title
84+
LegendColumnCount, //!< Legend column count
85+
//scalebar item
86+
ScalebarFillColor, //!< Scalebar fill color
87+
ScalebarFillColor2, //!< Scalebar secondary fill color
88+
ScalebarLineColor, //!< Scalebar line color
89+
ScalebarLineWidth, //!< Scalebar line width
90+
};
91+
92+
/**
93+
* \brief createLayoutFromCompositionXml is a factory that creates layout instances from a
94+
* QGIS 2.x XML composition \a document
95+
* \param parentElement is the Composition element
96+
* \param document
97+
* \param context
98+
* \return a QgsLayout instance
99+
*/
100+
static QgsLayout *createLayoutFromCompositionXml( const QDomElement &parentElement,
101+
const QgsReadWriteContext &context ) SIP_FACTORY;
102+
103+
104+
static QList<QgsLayoutItem *> addItemsFromCompositionXml( QgsLayout *layout,
105+
const QDomElement &parentElement,
106+
const QgsReadWriteContext &context,
107+
QPointF *position = nullptr,
108+
bool pasteInPlace = false );
109+
110+
private:
111+
//! Property definitions
112+
static QgsPropertiesDefinition sPropertyDefinitions;
113+
114+
static bool readLabelXml( QgsLayoutItemLabel *label,
115+
const QDomElement &itemElem,
116+
const QgsReadWriteContext &context );
117+
118+
static bool readShapeXml( QgsLayoutItemShape *layoutItem,
119+
const QDomElement &itemElem );
120+
121+
122+
/**
123+
* Sets item state from DOM element
124+
* \param itemElem is DOM node corresponding to item tag
125+
* \param doc is DOM document
126+
*/
127+
static bool readOldComposerObjectXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
128+
129+
/**
130+
* Reads all pre 3.0 data defined properties from an XML element.
131+
* \since QGIS 3.0
132+
* \see readDataDefinedProperty
133+
* \see writeDataDefinedPropertyMap
134+
*/
135+
static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
136+
QgsPropertyCollection &dataDefinedProperties );
137+
138+
/**
139+
* Reads a pre 3.0 data defined property from an XML DOM element.
140+
* \since QGIS 3.0
141+
* \see readDataDefinedPropertyMap
142+
*/
143+
static QgsProperty readOldDataDefinedProperty( const DataDefinedProperty property, const QDomElement &ddElem );
144+
145+
static void initPropertyDefinitions();
146+
static QgsPropertiesDefinition propertyDefinitions();
147+
148+
//! Reads parameter that are not subclass specific in document. Usually called from readXml methods of subclasses
149+
static bool readXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
150+
151+
//! Make some common import adjustments
152+
static void adjustPos( QgsLayout *layout, QgsLayoutItem *layoutItem, QDomNode &itemNode, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );
153+
154+
};
155+
156+
#endif // QGSCOMPOSITIONCONVERTER_H

src/core/layout/qgslayout.h

+1
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
678678
friend class QgsLayoutItemGroupUndoCommand;
679679
friend class QgsLayoutModel;
680680
friend class QgsLayoutMultiFrame;
681+
friend class QgsCompositionConverter;
681682
};
682683

683684
#endif //QGSLAYOUT_H

src/core/layout/qgslayoutitem.h

+1
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
10841084
friend class TestQgsLayoutItem;
10851085
friend class TestQgsLayoutView;
10861086
friend class QgsLayoutItemGroup;
1087+
friend class QgsCompositionConverter;
10871088
};
10881089

10891090
#endif //QGSLAYOUTITEM_H

src/core/layout/qgslayoutitemlabel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem
7878
* \see currentText()
7979
* \see setText()
8080
*/
81-
QString text() { return mText; }
81+
QString text() const { return mText; }
8282

8383
/**
8484
* Sets the label's preset \a text.

src/core/layout/qgslayoutitemshape.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ QgsLayoutItemShape::QgsLayoutItemShape( QgsLayout *layout )
4545
} );
4646
}
4747

48+
QgsLayoutItemShape *QgsLayoutItemShape::create( QgsLayout *layout )
49+
{
50+
return new QgsLayoutItemShape( layout );
51+
}
52+
4853
int QgsLayoutItemShape::type() const
4954
{
5055
return QgsLayoutItemRegistry::LayoutShape;

src/core/layout/qgslayoutitemshape.h

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
4949
*/
5050
explicit QgsLayoutItemShape( QgsLayout *layout );
5151

52+
/**
53+
* Returns a new shape item for the specified \a layout.
54+
*
55+
* The caller takes responsibility for deleting the returned object.
56+
*/
57+
static QgsLayoutItemShape *create( QgsLayout *layout ) SIP_FACTORY;
58+
59+
5260
int type() const override;
5361
QIcon icon() const override;
5462

tests/src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ SET(TESTS
8383
testqgscolorscheme.cpp
8484
testqgscolorschemeregistry.cpp
8585
testqgscomposermultiframe.cpp
86+
testqgscompositionconverter.cpp
8687
testqgsconnectionpool.cpp
8788
testcontrastenhancements.cpp
8889
testqgscoordinatereferencesystem.cpp

0 commit comments

Comments
 (0)