Skip to content

Commit

Permalink
[layout] Import HTML and atlas from 2.x composition
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 9, 2018
1 parent b40a598 commit 2b2dae8
Show file tree
Hide file tree
Showing 12 changed files with 509 additions and 160 deletions.
3 changes: 0 additions & 3 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1051,12 +1051,9 @@ 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
217 changes: 169 additions & 48 deletions src/core/layout/qgscompositionconverter.cpp

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions src/core/layout/qgscompositionconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

#include "qgspropertycollection.h"

class QgsLayout;
class QgsPrintLayout;
class QgsLayoutItem;
class QgsLayoutObject;
class QgsReadWriteContext;
class QgsProperty;
class QgsPropertyCollection;
Expand All @@ -41,6 +42,7 @@ class QgsLayoutItemPolyline;
class QgsLayoutItemMap;
class QgsLayoutItemScaleBar;
class QgsLayoutItemLegend;
class QgsLayoutItemHtml;


/**
Expand Down Expand Up @@ -119,28 +121,24 @@ class CORE_EXPORT QgsCompositionConverter


/**
* \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 project the QGIS project
* \return a QgsLayout instance
* 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< QgsLayout > createLayoutFromCompositionXml( const QDomElement &parentElement,
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 layout the lay
* \param parentElement
* \param position for pasting
* \param pasteInPlace if true element position is translated to \a position
* \return a list of layout items
* \return list of layout object items that have been added to the layout
* \since QGIS 3.0
*/
static QList<QgsLayoutItem *> addItemsFromCompositionXml( QgsLayout *layout,
static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
const QDomElement &parentElement,
QPointF *position = nullptr,
bool pasteInPlace = false );
Expand Down Expand Up @@ -189,8 +187,15 @@ class CORE_EXPORT QgsCompositionConverter
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( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
static bool readOldComposerObjectXml( QgsLayoutObject *layoutItem, const QDomElement &itemElem );

static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties );
Expand All @@ -205,7 +210,7 @@ class CORE_EXPORT QgsCompositionConverter
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 );
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 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
QDomNodeList compositionNodes = composerNodes.at( i ).toElement().elementsByTagName( QStringLiteral( "Composition" ) );
for ( int j = 0; j < compositionNodes.size(); ++j )
{
std::unique_ptr< QgsLayout > l( QgsCompositionConverter::createLayoutFromCompositionXml( compositionNodes.at( j ).toElement(), mProject ) );
std::unique_ptr< QgsPrintLayout > l( QgsCompositionConverter::createLayoutFromCompositionXml( compositionNodes.at( j ).toElement(), mProject ) );
if ( l )
{
if ( l->name().isEmpty() )
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGe
static void initPropertyDefinitions();

friend class TestQgsLayoutObject;
friend class QgsCompositionConverter;
};

#endif //QGSLAYOUTOBJECT_H
Loading

0 comments on commit 2b2dae8

Please sign in to comment.