Skip to content

Commit

Permalink
[layout] connect converted to loader code
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 9, 2018
1 parent e477879 commit c232b4f
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/core/layout/qgscompositionconverter.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgsproject.h"
#include "qgsmaplayerstylemanager.h"

#include "qgslayoutpagecollection.h"
#include "qgslayoutitemregistry.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
Expand Down Expand Up @@ -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() );
Expand Down
12 changes: 12 additions & 0 deletions src/core/layout/qgslayoutmanager.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgslayoutundostack.h"
#include "qgsprintlayout.h"
#include "qgsreport.h"
#include "qgscompositionconverter.h"

QgsLayoutManager::QgsLayoutManager( QgsProject *project )
: QObject( project )
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmultirenderchecker.cpp
Expand Up @@ -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() )
Expand Down
34 changes: 1 addition & 33 deletions tests/src/core/testqgscompositionconverter.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgssettings.h"


#include "qgslayoutpagecollection.h"
#include "qgslayoutitemlabel.h"
#include "qgslayoutitemshape.h"
#include "qgslayoutitempicture.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c232b4f

Please sign in to comment.