Skip to content

Commit

Permalink
[needs-docs] Drop setting for maximum number of point label candidates
Browse files Browse the repository at this point in the history
This setting is easily replaced by automatically calculated, optimised
values for each separate point plcaement mode individually
  • Loading branch information
nyalldawson committed Dec 26, 2019
1 parent 4f625ce commit df102a9
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 98 deletions.
Expand Up @@ -75,13 +75,21 @@ Sets whether a particual flag is enabled

void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const;
%Docstring
Gets number of candidate positions that will be generated for each label feature (default to 8)
Gets number of candidate positions that will be generated for each label feature.

.. deprecated:: QGIS 3.12
the ``candPoint`` argument is ignored.
%End

void setNumCandidatePositions( int candPoint, int candLine, int candPolygon );
%Docstring
Sets number of candidate positions that will be generated for each label feature
Sets the number of candidate positions that will be generated for each label feature.

.. deprecated:: QGIS 3.12
the ``candPoint`` argument is ignored.
%End


void setSearchMethod( Search s ) /Deprecated/;
%Docstring
Used to set which search method to use for removal collisions between labels
Expand Down
4 changes: 1 addition & 3 deletions src/app/labeling/qgslabelengineconfigdialog.cpp
Expand Up @@ -58,7 +58,6 @@ QgsLabelEngineConfigWidget::QgsLabelEngineConfigWidget( QWidget *parent )
// candidate numbers
int candPoint, candLine, candPolygon;
engineSettings.numCandidatePositions( candPoint, candLine, candPolygon );
spinCandPoint->setValue( candPoint );
spinCandLine->setValue( candLine );
spinCandPolygon->setValue( candPolygon );

Expand Down Expand Up @@ -109,7 +108,7 @@ void QgsLabelEngineConfigWidget::apply()
QgsLabelingEngineSettings engineSettings;

// save
engineSettings.setNumCandidatePositions( spinCandPoint->value(), spinCandLine->value(), spinCandPolygon->value() );
engineSettings.setNumCandidatePositions( 0, spinCandLine->value(), spinCandPolygon->value() );

engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, chkShowCandidates->isChecked() );
engineSettings.setFlag( QgsLabelingEngineSettings::UseAllLabels, chkShowAllLabels->isChecked() );
Expand All @@ -129,7 +128,6 @@ void QgsLabelEngineConfigWidget::apply()
void QgsLabelEngineConfigWidget::setDefaults()
{
pal::Pal p;
spinCandPoint->setValue( p.maximumNumberOfPointCandidates() );
spinCandLine->setValue( p.maximumNumberOfLineCandidates() );
spinCandPolygon->setValue( p.maximumNumberOfPolygonCandidates() );
chkShowCandidates->setChecked( false );
Expand Down
1 change: 0 additions & 1 deletion src/core/labeling/qgslabelingengine.cpp
Expand Up @@ -273,7 +273,6 @@ void QgsLabelingEngine::registerLabels( QgsRenderContext &context )
// set number of candidates generated per feature
int candPoint, candLine, candPolygon;
settings.numCandidatePositions( candPoint, candLine, candPolygon );
mPal->setMaximumNumberOfPointCandidates( candPoint );
mPal->setMaximumNumberOfLineCandidates( candLine );
mPal->setMaximumNumberOfPolygonCandidates( candPolygon );

Expand Down
2 changes: 0 additions & 2 deletions src/core/labeling/qgslabelingenginesettings.cpp
Expand Up @@ -32,7 +32,6 @@ void QgsLabelingEngineSettings::readSettingsFromProject( QgsProject *prj )
{
bool saved = false;
mSearchMethod = static_cast< Search >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( Chain ), &saved ) );
mCandPoint = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), 16, &saved );
mCandLine = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), 50, &saved );
mCandPolygon = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), 30, &saved );

Expand Down Expand Up @@ -60,7 +59,6 @@ void QgsLabelingEngineSettings::readSettingsFromProject( QgsProject *prj )
void QgsLabelingEngineSettings::writeSettingsToProject( QgsProject *project )
{
project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( mSearchMethod ) );
project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), mCandPoint );
project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), mCandLine );
project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), mCandPolygon );

Expand Down
30 changes: 25 additions & 5 deletions src/core/labeling/qgslabelingenginesettings.h
Expand Up @@ -83,10 +83,28 @@ class CORE_EXPORT QgsLabelingEngineSettings
//! Sets whether a particual flag is enabled
void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; }

