diff --git a/src/core/layout/qgscompositionconverter.cpp b/src/core/layout/qgscompositionconverter.cpp index f216abad109..74935cd46c4 100644 --- a/src/core/layout/qgscompositionconverter.cpp +++ b/src/core/layout/qgscompositionconverter.cpp @@ -50,6 +50,7 @@ #include "qgslayouttablecolumn.h" #include "qgslayoutmultiframe.h" #include "qgslayoutframe.h" +#include "qgslayoutguidecollection.h" QgsPropertiesDefinition QgsCompositionConverter::sPropertyDefinitions; @@ -122,6 +123,9 @@ std::unique_ptr< QgsPrintLayout > QgsCompositionConverter::createLayoutFromCompo std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( project ); + // Guides + layout->guides().setVisible( composerElement.attribute( QStringLiteral( "guidesVisible" ), QStringLiteral( "1" ) ).toInt() != 0 ); + // Create pages int pages = composerElement.attribute( QStringLiteral( "numPages" ) ).toInt( ); float paperHeight = composerElement.attribute( QStringLiteral( "paperHeight" ) ).toDouble( ); @@ -152,6 +156,20 @@ std::unique_ptr< QgsPrintLayout > QgsCompositionConverter::createLayoutFromCompo QgsLayoutItemPage *page = QgsLayoutItemPage::create( layout.get() ); page->setPageSize( pageSize ); layout->pageCollection()->addPage( page ); + //custom snap lines + QDomNodeList snapLineNodes = composerElement.elementsByTagName( QStringLiteral( "SnapLine" ) ); + for ( int i = 0; i < snapLineNodes.size(); ++i ) + { + QDomElement snapLineElem = snapLineNodes.at( i ).toElement(); + double x1 = snapLineElem.attribute( QStringLiteral( "x1" ) ).toDouble(); + double y1 = snapLineElem.attribute( QStringLiteral( "y1" ) ).toDouble(); + double x2 = snapLineElem.attribute( QStringLiteral( "x2" ) ).toDouble(); + // Not necessary: double y2 = snapLineElem.attribute( QStringLiteral( "y2" ) ).toDouble(); + Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal ); + QgsLayoutMeasurement position( x1 == x2 ? x1 : y1 ); + std::unique_ptr< QgsLayoutGuide > guide = qgis::make_unique< QgsLayoutGuide >( orientation, position, page ); + layout->guides().addGuide( guide.release() ); + } } addItemsFromCompositionXml( layout.get(), composerElement ); diff --git a/tests/src/core/testqgscompositionconverter.cpp b/tests/src/core/testqgscompositionconverter.cpp index 59b715fe9f2..7528d59ef5f 100644 --- a/tests/src/core/testqgscompositionconverter.cpp +++ b/tests/src/core/testqgscompositionconverter.cpp @@ -535,6 +535,9 @@ void TestQgsCompositionConverter::convertComposerTemplate() QCOMPARE( layout->pageCollection()->pageCount(), 2 ); QCOMPARE( layout->name(), QStringLiteral( "composer title" ) ); + // Check guides + QCOMPARE( layout->guides().rowCount( QModelIndex() ), 8 ); + } void TestQgsCompositionConverter::importComposerTemplate() diff --git a/tests/testdata/layouts/sample_project.qgs b/tests/testdata/layouts/sample_project.qgs index 743376b89c8..8c37aa23e44 100644 --- a/tests/testdata/layouts/sample_project.qgs +++ b/tests/testdata/layouts/sample_project.qgs @@ -65,7 +65,7 @@ - + @@ -82,6 +82,10 @@ + + + + @@ -436,7 +440,7 @@ - + @@ -505,13 +509,30 @@ - + + + + + + + + + + + + + + + + + + @@ -562,23 +583,6 @@ - - - - - - - - - - - - - - - - - @@ -602,7 +606,7 @@ - + @@ -612,8 +616,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - +