Skip to content
Permalink
Browse files

Added tests for pointdisplacementlabels

  • Loading branch information
henrik authored and nyalldawson committed Mar 24, 2019
1 parent 99bb45e commit e8584c0cf48ea17d0d33f1db30a2f33d49361582
@@ -101,13 +101,15 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsPointDistanceRenderer

/**
* Sets a factor for increasing the label distances from the symbol.
* /since QGIS 3.8
* \param factor addition factor
* \see labelDistanceFactor()
*/
void setLabelDistanceFactor( double factor ) { mLabelDistanceFactor = factor; }

/**
* Returns the factor for label distance from the symbol.
* /since QGIS 3.8
* \see setLabelDistanceFactor()
*/
double labelDistanceFactor() const { return mLabelDistanceFactor; }
@@ -40,6 +40,8 @@
QgsUnitTypes,
QgsMapUnitScale,
QgsMarkerSymbol,
QgsCategorizedSymbolRenderer,
QgsRendererCategory,
QgsSingleSymbolRenderer,
QgsPointClusterRenderer,
QgsMapSettings,
@@ -123,6 +125,16 @@ def _checkProperties(self, r):
self.assertEqual(r.embeddedRenderer().symbol().color().name(), '#fdbf6f')
self.assertEqual(r.labelDistanceFactor(), 0.25)

def _set_categorized_renderer(self):
renderer = QgsCategorizedSymbolRenderer(attrName='Class')
sym1 = QgsMarkerSymbol.createSimple({'color': '#ff00ff', 'size': '6', 'outline_style': 'no'})
cat1 = QgsRendererCategory('Biplane', sym1, 'Big')
renderer.addCategory(cat1)
sym2 = QgsMarkerSymbol.createSimple({'color': '#ff00ff', 'size': '3', 'outline_style': 'no'})
cat2 = QgsRendererCategory(['B52', 'Jet'], sym2, 'Smaller')
renderer.addCategory(cat2)
self.renderer.setEmbeddedRenderer(renderer)

def testGettersSetters(self):
""" test getters and setters """
r = QgsPointDisplacementRenderer()
@@ -228,6 +240,74 @@ def testRenderGridAdjust(self):
renderchecker.setControlName('expected_displacement_adjust_grid')
self.assertTrue(renderchecker.runTest('expected_displacement_adjust_grid'))

def testClusterRingLabels(self):
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_ring_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_ring_labels'))

def testClusterGridLabels(self):
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
self.layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_grid_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_grid_labels'))

def testClusterConcentricLabels(self):
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
self.layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_concentric_labels')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_concentric_labels'))

def testClusterRingLabelsDifferetSizes(self):
self._set_categorized_renderer()
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_ring_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_ring_labels_diff_size'))

def testClusterGridLabelsDifferetSizes(self):
self._set_categorized_renderer()
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
self.layer.renderer().setPlacement(QgsPointDisplacementRenderer.Grid)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_grid_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_grid_labels_diff_size'))

def testClusterConcentricLabelsDifferetSizes(self):
self._set_categorized_renderer()
self.layer.renderer().setTolerance(10)
self.layer.renderer().setLabelAttributeName('Class')
self.layer.renderer().setLabelDistanceFactor(0.35)
self.layer.renderer().setPlacement(QgsPointDisplacementRenderer.ConcentricRings)
renderchecker = QgsMultiRenderChecker()
renderchecker.setMapSettings(self.mapsettings)
renderchecker.setControlPathPrefix('displacement_renderer')
renderchecker.setControlName('expected_displacement_cluster_concentric_labels_diff_size')
self.assertTrue(renderchecker.runTest('expected_displacement_cluster_concentric_labels_diff_size'))



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

0 comments on commit e8584c0

Please sign in to comment.
You can’t perform that action at this time.