2
2
3
3
"""
4
4
***************************************************************************
5
- test_qgssymbollayer_createsld .py
5
+ test_qgssymbollayerv2_createsld .py
6
6
---------------------
7
7
Date : July 2016
8
8
Copyright : (C) 2016 by Andrea Aime
33
33
from qgis .PyQt .QtGui import QColor
34
34
35
35
from qgis .core import (
36
- QgsSimpleMarkerSymbolLayer , QgsUnitTypes , QgsSvgMarkerSymbolLayer ,
37
- QgsFontMarkerSymbolLayer , QgsEllipseSymbolLayer , QgsSimpleLineSymbolLayer ,
38
- QgsMarkerLineSymbolLayer , QgsMarkerSymbol , QgsSimpleFillSymbolLayer , QgsSVGFillSymbolLayer ,
36
+ QgsSimpleMarkerSymbolLayerV2 , QgsSymbolV2 , QgsSvgMarkerSymbolLayerV2 ,
37
+ QgsFontMarkerSymbolLayerV2 , QgsEllipseSymbolLayerV2 , QgsSimpleLineSymbolLayerV2 ,
38
+ QgsMarkerLineSymbolLayerV2 , QgsMarkerSymbolV2 , QgsSimpleFillSymbolLayerV2 , QgsSVGFillSymbolLayer ,
39
39
QgsLinePatternFillSymbolLayer , QgsPointPatternFillSymbolLayer , QgsVectorLayer )
40
40
from qgis .testing import start_app , unittest
41
41
from utilities import unitTestDataPath
45
45
start_app ()
46
46
47
47
48
- class TestQgsSymbolLayerCreateSld (unittest .TestCase ):
48
+ class TestQgsSymbolLayerV2CreateSld (unittest .TestCase ):
49
49
50
50
"""
51
51
This class tests the creation of SLD from QGis layers
52
52
"""
53
53
54
54
def testSimpleMarkerRotation (self ):
55
- symbol = QgsSimpleMarkerSymbolLayer (
55
+ symbol = QgsSimpleMarkerSymbolLayerV2 (
56
56
'star' , QColor (255 , 0 , 0 ), QColor (0 , 255 , 0 ), 10 )
57
57
symbol .setAngle (50 )
58
58
dom , root = self .symbolToSld (symbol )
@@ -87,7 +87,7 @@ def assertFloatEquals(self, expected, actual, tol):
87
87
self .assertLess (abs (expected - actual ), tol )
88
88
89
89
def testSimpleMarkerUnitDefault (self ):
90
- symbol = QgsSimpleMarkerSymbolLayer (
90
+ symbol = QgsSimpleMarkerSymbolLayerV2 (
91
91
'star' , QColor (255 , 0 , 0 ), QColor (0 , 255 , 0 ), 10 )
92
92
symbol .setOutlineWidth (3 )
93
93
symbol .setOffset (QPointF (5 , 10 ))
@@ -110,11 +110,11 @@ def assertStrokeWidth(self, root, svgParameterIdx, expectedWidth):
110
110
expectedWidth , strokeWidth .firstChild ().nodeValue ())
111
111
112
112
def testSimpleMarkerUnitPixels (self ):
113
- symbol = QgsSimpleMarkerSymbolLayer (
113
+ symbol = QgsSimpleMarkerSymbolLayerV2 (
114
114
'star' , QColor (255 , 0 , 0 ), QColor (0 , 255 , 0 ), 10 )
115
115
symbol .setOutlineWidth (3 )
116
116
symbol .setOffset (QPointF (5 , 10 ))
117
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
117
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
118
118
dom , root = self .symbolToSld (symbol )
119
119
# print("Marker unit mm: " + root.ownerDocument().toString())
120
120
@@ -126,7 +126,7 @@ def testSimpleMarkerUnitPixels(self):
126
126
self .assertStaticDisplacement (root , 5 , 10 )
127
127
128
128
def testSvgMarkerUnitDefault (self ):
129
- symbol = QgsSvgMarkerSymbolLayer ('symbols/star.svg' , 10 , 90 )
129
+ symbol = QgsSvgMarkerSymbolLayerV2 ('symbols/star.svg' , 10 , 90 )
130
130
symbol .setOffset (QPointF (5 , 10 ))
131
131
132
132
dom , root = self .symbolToSld (symbol )
@@ -140,9 +140,9 @@ def testSvgMarkerUnitDefault(self):
140
140
self .assertStaticDisplacement (root , 18 , 36 )
141
141
142
142
def testSvgMarkerUnitPixels (self ):
143
- symbol = QgsSvgMarkerSymbolLayer ('symbols/star.svg' , 10 , 0 )
143
+ symbol = QgsSvgMarkerSymbolLayerV2 ('symbols/star.svg' , 10 , 0 )
144
144
symbol .setOffset (QPointF (5 , 10 ))
145
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
145
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
146
146
dom , root = self .symbolToSld (symbol )
147
147
# print("Svg marker unit px: " + dom.toString())
148
148
@@ -151,7 +151,7 @@ def testSvgMarkerUnitPixels(self):
151
151
self .assertStaticDisplacement (root , 5 , 10 )
152
152
153
153
def testFontMarkerUnitDefault (self ):
154
- symbol = QgsFontMarkerSymbolLayer ('sans' , ',' , 10 , QColor ('black' ), 45 )
154
+ symbol = QgsFontMarkerSymbolLayerV2 ('sans' , ',' , 10 , QColor ('black' ), 45 )
155
155
symbol .setOffset (QPointF (5 , 10 ))
156
156
dom , root = self .symbolToSld (symbol )
157
157
# print "Font marker unit mm: " + dom.toString()
@@ -162,9 +162,9 @@ def testFontMarkerUnitDefault(self):
162
162
self .assertStaticDisplacement (root , 18 , 36 )
163
163
164
164
def testFontMarkerUnitPixel (self ):
165
- symbol = QgsFontMarkerSymbolLayer ('sans' , ',' , 10 , QColor ('black' ), 45 )
165
+ symbol = QgsFontMarkerSymbolLayerV2 ('sans' , ',' , 10 , QColor ('black' ), 45 )
166
166
symbol .setOffset (QPointF (5 , 10 ))
167
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
167
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
168
168
dom , root = self .symbolToSld (symbol )
169
169
# print ("Font marker unit mm: " + dom.toString())
170
170
@@ -175,7 +175,7 @@ def testFontMarkerUnitPixel(self):
175
175
176
176
def createEllipseSymbolLayer (self ):
177
177
# No way to build it programmatically...
178
- mTestName = 'QgsEllipseSymbolLayer '
178
+ mTestName = 'QgsEllipseSymbolLayerV2 '
179
179
mFilePath = QDir .toNativeSeparators (
180
180
'%s/symbol_layer/%s.sld' % (unitTestDataPath (), mTestName ))
181
181
@@ -184,14 +184,14 @@ def createEllipseSymbolLayer(self):
184
184
mFile .open (QIODevice .ReadOnly )
185
185
mDoc .setContent (mFile , True )
186
186
mFile .close ()
187
- mSymbolLayer = QgsEllipseSymbolLayer .createFromSld (
187
+ mSymbolLayer = QgsEllipseSymbolLayerV2 .createFromSld (
188
188
mDoc .elementsByTagName ('PointSymbolizer' ).item (0 ).toElement ())
189
189
return mSymbolLayer
190
190
191
191
def testEllipseMarkerUnitDefault (self ):
192
192
symbol = self .createEllipseSymbolLayer ()
193
193
symbol .setOffset (QPointF (5 , 10 ))
194
- symbol .setOutputUnit (QgsUnitTypes . RenderMillimeters )
194
+ symbol .setOutputUnit (QgsSymbolV2 . MM )
195
195
dom , root = self .symbolToSld (symbol )
196
196
# print ("Ellipse marker unit mm: " + dom.toString())
197
197
@@ -204,7 +204,7 @@ def testEllipseMarkerUnitDefault(self):
204
204
def testEllipseMarkerUnitPixel (self ):
205
205
symbol = self .createEllipseSymbolLayer ()
206
206
symbol .setOffset (QPointF (5 , 10 ))
207
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
207
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
208
208
dom , root = self .symbolToSld (symbol )
209
209
# print ("Ellipse marker unit mm: " + dom.toString())
210
210
@@ -215,7 +215,7 @@ def testEllipseMarkerUnitPixel(self):
215
215
self .assertStaticDisplacement (root , 5 , 10 )
216
216
217
217
def testSimpleLineUnitDefault (self ):
218
- symbol = QgsSimpleLineSymbolLayer (QColor ("black" ), 1 )
218
+ symbol = QgsSimpleLineSymbolLayerV2 (QColor ("black" ), 1 )
219
219
symbol .setCustomDashVector ([10 , 10 ])
220
220
symbol .setUseCustomDashPattern (True )
221
221
symbol .setOffset (5 )
@@ -228,11 +228,11 @@ def testSimpleLineUnitDefault(self):
228
228
self .assertStaticPerpendicularOffset (root , '18' )
229
229
230
230
def testSimpleLineUnitPixel (self ):
231
- symbol = QgsSimpleLineSymbolLayer (QColor ("black" ), 1 )
231
+ symbol = QgsSimpleLineSymbolLayerV2 (QColor ("black" ), 1 )
232
232
symbol .setCustomDashVector ([10 , 10 ])
233
233
symbol .setUseCustomDashPattern (True )
234
234
symbol .setOffset (5 )
235
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
235
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
236
236
dom , root = self .symbolToSld (symbol )
237
237
238
238
# print ("Simple line px: \n" + dom.toString())
@@ -242,9 +242,9 @@ def testSimpleLineUnitPixel(self):
242
242
self .assertStaticPerpendicularOffset (root , '5' )
243
243
244
244
def testMarkLineUnitDefault (self ):
245
- symbol = QgsMarkerLineSymbolLayer ()
245
+ symbol = QgsMarkerLineSymbolLayerV2 ()
246
246
symbol .setSubSymbol (
247
- QgsMarkerSymbol .createSimple ({'color' : '#ffffff' , 'size' : '3' }))
247
+ QgsMarkerSymbolV2 .createSimple ({'color' : '#ffffff' , 'size' : '3' }))
248
248
symbol .setInterval (5 )
249
249
symbol .setOffset (5 )
250
250
dom , root = self .symbolToSld (symbol )
@@ -258,12 +258,12 @@ def testMarkLineUnitDefault(self):
258
258
self .assertStaticPerpendicularOffset (root , '18' )
259
259
260
260
def testMarkLineUnitPixels (self ):
261
- symbol = QgsMarkerLineSymbolLayer ()
261
+ symbol = QgsMarkerLineSymbolLayerV2 ()
262
262
symbol .setSubSymbol (
263
- QgsMarkerSymbol .createSimple ({'color' : '#ffffff' , 'size' : '3' }))
263
+ QgsMarkerSymbolV2 .createSimple ({'color' : '#ffffff' , 'size' : '3' }))
264
264
symbol .setInterval (5 )
265
265
symbol .setOffset (5 )
266
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
266
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
267
267
dom , root = self .symbolToSld (symbol )
268
268
269
269
# print ("Mark line px: \n" + dom.toString())
@@ -275,7 +275,7 @@ def testMarkLineUnitPixels(self):
275
275
self .assertStaticPerpendicularOffset (root , '5' )
276
276
277
277
def testSimpleFillDefault (self ):
278
- symbol = QgsSimpleFillSymbolLayer (
278
+ symbol = QgsSimpleFillSymbolLayerV2 (
279
279
QColor ('red' ), Qt .SolidPattern , QColor ('green' ), Qt .SolidLine , 5 )
280
280
symbol .setOffset (QPointF (5 , 10 ))
281
281
@@ -287,10 +287,10 @@ def testSimpleFillDefault(self):
287
287
self .assertStaticDisplacement (root , 18 , 36 )
288
288
289
289
def testSimpleFillPixels (self ):
290
- symbol = QgsSimpleFillSymbolLayer (
290
+ symbol = QgsSimpleFillSymbolLayerV2 (
291
291
QColor ('red' ), Qt .SolidPattern , QColor ('green' ), Qt .SolidLine , 5 )
292
292
symbol .setOffset (QPointF (5 , 10 ))
293
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
293
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
294
294
295
295
dom , root = self .symbolToSld (symbol )
296
296
# print ( "Simple fill px: \n" + dom.toString())
@@ -315,7 +315,7 @@ def testSvgFillDefault(self):
315
315
def testSvgFillPixel (self ):
316
316
symbol = QgsSVGFillSymbolLayer ('test/star.svg' , 10 , 45 )
317
317
symbol .setSvgOutlineWidth (3 )
318
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
318
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
319
319
320
320
dom , root = self .symbolToSld (symbol )
321
321
# print ("Svg fill px: \n" + dom.toString())
@@ -346,7 +346,7 @@ def testLineFillPixels(self):
346
346
symbol .setLineAngle (45 )
347
347
symbol .setLineWidth (1 )
348
348
symbol .setOffset (5 )
349
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
349
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
350
350
351
351
dom , root = self .symbolToSld (symbol )
352
352
# print ("Line fill px: \n" + dom.toString())
@@ -365,7 +365,7 @@ def testPointFillDefault(self):
365
365
366
366
def testPointFillpixels (self ):
367
367
symbol = QgsPointPatternFillSymbolLayer ()
368
- symbol .setOutputUnit (QgsUnitTypes . RenderPixels )
368
+ symbol .setOutputUnit (QgsSymbolV2 . Pixel )
369
369
dom , root = self .symbolToSld (symbol )
370
370
# print ("Point fill px: \n" + dom.toString())
371
371
0 commit comments