Skip to content

Commit 34c80f9

Browse files
committedJan 9, 2018
[layout] Address PR comments and add test for layoutObjects template
1 parent 353b88a commit 34c80f9

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed
 

‎src/core/layout/qgscompositionconverter.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,12 +1206,8 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
12061206
layoutItem->setWrapString( itemElem.attribute( QStringLiteral( "wrapChar" ) ) );
12071207

12081208
layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral( "resizeToContents" ), QStringLiteral( "1" ) ) != QLatin1String( "0" );
1209-
12101209
layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "0" ) ).toInt();
1211-
1212-
/* TODO: atlas
1213-
mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
1214-
*/
1210+
layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
12151211

12161212
// QGIS >= 2.6
12171213
QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree" ) );
@@ -1247,8 +1243,6 @@ bool QgsCompositionConverter::readAtlasXml( QgsLayoutAtlas *atlasItem, const QDo
12471243
atlasItem->setCoverageLayer( layerRef.resolveWeakly( project ) );
12481244

12491245
atlasItem->setPageNameExpression( itemElem.attribute( QStringLiteral( "pageNameExpression" ), QString() ) );
1250-
// TODO: gone?
1251-
//layoutItem->mSingleFile = itemElem.attribute( QStringLiteral( "singleFile" ), QStringLiteral( "false" ) ) == QLatin1String( "true" );
12521246
QString errorString;
12531247
atlasItem->setFilenameExpression( itemElem.attribute( QStringLiteral( "filenamePattern" ), QLatin1String( "" ) ), errorString );
12541248
// note: no error reporting for errorString
@@ -1268,9 +1262,6 @@ bool QgsCompositionConverter::readAtlasXml( QgsLayoutAtlas *atlasItem, const QDo
12681262

12691263
atlasItem->setHideCoverage( itemElem.attribute( QStringLiteral( "hideCoverage" ), QStringLiteral( "false" ) ) == QLatin1String( "true" ) );
12701264

1271-
// TODO: gone?
1272-
// layoutItem->setFileFormat = atlasElem.attribute( QStringLiteral( "fileFormat" ), QStringLiteral( "png" ) );
1273-
12741265
return true;
12751266

12761267
}

‎src/core/layout/qgscompositionconverter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ class CORE_EXPORT QgsCompositionConverter
125125
* createLayoutFromCompositionXml is a factory that creates layout instances from a
126126
* QGIS 2.x XML composition \a parentElement and a QGIS \a project
127127
* \return a QgsPrintLayout instance
128-
* \since QGIS 3.0
129128
*/
130129
static std::unique_ptr<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
131130
QgsProject *project );
@@ -134,10 +133,11 @@ class CORE_EXPORT QgsCompositionConverter
134133
/**
135134
* addItemsFromCompositionXml parse a QGIS 2.x composition XML in the \a parentElement,
136135
* converts the 2.x items to the new layout elements and add them to the \a layout
136+
* \param layout where the items will be added
137+
* \param parentElement parent DOM element
137138
* \param position for pasting
138139
* \param pasteInPlace if true element position is translated to \a position
139140
* \return list of layout object items that have been added to the layout
140-
* \since QGIS 3.0
141141
*/
142142
static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
143143
const QDomElement &parentElement,

‎tests/src/core/testqgscompositionconverter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void TestQgsCompositionConverter::importComposerTemplateShape()
225225
QCOMPARE( shape->pos().y(), 83.1791 );
226226
QCOMPARE( shape->sizeWithUnits().width(), 12.0988 );
227227
QCOMPARE( shape->sizeWithUnits().height(), 33.2716 );
228+
QCOMPARE( shape->sizeWithUnits().units(), QgsUnitTypes::LayoutUnit::LayoutMillimeters );
228229
QCOMPARE( shape->referencePoint(), QgsLayoutItem::ReferencePoint::MiddleRight );
229230
QCOMPARE( shape->frameStrokeColor(), QColor( 0, 0, 0, 255 ) );
230231
QCOMPARE( shape->frameStrokeWidth().length(), 0.3 );
@@ -457,11 +458,11 @@ void TestQgsCompositionConverter::importComposerTemplateAttributeTable()
457458
QVERIFY( layout.get() );
458459
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
459460

460-
QList<QgsLayoutMultiFrame *> items = layout->multiFrames();
461+
// Check the table
462+
QList<QgsLayoutItemAttributeTable *> items;
463+
layout->layoutObjects<QgsLayoutItemAttributeTable>( items );
461464
QVERIFY( items.size() > 0 );
462-
463-
// Check the HTML
464-
const QgsLayoutItemAttributeTable *table = qobject_cast<QgsLayoutItemAttributeTable * >( items.at( 0 ) );
465+
const QgsLayoutItemAttributeTable *table = items.at( 0 );
465466
QVERIFY( table );
466467
QVERIFY( table->sourceLayer() );
467468
QVERIFY( table->sourceLayer()->isValid() );
@@ -481,11 +482,11 @@ void TestQgsCompositionConverter::importComposerTemplateHtml()
481482
QVERIFY( layout.get() );
482483
QCOMPARE( layout->pageCollection()->pageCount(), 7 );
483484

484-
QList<QgsLayoutMultiFrame *> items = layout->multiFrames();
485-
QVERIFY( items.size() > 0 );
486-
487485
// Check the HTML
488-
const QgsLayoutItemHtml *html = qobject_cast<QgsLayoutItemHtml * >( items.at( 0 ) );
486+
QList<QgsLayoutItemHtml *> items;
487+
layout->layoutObjects<QgsLayoutItemHtml>( items );
488+
QVERIFY( items.size() > 0 );
489+
const QgsLayoutItemHtml *html = items.at( 0 );
489490
QVERIFY( html );
490491
QCOMPARE( html->contentMode(), QgsLayoutItemHtml::ContentMode::ManualHtml );
491492
QCOMPARE( html->html(), QStringLiteral( "<div style=\"height:5000px; background-color:green; color:white;\">aaaaA</div>\t\n" ) );
@@ -609,7 +610,6 @@ void TestQgsCompositionConverter::importComposerTemplate()
609610
// We have at least one item linked to a map for this test
610611
QVERIFY( count > 0 );
611612
}
612-
// TODO: attr table (not yet imported)
613613

614614
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
615615
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 1 );
@@ -642,7 +642,7 @@ void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const Q
642642
QSize size( layout->pageCollection()->page( pageNumber )->sizeWithUnits().width() * 3.77, layout->pageCollection()->page( pageNumber )->sizeWithUnits().height() * 3.77 );
643643
checker.setSize( size );
644644
checker.setControlPathPrefix( QStringLiteral( "compositionconverter" ) );
645-
QVERIFY( checker.testLayout( mReport, pageNumber ) );
645+
QVERIFY( checker.testLayout( mReport, pageNumber, 0, true ) );
646646
}
647647

648648

0 commit comments

Comments
 (0)
Please sign in to comment.