Skip to content
Permalink
Browse files
Fix tests
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent b833c24 commit f1b29406238446e370bea68b1c83933e9a407930
@@ -123,6 +123,7 @@ void QgsPropertyCollection::clear()
mDirty = false;
mHasActiveProperties = false;
mHasDynamicProperties = false;
mCount = 0;
}

void QgsPropertyCollection::setProperty( int key, const QgsProperty& property )
@@ -40,7 +40,8 @@
QgsArrowSymbolLayer,
QgsSymbol,
QgsMultiRenderChecker,
QgsDataDefined
QgsProperty,
QgsSymbolLayer
)

from qgis.testing import start_app, unittest
@@ -78,12 +79,12 @@ def tearDown(self):
def test_1(self):
sym = self.lines_layer.renderer().symbol()
sym_layer = QgsArrowSymbolLayer.create({'head_length': '6.5', 'head_thickness': '6.5'})
dd = QgsDataDefined("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty("arrow_width", dd)
dd2 = QgsDataDefined("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty("head_length", dd2)
dd3 = QgsDataDefined("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty("head_thickness", dd3)
dd = QgsProperty.fromExpression("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty(QgsSymbolLayer.PropertyArrowWidth, dd)
dd2 = QgsProperty.fromExpression("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty(QgsSymbolLayer.PropertyArrowHeadLength, dd2)
dd3 = QgsProperty.fromExpression("(@geometry_point_num % 4) * 2")
sym_layer.setDataDefinedProperty(QgsSymbolLayer.PropertyArrowHeadThickness, dd3)
fill_sym = QgsFillSymbol.createSimple({'color': '#8bcfff', 'outline_color': '#000000', 'outline_style': 'solid', 'outline_width': '1'})
sym_layer.setSubSymbol(fill_sym)
sym.changeSymbolLayer(0, sym_layer)
@@ -19,7 +19,7 @@
QgsComposition,
QgsComposerLabel,
QgsComposerObject,
QgsExpressionBasedProperty)
QgsProperty)
from qgis.PyQt.QtGui import (QColor)
start_app()

@@ -39,7 +39,7 @@ def testDataDefinedFrameColor(self):
self.assertEqual(item.frameOutlineColor(), QColor(255, 0, 0))
self.assertEqual(item.pen().color().name(), QColor(255, 0, 0).name())

item.dataDefinedProperties().setProperty(QgsComposerObject.FrameColor, QgsExpressionBasedProperty("'blue'"))
item.dataDefinedProperties().setProperty(QgsComposerObject.FrameColor, QgsProperty.fromExpression("'blue'"))
item.refreshDataDefinedProperty()
self.assertEqual(item.frameOutlineColor(), QColor(255, 0, 0)) # should not change
self.assertEqual(item.pen().color().name(), QColor(0, 0, 255).name())
@@ -57,7 +57,7 @@ def testDataDefinedBackgroundColor(self):
self.assertEqual(item.backgroundColor(), QColor(255, 0, 0))
self.assertEqual(item.brush().color().name(), QColor(255, 0, 0).name())

item.dataDefinedProperties().setProperty(QgsComposerObject.BackgroundColor, QgsExpressionBasedProperty("'blue'"))
item.dataDefinedProperties().setProperty(QgsComposerObject.BackgroundColor, QgsProperty.fromExpression("'blue'"))
item.refreshDataDefinedProperty()
self.assertEqual(item.backgroundColor(), QColor(255, 0, 0)) # should not change
self.assertEqual(item.brush().color().name(), QColor(0, 0, 255).name())
@@ -26,7 +26,7 @@
QgsRectangle,
QgsProject,
QgsComposerObject,
QgsExpressionBasedProperty
QgsProperty
)
from qgis.testing import (start_app,
unittest
@@ -215,7 +215,7 @@ def testDataDefinedTitle(self):
self.assertEqual(legend.title(), 'original')
self.assertEqual(legend.legendSettings().title(), 'original')

legend.dataDefinedProperties().setProperty(QgsComposerObject.LegendTitle, QgsExpressionBasedProperty("'new'"))
legend.dataDefinedProperties().setProperty(QgsComposerObject.LegendTitle, QgsProperty.fromExpression("'new'"))
legend.refreshDataDefinedProperty()
self.assertEqual(legend.title(), 'original')
self.assertEqual(legend.legendSettings().title(), 'new')
@@ -233,7 +233,7 @@ def testDataDefinedColumnCount(self):
self.assertEqual(legend.columnCount(), 2)
self.assertEqual(legend.legendSettings().columnCount(), 2)

legend.dataDefinedProperties().setProperty(QgsComposerObject.LegendColumnCount, QgsExpressionBasedProperty("5"))
legend.dataDefinedProperties().setProperty(QgsComposerObject.LegendColumnCount, QgsProperty.fromExpression("5"))
legend.refreshDataDefinedProperty()
self.assertEqual(legend.columnCount(), 2)
self.assertEqual(legend.legendSettings().columnCount(), 5)
@@ -23,7 +23,10 @@

from qgis.PyQt.QtCore import QThreadPool, qDebug

from qgis.core import QgsPalLayerSettings, QgsSingleSymbolRenderer, QgsMarkerSymbol
from qgis.core import (QgsPalLayerSettings,
QgsSingleSymbolRenderer,
QgsMarkerSymbol,
QgsProperty)
from utilities import getTempfilePath, renderMapToImage, mapSettingsString

from test_qgspallabeling_base import TestQgsPalLabeling, runSuite
@@ -232,7 +235,7 @@ def test_point_dd_ordered_placement(self):
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.lyr.setDataDefinedProperty(QgsPalLayerSettings.PredefinedPositionOrder, True, True, "'T,B'", None)
self.lyr.properties().setProperty(QgsPalLayerSettings.PredefinedPositionOrder, QgsProperty.fromExpression("'T,B'"))
self.checkTest()
self.removeMapLayer(self.layer)
self.lyr.removeDataDefinedProperty(QgsPalLayerSettings.PredefinedPositionOrder)
@@ -245,7 +248,7 @@ def test_point_dd_ordered_placement1(self):
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.lyr.setDataDefinedProperty(QgsPalLayerSettings.PredefinedPositionOrder, True, True, "'T,B'", None)
self.lyr.properties().setProperty(QgsPalLayerSettings.PredefinedPositionOrder, QgsProperty.fromExpression("'T,B'"))
self.checkTest()
self.removeMapLayer(obstacleLayer)
self.removeMapLayer(self.layer)
@@ -41,7 +41,8 @@
QgsSingleSymbolRenderer,
QgsPointDisplacementRenderer,
QgsMapSettings,
QgsDataDefined
QgsProperty,
QgsSymbolLayer
)
from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)
@@ -170,8 +171,8 @@ def testRenderVariables(self):
old_marker = self.layer.renderer().clusterSymbol().clone()

new_marker = QgsMarkerSymbol.createSimple({'color': '#ffff00', 'size': '3', 'outline_style': 'no'})
new_marker.symbolLayer(0).setDataDefinedProperty('color', QgsDataDefined('@cluster_color'))
new_marker.symbolLayer(0).setDataDefinedProperty('size', QgsDataDefined('@cluster_size*2'))
new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('@cluster_color'))
new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertySize, QgsProperty.fromExpression('@cluster_size*2'))
self.layer.renderer().setClusterSymbol(new_marker)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
@@ -43,7 +43,8 @@
QgsSingleSymbolRenderer,
QgsPointClusterRenderer,
QgsMapSettings,
QgsDataDefined
QgsProperty,
QgsSymbolLayer
)
from qgis.testing import start_app, unittest
from utilities import (unitTestDataPath)
@@ -193,8 +194,8 @@ def testRenderVariables(self):
old_marker = self.layer.renderer().centerSymbol().clone()

