|
| 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