|
| 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 |
0 commit comments