//! Gets number of candidate positions that will be generated for each label feature (default to 8)
void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; }
//! Sets number of candidate positions that will be generated for each label feature
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; }
/**
* Gets number of candidate positions that will be generated for each label feature.
* \deprecated Since QGIS 3.12 the \a candPoint argument is ignored.
*/
void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const
{
Q_UNUSED( candPoint )
candLine = mCandLine;
candPolygon = mCandPolygon;
}

/**
* Sets the number of candidate positions that will be generated for each label feature.
* \deprecated Since QGIS 3.12 the \a candPoint argument is ignored.
*/
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon )
{
Q_UNUSED( candPoint )
mCandLine = candLine;
mCandPolygon = candPolygon;
}


/**
* Used to set which search method to use for removal collisions between labels
Expand Down Expand Up @@ -169,7 +187,9 @@ class CORE_EXPORT QgsLabelingEngineSettings
//! search method to use for removal collisions between labels
Search mSearchMethod = Chain;
//! Number of candedate positions that will be generated for features
int mCandPoint = 16, mCandLine = 50, mCandPolygon = 30;
int mCandLine = 50, mCandPolygon = 30;



QColor mUnplacedLabelColor = QColor( 255, 0, 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/costcalculator.cpp
Expand Up @@ -189,7 +189,7 @@ void CostCalculator::setCandidateCostFromPolygon( LabelPosition *lp, PalRtree<Fe
std::size_t CostCalculator::finalizeCandidatesCosts( Feats *feat, std::size_t max_p, PalRtree<FeaturePart> *obstacles, double bbx[4], double bby[4] )
{
// If candidates list is smaller than expected
if ( max_p > feat->candidates.size() )
if ( max_p == 0 || max_p > feat->candidates.size() )
max_p = feat->candidates.size();
//
// sort candidates list, best label to worst
Expand Down
11 changes: 6 additions & 5 deletions src/core/pal/feature.cpp
Expand Up @@ -343,7 +343,7 @@ std::unique_ptr<LabelPosition> FeaturePart::createCandidatePointOnSurface( Point

std::size_t FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x, double y, std::vector< std::unique_ptr< LabelPosition > > &lPos, double angle )
{
QVector< QgsPalLayerSettings::PredefinedPointPosition > positions = mLF->predefinedPositionOrder();
const QVector< QgsPalLayerSettings::PredefinedPointPosition > positions = mLF->predefinedPositionOrder();
double labelWidth = getLabelWidth( angle );
double labelHeight = getLabelHeight( angle );
double distanceToLabel = getLabelDistance();
Expand All @@ -354,10 +354,9 @@ std::size_t FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x,

double cost = 0.0001;
int i = 0;
const auto constPositions = positions;

const std::size_t maxNumberCandidates = mLF->layer()->maximumPointLabelCandidates();
for ( QgsPalLayerSettings::PredefinedPointPosition position : constPositions )
for ( QgsPalLayerSettings::PredefinedPointPosition position : positions )
{
double alpha = 0.0;
double deltaX = 0;
Expand Down Expand Up @@ -462,7 +461,7 @@ std::size_t FeaturePart::createCandidatesAtOrderedPositionsOverPoint( double x,
lPos.emplace_back( qgis::make_unique< LabelPosition >( i, labelX, labelY, labelWidth, labelHeight, angle, cost, this, false, quadrant ) );
//TODO - tweak
cost += 0.001;
if ( lPos.size() >= maxNumberCandidates )
if ( maxNumberCandidates > 0 && lPos.size() >= maxNumberCandidates )
break;
}
++i;
Expand All @@ -477,7 +476,9 @@ std::size_t FeaturePart::createCandidatesAroundPoint( double x, double y, std::v
double labelHeight = getLabelHeight( angle );
double distanceToLabel = getLabelDistance();

const std::size_t maxNumberCandidates = mLF->layer()->maximumPointLabelCandidates();
std::size_t maxNumberCandidates = mLF->layer()->maximumPointLabelCandidates();
if ( maxNumberCandidates == 0 )
maxNumberCandidates = 16;

int icost = 0;
int inc = 2;
Expand Down
10 changes: 5 additions & 5 deletions src/core/pal/layer.h
Expand Up @@ -109,15 +109,15 @@ namespace pal
// to avoid the engine processing endlessly...
const int size = mHashtable.size();
if ( size > 1000 )
return std::min( pal->mMaxPointCandidates, 4 );
return 4;
else if ( size > 500 )
return std::min( pal->mMaxPointCandidates, 6 );
return 6;
else if ( size > 200 )
return std::min( pal->mMaxPointCandidates, 8 );
return 8;
else if ( size > 100 )
return std::min( pal->mMaxPointCandidates, 12 );
return 12;
else
return pal->mMaxPointCandidates;
return 0;
}

/**
Expand Down
19 changes: 4 additions & 15 deletions src/core/pal/pal.cpp
Expand Up @@ -93,8 +93,6 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
double bbx[4];
double bby[4];

std::size_t max_p = 0;

bbx[0] = bbx[3] = prob->mMapExtentBounds[0] = extent.xMinimum();
bby[0] = bby[1] = prob->mMapExtentBounds[1] = extent.yMinimum();
bbx[1] = bbx[2] = prob->mMapExtentBounds[2] = extent.xMaximum();
Expand Down Expand Up @@ -289,14 +287,17 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom
prob->mFeatStartId[i] = idlp;
prob->mInactiveCost[i] = std::pow( 2, 10 - 10 * feat->priority );

std::size_t max_p = 0;
switch ( feat->feature->getGeosType() )
{
case GEOS_POINT:
max_p = feat->feature->layer()->maximumPointLabelCandidates();
// no max at this stage, use all the candidates generated
break;

case GEOS_LINESTRING:
max_p = feat->feature->layer()->maximumLineLabelCandidates();
break;

case GEOS_POLYGON:
max_p = feat->feature->layer()->maximumPolygonLabelCandidates();
break;
Expand Down Expand Up @@ -442,13 +443,6 @@ QList<LabelPosition *> Pal::solveProblem( Problem *prob, bool displayAll, QList<
return prob->getSolution( displayAll, unlabeled );
}


void Pal::setMaximumNumberOfPointCandidates( int candidates )
{
if ( candidates > 0 )
this->mMaxPointCandidates = candidates;
}

void Pal::setMaximumNumberOfLineCandidates( int line_p )
{
if ( line_p > 0 )
Expand Down Expand Up @@ -500,11 +494,6 @@ void Pal::setShowPartialLabels( bool show )
this->mShowPartialLabels = show;
}

int Pal::maximumNumberOfPointCandidates() const
{
return mMaxPointCandidates;
}

int Pal::maximumNumberOfLineCandidates() const
{
return mMaxLineCandidates;
Expand Down
17 changes: 0 additions & 17 deletions src/core/pal/pal.h
Expand Up @@ -173,13 +173,6 @@ namespace pal
*/
bool showPartialLabels() const;

