73 changes: 62 additions & 11 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ),
mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mComposition = composition;
Expand Down Expand Up @@ -85,10 +87,12 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ),
mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mOverviewFrameMapSymbol = 0;
Expand Down Expand Up @@ -631,8 +635,9 @@ bool QgsComposerMap::containsWMSLayer() const
return false;
}

bool QgsComposerMap::containsBlendModes() const
bool QgsComposerMap::containsAdvancedEffects() const
{
// check if map contains advanced effects like blend modes, or flattened layers for transparency
if ( !mMapRenderer )
{
return false;
Expand All @@ -655,10 +660,19 @@ bool QgsComposerMap::containsBlendModes() const
{
return true;
}
// if vector layer and has labels, check label blend modes
// if vector layer, check labels and feature blend mode
QgsVectorLayer* currentVectorLayer = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( currentVectorLayer )
{
if ( currentVectorLayer->layerTransparency() != 0 )
{
return true;
}
if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
{
return true;
}
// check label blend modes
if ( lbl->willUseLayer( currentVectorLayer ) )
{
// Check all label blending properties
Expand Down Expand Up @@ -782,6 +796,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
gridElem.setAttribute( "crossLength", QString::number( mCrossLength ) );
gridElem.setAttribute( "gridFrameStyle", mGridFrameStyle );
gridElem.setAttribute( "gridFrameWidth", QString::number( mGridFrameWidth ) );
gridElem.setAttribute( "gridBlendMode", QgsMapRenderer::getBlendModeEnum( mGridBlendMode ) );
QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mGridLineSymbol, doc );
gridElem.appendChild( gridLineStyleElem );

Expand All @@ -800,6 +815,12 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
annotationElem.setAttribute( "frameDistance", QString::number( mAnnotationFrameDistance ) );
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );
//annotation font color
QDomElement annotationFontColorElem = doc.createElement( "fontColor" );
annotationFontColorElem.setAttribute( "red", mGridAnnotationFontColor.red() );
annotationFontColorElem.setAttribute( "green", mGridAnnotationFontColor.green() );
annotationFontColorElem.setAttribute( "blue", mGridAnnotationFontColor.blue() );
annotationElem.appendChild( annotationFontColorElem );

gridElem.appendChild( annotationElem );
composerMapElem.appendChild( gridElem );
Expand Down Expand Up @@ -928,6 +949,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mCrossLength = gridElem.attribute( "crossLength", "3" ).toDouble();
mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt();
mGridFrameWidth = gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble();
setGridBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) gridElem.attribute( "gridBlendMode", "0" ).toUInt() ) );

QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
delete mGridLineSymbol;
Expand Down Expand Up @@ -961,6 +983,22 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );

//annotation font color
QDomNodeList annotationFontColorList = annotationElem.elementsByTagName( "fontColor" );
if ( annotationFontColorList.size() > 0 )
{
QDomElement fontColorElem = annotationFontColorList.at( 0 ).toElement();
int red = fontColorElem.attribute( "red", "0" ).toInt();
int green = fontColorElem.attribute( "green", "0" ).toInt();
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
mGridAnnotationFontColor = QColor( red, green, blue );
}
else
{
mGridAnnotationFontColor = QColor( 0, 0, 0 );
}

mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
}
}
Expand Down Expand Up @@ -1025,6 +1063,10 @@ void QgsComposerMap::drawGrid( QPainter* p )
QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
p->setClipRect( thisPaintRect );

// set the blend mode for drawing grid lines
p->save();
p->setCompositionMode( mGridBlendMode );

//simpler approach: draw vertical lines first, then horizontal ones
if ( mGridStyle == QgsComposerMap::Solid )
{
Expand Down Expand Up @@ -1085,6 +1127,8 @@ void QgsComposerMap::drawGrid( QPainter* p )
drawGridLine( QLineF( hIt->second.p2(), crossEnd1 ), p );
}
}
// reset composition mode
p->restore();

p->setClipRect( thisPaintRect , Qt::NoClip );

Expand All @@ -1097,6 +1141,7 @@ void QgsComposerMap::drawGrid( QPainter* p )
{
drawCoordinateAnnotations( p, horizontalLines, verticalLines );
}

}

