Skip to content
Permalink
Browse files

Fix failing tests, add tests for ordered placement

Sponsored by Andreas Neumann
  • Loading branch information
nyalldawson committed Jan 11, 2016
1 parent 7479bf3 commit 6499439cc5c1d0fbc67e96e7126c529a3f10472a
Showing with 1,360 additions and 2 deletions.
  1. +26 −1 python/core/qgspallabeling.sip
  2. +0 −1 src/core/pal/feature.h
  3. +72 −0 tests/src/python/test_qgspallabeling_placement.py
  4. BIN ...rol_images/expected_pal_placement/sp_point_dd_ordered_placement/sp_point_dd_ordered_placement.png
  5. BIN ...mages/expected_pal_placement/sp_point_dd_ordered_placement/sp_point_dd_ordered_placement_mask.png
  6. BIN ...l_images/expected_pal_placement/sp_point_dd_ordered_placement1/sp_point_dd_ordered_placement1.png
  7. BIN ...ges/expected_pal_placement/sp_point_dd_ordered_placement1/sp_point_dd_ordered_placement1_mask.png
  8. BIN ...control_images/expected_pal_placement/sp_point_ordered_placement1/sp_point_ordered_placement1.png
  9. BIN ...ol_images/expected_pal_placement/sp_point_ordered_placement1/sp_point_ordered_placement1_mask.png
  10. BIN ...control_images/expected_pal_placement/sp_point_ordered_placement2/sp_point_ordered_placement2.png
  11. BIN ...ol_images/expected_pal_placement/sp_point_ordered_placement2/sp_point_ordered_placement2_mask.png
  12. BIN ...control_images/expected_pal_placement/sp_point_ordered_placement3/sp_point_ordered_placement3.png
  13. BIN ...ol_images/expected_pal_placement/sp_point_ordered_placement3/sp_point_ordered_placement3_mask.png
  14. BIN ...control_images/expected_pal_placement/sp_point_ordered_placement4/sp_point_ordered_placement4.png
  15. BIN ...ol_images/expected_pal_placement/sp_point_ordered_placement4/sp_point_ordered_placement4_mask.png
  16. BIN tests/testdata/labeling/pal_features_v3.sqlite
  17. +252 −0 tests/testdata/labeling/point_ordered_obstacle1.qml
  18. +252 −0 tests/testdata/labeling/point_ordered_obstacle2.qml
  19. +252 −0 tests/testdata/labeling/point_ordered_obstacle3.qml
  20. +252 −0 tests/testdata/labeling/point_ordered_obstacle_top.qml
  21. +254 −0 tests/testdata/labeling/point_ordered_placement.qml
@@ -100,7 +100,25 @@ class QgsPalLayerSettings
Line, /**< Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon's perimeter. Applies to line or polygon layers only. */
Curved, /** Arranges candidates following the curvature of a line feature. Applies to line layers only.*/
Horizontal, /**< Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only.*/
Free /**< Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the polygon's orientation. Applies to polygon layers only.*/
Free, /**< Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the polygon's orientation. Applies to polygon layers only.*/
OrderedPositionsAroundPoint, /**< Candidates are placed in predefined positions around a point. Peference is given to positions with greatest cartographic appeal, eg top right, bottom right, etc. Applies to point layers only.*/
};

//! Positions for labels when using the QgsPalLabeling::OrderedPositionsAroundPoint placement mode
enum PredefinedPointPosition
{
TopLeft, //!< Label on top-left of point
TopSlightlyLeft, //! Label on top of point, slightly left of center
TopMiddle, //!< Label directly above point
TopSlightlyRight, //! Label on top of point, slightly right of center
TopRight, //!< Label on top-right of point
MiddleLeft, //!< Label on left of point
MiddleRight, //!< Label on right of point
BottomLeft, //!< Label on bottom-left of point
BottomSlightlyLeft, //! Label below point, slightly left of center
BottomMiddle, //!< Label directly below point
BottomSlightlyRight, //! Label below point, slightly right of center
BottomRight, //!< Label on bottom right of point
};

/** Line placement flags, which control how candidates are generated for a linear feature.
@@ -304,6 +322,7 @@ class QgsPalLayerSettings
RepeatDistance,
RepeatDistanceUnit,
Priority,
PredefinedPositionOrder,

// rendering
ScaleVisibility,
@@ -437,6 +456,12 @@ class QgsPalLayerSettings
bool centroidWhole; // whether centroid calculated from whole or visible polygon
bool centroidInside; // whether centroid-point calculated must be inside polygon

/** Ordered list of predefined label positions for points. Positions earlier
* in the list will be prioritised over later positions. Only used when the placement
* is set to QgsPalLayerSettings::OrderedPositionsAroundPoint.
*/
QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder;

/** True if only labels which completely fit within a polygon are allowed.
*/
bool fitInPolygonOnly;
@@ -147,7 +147,6 @@ namespace pal
* @param y y coordinate of the point
* @param lPos pointer to an array of candidates, will be filled by generated candidate
* @param angle orientation of the label
* @param mapShape optional geometry of source polygon
* @returns the number of generated candidates
*/
int createCandidatesAtOrderedPositionsOverPoint( double x, double y, QList<LabelPosition *> &lPos, double angle );
@@ -185,6 +185,78 @@ def test_multipolygon_obstacle(self):
self.removeMapLayer(polyLayer)
self.layer = None

def test_point_ordered_placement1(self):
# Test ordered placements for point
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.checkTest()
self.removeMapLayer(self.layer)
self.layer = None

def test_point_ordered_placement2(self):
# Test ordered placements for point (1 obstacle)
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
obstacleLayer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_obstacle1')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.checkTest()
self.removeMapLayer(obstacleLayer)
self.removeMapLayer(self.layer)
self.layer = None

def test_point_ordered_placement3(self):
# Test ordered placements for point (2 obstacle)
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
obstacleLayer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_obstacle2')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.checkTest()
self.removeMapLayer(obstacleLayer)
self.removeMapLayer(self.layer)
self.layer = None

def test_point_ordered_placement4(self):
# Test ordered placements for point (3 obstacle)
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
obstacleLayer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_obstacle3')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
self.lyr.dist = 2
self.checkTest()
self.removeMapLayer(obstacleLayer)
self.removeMapLayer(self.layer)
self.layer = None

def test_point_dd_ordered_placement(self):
# Test ordered placements for point with data defined order
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
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.checkTest()
self.removeMapLayer(self.layer)
self.lyr.removeDataDefinedProperty(QgsPalLayerSettings.PredefinedPositionOrder)
self.layer = None

def test_point_dd_ordered_placement1(self):
# Test ordered placements for point with data defined order and obstacle
self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
obstacleLayer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_obstacle_top')
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.checkTest()
self.removeMapLayer(obstacleLayer)
self.removeMapLayer(self.layer)
self.lyr.removeDataDefinedProperty(QgsPalLayerSettings.PredefinedPositionOrder)
self.layer = None

if __name__ == '__main__':
# NOTE: unless PAL_SUITE env var is set all test class methods will be run
# SEE: test_qgspallabeling_tests.suiteTests() to define suite
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 6499439

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