Add API to pal to return unplaced labels after calculating the solution

to the labeling problem

And improve dox
This commit is contained in:
Nyall Dawson 2019-07-19 14:33:59 +10:00
parent 39d4145aae
commit 4868c266e3
4 changed files with 33 additions and 5 deletions

View File

@ -455,7 +455,7 @@ std::unique_ptr<Problem> Pal::extractProblem( const QgsRectangle &extent, const
return extract( extent, mapBoundary );
}
QList<LabelPosition *> Pal::solveProblem( Problem *prob, bool displayAll )
QList<LabelPosition *> Pal::solveProblem( Problem *prob, bool displayAll, QList<LabelPosition *> *unlabeled )
{
if ( !prob )
return QList<LabelPosition *>();
@ -476,7 +476,7 @@ QList<LabelPosition *> Pal::solveProblem( Problem *prob, bool displayAll )
return QList<LabelPosition *>();
}
return prob->getSolution( displayAll );
return prob->getSolution( displayAll, unlabeled );
}

View File

@ -143,7 +143,19 @@ namespace pal
*/
std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
QList<LabelPosition *> 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<LabelPosition *> solveProblem( Problem *prob, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
/**
*\brief Set flag show partial label

View File

@ -2216,7 +2216,7 @@ bool Problem::compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 )
return l1->getWidth() * l1->getHeight() > l2->getWidth() * l2->getHeight();
}
QList<LabelPosition *> Problem::getSolution( bool returnInactive )
QList<LabelPosition *> Problem::getSolution( bool returnInactive, QList<LabelPosition *> *unlabeled )
{
int i;
QList<LabelPosition *> solList;
@ -2238,6 +2238,10 @@ QList<LabelPosition *> 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

View File

@ -150,7 +150,19 @@ namespace pal
*/
void chain_search();
QList<LabelPosition *> 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<LabelPosition *> getSolution( bool returnInactive, QList<LabelPosition *> *unlabeled = nullptr );
PalStat *getStats();