void QgsComposerMap::drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines )
Expand Down Expand Up @@ -1377,7 +1422,7 @@ void QgsComposerMap::drawAnnotation( QPainter* p, const QPointF& pos, int rotati
p->save();
p->translate( pos );
p->rotate( rotation );
p->setPen( QColor( 0, 0, 0 ) );
p->setPen( QPen( QColor( mGridAnnotationFontColor ) ) );
drawText( p, 0, 0, annotationText, mGridAnnotationFont );
p->restore();
}
Expand Down Expand Up @@ -1587,6 +1632,12 @@ QPen QgsComposerMap::gridPen() const
return p;
}

void QgsComposerMap::setGridBlendMode( QPainter::CompositionMode blendMode )
{
mGridBlendMode = blendMode;
update();
}

QRectF QgsComposerMap::boundingRect() const
{
return mCurrentRectangle;
Expand Down
20 changes: 18 additions & 2 deletions src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**True if composer map renders a WMS layer*/
bool containsWMSLayer() const;

/**True if composer map contains layers with blend modes*/
bool containsBlendModes() const;
/**True if composer map contains layers with blend modes or flattened layers for vectors */
bool containsAdvancedEffects() const;

/** stores state in Dom node
* @param elem is Dom element corresponding to 'Composer' tag
Expand Down Expand Up @@ -246,6 +246,13 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
QFont gridAnnotationFont() const { return mGridAnnotationFont; }

/**Sets font color for grid annotations
@note: this function was added in version 2.0*/
void setAnnotationFontColor( const QColor& c ) {mGridAnnotationFontColor = c;}
/**Get font color for grid annotations
@note: this function was added in version 2.0*/
QColor annotationFontColor() const {return mGridAnnotationFontColor;}

/**Sets coordinate precision for grid annotations
@note this function was added in version 1.4*/
void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
Expand Down Expand Up @@ -328,6 +335,11 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setGridLineSymbol( QgsLineSymbolV2* symbol );
QgsLineSymbolV2* gridLineSymbol() { return mGridLineSymbol; }

/** Returns the grid's blending mode */
QPainter::CompositionMode gridBlendMode() const {return mGridBlendMode;}
/** Sets the grid's blending mode*/
void setGridBlendMode( QPainter::CompositionMode blendMode );

/**Sets mId to a number not yet used in the composition. mId is kept if it is not in use.
Usually, this function is called before adding the composer map to the composition*/
void assignFreeId();
Expand Down Expand Up @@ -417,10 +429,14 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
double mGridOffsetY;
/**Font for grid line annotation*/
QFont mGridAnnotationFont;
/**Font color for grid line annotation*/
QColor mGridAnnotationFontColor;
/**Digits after the dot*/
int mGridAnnotationPrecision;
/**True if coordinate values should be drawn*/
bool mShowGridAnnotation;
/**Blend mode for grid*/
QPainter::CompositionMode mGridBlendMode;

/**Annotation position for left map side (inside / outside / not shown)*/
GridAnnotationPosition mLeftGridAnnotationPosition;
Expand Down
47 changes: 33 additions & 14 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,30 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
// before compositing this on the map. This effectively flattens the layer and prevents
// blending occuring between objects on the layer
// (this is not required for raster layers or when layer caching is enabled, since that has the same effect)
if (( mRenderContext.useAdvancedEffects() ) && ( ml->blendMode() != QPainter::CompositionMode_SourceOver ) &&
( ml->type() != QgsMapLayer::RasterLayer ) &&
( split || !mySettings.value( "/qgis/enable_render_caching", false ).toBool() ) )
bool flattenedLayer = false;
if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
{
mypFlattenedImage = new QImage( mRenderContext.painter()->device()->width(),
mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
mypFlattenedImage->fill( 0 );
QPainter * mypPainter = new QPainter( mypFlattenedImage );
if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
if (( vl->blendMode() != QPainter::CompositionMode_SourceOver && ( split || !mySettings.value( "/qgis/enable_render_caching", false ).toBool() ) )
|| ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
|| ( vl->layerTransparency() != 0 ) )

{
mypPainter->setRenderHint( QPainter::Antialiasing );
flattenedLayer = true;
mypFlattenedImage = new QImage( mRenderContext.painter()->device()->width(),
mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
mypFlattenedImage->fill( 0 );
QPainter * mypPainter = new QPainter( mypFlattenedImage );
if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
{
mypPainter->setRenderHint( QPainter::Antialiasing );
}
mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
mRenderContext.setPainter( mypPainter );

// set the painter to the feature blend mode
mypPainter->setCompositionMode( vl->featureBlendMode() );
}
mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
mRenderContext.setPainter( mypPainter );
}

if ( scaleRaster )
Expand Down Expand Up @@ -584,10 +594,19 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
}

// If we flattened this layer for alternate blend modes, composite it now
if (( mRenderContext.useAdvancedEffects() ) && ( ml->blendMode() != QPainter::CompositionMode_SourceOver ) &&
( ml->type() != QgsMapLayer::RasterLayer ) &&
( split || !mySettings.value( "/qgis/enable_render_caching", false ).toBool() ) )
if ( flattenedLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
if ( vl->layerTransparency() != 0 )
{
// a layer transparency has been set, so update the alpha for the flattened layer
// by combining it with the layer transparency
QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->layerTransparency() / 100 ) );
// use destination in composition mode to merge source's alpha with destination
mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
mRenderContext.painter()->fillRect( mypFlattenedImage->rect(), transparentFillColor );
}

delete mRenderContext.painter();
mRenderContext.setPainter( mypContextPainter );
mypContextPainter->save();
Expand Down
54 changes: 54 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mRendererV2( NULL )
, mLabel( 0 )
, mLabelOn( false )
, mFeatureBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal feature blending
, mLayerTransparency( 0 )
, mVertexMarkerOnlyForSelection( false )
, mCache( new QgsGeometryCache( this ) )
, mEditBuffer( 0 )
Expand Down Expand Up @@ -1759,6 +1761,22 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) e.text().toInt() ) );
}