new_marker = QgsMarkerSymbol.createSimple({'color': '#ffff00', 'size': '3', 'outline_style': 'no'})
new_marker.symbolLayer(0).setDataDefinedProperty('color', QgsDataDefined('@cluster_color'))
new_marker.symbolLayer(0).setDataDefinedProperty('size', QgsDataDefined('@cluster_size*2'))
new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('@cluster_color'))
new_marker.symbolLayer(0).setDataDefinedProperty(QgsSymbolLayer.PropertySize, QgsProperty.fromExpression('@cluster_size*2'))
self.layer.renderer().setCenterSymbol(new_marker)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
@@ -37,7 +37,8 @@
QgsSingleSymbolRenderer,
QgsFillSymbol,
QgsRenderContext,
QgsDataDefined
QgsProperty,
QgsSymbolLayer
)

from qgis.testing import unittest, start_app
@@ -71,7 +72,7 @@ def testPartNum(self):
sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f'})

renderer = QgsSingleSymbolRenderer(sym1)
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty('color', QgsDataDefined('color_rgb( (@geometry_part_num - 1) * 200, 0, 0 )'))
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('color_rgb( (@geometry_part_num - 1) * 200, 0, 0 )'))
self.layer.setRenderer(renderer)

# Setup rendering check
@@ -87,7 +88,7 @@ def testPartCount(self):
sym1 = QgsFillSymbol.createSimple({'color': '#fdbf6f'})

