Skip to content
Permalink
Browse files

[layout] Fix title from name when converting a composition

  • Loading branch information
elpaso committed Jan 3, 2018
1 parent 858a71f commit b40a5986f63fbc7e1ce1a052d1009f2aeb349fda
Showing with 30 additions and 3 deletions.
  1. +8 −3 src/core/layout/qgslayoutmanager.cpp
  2. +22 −0 tests/src/core/testqgscompositionconverter.cpp
@@ -189,17 +189,22 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
QDomNodeList composerNodes = element.elementsByTagName( QStringLiteral( "Composer" ) );
for ( int i = 0; i < composerNodes.size(); ++i )
{
// This legacy title is the Composer "title" (that can be overridden by the Composition "name")
QString legacyTitle = composerNodes.at( i ).toElement().attribute( QStringLiteral( "title" ) );
// Convert compositions to layouts
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 ) );
if ( l )
addLayout( l.release() );
{
if ( l->name().isEmpty() )
l->setName( legacyTitle );
result = result && addLayout( l.release() );
}
}

// legacy import
QString legacyTitle = composerNodes.at( i ).toElement().attribute( QStringLiteral( "title" ) );
// legacy import (to be removed!)
QgsComposition *c = createCompositionFromXml( composerNodes.at( i ).toElement(), doc );
if ( !c )
{
@@ -29,6 +29,7 @@
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"

#include "qgslayoutmanager.h"
#include "qgslayoutpagecollection.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
@@ -103,6 +104,12 @@ class TestQgsCompositionConverter: public QObject
*/
void importComposerTemplate();

/**
* Test automatic conversion from a composer template
*/
void convertComposerTemplate();


private:

void checkRenderedImage( QgsLayout *layout, const QString testName, const int pageNumber = 0 );
@@ -441,6 +448,21 @@ void TestQgsCompositionConverter::importComposerTemplateScaleBar()

}


void TestQgsCompositionConverter::convertComposerTemplate()
{

QgsProject project;
project.read( QStringLiteral( TEST_DATA_DIR ) + "/layouts/sample_project.qgs" );

QgsLayout *layout = project.layoutManager()->layouts().first();

QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 2 );
QCOMPARE( layout->name(), QStringLiteral( "composer title" ) );

}

void TestQgsCompositionConverter::importComposerTemplate()
{
QDomElement docElem( loadComposition( "2x_template.qpt" ) );

0 comments on commit b40a598

Please sign in to comment.
You can’t perform that action at this time.