QgsPaintEffect::QgsPaintEffect( const QgsPaintEffect &other ) : mEnabled( other.enabled() ) , mDrawMode( other.drawMode() ) , requiresQPainterDpiFix( true ) , mPicture( nullptr ) , mSourceImage( nullptr ) , mOwnsImage( false ) , mPrevPainter( nullptr ) , mEffectPainter( nullptr ) , mTempPicture( nullptr ) { }
void QgsMarkerSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) { startRender( context ); QgsPaintEffect *effect = paintEffect(); if ( effect && effect->enabled() ) { QgsEffectPainter p( context.renderContext(), effect ); renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context ); } else { renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context ); } stopRender( context ); }
void QgsFillSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) { QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width(), size.height() ) ); startRender( context ); QgsPaintEffect *effect = paintEffect(); if ( effect && effect->enabled() ) { QgsEffectPainter p( context.renderContext(), effect ); renderPolygon( poly, nullptr, context ); } else { renderPolygon( poly, nullptr, context ); } stopRender( context ); }
void QgsLineSymbolV2::renderPolylineUsingLayer( QgsLineSymbolLayerV2 *layer, const QPolygonF &points, QgsSymbolV2RenderContext &context ) { QgsPaintEffect* effect = layer->paintEffect(); if ( effect && effect->enabled() ) { QPainter* p = context.renderContext().painter(); p->save(); p->translate( points.boundingRect().topLeft() ); effect->begin( context.renderContext() ); layer->renderPolyline( points.translated( -points.boundingRect().topLeft() ), context ); effect->end( context.renderContext() ); p->restore(); } else { layer->renderPolyline( points, context ); } }
void QgsLineSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) { QPolygonF points; // we're adding 0.5 to get rid of blurred preview: // drawing antialiased lines of width 1 at (x,0)-(x,100) creates 2px line points << QPointF( 0, int( size.height() / 2 ) + 0.5 ) << QPointF( size.width(), int( size.height() / 2 ) + 0.5 ); startRender( context ); QgsPaintEffect *effect = paintEffect(); if ( effect && effect->enabled() ) { QgsEffectPainter p( context.renderContext(), effect ); renderPolyline( points, context ); } else { renderPolyline( points, context ); } stopRender( context ); }
void QgsFillSymbolV2::renderPolygonUsingLayer( QgsSymbolLayerV2* layer, const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context ) { QgsSymbolV2::SymbolType layertype = layer->type(); QgsPaintEffect* effect = layer->paintEffect(); if ( effect && effect->enabled() ) { QRectF bounds = polygonBounds( points, rings ); QList<QPolygonF>* translatedRings = translateRings( rings, -bounds.left(), -bounds.top() ); QPainter* p = context.renderContext().painter(); p->save(); p->translate( bounds.topLeft() ); effect->begin( context.renderContext() ); if ( layertype == QgsSymbolV2::Fill ) { (( QgsFillSymbolLayerV2* )layer )->renderPolygon( points.translated( -bounds.topLeft() ), translatedRings, context ); } else if ( layertype == QgsSymbolV2::Line ) { (( QgsLineSymbolLayerV2* )layer )->renderPolygonOutline( points.translated( -bounds.topLeft() ), translatedRings, context ); } delete translatedRings; effect->end( context.renderContext() ); p->restore(); } else { if ( layertype == QgsSymbolV2::Fill ) { (( QgsFillSymbolLayerV2* )layer )->renderPolygon( points, rings, context ); } else if ( layertype == QgsSymbolV2::Line ) { (( QgsLineSymbolLayerV2* )layer )->renderPolygonOutline( points, rings, context ); } } }
void QgsMarkerSymbolV2::renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, const QPointF& point, QgsSymbolV2RenderContext& context ) { static QPointF nullPoint( 0, 0 ); QgsPaintEffect* effect = layer->paintEffect(); if ( effect && effect->enabled() ) { QPainter* p = context.renderContext().painter(); p->save(); p->translate( point ); effect->begin( context.renderContext() ); layer->renderPoint( nullPoint, context ); effect->end( context.renderContext() ); p->restore(); } else { layer->renderPoint( point, context ); } }
void QgsEffectStack::draw( QgsRenderContext &context ) { QPainter* destPainter = context.painter(); //first, we build up a list of rendered effects //we do this moving backwards through the stack, so that each effect's results //becomes the source of the previous effect QPicture* sourcePic = new QPicture( *source() ); QPicture* currentPic = sourcePic; QList< QPicture* > results; for ( int i = mEffectList.count() - 1; i >= 0; --i ) { QgsPaintEffect* effect = mEffectList.at( i ); if ( !effect->enabled() ) { continue; } QPicture* pic; if ( effect->type() == "drawSource" ) { //draw source is always the original source, regardless of previous effect results pic = sourcePic; } else { pic = currentPic; } QPicture *resultPic = new QPicture(); QPainter p( resultPic ); context.setPainter( &p ); //effect stack has it's own handling of the QPicture DPI issue, so //we disable QgsPaintEffect's internal workaround effect->requiresQPainterDpiFix = false; effect->render( *pic, context ); effect->requiresQPainterDpiFix = true; p.end(); results << resultPic; if ( mEffectList.at( i )->drawMode() != QgsPaintEffect::Render ) { currentPic = resultPic; } } delete sourcePic; sourcePic = nullptr; context.setPainter( destPainter ); //then, we render all the results in the opposite order for ( int i = 0; i < mEffectList.count(); ++i ) { if ( !mEffectList[i]->enabled() ) { continue; } QPicture* pic = results.takeLast(); if ( mEffectList.at( i )->drawMode() != QgsPaintEffect::Modifier ) { context.painter()->save(); fixQPictureDpi( context.painter() ); context.painter()->drawPicture( 0, 0, *pic ); context.painter()->restore(); } delete pic; } }
QgsPaintEffect::QgsPaintEffect( const QgsPaintEffect &other ) : mEnabled( other.enabled() ) , mDrawMode( other.drawMode() ) { }