// get and set the feature blend mode if it exists
QDomNode featureBlendModeNode = node.namedItem( "featureBlendMode" );
if ( !featureBlendModeNode.isNull() )
{
QDomElement e = featureBlendModeNode.toElement();
setFeatureBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) e.text().toInt() ) );
}

// get and set the layer transparency if it exists
QDomNode layerTransparencyNode = node.namedItem( "layerTransparency" );
if ( !layerTransparencyNode.isNull() )
{
QDomElement e = layerTransparencyNode.toElement();
setLayerTransparency( e.text().toInt() );
}

// use scale dependent visibility flag
QDomElement e = node.toElement();
mLabel->setScaleBasedVisibility( e.attribute( "scaleBasedLabelVisibilityFlag", "0" ) == "1" );
Expand Down Expand Up @@ -2084,6 +2102,18 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
blendModeElem.appendChild( blendModeText );
node.appendChild( blendModeElem );

// add the feature blend mode field
QDomElement featureBlendModeElem = doc.createElement( "featureBlendMode" );
QDomText featureBlendModeText = doc.createTextNode( QString::number( QgsMapRenderer::getBlendModeEnum( featureBlendMode() ) ) );
featureBlendModeElem.appendChild( featureBlendModeText );
node.appendChild( featureBlendModeElem );

// add the layer transparency
QDomElement layerTransparencyElem = doc.createElement( "layerTransparency" );
QDomText layerTransparencyText = doc.createTextNode( QString::number( layerTransparency() ) );
layerTransparencyElem.appendChild( layerTransparencyText );
node.appendChild( layerTransparencyElem );

// add the display field
QDomElement dField = doc.createElement( "displayfield" );
QDomText dFieldText = doc.createTextNode( displayField() );
Expand Down Expand Up @@ -3340,6 +3370,30 @@ QVariant QgsVectorLayer::maximumValue( int index )
return QVariant();
}

/** Write blend mode for features */
void QgsVectorLayer::setFeatureBlendMode( const QPainter::CompositionMode featureBlendMode )
{
mFeatureBlendMode = featureBlendMode;
}

/** Read blend mode for layer */
QPainter::CompositionMode QgsVectorLayer::featureBlendMode() const
{
return mFeatureBlendMode;
}

/** Write transparency for layer */
void QgsVectorLayer::setLayerTransparency( int layerTransparency )
{
mLayerTransparency = layerTransparency;
}