/**
* Sets the maximum number of candidates to generate for points features.
*
* The larger the value, the longer the labeling solution will take to calculate.
*/
void setMaximumNumberOfPointCandidates( int candidates );

/**
* Sets the maximum number of candidates to generate for line features.
*
Expand All @@ -194,11 +187,6 @@ namespace pal
*/
void setMaximumNumberOfPolygonCandidates( int candidates );

/**
* Returns the number of candidates to generate for point features.
*/
int maximumNumberOfPointCandidates() const;

/**
* Returns the number of candidates to generate for line features.
*/
Expand Down Expand Up @@ -229,11 +217,6 @@ namespace pal

QMutex mMutex;

/**
* Maximum number of candidates for a point.
*/
int mMaxPointCandidates = 16;

/**
* Maximum number of candidates for a line.
*/
Expand Down
54 changes: 12 additions & 42 deletions src/ui/labeling/qgslabelengineconfigdialog.ui
Expand Up @@ -50,24 +50,21 @@
<string>Number of Candidates</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Point</string>
</property>
<item row="0" column="1">
<widget class="QSpinBox" name="spinCandLine">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinCandPoint">
<item row="1" column="1">
<widget class="QSpinBox" name="spinCandPolygon">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
Expand All @@ -79,7 +76,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand All @@ -95,20 +92,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinCandLine">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand All @@ -124,19 +108,6 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinCandPolygon">
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -288,7 +259,6 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>spinCandPoint</tabstop>
<tabstop>spinCandLine</tabstop>
<tabstop>spinCandPolygon</tabstop>
<tabstop>mTextRenderFormatComboBox</tabstop>
Expand Down

0 comments on commit df102a9

Please sign in to comment.