Skip to content

Commit

Permalink
Fix failing tests, add tests for ordered placement
Browse files Browse the repository at this point in the history
Sponsored by Andreas Neumann
  • Loading branch information
nyalldawson committed Jan 11, 2016
1 parent 7479bf3 commit 6499439
Show file tree
Hide file tree
Showing 21 changed files with 1,360 additions and 2 deletions.
27 changes: 26 additions & 1 deletion python/core/qgspallabeling.sip
Expand Up @@ -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.
Expand Down Expand Up @@ -304,6 +322,7 @@ class QgsPalLayerSettings
RepeatDistance,
RepeatDistanceUnit,
Priority,
PredefinedPositionOrder,

// rendering
ScaleVisibility,
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/core/pal/feature.h
Expand Up @@ -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 );
Expand Down
72 changes: 72 additions & 0 deletions tests/src/python/test_qgspallabeling_placement.py
Expand Up @@ -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
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testdata/labeling/pal_features_v3.sqlite
Binary file not shown.

0 comments on commit 6499439

Please sign in to comment.