/** Read transparency for layer */
int QgsVectorLayer::layerTransparency() const
{
return mLayerTransparency;
}

void QgsVectorLayer::stopRendererV2( QgsRenderContext& rendererContext, QgsSingleSymbolRendererV2* selRenderer )
{
mRendererV2->stopRender( rendererContext );
Expand Down
24 changes: 24 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,24 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
@note added in 1.7*/
QVariant maximumValue( int index );

/* Set the blending mode used for rendering each feature
* @note added in 2.0
*/
void setFeatureBlendMode( const QPainter::CompositionMode blendMode );
/* Returns the current blending mode for features
* @note added in 2.0
*/
QPainter::CompositionMode featureBlendMode() const;

/* Set the transparency for the vector layer
* @note added in 2.0
*/
void setLayerTransparency( int layerTransparency );
/* Returns the current transparency for the vector layer
* @note added in 2.0
*/
int layerTransparency() const;

public slots:
/**
* Select feature by its ID
Expand Down Expand Up @@ -1480,6 +1498,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Display labels */
bool mLabelOn;

/** Blend mode for features */
QPainter::CompositionMode mFeatureBlendMode;

/** Layer transparency */
int mLayerTransparency;

/**The current type of editing marker*/
QgsVectorLayer::VertexMarkerType mCurrentVertexMarkerType;

Expand Down
17 changes: 16 additions & 1 deletion src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ QgsRendererV2PropertiesDialog::QgsRendererV2PropertiesDialog( QgsVectorLayer* la
// Blend mode
mBlendModeComboBox->setBlendMode( mLayer->blendMode() );

// Feature blend mode
mFeatureBlendComboBox->setBlendMode( mLayer->featureBlendMode() );

// Layer transparency
mLayerTransparencySlider->setValue( mLayer->layerTransparency() );
mLayerTransparencySpnBx->setValue( mLayer->layerTransparency() );

// connect layer transparency slider and spin box
connect( mLayerTransparencySlider, SIGNAL( valueChanged( int ) ), mLayerTransparencySpnBx, SLOT( setValue( int ) ) );
connect( mLayerTransparencySpnBx, SIGNAL( valueChanged( int ) ), mLayerTransparencySlider, SLOT( setValue( int ) ) );

QPixmap pix;
QgsRendererV2Registry* reg = QgsRendererV2Registry::instance();
QStringList renderers = reg->renderersList();
Expand Down Expand Up @@ -173,8 +184,12 @@ void QgsRendererV2PropertiesDialog::apply()
mLayer->setRendererV2( renderer->clone() );
}

// set the blend mode for the layer
// set the blend modes for the layer
mLayer->setBlendMode( mBlendModeComboBox->blendMode() );
mLayer->setFeatureBlendMode( mFeatureBlendComboBox->blendMode() );

// set transparency for the layer
mLayer->setLayerTransparency( mLayerTransparencySlider->value() );
}

void QgsRendererV2PropertiesDialog::onOK()
Expand Down
32 changes: 27 additions & 5 deletions src/ui/qgscomposermapwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<x>0</x>
<y>-202</y>
<width>440</width>
<height>1310</height>
<height>1380</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -448,6 +448,16 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QgsBlendModeComboBox" name="mGridBlendComboBox"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mGridBlendLabel">
<property name="text">
<string>Blend mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -583,7 +593,7 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="11" column="0">
<widget class="QLabel" name="mDistanceToFrameLabel">
<property name="text">
<string>Distance to map frame</string>
Expand All @@ -596,10 +606,10 @@
</property>
</widget>
</item>
<item row="10" column="1">
<item row="11" column="1">
<widget class="QDoubleSpinBox" name="mDistanceToMapFrameSpinBox"/>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
<property name="text">
<string>Coordinate precision</string>
Expand All @@ -612,9 +622,16 @@
</property>
</widget>
</item>
<item row="11" column="1">
<item row="12" column="1">
<widget class="QSpinBox" name="mCoordinatePrecisionSpinBox"/>
</item>
<item row="10" column="1">
<widget class="QgsColorButton" name="mAnnotationFontColorButton">
<property name="text">
<string>Font color...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -702,6 +719,11 @@
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
79 changes: 69 additions & 10 deletions src/ui/qgsrendererv2propsdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,69 @@
<string>Renderer settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QgsCollapsibleGroupBox" name="groupBox">
<property name="title">
<string>Layer rendering</string>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="mLayerTransparencySlider">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mLayerTransparencySpnBx">
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblTransparency">
<property name="text">
<string>Layer transparency</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QgsBlendModeComboBox" name="mFeatureBlendComboBox"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="lblFeatureBlend">
<property name="text">
<string>Feature blending mode</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblLayerBlend">
<property name="text">
<string>Layer blending mode</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand All @@ -32,16 +95,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Blending mode</string>
</property>
</widget>
</item>
<item>
<widget class="QgsBlendModeComboBox" name="mBlendModeComboBox"/>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -89,6 +142,12 @@
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cboRenderers</tabstop>
Expand Down
40 changes: 40 additions & 0 deletions tests/src/core/testqgsblendmodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ class TestQgsBlendModes: public QObject
void cleanup() {};// will be called after every testfunction.