renderer = QgsSingleSymbolRenderer(sym1)
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty('color', QgsDataDefined('color_rgb( (@geometry_part_count - 1) * 200, 0, 0 )'))
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('color_rgb( (@geometry_part_count - 1) * 200, 0, 0 )'))
self.layer.setRenderer(renderer)

# Setup rendering check
@@ -103,7 +104,7 @@ def testSymbolColor(self):
sym1 = QgsFillSymbol.createSimple({'color': '#ff0000'})

renderer = QgsSingleSymbolRenderer(sym1)
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty('color', QgsDataDefined('set_color_part( @symbol_color, \'value\', "Value" * 4)'))
renderer.symbols(QgsRenderContext())[0].symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromExpression('set_color_part( @symbol_color, \'value\', "Value" * 4)'))
self.layer.setRenderer(renderer)

# Setup rendering check
@@ -70,7 +70,7 @@
QgsProject,
QgsMultiRenderChecker,
QgsSingleSymbolRenderer,
QgsDataDefined
QgsProperty
)
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
@@ -408,7 +408,7 @@ def testRenderFillLayerDataDefined(self):
QgsProject.instance().addMapLayer(polys_layer)

layer = QgsSimpleFillSymbolLayer()
layer.setDataDefinedProperty("enabled", QgsDataDefined("Name='Lake'"))
layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLayerEnabled, QgsProperty.fromExpression("Name='Lake'"))
layer.setBorderStyle(Qt.NoPen)
layer.setColor(QColor(100, 150, 150))

@@ -473,7 +473,7 @@ def testRenderLineLayerDataDefined(self):
QgsProject.instance().addMapLayer(lines_layer)

layer = QgsSimpleLineSymbolLayer()
layer.setDataDefinedProperty("enabled", QgsDataDefined("Name='Highway'"))
layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLayerEnabled, QgsProperty.fromExpression("Name='Highway'"))
layer.setColor(QColor(100, 150, 150))
layer.setWidth(5)

@@ -536,7 +536,7 @@ def testRenderMarkerLayerDataDefined(self):
QgsProject.instance().addMapLayer(points_layer)

layer = QgsSimpleMarkerSymbolLayer()
layer.setDataDefinedProperty("enabled", QgsDataDefined("Class='Biplane'"))
layer.setDataDefinedProperty(QgsSymbolLayer.PropertyLayerEnabled, QgsProperty.fromExpression("Class='Biplane'"))
layer.setColor(QColor(100, 150, 150))
layer.setSize(5)
layer.setOutlineStyle(Qt.NoPen)

0 comments on commit f1b2940

Please sign in to comment.