Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[layout] Fix title from name when converting a composition
- Loading branch information
|
@@ -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" ) ); |
|
|