void QgsPaintEffectPropertiesWidget::effectTypeChanged() { QgsPaintEffect* effect = mEffect; if ( !effect ) return; QString newEffectType = mEffectTypeCombo->currentData().toString(); if ( effect->type() == newEffectType ) return; // get creation function for new effect from registry QgsPaintEffectRegistry* registry = QgsApplication::paintEffectRegistry(); QgsPaintEffectAbstractMetadata* am = registry->effectMetadata( newEffectType ); if ( !am ) // check whether the metadata is assigned return; // change effect to a new (with different type) // base new effect on existing effect's properties QgsPaintEffect* newEffect = am->createPaintEffect( effect->properties() ); if ( !newEffect ) return; updateEffectWidget( newEffect ); emit changeEffect( newEffect ); mEffect = newEffect; }
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; } }