Skip to content

Commit

Permalink
[labeling] When set to Show all Labels for a layer, use the default
Browse files Browse the repository at this point in the history
fallback candidate placement to show the label for a feature in the
case that NO candidates were registered for that feature

E.g. this fixes the situation where a line layer with lines too
short for the labels (=> no candidates for these short lines) results
in missing labels even when "Display All" is ticked.

(not a regression - it's an unhandled situation which has been around forever)
  • Loading branch information
nyalldawson committed Jun 9, 2020
1 parent 7c51d14 commit c8725af
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/pal/pal.cpp
Expand Up @@ -211,10 +211,30 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
}
else
{
// features with no candidates are recorded in the unlabeled feature list
// no candidates, so generate a default "point on surface" one
std::unique_ptr< LabelPosition > unplacedPosition = featurePart->createCandidatePointOnSurface( featurePart );
if ( unplacedPosition )
if ( !unplacedPosition )
continue;

if ( layer->displayAll() )
{
// if we are displaying all labels, we throw the default candidate in too
unplacedPosition->insertIntoIndex( allCandidatesFirstRound );
candidates.emplace_back( std::move( unplacedPosition ) );

// valid features are added to fFeats
std::unique_ptr< Feats > ft = qgis::make_unique< Feats >();
ft->feature = featurePart;
ft->shape = nullptr;
ft->candidates = std::move( candidates );
ft->priority = featurePart->calculatePriority();
features.emplace_back( std::move( ft ) );
}
else
{
// not displaying all labels for this layer, so it goes into the unlabeled feature list
prob->positionsWithNoCandidates()->emplace_back( std::move( unplacedPosition ) );
}
}
}
if ( isCanceled() )
Expand Down

0 comments on commit c8725af

Please sign in to comment.