[layout] Address PR comments and add test for layoutObjects template

This commit is contained in:
Alessandro Pasotti 2018-01-09 13:27:33 +01:00
parent 353b88a857
commit 34c80f9f55
3 changed files with 13 additions and 22 deletions

View File

@ -1206,12 +1206,8 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
layoutItem->setWrapString( itemElem.attribute( QStringLiteral( "wrapChar" ) ) );
layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral( "resizeToContents" ), QStringLiteral( "1" ) ) != QLatin1String( "0" );
layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "0" ) ).toInt();
/* TODO: atlas
mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
*/
layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
// QGIS >= 2.6
QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree" ) );
@ -1247,8 +1243,6 @@ bool QgsCompositionConverter::readAtlasXml( QgsLayoutAtlas *atlasItem, const QDo
atlasItem->setCoverageLayer( layerRef.resolveWeakly( project ) );
atlasItem->setPageNameExpression( itemElem.attribute( QStringLiteral( "pageNameExpression" ), QString() ) );
// TODO: gone?
//layoutItem->mSingleFile = itemElem.attribute( QStringLiteral( "singleFile" ), QStringLiteral( "false" ) ) == QLatin1String( "true" );
QString errorString;
atlasItem->setFilenameExpression( itemElem.attribute( QStringLiteral( "filenamePattern" ), QLatin1String( "" ) ), errorString );
// note: no error reporting for errorString
@ -1268,9 +1262,6 @@ bool QgsCompositionConverter::readAtlasXml( QgsLayoutAtlas *atlasItem, const QDo
atlasItem->setHideCoverage( itemElem.attribute( QStringLiteral( "hideCoverage" ), QStringLiteral( "false" ) ) == QLatin1String( "true" ) );
// TODO: gone?
// layoutItem->setFileFormat = atlasElem.attribute( QStringLiteral( "fileFormat" ), QStringLiteral( "png" ) );
return true;
}

View File

@ -125,7 +125,6 @@ class CORE_EXPORT QgsCompositionConverter
* 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<QgsPrintLayout> createLayoutFromCompositionXml( const QDomElement &composerElement,
QgsProject *project );
@ -134,10 +133,11 @@ class CORE_EXPORT QgsCompositionConverter
/**
* 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 where the items will be added
* \param parentElement parent DOM element
* \param position for pasting
* \param pasteInPlace if true element position is translated to \a position
* \return list of layout object items that have been added to the layout
* \since QGIS 3.0
*/
static QList<QgsLayoutObject *> addItemsFromCompositionXml( QgsPrintLayout *layout,
const QDomElement &parentElement,

View File

@ -225,6 +225,7 @@ void TestQgsCompositionConverter::importComposerTemplateShape()
QCOMPARE( shape->pos().y(), 83.1791 );
QCOMPARE( shape->sizeWithUnits().width(), 12.0988 );
QCOMPARE( shape->sizeWithUnits().height(), 33.2716 );
QCOMPARE( shape->sizeWithUnits().units(), QgsUnitTypes::LayoutUnit::LayoutMillimeters );
QCOMPARE( shape->referencePoint(), QgsLayoutItem::ReferencePoint::MiddleRight );
QCOMPARE( shape->frameStrokeColor(), QColor( 0, 0, 0, 255 ) );
QCOMPARE( shape->frameStrokeWidth().length(), 0.3 );
@ -457,11 +458,11 @@ void TestQgsCompositionConverter::importComposerTemplateAttributeTable()
QVERIFY( layout.get() );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
QList<QgsLayoutMultiFrame *> items = layout->multiFrames();
// Check the table
QList<QgsLayoutItemAttributeTable *> items;
layout->layoutObjects<QgsLayoutItemAttributeTable>( items );
QVERIFY( items.size() > 0 );
// Check the HTML
const QgsLayoutItemAttributeTable *table = qobject_cast<QgsLayoutItemAttributeTable * >( items.at( 0 ) );
const QgsLayoutItemAttributeTable *table = items.at( 0 );
QVERIFY( table );
QVERIFY( table->sourceLayer() );
QVERIFY( table->sourceLayer()->isValid() );
@ -481,11 +482,11 @@ void TestQgsCompositionConverter::importComposerTemplateHtml()
QVERIFY( layout.get() );
QCOMPARE( layout->pageCollection()->pageCount(), 7 );
QList<QgsLayoutMultiFrame *> items = layout->multiFrames();
QVERIFY( items.size() > 0 );
// Check the HTML
const QgsLayoutItemHtml *html = qobject_cast<QgsLayoutItemHtml * >( items.at( 0 ) );
QList<QgsLayoutItemHtml *> items;
layout->layoutObjects<QgsLayoutItemHtml>( items );
QVERIFY( items.size() > 0 );
const QgsLayoutItemHtml *html = items.at( 0 );
QVERIFY( html );
QCOMPARE( html->contentMode(), QgsLayoutItemHtml::ContentMode::ManualHtml );
QCOMPARE( html->html(), QStringLiteral( "<div style=\"height:5000px; background-color:green; color:white;\">aaaaA</div>\t\n" ) );
@ -609,7 +610,6 @@ void TestQgsCompositionConverter::importComposerTemplate()
// We have at least one item linked to a map for this test
QVERIFY( count > 0 );
}
// TODO: attr table (not yet imported)
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 1 );
@ -642,7 +642,7 @@ void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const Q
QSize size( layout->pageCollection()->page( pageNumber )->sizeWithUnits().width() * 3.77, layout->pageCollection()->page( pageNumber )->sizeWithUnits().height() * 3.77 );
checker.setSize( size );
checker.setControlPathPrefix( QStringLiteral( "compositionconverter" ) );
QVERIFY( checker.testLayout( mReport, pageNumber ) );
QVERIFY( checker.testLayout( mReport, pageNumber, 0, true ) );
}