void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) { Q_UNUSED( itemStyle ); Q_UNUSED( pWidget ); if ( !painter || !mComposition || !mComposition->pagesVisible() ) { return; } //setup painter scaling to dots so that raster symbology is drawn to scale double dotsPerMM = painter->device()->logicalDpiX() / 25.4; //setup render context QgsMapSettings ms = mComposition->mapSettings(); //context units should be in dots ms.setOutputDpi( painter->device()->logicalDpiX() ); QgsRenderContext context = QgsRenderContext::fromMapSettings( ms ); context.setPainter( painter ); context.setForceVectorOutput( true ); QgsExpressionContext* expressionContext = createExpressionContext(); context.setExpressionContext( *expressionContext ); delete expressionContext; painter->save(); if ( mComposition->plotStyle() == QgsComposition::Preview ) { //if in preview mode, draw page border and shadow so that it's //still possible to tell where pages with a transparent style begin and end painter->setRenderHint( QPainter::Antialiasing, false ); //shadow painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) ); painter->setPen( Qt::NoPen ); painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) ); //page area painter->setBrush( QColor( 215, 215, 215 ) ); painter->setPen( QPen( QColor( 100, 100, 100 ) ) ); painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) ); } painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots painter->setRenderHint( QPainter::Antialiasing ); mComposition->pageStyleSymbol()->startRender( context ); calculatePageMargin(); QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin * dotsPerMM, mPageMargin * dotsPerMM, ( rect().width() - 2 * mPageMargin ) * dotsPerMM, ( rect().height() - 2 * mPageMargin ) * dotsPerMM ) ); QList<QPolygonF> rings; //empty list mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, nullptr, context ); mComposition->pageStyleSymbol()->stopRender( context ); painter->restore(); }
void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) { Q_UNUSED( itemStyle ); Q_UNUSED( pWidget ); if ( !painter ) { return; } QgsRenderContext context; context.setPainter( painter ); context.setScaleFactor( 1.0 ); if ( mComposition->plotStyle() == QgsComposition::Preview ) { context.setRasterScaleFactor( horizontalViewScaleFactor() ); } else { context.setRasterScaleFactor( mComposition->printResolution() / 25.4 ); } painter->save(); if ( mComposition->plotStyle() == QgsComposition::Preview ) { //if in preview mode, draw page border and shadow so that it's //still possible to tell where pages with a transparent style begin and end painter->setRenderHint( QPainter::Antialiasing, false ); //shadow painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) ); painter->setPen( Qt::NoPen ); painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) ); //page area painter->setBrush( QColor( 215, 215, 215 ) ); painter->setPen( QPen( QColor( 100, 100, 100 ) ) ); painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) ); } painter->setRenderHint( QPainter::Antialiasing ); mComposition->pageStyleSymbol()->startRender( context ); calculatePageMargin(); QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) ); QList<QPolygonF> rings; //empty list mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context ); mComposition->pageStyleSymbol()->stopRender( context ); painter->restore(); }