Skip to content
Permalink
Browse files

Remove some more QgsComposition::mapSettings use

  • Loading branch information
nyalldawson committed Jan 17, 2017
1 parent 308fc56 commit 305f9f0e98741dfbd6f4fa0c073062fc41797d62
@@ -249,5 +249,5 @@ class QgsComposerUtils
* QgsComposition::referenceMap().
* @note added in QGIS 3.0
*/
static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter& painter );
static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter* painter );
};
@@ -182,7 +182,7 @@ void QgsComposerArrow::drawLine( QPainter *painter )
painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); //scale painter from mm to dots

//setup render context
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );

QgsExpressionContext expressionContext = createExpressionContext();
@@ -111,10 +111,10 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem
mSettings.setMmPerMapUnit( mComposerMap->mapUnitsToMM() );

// use a temporary QgsMapSettings to find out real map scale
QgsMapSettings ms = mComposerMap->composition()->mapSettings();
ms.setOutputSize( QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM ).toSize() );
ms.setExtent( *mComposerMap->currentMapExtent() );
ms.setOutputDpi( dpi );
QSizeF mapSizePixels = QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM );
QgsRectangle mapExtent = *mComposerMap->currentMapExtent();

QgsMapSettings ms = mComposerMap->mapSettings( mapExtent, mapSizePixels, dpi );
mSettings.setMapScale( ms.scale() );
}
mInitialMapScaleCalculated = true;
@@ -636,7 +636,7 @@ void QgsComposerMapGrid::draw( QPainter* p )
p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); //scale painter from mm to dots

//setup render context
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *p );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, p );
context.setForceVectorOutput( true );
QgsExpressionContext expressionContext = createExpressionContext();
context.setExpressionContext( expressionContext );
@@ -2056,8 +2056,7 @@ void QgsComposerMapGrid::calculateMaxExtension( double& top, double& right, doub
}

//setup render context
QgsMapSettings ms = mComposerMap->composition()->mapSettings();
QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, nullptr );
QgsExpressionContext expressionContext = createExpressionContext();
context.setExpressionContext( expressionContext );

@@ -92,7 +92,7 @@ void QgsComposerMapOverview::draw( QPainter *painter )
double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

//setup render context
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );
QgsExpressionContext expressionContext = createExpressionContext();
context.setExpressionContext( expressionContext );
@@ -137,7 +137,7 @@ void QgsComposerNodesItem::drawNodes( QPainter *painter ) const
symbol.data()->setSize( rectSize );
symbol.data()->setAngle( 45 );

QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );

QgsExpressionContext expressionContext = createExpressionContext();
@@ -168,7 +168,7 @@ void QgsComposerNodesItem::drawSelectedNode( QPainter *painter ) const
symbol.reset( QgsMarkerSymbol::createSimple( properties ) );
symbol.data()->setSize( rectSize );

QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );

QgsExpressionContext expressionContext = createExpressionContext();
@@ -73,7 +73,7 @@ void QgsComposerPolygon::_draw( QPainter *painter )
//setup painter scaling to dots so that raster symbology is drawn to scale
const double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );
context.setExpressionContext( createExpressionContext() );

@@ -100,7 +100,7 @@ void QgsComposerPolyline::_draw( QPainter *painter )
{
double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );

QgsExpressionContext expressionContext = createExpressionContext();
@@ -179,7 +179,7 @@ void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
double dotsPerMM = p->device()->logicalDpiX() / 25.4;

//setup render context
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *p );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, p );
context.setForceVectorOutput( true );
QgsExpressionContext expressionContext = createExpressionContext();
context.setExpressionContext( expressionContext );
@@ -548,15 +548,16 @@ void QgsComposerUtils::drawText( QPainter *painter, const QRectF &rect, const QS
painter->restore();
}

