[layouts] Removed diff images and adapted tests

to use QGIS font

Also addressed comments in the PR
This commit is contained in:
Alessandro Pasotti 2017-12-20 16:06:45 +01:00
parent 943025c204
commit a5fc57078c
11 changed files with 184 additions and 166 deletions

View File

@ -105,20 +105,21 @@ QgsPropertiesDefinition QgsCompositionConverter::propertyDefinitions()
}
QgsLayout *QgsCompositionConverter::createLayoutFromCompositionXml( const QDomElement &parentElement, QgsProject *project )
std::unique_ptr< QgsLayout > QgsCompositionConverter::createLayoutFromCompositionXml( const QDomElement &parentElement, QgsProject *project )
{
initPropertyDefinitions();
QgsLayout *layout = new QgsLayout( project );
std::unique_ptr< QgsLayout > layout = qgis::make_unique< QgsLayout >( project );
// Create pages
int pages = parentElement.attribute( QStringLiteral( "numPages" ) ).toInt( );
float paperHeight = parentElement.attribute( QStringLiteral( "paperHeight" ) ).toFloat( );
float paperWidth = parentElement.attribute( QStringLiteral( "paperWidth" ) ).toFloat( );
float paperHeight = parentElement.attribute( QStringLiteral( "paperHeight" ) ).toDouble( );
float paperWidth = parentElement.attribute( QStringLiteral( "paperWidth" ) ).toDouble( );
if ( parentElement.elementsByTagName( QStringLiteral( "symbol" ) ).size() )
{
QDomElement symbolElement = parentElement.elementsByTagName( QStringLiteral( "symbol" ) ).at( 0 ).toElement();
QgsReadWriteContext context;
context.setPathResolver( project->pathResolver() );
if ( project )
context.setPathResolver( project->pathResolver() );
QgsFillSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context );
if ( symbol )
layout->pageCollection()->setPageStyleSymbol( symbol );
@ -126,26 +127,25 @@ QgsLayout *QgsCompositionConverter::createLayoutFromCompositionXml( const QDomEl
QString name = parentElement.attribute( QStringLiteral( "name" ) );
layout->setName( name );
// TODO: check that it is always landscape
QgsLayoutSize pageSize( paperWidth, paperHeight );
for ( int j = 0; j < pages; j++ )
{
QgsLayoutItemPage *page = QgsLayoutItemPage::create( layout );
QgsLayoutItemPage *page = QgsLayoutItemPage::create( layout.get() );
page->setPageSize( pageSize );
layout->pageCollection()->addPage( page );
}
addItemsFromCompositionXml( layout, parentElement );
addItemsFromCompositionXml( layout.get(), parentElement );
return layout;
}
void QgsCompositionConverter::adjustPos( QgsLayout *layout, QgsLayoutItem *layoutItem, QDomNode &itemNode, QPointF *position, bool &pasteInPlace, int zOrderOffset, QPointF &pasteShiftPos, int &pageNumber )
{
Q_UNUSED( itemNode );
if ( position )
{
if ( pasteInPlace )
{
QgsLayoutPoint posOnPage = QgsLayoutPoint::decodePoint( itemNode.toElement().attribute( QStringLiteral( "positionOnPage" ) ) );
layoutItem->attemptMove( posOnPage, true, false, pageNumber );
layoutItem->attemptMove( QgsLayoutPoint( *position ), true, false, pageNumber );
}
else
{
@ -171,12 +171,79 @@ void QgsCompositionConverter::restoreGeneralComposeItemProperties( QgsLayoutItem
//check for old (pre 2.1) rotation attribute
layoutItem->setItemRotation( composerItemElem.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble(), false );
}
QgsCompositionConverter::readXml( layoutItem, composerItemElem );
}
}
// Frame color
QRectF QgsCompositionConverter::itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem )
{
int page;
double x, y, pagex, pagey, width, height;
bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
// Background color
x = itemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk );
y = itemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk );
page = itemElem.attribute( QStringLiteral( "page" ) ).toInt( &pageOk );
pagex = itemElem.attribute( QStringLiteral( "pagex" ) ).toDouble( &pagexOk );
pagey = itemElem.attribute( QStringLiteral( "pagey" ) ).toDouble( &pageyOk );
width = itemElem.attribute( QStringLiteral( "width" ) ).toDouble( &widthOk );
height = itemElem.attribute( QStringLiteral( "height" ) ).toDouble( &heightOk );
layoutItem->mReferencePoint = static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral( "positionMode" ) ).toInt( &positionModeOk ) );
if ( !positionModeOk )
{
layoutItem->setReferencePoint( QgsLayoutItem::ReferencePoint::UpperLeft );
}
if ( pageOk && pagexOk && pageyOk )
{
xOk = true;
yOk = true;
x = pagex;
// position in the page (1-based)
if ( page <= layoutItem->layout()->pageCollection()->pageCount() )
{
QgsLayoutItemPage *pageObject = layoutItem->layout()->pageCollection()->pages().at( page - 1 );
y = ( page - 1 )
* ( pageObject->sizeWithUnits().height()
+ layoutItem->layout()->pageCollection()->spaceBetweenPages() )
+ pagey;
}
else
{
y = pagey;
}
}
return QRectF( x, y, width, height );
}
QPointF QgsCompositionConverter::minPointFromXml( const QDomElement &elem )
{
double minX = std::numeric_limits<double>::max();
double minY = std::numeric_limits<double>::max();
QDomNodeList composerItemList = elem.elementsByTagName( QStringLiteral( "ComposerItem" ) );
for ( int i = 0; i < composerItemList.size(); ++i )
{
QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
double x, y;
bool xOk, yOk;
x = currentComposerItemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk );
y = currentComposerItemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk );
if ( !xOk || !yOk )
{
continue;
}
minX = std::min( minX, x );
minY = std::min( minY, y );
}
if ( minX < std::numeric_limits<double>::max() )
{
return QPointF( minX, minY );
}
else
{
return QPointF( 0, 0 );
}
}
@ -200,8 +267,7 @@ QList<QgsLayoutItem *> QgsCompositionConverter::addItemsFromCompositionXml( QgsL
//If we are placing items relative to a certain point, then calculate how much we need
//to shift the items by so that they are placed at this point
//First, calculate the minimum position from the xml
// TODO: check this!
QPointF minItemPos = layout->minPointFromXml( parentElement );
QPointF minItemPos = minPointFromXml( parentElement );
//next, calculate how much each item needs to be shifted from its original position
//so that it's placed at the correct relative position
pasteShiftPos = *position - minItemPos;
@ -383,7 +449,8 @@ bool QgsCompositionConverter::readShapeXml( QgsLayoutItemShape *layoutItem, cons
restoreGeneralComposeItemProperties( layoutItem, itemElem );
QgsReadWriteContext context;
context.setPathResolver( project->pathResolver() );
if ( project )
context.setPathResolver( project->pathResolver() );
if ( itemElem.elementsByTagName( QStringLiteral( "symbol" ) ).size() )
{
@ -391,12 +458,7 @@ bool QgsCompositionConverter::readShapeXml( QgsLayoutItemShape *layoutItem, cons
QgsFillSymbol *shapeStyleSymbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context );
if ( shapeStyleSymbol )
layoutItem->setSymbol( shapeStyleSymbol );
} /*
QDomElement shapeStyleSymbolElem = itemElem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !shapeStyleSymbolElem.isNull() )
{
layoutItem->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( shapeStyleSymbolElem, context ) );
} */
}
else
{
//upgrade project file from 2.0 to use symbol styling
@ -431,10 +493,10 @@ bool QgsCompositionConverter::readShapeXml( QgsLayoutItemShape *layoutItem, cons
double penWidth;
penWidth = itemElem.attribute( QStringLiteral( "outlineWidth" ) ).toDouble( &widthOk );
penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
penRed = frameColorElem.attribute( QStringLiteral( "red" ) ).toInt( &redOk );
penGreen = frameColorElem.attribute( QStringLiteral( "green" ) ).toInt( &greenOk );
penBlue = frameColorElem.attribute( QStringLiteral( "blue" ) ).toInt( &blueOk );
penAlpha = frameColorElem.attribute( QStringLiteral( "alpha" ) ).toInt( &alphaOk );
if ( redOk && greenOk && blueOk && alphaOk && widthOk )
{
@ -449,10 +511,10 @@ bool QgsCompositionConverter::readShapeXml( QgsLayoutItemShape *layoutItem, cons
bool redOk, greenOk, blueOk, alphaOk;
int fillRed, fillGreen, fillBlue, fillAlpha;
fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toDouble( &redOk );
fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toDouble( &greenOk );
fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toDouble( &blueOk );
fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toDouble( &alphaOk );
fillRed = fillColorElem.attribute( QStringLiteral( "red" ) ).toInt( &redOk );
fillGreen = fillColorElem.attribute( QStringLiteral( "green" ) ).toInt( &greenOk );
fillBlue = fillColorElem.attribute( QStringLiteral( "blue" ) ).toInt( &blueOk );
fillAlpha = fillColorElem.attribute( QStringLiteral( "alpha" ) ).toInt( &alphaOk );
if ( redOk && greenOk && blueOk && alphaOk )
{
@ -632,7 +694,9 @@ bool QgsCompositionConverter::readMapXml( QgsLayoutItemMap *layoutItem, const QD
*/
QgsReadWriteContext context;
context.setPathResolver( project->pathResolver() );
if ( project )
context.setPathResolver( project->pathResolver() );
//extent
QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral( "Extent" ) );
@ -812,29 +876,6 @@ bool QgsCompositionConverter::readMapXml( QgsLayoutItemMap *layoutItem, const QD
layoutItem->mGridStack->addGrid( mapGrid );
}
/* TODO: skip?
//load overview in old xml format
QDomElement overviewFrameElem = itemElem.firstChildElement( QStringLiteral( "overviewFrame" ) );
if ( !overviewFrameElem.isNull() )
{
QgsComposerMapOverview *mapOverview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( mOverviewStack->size() + 1 ), this );
mapOverview->setFrameMap( overviewFrameElem.attribute( QStringLiteral( "overviewFrameMap" ), QStringLiteral( "-1" ) ).toInt() );
mapOverview->setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( overviewFrameElem.attribute( QStringLiteral( "overviewBlendMode" ), QStringLiteral( "0" ) ).toUInt() ) ) );
mapOverview->setInverted( overviewFrameElem.attribute( QStringLiteral( "overviewInverted" ) ).compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 );
mapOverview->setCentered( overviewFrameElem.attribute( QStringLiteral( "overviewCentered" ) ).compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 );
QgsFillSymbol *fillSymbol = nullptr;
QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( QStringLiteral( "symbol" ) );
if ( !overviewFrameSymbolElem.isNull() )
{
fillSymbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( overviewFrameSymbolElem, context );
mapOverview->setFrameSymbol( fillSymbol );
}
mOverviewStack->addOverview( mapOverview );
}
*/
//atlas TODO:
/*
QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral( "AtlasMap" ) );
@ -1208,49 +1249,8 @@ bool QgsCompositionConverter::readXml( QgsLayoutItem *layoutItem, const QDomElem
}
layoutItem->mTemplateUuid = itemElem.attribute( "templateUuid" );
int page;
double x, y, pagex, pagey, width, height;
bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;
x = itemElem.attribute( QStringLiteral( "x" ) ).toDouble( &xOk );
y = itemElem.attribute( QStringLiteral( "y" ) ).toDouble( &yOk );
page = itemElem.attribute( QStringLiteral( "page" ) ).toInt( &pageOk );
pagex = itemElem.attribute( QStringLiteral( "pagex" ) ).toDouble( &pagexOk );
pagey = itemElem.attribute( QStringLiteral( "pagey" ) ).toDouble( &pageyOk );
width = itemElem.attribute( QStringLiteral( "width" ) ).toDouble( &widthOk );
height = itemElem.attribute( QStringLiteral( "height" ) ).toDouble( &heightOk );
layoutItem->mReferencePoint = static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral( "positionMode" ) ).toInt( &positionModeOK ) );
if ( !positionModeOK )
{
layoutItem->setReferencePoint( QgsLayoutItem::ReferencePoint::UpperLeft );
}
if ( pageOk && pagexOk && pageyOk )
{
xOk = true;
yOk = true;
x = pagex;
// position in the page (1-based)
if ( page <= layoutItem->layout()->pageCollection()->pageCount() )
{
QgsLayoutItemPage *pageObject = layoutItem->layout()->pageCollection()->pages().at( page - 1 );
y = ( page - 1 )
* ( pageObject->sizeWithUnits().height()
+ layoutItem->layout()->pageCollection()->spaceBetweenPages() )
+ pagey;
}
else
{
y = pagey;
}
}
if ( !xOk || !yOk || !widthOk || !heightOk )
{
return false;
}
QRectF position = itemPosition( layoutItem, itemElem );
// TODO: missing?
// mLastValidViewScaleFactor = itemElem.attribute( QStringLiteral( "lastValidViewScaleFactor" ), QStringLiteral( "-1" ) ).toDouble();
@ -1323,7 +1323,7 @@ bool QgsCompositionConverter::readXml( QgsLayoutItem *layoutItem, const QDomElem
layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
// positioning
layoutItem->attemptSetSceneRect( QRectF( x, y, width, height ) );
layoutItem->attemptSetSceneRect( position );
//rotation
layoutItem->setItemRotation( itemElem.attribute( QStringLiteral( "itemRotation" ), QStringLiteral( "0" ) ).toDouble(), false );

View File

@ -125,9 +125,8 @@ class CORE_EXPORT QgsCompositionConverter
* \param project the QGIS project
* \return a QgsLayout instance
* \since QGIS 3.0
* \note Not available in Python bindings.
*/
static QgsLayout *createLayoutFromCompositionXml( const QDomElement &parentElement,
static std::unique_ptr< QgsLayout > createLayoutFromCompositionXml( const QDomElement &parentElement,
QgsProject *project );
@ -140,7 +139,6 @@ class CORE_EXPORT QgsCompositionConverter
* \param pasteInPlace if true element position is translated to \a position
* \return a list of layout items
* \since QGIS 3.0
* \note Not available in Python bindings.
*/
static QList<QgsLayoutItem *> addItemsFromCompositionXml( QgsLayout *layout,
const QDomElement &parentElement,
@ -207,6 +205,12 @@ class CORE_EXPORT QgsCompositionConverter
//! Restore general composer item properties
static void restoreGeneralComposeItemProperties( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
//! Get item position
static QRectF itemPosition( QgsLayoutItem *layoutItem, const QDomElement &itemElem );
//! Calculates the item minimum position from an xml string
static QPointF minPointFromXml( const QDomElement &elem );
};
#endif // QGSCOMPOSITIONCONVERTER_H

View File

@ -193,10 +193,9 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
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 );
std::unique_ptr< QgsLayout > l( QgsCompositionConverter::createLayoutFromCompositionXml( compositionNodes.at( j ).toElement(), mProject ) );
if ( l )
addLayout( l );
addLayout( l.release() );
}
// legacy import

View File

@ -142,9 +142,8 @@ void TestQgsCompositionConverter::cleanup()
void TestQgsCompositionConverter::importComposerTemplateLabel()
{
QDomElement docElem( loadComposition( "2x_template_label.qpt" ) );
QgsReadWriteContext context;
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -153,22 +152,20 @@ void TestQgsCompositionConverter::importComposerTemplateLabel()
layout->layoutItems<QgsLayoutItemLabel>( items );
QVERIFY( items.size() > 0 );
//exportLayout( layout, QTest::currentTestFunction() );
// Check the label
const QgsLayoutItemLabel *label = items.at( 0 );
QVERIFY( label );
QCOMPARE( label->text(), QStringLiteral( "QGIS" ) );
QCOMPARE( label->pos().x(), 55.5333 );
QCOMPARE( label->pos().y(), 35.3929 );
QCOMPARE( label->sizeWithUnits().width(), 10.875 );
QCOMPARE( label->sizeWithUnits().height(), 6.0 );
QCOMPARE( label->referencePoint(), QgsLayoutItem::ReferencePoint::LowerRight );
QCOMPARE( label->sizeWithUnits().width(), 15.3686 );
QCOMPARE( label->sizeWithUnits().height(), 7.93747 );
QCOMPARE( label->referencePoint(), QgsLayoutItem::ReferencePoint::UpperRight );
QCOMPARE( label->frameStrokeColor(), QColor( 251, 0, 0, 255 ) );
QCOMPARE( label->frameStrokeWidth().length(), 0.2 );
QCOMPARE( ( int )label->rotation(), 4 );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
}
@ -178,7 +175,7 @@ void TestQgsCompositionConverter::importComposerTemplateShape()
QDomElement docElem( loadComposition( "2x_template_shape.qpt" ) );
QgsReadWriteContext context;
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -187,8 +184,6 @@ void TestQgsCompositionConverter::importComposerTemplateShape()
layout->layoutItems<QgsLayoutItemShape>( items );
QVERIFY( items.size() > 0 );
//exportLayout( layout, QTest::currentTestFunction() );
// Check the shape
const QgsLayoutItemShape *shape = items.at( 0 );
QCOMPARE( shape->pos().x(), 261.132 );
@ -203,7 +198,7 @@ void TestQgsCompositionConverter::importComposerTemplateShape()
QCOMPARE( shape->hasFrame(), false );
QCOMPARE( shape->hasBackground(), false );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
}
@ -213,7 +208,7 @@ void TestQgsCompositionConverter::importComposerTemplatePicture()
QDomElement docElem( loadComposition( "2x_template_pictures.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -231,7 +226,7 @@ void TestQgsCompositionConverter::importComposerTemplatePicture()
QCOMPARE( item->pos().y(), 12.6029 );
QVERIFY( item->isVisible() );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -242,7 +237,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolygon()
QDomElement docElem( loadComposition( "2x_template_polygon.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -254,7 +249,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolygon()
QVERIFY( item->isVisible() );
QCOMPARE( item->nodes().count(), 7 );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -265,7 +260,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolyline()
QDomElement docElem( loadComposition( "2x_template_polyline.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -281,7 +276,7 @@ void TestQgsCompositionConverter::importComposerTemplatePolyline()
//QCOMPARE( item->nodes().at(0), QPointF( 266.622, 371.215) );
//QCOMPARE( item->nodes().at(1), QPointF( 261.581, 296.606) );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -292,7 +287,7 @@ void TestQgsCompositionConverter::importComposerTemplateArrow()
QDomElement docElem( loadComposition( "2x_template_arrow.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -306,7 +301,7 @@ void TestQgsCompositionConverter::importComposerTemplateArrow()
QCOMPARE( item->startMarker(), QgsLayoutItemPolyline::MarkerMode::NoMarker );
QCOMPARE( item->endMarker(), QgsLayoutItemPolyline::MarkerMode::ArrowHead );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -318,7 +313,7 @@ void TestQgsCompositionConverter::importComposerTemplateMap()
QDomElement docElem( loadComposition( "2x_template_map_overview.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -329,7 +324,7 @@ void TestQgsCompositionConverter::importComposerTemplateMap()
QgsLayoutItemMap *item = items.at( 0 );
QVERIFY( item->isVisible() );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -340,7 +335,7 @@ void TestQgsCompositionConverter::importComposerTemplateLegend()
QDomElement docElem( loadComposition( "2x_template_legend.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -351,7 +346,7 @@ void TestQgsCompositionConverter::importComposerTemplateLegend()
QgsLayoutItemLegend *item = items.at( 0 );
QVERIFY( item->isVisible() );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -362,7 +357,7 @@ void TestQgsCompositionConverter::importComposerTemplateScaleBar()
QDomElement docElem( loadComposition( "2x_template_scalebar.qpt" ) );
QVERIFY( !docElem.isNull() );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 1 );
@ -373,7 +368,7 @@ void TestQgsCompositionConverter::importComposerTemplateScaleBar()
QgsLayoutItemScaleBar *item = items.at( 0 );
QVERIFY( item->isVisible() );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
qDeleteAll( items );
@ -383,15 +378,14 @@ void TestQgsCompositionConverter::importComposerTemplate()
{
QDomElement docElem( loadComposition( "2x_template.qpt" ) );
QgsProject project;
QgsLayout *layout = QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project );
std::unique_ptr< QgsLayout > layout( QgsCompositionConverter::createLayoutFromCompositionXml( docElem, &project ) );
QVERIFY( layout );
QCOMPARE( layout->pageCollection()->pageCount(), 2 );
checkRenderedImage( layout, QTest::currentTestFunction(), 0 );
checkRenderedImage( layout, QTest::currentTestFunction(), 1 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 0 );
checkRenderedImage( layout.get(), QTest::currentTestFunction(), 1 );
delete layout;
}
void TestQgsCompositionConverter::checkRenderedImage( QgsLayout *layout, const QString testName, const int pageNumber )

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -440,7 +440,7 @@
</ComposerItem>
</ComposerShape>
<ComposerScaleBar style="Double Box" numMapUnitsPerScaleBarUnit="2000" alignment="1" height="3" numSegments="6" boxContentSpace="4" segmentSizeMode="0" outlineWidth="0.4" segmentMillimeters="5.64513" lineCapStyle="square" numUnitsPerSegment="250000" mapId="0" lineJoinStyle="round" numSegmentsLeft="3" labelBarSpace="5" unitType="meters" unitLabel="hh" maxBarWidth="150" minBarWidth="50">
<scaleBarFont description="MS Shell Dlg 2,12,-1,5,50,0,0,0,0,0" style=""/>
<scaleBarFont description="QGIS Vera Sans,12,-1,5,50,0,0,0,0,0" style=""/>
<fillColor red="227" green="26" alpha="255" blue="28"/>
<fillColor2 red="253" green="191" alpha="255" blue="111"/>
<strokeColor red="255" green="127" alpha="255" blue="0"/>
@ -461,19 +461,19 @@
<ComposerLegend rasterBorder="1" rasterBorderColor="0,0,0,255" columnSpace="1" wmsLegendWidth="50" equalColumnWidth="1" wrapChar=" " rasterBorderWidth="0" lineSpacing="1" boxSpace="5" fontColor="#f065ec" title="My Legend" columnCount="2" symbolWidth="12" titleAlignment="4" resizeToContents="1" wmsLegendHeight="25" splitLayer="1" map="0" legendFilterByAtlas="0" symbolHeight="9">
<styles>
<style name="title" marginBottom="6">
<styleFont description="MS Shell Dlg 2,36,-1,5,50,0,0,0,0,0" style=""/>
<styleFont description="QGIS Vera Sans,36,-1,5,50,0,0,0,0,0" style=""/>
</style>
<style name="group" marginTop="5">
<styleFont description="MS Shell Dlg 2,14,-1,5,50,0,0,0,0,0" style=""/>
<styleFont description="QGIS Vera Sans,14,-1,5,50,0,0,0,0,0" style=""/>
</style>
<style name="subgroup" marginTop="4">
<styleFont description="MS Shell Dlg 2,12,-1,5,50,0,0,0,0,0" style=""/>
<styleFont description="QGIS Vera Sans,12,-1,5,50,0,0,0,0,0" style=""/>
</style>
<style name="symbol" marginTop="3">
<styleFont description="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0" style=""/>
<styleFont description="QGIS Vera Sans,8.25,-1,5,50,0,0,0,0,0" style=""/>
</style>
<style marginLeft="4" name="symbolLabel" marginTop="3">
<styleFont description="MS Shell Dlg 2,12,-1,5,50,0,0,0,0,0" style=""/>
<styleFont description="QGIS Vera Sans,12,-1,5,50,0,0,0,0,0" style=""/>
</style>
</styles>
<layer-tree-group>
@ -500,7 +500,7 @@
</ComposerItem>
</ComposerLegend>
<ComposerLabel marginY="-3" htmlState="2" valign="32" labelText="QGIS &lt;b>is good&lt;/b>" halign="2" marginX="5">
<LabelFont description="MS Shell Dlg 2,10,-1,5,50,0,0,0,0,0" style=""/>
<LabelFont description="QGIS Vera Sans,10,-1,5,50,0,0,0,0,0" style=""/>
<FontColor red="13" green="146" blue="255"/>
<ComposerItem pagex="223.827" uuid="{ea2ebb22-69b6-415c-b5e2-fb75296d86cf}" background="false" height="15.6276" y="59.9898" page="1" x="223.827" itemRotation="0" frameJoinStyle="miter" outlineWidth="0.3" visibility="1" positionLock="false" id="" blendMode="0" opacity="1" positionMode="0" pagey="59.9898" excludeFromExports="0" zValue="5" width="55.4527" lastValidViewScaleFactor="-1" frame="false">
<FrameColor red="0" green="0" alpha="255" blue="0"/>
@ -516,7 +516,7 @@
</ComposerItem>
</ComposerLabel>
<ComposerLabel marginY="1" htmlState="0" valign="32" labelText="my label [% format_date( to_date( '2017-12-12'), 'yyyy-MM-dd')%]" halign="1" marginX="1">
<LabelFont description="MS Shell Dlg 2,10,-1,5,50,0,0,0,0,0" style=""/>
<LabelFont description="QGIS Vera Sans,10,-1,5,50,0,0,0,0,0" style=""/>
<FontColor red="0" green="0" blue="0"/>
<ComposerItem pagex="214.753" uuid="{2ad09482-99c4-4fc2-a7df-d48103d320fc}" background="false" height="16.6358" y="46.8828" page="1" x="214.753" itemRotation="0" frameJoinStyle="miter" outlineWidth="0.3" visibility="1" positionLock="false" id="" blendMode="0" opacity="1" positionMode="0" pagey="46.8828" excludeFromExports="0" zValue="4" width="59.9898" lastValidViewScaleFactor="-1" frame="false">
<FrameColor red="0" green="0" alpha="255" blue="0"/>
@ -659,7 +659,7 @@
</layer>
</symbol>
</markerStyle>
<annotationFontProperties description="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0" style=""/>
<annotationFontProperties description="QGIS Vera Sans,8.25,-1,5,50,0,0,0,0,0" style=""/>
</ComposerMapGrid>
<AtlasMap atlasDriven="0" margin="0.10000000000000001" scalingMode="2"/>
<ComposerItem pagex="24.1399" uuid="{5c70116e-a26b-4e05-ac30-466c4f893dbb}" background="true" height="198" y="6" page="1" x="24.1399" itemRotation="0" frameJoinStyle="round" outlineWidth="0.6" visibility="1" positionLock="false" id="my map" blendMode="0" opacity="0.78" positionMode="0" pagey="6" excludeFromExports="0" zValue="1" width="102" lastValidViewScaleFactor="2.87787" frame="true">
@ -720,8 +720,8 @@
<customproperties/>
</ComposerHtml>
<ComposerAttributeTableV2 vectorLayerProvider="ogr" showOnlyVisibleFeatures="1" wrapBehavior="0" composerMap="0" showUniqueRowsOnly="1" showGrid="1" resizeMode="0" source="0" vectorLayerSource="/home/ale/dev/QGIS/tests/testdata/points.shp" headerMode="1" emptyTableMessage="" vectorLayer="points20171212162310546" backgroundColor="240,33,33,255" headerHAlignment="2" cellMargin="1.2" relationId="" emptyTableMode="1" wrapString="" horizontalGrid="1" featureFilter="" filterToAtlasIntersection="0" headerFontColor="194,143,12,255" vectorLayerName="points" filterFeatures="false" showEmptyRows="0" contentFontColor="115,115,115,255" gridColor="245,57,220,255" verticalGrid="1" maxFeatures="30" gridStrokeWidth="0.7">
<headerFontProperties description="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0" style=""/>
<contentFontProperties description="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0" style=""/>
<headerFontProperties description="QGIS Vera Sans,8.25,-1,5,50,0,0,0,0,0" style=""/>
<contentFontProperties description="QGIS Vera Sans,8.25,-1,5,50,0,0,0,0,0" style=""/>
<displayColumns>
<column heading="Class" sortByRank="0" width="0" attribute="Class" hAlignment="1" sortOrder="0" vAlignment="128">
<backgroundColor red="0" green="0" alpha="0" blue="0"/>

View File

@ -1,29 +1,50 @@
<Composer title="test_label" visible="1">
<Composition resizeToContentsMarginLeft="0" snapping="0" showPages="1" guidesVisible="1" resizeToContentsMarginTop="0" worldFileMap="" alignmentSnap="1" printResolution="300" paperWidth="297" gridVisible="0" snapGridOffsetX="0" smartGuides="1" snapGridOffsetY="0" resizeToContentsMarginRight="0" snapTolerancePixels="5" printAsRaster="0" generateWorldFile="0" paperHeight="210" numPages="1" snapGridResolution="10" resizeToContentsMarginBottom="0">
<symbol alpha="1" clip_to_extent="1" type="fill" name="">
<layer pass="0" class="SimpleFill" locked="0">
<prop k="border_width_map_unit_scale" v="0,0,0,0,0,0"/>
<prop k="color" v="255,255,255,255"/>
<prop k="joinstyle" v="miter"/>
<prop k="offset" v="0,0"/>
<prop k="offset_map_unit_scale" v="0,0,0,0,0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_color" v="0,0,0,255"/>
<prop k="outline_style" v="no"/>
<prop k="outline_width" v="0.26"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="style" v="solid"/>
<Composer>
<Composition alignmentSnap="1" resizeToContentsMarginTop="0" snapGridResolution="10" worldFileMap="" guidesVisible="1" gridVisible="0" paperHeight="210" resizeToContentsMarginRight="0" numPages="1" resizeToContentsMarginLeft="0" snapTolerancePixels="5" paperWidth="297" snapGridOffsetX="0" printResolution="300" name="" resizeToContentsMarginBottom="0" printAsRaster="0" snapping="0" generateWorldFile="0" snapGridOffsetY="0" smartGuides="1" showPages="1">
<symbol type="fill" alpha="1" clip_to_extent="1" name="">
<layer pass="0" locked="0" enabled="1" class="SimpleFill">
<prop v="3x:0,0,0,0,0,0" k="border_width_map_unit_scale"/>
<prop v="255,255,255,255" k="color"/>
<prop v="miter" k="joinstyle"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="0,0,0,255" k="outline_color"/>
<prop v="no" k="outline_style"/>
<prop v="0.26" k="outline_width"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="solid" k="style"/>
<data_defined_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
<ComposerLabel valign="32" marginX="1" marginY="1" labelText="QGIS" htmlState="0" halign="1">
<LabelFont description="Ubuntu,10,-1,5,50,0,0,0,0,0" style=""/>
<FontColor red="0" blue="0" green="0"/>
<ComposerItem pagey="35.3929" page="1" id="" lastValidViewScaleFactor="-1" positionMode="8" positionLock="false" x="55.5333" y="35.3929" visibility="1" zValue="1" background="true" transparency="0" frameJoinStyle="miter" blendMode="0" width="10.875" outlineWidth="0.2" excludeFromExports="0" uuid="{cd959c12-5d4b-4e2b-a57d-fd205da26cae}" height="6" itemRotation="4" frame="true" pagex="55.5333">
<FrameColor alpha="255" red="251" blue="0" green="0"/>
<BackgroundColor alpha="255" red="239" blue="241" green="240"/>
<ComposerLabel htmlState="0" valign="32" halign="1" marginX="1" marginY="1" labelText="QGIS">
<LabelFont description="QGIS Vera Sans,13,-1,5,75,0,0,0,0,0,Bold" style="Bold"/>
<FontColor red="0" green="0" blue="0"/>
<ComposerItem opacity="1" id="" y="35.3929" pagey="35.3929" width="15.3686" itemRotation="4" frameJoinStyle="miter" height="7.93747" outlineWidth="0.2" page="1" background="true" visibility="1" excludeFromExports="0" uuid="{68ea82e4-2061-43cd-8521-6bb93f1a9db3}" blendMode="0" frame="true" positionMode="2" lastValidViewScaleFactor="-1" x="55.5333" pagex="55.5333" zValue="1" positionLock="false">
<FrameColor red="251" green="0" alpha="255" blue="0"/>
<BackgroundColor red="239" green="240" alpha="255" blue="241"/>
<dataDefinedProperties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</dataDefinedProperties>
<customproperties/>
</ComposerItem>
</ComposerLabel>
<dataDefinedProperties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</dataDefinedProperties>
<customproperties/>
</Composition>
</Composer>

View File

@ -128,7 +128,7 @@
</layer>
</symbol>
</markerStyle>
<annotationFontProperties style="" description="MS Shell Dlg 2,8.25,-1,5,50,0,0,0,0,0"/>
<annotationFontProperties style="" description="QGIS Vera Sans,8.25,-1,5,50,0,0,0,0,0"/>
</ComposerMapGrid>
<ComposerMapOverview show="1" name="Overview 1" centered="0" inverted="0" frameMap="1" blendMode="0" uuid="{088d7dd9-056d-4895-a3b1-230df2115416}">
<symbol name="" alpha="0.3" type="fill" clip_to_extent="1">