Skip to content

Commit

Permalink
[layout] Converter: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 9, 2018
1 parent 97c005a commit da3636e
Show file tree
Hide file tree
Showing 18 changed files with 3,360 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/core/layout/qgslayoutitemlabel.sip
Expand Up @@ -61,7 +61,7 @@ Returns the required item size (in layout units) for the label's text to fill th
.. seealso:: :py:func:`adjustSizeToText()`
%End

QString text();
QString text() const;
%Docstring
Returns the label's preset text.

Expand Down
10 changes: 10 additions & 0 deletions python/core/layout/qgslayoutitemshape.sip
Expand Up @@ -34,6 +34,16 @@ class QgsLayoutItemShape : QgsLayoutItem
Constructor for QgsLayoutItemShape, with the specified parent ``layout``.
%End

static QgsLayoutItemShape *create( QgsLayout *layout ) /Factory/;
%Docstring
Returns a new shape item for the specified ``layout``.

The caller takes responsibility for deleting the returned object.

:rtype: QgsLayoutItemShape
%End


virtual int type() const;

virtual QIcon icon() const;
Expand Down
5 changes: 5 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -418,6 +418,7 @@ SET(QGIS_CORE_SRCS
layout/qgsreport.cpp
layout/qgsreportsectionfieldgroup.cpp
layout/qgsreportsectionlayout.cpp
layout/qgscompositionconverter.cpp

pal/costcalculator.cpp
pal/feature.cpp
Expand Down Expand Up @@ -1050,8 +1051,12 @@ SET(QGIS_CORE_HDRS
layout/qgslayoutsnapper.h
layout/qgslayoutundocommand.h
layout/qgslayoututils.h
<<<<<<< 2b8143a20674b8598fad5ee489def7ebd539cb5b
layout/qgsreportsectionfieldgroup.h
layout/qgsreportsectionlayout.h
=======
layout/qgscompositionconverter.h
>>>>>>> [layout] Converter: initial implementation

metadata/qgslayermetadata.h
metadata/qgslayermetadatavalidator.h
Expand Down
657 changes: 657 additions & 0 deletions src/core/layout/qgscompositionconverter.cpp

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions src/core/layout/qgscompositionconverter.h
@@ -0,0 +1,156 @@
/***************************************************************************
qgscompositionconverter.h - Convert a QGIS 2.x composition to a layout
---------------------
begin : 13.12.2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo dot com
***************************************************************************
* *
* 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 "qgspropertycollection.h"

class QgsLayout;
class QgsLayoutItem;
class QgsLayoutItemLabel;
class QgsLayoutItemShape;
class QgsReadWriteContext;
class QgsProperty;
class QgsPropertyCollection;

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
};

/**
* \brief createLayoutFromCompositionXml is a factory that creates layout instances from a
* QGIS 2.x XML composition \a document
* \param parentElement is the Composition element
* \param document
* \param context
* \return a QgsLayout instance
*/
static QgsLayout *createLayoutFromCompositionXml( const QDomElement &parentElement,
const QgsReadWriteContext &context ) SIP_FACTORY;


static QList<QgsLayoutItem *> addItemsFromCompositionXml( QgsLayout *layout,
const QDomElement &parentElement,
const QgsReadWriteContext &context,
QPointF *position = nullptr,
bool pasteInPlace = false );

private:
//! Property definitions
static QgsPropertiesDefinition sPropertyDefinitions;

static bool readLabelXml( QgsLayoutItemLabel *label,
const QDomElement &itemElem,
const QgsReadWriteContext &context );

static bool readShapeXml( QgsLayoutItemShape *layoutItem,
const QDomElement &itemElem );


/**
* Sets item state from DOM element
* \param itemElem is DOM node corresponding to item tag
* \param doc is DOM document
*/
static bool readOldComposerObjectXml( QgsLayoutItem *layoutItem, const QDomElement &itemElem );

/**
* Reads all pre 3.0 data defined properties from an XML element.
* \since QGIS 3.0
* \see readDataDefinedProperty
* \see writeDataDefinedPropertyMap
*/
static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties );

/**
* Reads a pre 3.0 data defined property from an XML DOM element.
* \since QGIS 3.0
* \see readDataDefinedPropertyMap
*/
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( QgsLayout *layout, QgsLayoutItem *layoutItem, QDomNode &itemNode, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber );

};

#endif // QGSCOMPOSITIONCONVERTER_H
1 change: 1 addition & 0 deletions src/core/layout/qgslayout.h
Expand Up @@ -678,6 +678,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
friend class QgsLayoutItemGroupUndoCommand;
friend class QgsLayoutModel;
friend class QgsLayoutMultiFrame;
friend class QgsCompositionConverter;
};

#endif //QGSLAYOUT_H
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitem.h
Expand Up @@ -1084,6 +1084,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
friend class TestQgsLayoutItem;
friend class TestQgsLayoutView;
friend class QgsLayoutItemGroup;
friend class QgsCompositionConverter;
};

#endif //QGSLAYOUTITEM_H
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemlabel.h
Expand Up @@ -78,7 +78,7 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem
* \see currentText()
* \see setText()
*/
QString text() { return mText; }
QString text() const { return mText; }

/**
* Sets the label's preset \a text.
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutitemshape.cpp
Expand Up @@ -45,6 +45,11 @@ QgsLayoutItemShape::QgsLayoutItemShape( QgsLayout *layout )
} );
}

QgsLayoutItemShape *QgsLayoutItemShape::create( QgsLayout *layout )
{
return new QgsLayoutItemShape( layout );
}

int QgsLayoutItemShape::type() const
{
return QgsLayoutItemRegistry::LayoutShape;
Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutitemshape.h
Expand Up @@ -49,6 +49,14 @@ class CORE_EXPORT QgsLayoutItemShape : public QgsLayoutItem
*/
explicit QgsLayoutItemShape( QgsLayout *layout );

/**
* Returns a new shape item for the specified \a layout.
*
* The caller takes responsibility for deleting the returned object.
*/
static QgsLayoutItemShape *create( QgsLayout *layout ) SIP_FACTORY;


int type() const override;
QIcon icon() const override;

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -83,6 +83,7 @@ SET(TESTS
testqgscolorscheme.cpp
testqgscolorschemeregistry.cpp
testqgscomposermultiframe.cpp
testqgscompositionconverter.cpp
testqgsconnectionpool.cpp
testcontrastenhancements.cpp
testqgscoordinatereferencesystem.cpp
Expand Down

0 comments on commit da3636e

Please sign in to comment.