QgsRenderContext QgsComposerUtils::createRenderContext( QgsComposition* composition, QPainter &painter )
QgsRenderContext QgsComposerUtils::createRenderContext( QgsComposition* composition, QPainter* painter )
{
QgsComposerMap* referenceMap = composition ? composition->referenceMap() : nullptr;
if ( !referenceMap )
{
return QgsRenderContext::fromQPainter( &painter );
return QgsRenderContext::fromQPainter( painter );
}

int dpi = painter.device()->logicalDpiX();
// default to 88 dpi if no painter specified
int dpi = ( painter && painter->device() ) ? painter->device()->logicalDpiX() : 88;
double dotsPerMM = dpi / 25.4;

// get map settings from reference map
@@ -565,6 +566,7 @@ QgsRenderContext QgsComposerUtils::createRenderContext( QgsComposition* composit
QgsMapSettings ms = referenceMap->mapSettings( extent, mapSizeMM * dotsPerMM, dpi );

QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
context.setPainter( &painter );
if ( painter )
context.setPainter( painter );
return context;
}
@@ -272,7 +272,7 @@ class CORE_EXPORT QgsComposerUtils
* QgsComposition::referenceMap().
* @note added in QGIS 3.0
*/
static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter& painter );
static QgsRenderContext createRenderContext( QgsComposition* composition, QPainter* painter );

};

@@ -156,7 +156,7 @@ void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* ite
double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

//setup render context
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, *painter );
QgsRenderContext context = QgsComposerUtils::createRenderContext( mComposition, painter );
context.setForceVectorOutput( true );

QgsExpressionContext expressionContext = createExpressionContext();
@@ -712,31 +712,47 @@ void TestQgsComposerUtils::createRenderContext()
QPainter p( &testImage );

// no composition
QgsRenderContext rc = QgsComposerUtils::createRenderContext( nullptr, p );
QgsRenderContext rc = QgsComposerUtils::createRenderContext( nullptr, &p );
QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 );
QCOMPARE( rc.painter(), &p );

// no composition, no painter
rc = QgsComposerUtils::createRenderContext( nullptr, nullptr );
QGSCOMPARENEAR( rc.scaleFactor(), 88 / 25.4, 0.001 );
QVERIFY( !rc.painter() );

//create composition with no reference map
QgsRectangle extent( 2000, 2800, 2500, 2900 );
QgsMapSettings ms;
ms.setExtent( extent );
QgsComposition* composition = new QgsComposition( ms, QgsProject::instance() );
rc = QgsComposerUtils::createRenderContext( composition, p );
rc = QgsComposerUtils::createRenderContext( composition, &p );
QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 );
QCOMPARE( rc.painter(), &p );

// composition, no map, no painter
rc = QgsComposerUtils::createRenderContext( composition, nullptr );
QGSCOMPARENEAR( rc.scaleFactor(), 88 / 25.4, 0.001 );
QVERIFY( !rc.painter() );

// add a reference map
QgsComposerMap* map = new QgsComposerMap( composition );
map->setNewExtent( extent );
map->setSceneRect( QRectF( 30, 60, 200, 100 ) );
composition->addComposerMap( map );
composition->setReferenceMap( map );

rc = QgsComposerUtils::createRenderContext( composition, p );
rc = QgsComposerUtils::createRenderContext( composition, &p );
QGSCOMPARENEAR( rc.scaleFactor(), 150 / 25.4, 0.001 );
QGSCOMPARENEAR( rc.rendererScale(), map->scale(), 100000 );
QGSCOMPARENEAR( rc.rendererScale(), map->scale(), 1000000 );
QCOMPARE( rc.painter(), &p );

// composition, reference map, no painter
rc = QgsComposerUtils::createRenderContext( composition, nullptr );
QGSCOMPARENEAR( rc.scaleFactor(), 88 / 25.4, 0.001 );
QGSCOMPARENEAR( rc.rendererScale(), map->scale(), 1000000 );
QVERIFY( !rc.painter() );

p.end();
}

0 comments on commit 305f9f0

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