void vectorBlending();
void featureBlending();
void vectorLayerTransparency();
void rasterBlending();
private:
bool imageCheck( QString theType ); //as above
QgsMapRenderer * mpMapRenderer;
QgsMapLayer * mpPointsLayer;
QgsMapLayer * mpPolysLayer;
QgsVectorLayer * mpLinesLayer;
QgsRasterLayer* mRasterLayer1;
QgsRasterLayer* mRasterLayer2;
QString mTestDataDir;
Expand Down Expand Up @@ -85,6 +88,14 @@ void TestQgsBlendModes::initTestCase()
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );

//create a line layer that will be used in tests
QString myLinesFileName = mTestDataDir + "lines.shp";
QFileInfo myLineFileInfo( myLinesFileName );
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
myLineFileInfo.completeBaseName(), "ogr" );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLinesLayer );

//create two raster layers
QFileInfo rasterFileInfo( mTestDataDir + "landsat.tif" );
mRasterLayer1 = new QgsRasterLayer( rasterFileInfo.filePath(),
Expand Down Expand Up @@ -121,6 +132,35 @@ void TestQgsBlendModes::vectorBlending()
QVERIFY( imageCheck( "vector_blendmodes" ) );
}

void TestQgsBlendModes::featureBlending()
{
//Add two vector layers
QStringList myLayers;
myLayers << mpLinesLayer->id();
myLayers << mpPolysLayer->id();
mpMapRenderer->setLayerSet( myLayers );

//Set feature blending modes for point layer
mpLinesLayer->setFeatureBlendMode( QPainter::CompositionMode_Plus );
mpMapRenderer->setExtent( mpPointsLayer->extent() );
QVERIFY( imageCheck( "vector_featureblendmodes" ) );
}

void TestQgsBlendModes::vectorLayerTransparency()
{
//Add two vector layers
QStringList myLayers;
myLayers << mpLinesLayer->id();
myLayers << mpPolysLayer->id();
mpMapRenderer->setLayerSet( myLayers );
mpLinesLayer->setFeatureBlendMode( QPainter::CompositionMode_SourceOver );

//Set feature blending modes for point layer
mpLinesLayer->setLayerTransparency( 50 );
mpMapRenderer->setExtent( mpPointsLayer->extent() );
QVERIFY( imageCheck( "vector_layertransparency" ) );
}

