Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add python bindings and tests for grid blending, grid annotation font…
… color, vector feature blending and vector layer transparency
  • Loading branch information
nyalldawson committed May 13, 2013
1 parent 6342b74 commit 519fe2f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
12 changes: 12 additions & 0 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -208,6 +208,11 @@ class QgsComposerMap : QgsComposerItem
@note this function was added in version 1.4*/
void setGridAnnotationFont( const QFont& f );
QFont gridAnnotationFont() const;

/**Sets font color for grid annotations
@note this function was added in version 2.0*/
void setAnnotationFontColor( const QColor& c );
QColor annotationFontColor() const;

/**Sets coordinate precision for grid annotations
@note this function was added in version 1.4*/
Expand Down Expand Up @@ -242,6 +247,13 @@ class QgsComposerMap : QgsComposerItem
@note: this function was added in version 1.9*/
void setGridFrameWidth( double w );
double gridFrameWidth() const;

/** Returns the grid's blending mode
@note added in version 2.0*/
const QPainter::CompositionMode gridBlendMode() const;
/** Sets the grid's blending mode
@note added in version 2.0*/
void setGridBlendMode( const QPainter::CompositionMode blendMode );

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
@note this function was added in version 1.4*/
Expand Down
20 changes: 19 additions & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -755,7 +755,25 @@ class QgsVectorLayer : QgsMapLayer
@note this method was added in version 1.1
*/
QgsVectorOverlay* findOverlayByType( const QString& typeName );


/* 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
*/
const QPainter::CompositionMode featureBlendMode() const;

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

//! Buffer with uncommitted editing operations. Only valid after editing has been turned on.
QgsVectorLayerEditBuffer* editBuffer();

Expand Down
49 changes: 49 additions & 0 deletions tests/src/python/test_qgsblendmodes.py
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
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

0 comments on commit 519fe2f

Please sign in to comment.