Skip to content

Commit 9e870c7

Browse files
committedMay 1, 2013
Add tests for python bindings for composer item blending and transparency
Add python bindings for composer item background
1 parent d8fd259 commit 9e870c7

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed
 

‎python/core/composer/qgscomposeritem.sip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,16 @@ class QgsComposerItem: QObject, QGraphicsRectItem
305305
@note there is not setter since one can't manually set the id*/
306306
QString uuid() const;
307307

308+
/** Gets the background color for this item
309+
* @note introduced in 2.0
310+
*/
311+
const QColor backgroundColor() const;
312+
313+
/** Sets the background color for this item
314+
* @note introduced in 2.0
315+
*/
316+
void setBackgroundColor( const QColor& backgroundColor );
317+
308318
/* Returns the current blending mode for the composer item
309319
@note added in version 1.9*/
310320
const QPainter::CompositionMode blendMode() const;

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ADD_PYTHON_TEST(PyQgsComposerHtml test_qgscomposerhtml.py)
1515
ADD_PYTHON_TEST(PyQgsComposition test_qgscomposition.py)
1616
ADD_PYTHON_TEST(PyQgsAnalysis test_qgsanalysis.py)
1717
ADD_PYTHON_TEST(PyQgsComposerMap test_qgscomposermap.py)
18+
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
1819
ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
1920
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
2021
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsComposerEffects.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = '(C) 2012 by Dr. Horst Düster / Dr. Marco Hugentobler'
10+
__date__ = '20/08/2012'
11+
__copyright__ = 'Copyright 2012, The Quantum GIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import os
16+
from PyQt4.QtCore import (QStringList,
17+
QFileInfo)
18+
from PyQt4.QtXml import QDomDocument
19+
from PyQt4.QtGui import (QPainter, QColor)
20+
21+
from qgis.core import (QgsComposerShape,
22+
QgsRectangle,
23+
QgsComposition,
24+
QgsMapRenderer
25+
)
26+
from utilities import (unitTestDataPath,
27+
getQgisTestApp,
28+
TestCase,
29+
unittest,
30+
expectedFailure
31+
)
32+
from qgscompositionchecker import QgsCompositionChecker
33+
34+
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
35+
TEST_DATA_DIR = unitTestDataPath()
36+
37+
38+
class TestQgsComposerEffects(TestCase):
39+
40+
def __init__(self, methodName):
41+
"""Run once on class initialisation."""
42+
unittest.TestCase.__init__(self, methodName)
43+
44+
# create composition
45+
self.mMapRenderer = QgsMapRenderer()
46+
self.mComposition = QgsComposition(self.mMapRenderer)
47+
self.mComposition.setPaperSize(297, 210)
48+
49+
self.mComposerRect1 = QgsComposerShape(20, 20, 150, 100, self.mComposition)
50+
self.mComposerRect1.setShapeType(QgsComposerShape.Rectangle)
51+
self.mComposerRect1.setBackgroundColor(QColor.fromRgb(255, 150, 0))
52+
self.mComposition.addComposerShape(self.mComposerRect1)
53+
54+
self.mComposerRect2 = QgsComposerShape(50, 50, 150, 100, self.mComposition)
55+
self.mComposerRect2.setShapeType(QgsComposerShape.Rectangle)
56+
self.mComposerRect2.setBackgroundColor(QColor.fromRgb(0, 100, 150))
57+
self.mComposition.addComposerShape(self.mComposerRect2)
58+
59+
def testBlendModes(self):
60+
"""Test that blend modes work for composer items."""
61+
62+
self.mComposerRect2.setBlendMode(QPainter.CompositionMode_Multiply)
63+
64+
checker = QgsCompositionChecker()
65+
myPath = os.path.join(TEST_DATA_DIR,
66+
'control_images',
67+
'expected_composereffects',
68+
'composereffect_blend.png')
69+
myTestResult, myMessage = checker.testComposition('Composer effects blending',
70+
self.mComposition, myPath)
71+
self.mComposerRect2.setBlendMode(QPainter.CompositionMode_SourceOver)
72+
73+
assert myTestResult == True, myMessage
74+
75+
def testTransparency(self):
76+
"""Test that transparency works for composer items."""
77+
78+
self.mComposerRect2.setTransparency( 50 )
79+
80+
checker = QgsCompositionChecker()
81+
myPath = os.path.join(TEST_DATA_DIR,
82+
'control_images',
83+
'expected_composereffects',
84+
'composereffect_transparency.png')
85+
myTestResult, myMessage = checker.testComposition('Composer effects transparency',
86+
self.mComposition, myPath)
87+
self.mComposerRect2.setTransparency( 100 )
88+
89+
assert myTestResult == True, myMessage
90+
91+
if __name__ == '__main__':
92+
unittest.main()
93+

0 commit comments

Comments
 (0)
Please sign in to comment.