void TestQgsBlendModes::rasterBlending()
{
//Add two raster layers to map renderer
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ void TestQgsComposerMap::grid()
mComposerMap->setGridIntervalY( 2000 );
mComposerMap->setShowGridAnnotation( true );
mComposerMap->setGridPenWidth( 0.5 );
mComposerMap->setGridPenColor( QColor( 0, 255, 0 ) );
mComposerMap->setGridAnnotationPrecision( 0 );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, QgsComposerMap::Left );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Right );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, QgsComposerMap::Top );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Bottom );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Right );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Bottom );
mComposerMap->setAnnotationFontColor( QColor( 255, 0, 0, 150 ) );
mComposerMap->setGridBlendMode( QPainter::CompositionMode_Overlay );
QgsCompositionChecker checker( "Composer map grid", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composermap" + QDir::separator() + "composermap_landsat_grid.png" ) );
bool testResult = checker.testComposition();
Expand Down Expand Up @@ -200,6 +203,10 @@ void TestQgsComposerMap::uniqueId()

void TestQgsComposerMap::zebraStyle()
{
mComposerMap->setGridPenColor( QColor( 0, 0, 0 ) );
mComposerMap->setAnnotationFontColor( QColor( 0, 0, 0, 0 ) );
mComposerMap->setGridBlendMode( QPainter::CompositionMode_SourceOver );

mComposerMap->setGridFrameStyle( QgsComposerMap::Zebra );
mComposerMap->setGridEnabled( true );

Expand Down
49 changes: 49 additions & 0 deletions tests/src/python/test_qgsblendmodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def __init__(self, methodName):
self.mPolygonLayer = QgsVectorLayer(myShpFile, 'Polygons', 'ogr')
self.mMapRegistry.addMapLayer(self.mPolygonLayer)

# create line layer
myShpFile = os.path.join(TEST_DATA_DIR, 'lines.shp')
self.mLineLayer = QgsVectorLayer(myShpFile, 'Lines', 'ogr')
self.mMapRegistry.addMapLayer(self.mLineLayer)

# create two raster layers
myRasterFile = os.path.join(TEST_DATA_DIR, 'landsat.tif')
self.mRasterLayer1 = QgsRasterLayer(myRasterFile, "raster1")
Expand Down Expand Up @@ -108,6 +113,50 @@ def testVectorBlending(self):
myMessage = ('vector blending failed')
assert myResult, myMessage

def testVectorFeatureBlending(self):
"""Test that feature blend modes work for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
self.mMapRenderer.setExtent(self.mPointLayer.extent())
self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Multiply)

#Set feature blending for line layer
self.mLineLayer.setFeatureBlendMode(QPainter.CompositionMode_Plus)

checker = QgsRenderChecker()
checker.setControlName("expected_vector_featureblendmodes")
checker.setMapRenderer(self.mMapRenderer)

myResult = checker.runTest("vector_featureblendmodes");
myMessage = ('vector feature blending failed')
assert myResult, myMessage

def testVectorLayerTransparency(self):
"""Test that layer transparency works for vector layers."""

#Add vector layers to map
myLayers = QStringList()
myLayers.append(self.mLineLayer.id())
myLayers.append(self.mPolygonLayer.id())
self.mMapRenderer.setLayerSet(myLayers)
self.mMapRenderer.setExtent(self.mPointLayer.extent())
self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Multiply)

#Set feature blending for line layer
self.mLineLayer.setLayerTransparency( 50 )

checker = QgsRenderChecker()
checker.setControlName("expected_vector_layertransparency")
checker.setMapRenderer(self.mMapRenderer)

myResult = checker.runTest("vector_layertransparency");
myMessage = ('vector layer transparency failed')
assert myResult, myMessage

def testRasterBlending(self):
"""Test that blend modes work for raster layers."""
#Add raster layers to map
Expand Down
6 changes: 5 additions & 1 deletion tests/src/python/test_qgscomposermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from PyQt4.QtCore import (QStringList,
QFileInfo)
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import QPainter
from PyQt4.QtGui import (QPainter,
QColor)

from qgis.core import (QgsComposerMap,
QgsRectangle,
Expand Down Expand Up @@ -76,6 +77,7 @@ def testGrid(self):
self.mComposerMap.setGridIntervalY(2000)
self.mComposerMap.setShowGridAnnotation(True)
self.mComposerMap.setGridPenWidth(0.5)
self.mComposerMap.setGridPenColor(QColor(0,255,0))
self.mComposerMap.setGridAnnotationPrecision(0)
self.mComposerMap.setGridAnnotationPosition(QgsComposerMap.Disabled,
QgsComposerMap.Left)
Expand All @@ -91,6 +93,8 @@ def testGrid(self):
QgsComposerMap.Right)
self.mComposerMap.setGridAnnotationDirection(QgsComposerMap.Horizontal,
QgsComposerMap.Bottom)
self.mComposerMap.setAnnotationFontColor(QColor(255,0,0,150))
self.mComposerMap.setGridBlendMode(QPainter.CompositionMode_Overlay)
checker = QgsCompositionChecker()
myPath = os.path.join(TEST_DATA_DIR,
'control_images',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.