Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for python bindings for composer item blending and transpar…
…ency

Add python bindings for composer item background
  • Loading branch information
nyalldawson committed May 1, 2013
1 parent d8fd259 commit 9e870c7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/core/composer/qgscomposeritem.sip
Expand Up @@ -305,6 +305,16 @@ class QgsComposerItem: QObject, QGraphicsRectItem
@note there is not setter since one can't manually set the id*/
QString uuid() const;

/** Gets the background color for this item
* @note introduced in 2.0
*/
const QColor backgroundColor() const;

/** Sets the background color for this item
* @note introduced in 2.0
*/
void setBackgroundColor( const QColor& backgroundColor );

/* Returns the current blending mode for the composer item
@note added in version 1.9*/
const QPainter::CompositionMode blendMode() const;
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -15,6 +15,7 @@ ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py)
ADD_PYTHON_TEST(PyQgsAnalysis test_qgsanalysis.py)
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
Expand Down
93 changes: 93 additions & 0 deletions tests/src/python/test_qgscomposereffects.py
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsComposerEffects.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '(C) 2012 by Dr. Horst Düster / Dr. Marco Hugentobler'
__date__ = '20/08/2012'
__copyright__ = 'Copyright 2012, The Quantum GIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import (QStringList,
QFileInfo)
from PyQt4.QtXml import QDomDocument
from PyQt4.QtGui import (QPainter, QColor)

from qgis.core import (QgsComposerShape,
QgsRectangle,
QgsComposition,
QgsMapRenderer
)
from utilities import (unitTestDataPath,
getQgisTestApp,
TestCase,
unittest,
expectedFailure
)
from qgscompositionchecker import QgsCompositionChecker

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsComposerEffects(TestCase):

def __init__(self, methodName):
"""Run once on class initialisation."""
unittest.TestCase.__init__(self, methodName)

# create composition
self.mMapRenderer = QgsMapRenderer()
self.mComposition = QgsComposition(self.mMapRenderer)
self.mComposition.setPaperSize(297, 210)

self.mComposerRect1 = QgsComposerShape(20, 20, 150, 100, self.mComposition)
self.mComposerRect1.setShapeType(QgsComposerShape.Rectangle)
self.mComposerRect1.setBackgroundColor(QColor.fromRgb(255, 150, 0))
self.mComposition.addComposerShape(self.mComposerRect1)

self.mComposerRect2 = QgsComposerShape(50, 50, 150, 100, self.mComposition)
self.mComposerRect2.setShapeType(QgsComposerShape.Rectangle)
self.mComposerRect2.setBackgroundColor(QColor.fromRgb(0, 100, 150))
self.mComposition.addComposerShape(self.mComposerRect2)

def testBlendModes(self):
"""Test that blend modes work for composer items."""

self.mComposerRect2.setBlendMode(QPainter.CompositionMode_Multiply)

checker = QgsCompositionChecker()
myPath = os.path.join(TEST_DATA_DIR,
'control_images',
'expected_composereffects',
'composereffect_blend.png')
myTestResult, myMessage = checker.testComposition('Composer effects blending',
self.mComposition, myPath)
self.mComposerRect2.setBlendMode(QPainter.CompositionMode_SourceOver)

assert myTestResult == True, myMessage

def testTransparency(self):
"""Test that transparency works for composer items."""

self.mComposerRect2.setTransparency( 50 )

checker = QgsCompositionChecker()
myPath = os.path.join(TEST_DATA_DIR,
'control_images',
'expected_composereffects',
'composereffect_transparency.png')
myTestResult, myMessage = checker.testComposition('Composer effects transparency',
self.mComposition, myPath)
self.mComposerRect2.setTransparency( 100 )

assert myTestResult == True, myMessage

if __name__ == '__main__':
unittest.main()

0 comments on commit 9e870c7

Please sign in to comment.