[labels] Ensure that we show labels where we've ripped away all the candidates

when showing "unplaced labels"
This commit is contained in:
Nyall Dawson 2019-12-02 16:25:33 +10:00
parent 2c7f89a769
commit 435287260c
2 changed files with 18 additions and 5 deletions

View File

@ -389,15 +389,26 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
{
// v2 placement rips out candidates where the candidate cost is too high when compared to
// their inactive cost
feat->candidates.erase( std::remove_if( feat->candidates.begin(), feat->candidates.end(), [ & ]( std::unique_ptr< LabelPosition > &candidate )
// note, we start this at the SECOND candidate (you'll see why after this loop)
feat->candidates.erase( std::remove_if( feat->candidates.begin() + 1, feat->candidates.end(), [ & ]( std::unique_ptr< LabelPosition > &candidate )
{
if ( candidate->hasHardObstacleConflict() )
{
feat->candidates.back()->removeFromIndex( prob->mAllCandidatesIndex );
candidate->removeFromIndex( prob->mAllCandidatesIndex );
return true;
}
return false;
} ), feat->candidates.end() );
if ( feat->candidates.size() == 1 && feat->candidates[ 0 ]->hasHardObstacleConflict() )
{
// we've ended up removing ALL candidates for this label. Oh well, that's allowed. We just need to
// make sure we move this last candidate to the unplaced labels list
feat->candidates.front()->removeFromIndex( prob->mAllCandidatesIndex );
prob->positionsWithNoCandidates()->emplace_back( std::move( feat->candidates.front() ) );
feat->candidates.clear();
}
}
}

View File

@ -752,14 +752,16 @@ QList<LabelPosition *> Problem::getSolution( bool returnInactive, QList<LabelPos
solList.push_back( mLabelPositions[ mSol.activeLabelIds[i] ].get() ); // active labels
}
else if ( returnInactive
|| mLabelPositions.at( mFeatStartId[i] )->getFeaturePart()->layer()->displayAll()
|| mLabelPositions.at( mFeatStartId[i] )->getFeaturePart()->alwaysShow() )
|| ( mFeatStartId[i] < static_cast< int >( mLabelPositions.size() ) &&
( mLabelPositions.at( mFeatStartId[i] )->getFeaturePart()->layer()->displayAll()
|| mLabelPositions.at( mFeatStartId[i] )->getFeaturePart()->alwaysShow() ) ) )
{
solList.push_back( mLabelPositions[ mFeatStartId[i] ].get() ); // unplaced label
}
else if ( unlabeled )
{
unlabeled->push_back( mLabelPositions[ mFeatStartId[i] ].get() );
if ( mFeatStartId[i] < static_cast< int >( mLabelPositions.size() ) )
unlabeled->push_back( mLabelPositions[ mFeatStartId[i] ].get() );
}
}