Skip to content

Commit

Permalink
Force a small minimum distance when label outside mode is used, so th…
Browse files Browse the repository at this point in the history
…at labels don't touch the polygon by default
  • Loading branch information
nyalldawson committed May 3, 2020
1 parent af9bf7e commit 17c47f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/core/labeling/qgspallabeling.cpp
Expand Up @@ -2505,10 +2505,20 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext

// when using certain placement modes, we force a tiny minimum distance. This ensures that
// candidates are created just offset from a border and avoids candidates being incorrectly flagged as colliding with neighbours
if ( placement == QgsPalLayerSettings::Line || placement == QgsPalLayerSettings::Curved || placement == QgsPalLayerSettings::PerimeterCurved )
if ( placement == QgsPalLayerSettings::Line
|| placement == QgsPalLayerSettings::Curved
|| placement == QgsPalLayerSettings::PerimeterCurved )
{
distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
}
else if ( placement == QgsPalLayerSettings::OutsidePolygons
|| ( ( placement == QgsPalLayerSettings::Horizontal
|| placement == QgsPalLayerSettings::AroundPoint
|| placement == QgsPalLayerSettings::OverPoint ||
placement == QgsPalLayerSettings::Free ) && polygonPlacementFlags() & QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon ) )
{
distance = std::max( distance, 1.0 );
}

if ( !qgsDoubleNear( distance, 0.0 ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgstextformatwidgetbase.ui
Expand Up @@ -694,7 +694,7 @@
<item>
<widget class="QStackedWidget" name="mLabelStackedWidget">
<property name="currentIndex">
<number>6</number>
<number>7</number>
</property>
<widget class="QWidget" name="mLabelPage_Text">
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down

0 comments on commit 17c47f5

Please sign in to comment.