Skip to content
Permalink
Browse files

[layout] connect converted to loader code

  • Loading branch information
elpaso committed Dec 19, 2017
1 parent e477879 commit c232b4fe9c7cb37b3b6b6ad0f896ceda30daa5bd
@@ -30,6 +30,7 @@
#include "qgsproject.h"
#include "qgsmaplayerstylemanager.h"

#include "qgslayoutpagecollection.h"
#include "qgslayoutitemregistry.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
@@ -860,6 +861,7 @@ bool QgsCompositionConverter::readMapXml( QgsLayoutItemMap *layoutItem, const QD

bool QgsCompositionConverter::readScaleBarXml( QgsLayoutItemScaleBar *layoutItem, const QDomElement &itemElem, const QgsProject *project )
{
Q_UNUSED( project );
restoreGeneralComposeItemProperties( layoutItem, itemElem );

layoutItem->setHeight( itemElem.attribute( QStringLiteral( "height" ), QStringLiteral( "5.0" ) ).toDouble() );
@@ -20,6 +20,7 @@
#include "qgslayoutundostack.h"
#include "qgsprintlayout.h"
#include "qgsreport.h"
#include "qgscompositionconverter.h"

QgsLayoutManager::QgsLayoutManager( QgsProject *project )
: QObject( project )
@@ -188,6 +189,17 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
QDomNodeList composerNodes = element.elementsByTagName( QStringLiteral( "Composer" ) );
for ( int i = 0; i < composerNodes.size(); ++i )
{
// Convert compositions to layouts
QDomNodeList compositionNodes = composerNodes.at( i ).toElement().elementsByTagName( QStringLiteral( "Composition" ) );
for ( int j = 0; j < compositionNodes.size(); ++j )
{
QgsLayout *l = nullptr;
l = QgsCompositionConverter::createLayoutFromCompositionXml( compositionNodes.at( j ).toElement(), mProject );
if ( l )
addLayout( l );
}

// legacy import
QString legacyTitle = composerNodes.at( i ).toElement().attribute( QStringLiteral( "title" ) );
QgsComposition *c = createCompositionFromXml( composerNodes.at( i ).toElement(), doc );
if ( !c )
@@ -207,7 +207,8 @@ bool QgsLayoutChecker::testLayout( QString &checkedReport, int page, int pixelDi
_outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
_outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
QPainter _p( &_outputImage );
mLayout->exporter().renderPage( &_p, page );
QgsLayoutExporter _exporter( mLayout );
_exporter.renderPage( &_p, page );
_p.end();

if ( ! QDir( controlImagePath() ).exists() )
@@ -27,6 +27,7 @@
#include "qgssettings.h"


#include "qgslayoutpagecollection.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempicture.h"
@@ -100,11 +101,8 @@ class TestQgsCompositionConverter: public QObject

private:


void checkRenderedImage( QgsLayout *layout, const QString testName, const int pageNumber = 0 );

void exportLayout( QgsLayout *layout, const QString testName );

QDomElement loadComposition( const QString name );

QString mReport;
@@ -405,36 +403,6 @@ void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const Q
QVERIFY( checker.testLayout( mReport, pageNumber ) );
}

void TestQgsCompositionConverter::exportLayout( QgsLayout *layout, const QString testName )
{
// Save the template for inspection
QTemporaryFile tmpTemplate( QString( "%1_converted-XXXXXX.qpt" ).arg( testName ) );
tmpTemplate.setAutoRemove( false );
tmpTemplate.open();
tmpTemplate.close();
QgsReadWriteContext context;
layout->saveAsTemplate( tmpTemplate.fileName(), context );
qDebug() << tmpTemplate.fileName();

for ( int i = 0; i < layout->pageCollection()->pageCount(); ++i )
{
QgsLayoutItemPage *page = layout->pageCollection()->pages().at( i );
QSize size;
QgsLayoutSize pageSize = page->sizeWithUnits();
size.setHeight( pageSize.height() * 3.77 );
size.setWidth( pageSize.width() * 3.77 );

QImage outputImage( size, QImage::Format_RGB32 );
outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
QPainter p( &outputImage );
layout->exporter().renderPage( &p, i );
p.end();

QString renderedFilePath = tmpTemplate.fileName() + QString( "_%1_.png" ).arg( i );
outputImage.save( renderedFilePath, "PNG" );
}
}

QDomElement TestQgsCompositionConverter::loadComposition( const QString name )
{
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit c232b4f

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