diff --git a/src/core/pal/pal.cpp b/src/core/pal/pal.cpp index bfc04433d57..d429940b574 100644 --- a/src/core/pal/pal.cpp +++ b/src/core/pal/pal.cpp @@ -455,7 +455,7 @@ std::unique_ptr Pal::extractProblem( const QgsRectangle &extent, const return extract( extent, mapBoundary ); } -QList Pal::solveProblem( Problem *prob, bool displayAll ) +QList Pal::solveProblem( Problem *prob, bool displayAll, QList *unlabeled ) { if ( !prob ) return QList(); @@ -476,7 +476,7 @@ QList Pal::solveProblem( Problem *prob, bool displayAll ) return QList(); } - return prob->getSolution( displayAll ); + return prob->getSolution( displayAll, unlabeled ); } diff --git a/src/core/pal/pal.h b/src/core/pal/pal.h index 1e8cf8778fb..6d5ff4419ed 100644 --- a/src/core/pal/pal.h +++ b/src/core/pal/pal.h @@ -143,7 +143,19 @@ namespace pal */ std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary ); - QList solveProblem( Problem *prob, bool displayAll ); + /** + * Solves the labeling problem, selecting the best candidate locations for all labels and returns a list of these + * calculated label positions. + * + * If \a displayAll is true, then the best positions for ALL labels will be returned, regardless of whether these + * labels overlap other labels. + * + * If the optional \a unlabeled list is specified, it will be filled with a list of all feature labels which could + * not be placed in the returned solution (e.g. due to overlaps or other constraints). + * + * Ownership of the returned labels is not transferred - it resides with the pal object. + */ + QList solveProblem( Problem *prob, bool displayAll, QList *unlabeled = nullptr ); /** *\brief Set flag show partial label diff --git a/src/core/pal/problem.cpp b/src/core/pal/problem.cpp index ae298b77958..6df4fae696f 100644 --- a/src/core/pal/problem.cpp +++ b/src/core/pal/problem.cpp @@ -2216,7 +2216,7 @@ bool Problem::compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 ) return l1->getWidth() * l1->getHeight() > l2->getWidth() * l2->getHeight(); } -QList Problem::getSolution( bool returnInactive ) +QList Problem::getSolution( bool returnInactive, QList *unlabeled ) { int i; QList solList; @@ -2238,6 +2238,10 @@ QList Problem::getSolution( bool returnInactive ) { solList.push_back( mLabelPositions.at( featStartId[i] ) ); // unplaced label } + else if ( unlabeled ) + { + unlabeled->push_back( mLabelPositions.at( featStartId[i] ) ); + } } // if features collide, order by size, so smaller ones appear on top diff --git a/src/core/pal/problem.h b/src/core/pal/problem.h index 2506da46372..361a92aaeb1 100644 --- a/src/core/pal/problem.h +++ b/src/core/pal/problem.h @@ -150,7 +150,19 @@ namespace pal */ void chain_search(); - QList getSolution( bool returnInactive ); + /** + * Solves the labeling problem, selecting the best candidate locations for all labels and returns a list of these + * calculated label positions. + * + * If \a returnInactive is true, then the best positions for ALL labels will be returned, regardless of whether these + * labels overlap other labels. + * + * If the optional \a unlabeled list is specified, it will be filled with a list of all feature labels which could + * not be placed in the returned solution (e.g. due to overlaps or other constraints). + * + * Ownership of the returned labels is not transferred - it resides with the pal object. + */ + QList getSolution( bool returnInactive, QList *unlabeled = nullptr ); PalStat *getStats();