Skip to content

Commit 34a2ca0

Browse files
committedAug 8, 2019
[needs-docs][labeling] Drop setting to control label solution method
from project labeling settings This is an unnecessary setting, resulting in 1000's of extra, very complex and untested lines of code. Furthermore, the differences are almost non-existant and it's extremely unlikely end users would (or should) need to change this setting.
1 parent 6fd35f6 commit 34a2ca0

File tree

9 files changed

+74
-1695
lines changed

9 files changed

+74
-1695
lines changed
 

‎python/core/auto_generated/qgslabelingenginesettings.sip.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Stores global configuration for labeling engine
3333
typedef QFlags<QgsLabelingEngineSettings::Flag> Flags;
3434

3535

36+
3637
enum Search
3738
{
3839
Chain,
@@ -75,13 +76,18 @@ Gets number of candidate positions that will be generated for each label feature
7576
Sets number of candidate positions that will be generated for each label feature
7677
%End
7778

78-
void setSearchMethod( Search s );
79+
void setSearchMethod( Search s ) /Deprecated/;
7980
%Docstring
80-
Sets which search method to use for removal collisions between labels
81+
Used to set which search method to use for removal collisions between labels
82+
83+
.. deprecated:: since QGIS 3.10 - Chain is always used.
8184
%End
82-
Search searchMethod() const;
85+
86+
Search searchMethod() const /Deprecated/;
8387
%Docstring
8488
Which search method to use for removal collisions between labels
89+
90+
.. deprecated:: since QGIS 3.10 - Chain is always used.
8591
%End
8692

8793
void readSettingsFromProject( QgsProject *project );

‎src/app/qgslabelengineconfigdialog.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
3333

3434
QgsLabelingEngineSettings engineSettings = QgsProject::instance()->labelingEngineSettings();
3535

36-
// search method
37-
cboSearchMethod->setCurrentIndex( engineSettings.searchMethod() );
38-
3936
mTextRenderFormatComboBox->addItem( tr( "Always Render Labels as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
4037
mTextRenderFormatComboBox->addItem( tr( "Always Render Labels as Text" ), QgsRenderContext::TextFormatAlwaysText );
4138

@@ -64,8 +61,6 @@ void QgsLabelEngineConfigDialog::onOK()
6461
QgsLabelingEngineSettings engineSettings;
6562

6663
// save
67-
engineSettings.setSearchMethod( static_cast< QgsLabelingEngineSettings::Search >( cboSearchMethod->currentIndex() ) );
68-
6964
engineSettings.setNumCandidatePositions( spinCandPoint->value(), spinCandLine->value(), spinCandPolygon->value() );
7065

7166
engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, chkShowCandidates->isChecked() );
@@ -85,7 +80,6 @@ void QgsLabelEngineConfigDialog::onOK()
8580
void QgsLabelEngineConfigDialog::setDefaults()
8681
{
8782
pal::Pal p;
88-
cboSearchMethod->setCurrentIndex( static_cast<int>( p.getSearch() ) );
8983
spinCandPoint->setValue( p.getPointP() );
9084
spinCandLine->setValue( p.getLineP() );
9185
spinCandPolygon->setValue( p.getPolyP() );

‎src/core/pal/pal.cpp

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,6 @@ Pal::Pal()
4949
{
5050
// do not init and exit GEOS - we do it inside QGIS
5151
//initGEOS( geosNotice, geosError );
52-
53-
fnIsCanceled = nullptr;
54-
fnIsCanceledContext = nullptr;
55-
56-
ejChainDeg = 50;
57-
tenure = 10;
58-
candListSize = 0.2;
59-
60-
tabuMinIt = 3;
61-
tabuMaxIt = 4;
62-
searchMethod = POPMUSIC_CHAIN;
63-
popmusic_r = 30;
64-
65-
searchMethod = CHAIN;
66-
67-
setSearch( CHAIN );
68-
69-
point_p = 16;
70-
line_p = 50;
71-
poly_p = 30;
72-
73-
showPartial = true;
7452
}
7553

7654
void Pal::removeLayer( Layer *layer )
@@ -453,12 +431,7 @@ QList<LabelPosition *> Pal::solveProblem( Problem *prob, bool displayAll, QList<
453431

454432
try
455433
{
456-
if ( searchMethod == FALP )
457-
prob->init_sol_falp();
458-
else if ( searchMethod == CHAIN )
459-
prob->chain_search();
460-
else
461-
prob->popmusic();
434+
prob->chain_search();
462435
}
463436
catch ( InternalException::Empty & )
464437
{
@@ -555,51 +528,3 @@ bool Pal::getShowPartial()
555528
{
556529
return showPartial;
557530
}
558-
559-
SearchMethod Pal::getSearch()
560-
{
561-
return searchMethod;
562-
}
563-
564-
void Pal::setSearch( SearchMethod method )
565-
{
566-
switch ( method )
567-
{
568-
case POPMUSIC_CHAIN:
569-
searchMethod = method;
570-
popmusic_r = 30;
571-
tabuMinIt = 2;
572-
tabuMaxIt = 4;
573-
tenure = 10;
574-
ejChainDeg = 50;
575-
candListSize = 0.2;
576-
break;
577-
case CHAIN:
578-
searchMethod = method;
579-
ejChainDeg = 50;
580-
break;
581-
case POPMUSIC_TABU:
582-
searchMethod = method;
583-
popmusic_r = 25;
584-
tabuMinIt = 2;
585-
tabuMaxIt = 4;
586-
tenure = 10;
587-
ejChainDeg = 50;
588-
candListSize = 0.2;
589-
break;
590-
case POPMUSIC_TABU_CHAIN:
591-
searchMethod = method;
592-
popmusic_r = 25;
593-
tabuMinIt = 2;
594-
tabuMaxIt = 4;
595-
tenure = 10;
596-
ejChainDeg = 50;
597-
candListSize = 0.2;
598-
break;
599-
case FALP:
600-
searchMethod = method;
601-
break;
602-
}
603-
}
604-
605-

‎src/core/pal/pal.h

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,6 @@ namespace pal
208208
*/
209209
int getPolyP();
210210

211-
/**
212-
* \brief Select the search method to use.
213-
*
214-
* For interactive mapping using CHAIN is a good
215-
* idea because it is the fastest. Other methods, ordered by speedness, are POPMUSIC_TABU,
216-
* POPMUSIC_CHAIN and POPMUSIC_TABU_CHAIN, defined in pal::_searchMethod enumeration
217-
* \param method the method to use
218-
*/
219-
void setSearch( SearchMethod method );
220-
221-
/**
222-
* Returns the search method in use.
223-
*/
224-
SearchMethod getSearch();
225-
226211
private:
227212

228213
QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
@@ -232,39 +217,37 @@ namespace pal
232217
/**
233218
* \brief maximum # candidates for a point
234219
*/
235-
int point_p;
220+
int point_p = 16;
236221

237222
/**
238223
* \brief maximum # candidates for a line
239224
*/
240-
int line_p;
225+
int line_p = 50;
241226

242227
/**
243228
* \brief maximum # candidates for a polygon
244229
*/
245-
int poly_p;
246-
247-
SearchMethod searchMethod;
230+
int poly_p = 30;
248231

249232
/*
250233
* POPMUSIC Tuning
251234
*/
252-
int popmusic_r;
235+
int popmusic_r = 30;
253236

254-
int tabuMaxIt;
255-
int tabuMinIt;
237+
int tabuMaxIt = 4;
238+
int tabuMinIt = 2;
256239

257-
int ejChainDeg;
258-
int tenure;
259-
double candListSize;
240+
int ejChainDeg = 50;
241+
int tenure = 10;
242+
double candListSize = 0.2;
260243

261244
/**
262245
* \brief show partial labels (cut-off by the map canvas) or not
263246
*/
264-
bool showPartial;
247+
bool showPartial = true;
265248

266249
//! Callback that may be called from PAL to check whether the job has not been canceled in meanwhile
267-
FnIsCanceled fnIsCanceled;
250+
FnIsCanceled fnIsCanceled = nullptr;
268251
//! Application-specific context for the cancellation check function
269252
void *fnIsCanceledContext = nullptr;
270253

‎src/core/pal/problem.cpp

Lines changed: 37 additions & 1438 deletions
Large diffs are not rendered by default.

‎src/core/pal/problem.h

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,6 @@ namespace pal
5656
double cost;
5757
};
5858

59-
typedef struct _subpart
60-
{
61-
62-
/**
63-
* # of features in problem
64-
*/
65-
int probSize;
66-
67-
/**
68-
* # of features bounding the problem
69-
*/
70-
int borderSize;
71-
72-
/**
73-
* total # features (prob + border)
74-
*/
75-
int subSize;
76-
77-
/**
78-
* wrap bw sub feat and main feat
79-
*/
80-
int *sub = nullptr;
81-
82-
/**
83-
* sub solution
84-
*/
85-
int *sol = nullptr;
86-
87-
/**
88-
* first feat in sub part
89-
*/
90-
int seed;
91-
} SubPart;
92-
9359
typedef struct _chain
9460
{
9561
int degree;
@@ -140,11 +106,6 @@ namespace pal
140106

141107
void reduce();
142108

143-
/**
144-
* \brief popmusic framework
145-
*/
146-
void popmusic();
147-
148109
/**
149110
* \brief Test with very-large scale neighborhood
150111
*/
@@ -169,27 +130,6 @@ namespace pal
169130
/* useful only for postscript post-conversion*/
170131
//void toFile(char *label_file);
171132

172-
SubPart *subPart( int r, int featseed, int *isIn );
173-
174-
void initialization();
175-
176-
double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
177-
double compute_subsolution_cost( SubPart *part, int *s, int *nbOverlap );
178-
179-
/**
180-
* POPMUSIC, chain
181-
*/
182-
double popmusic_chain( SubPart *part );
183-
184-
double popmusic_tabu( SubPart *part );
185-
186-
/**
187-
*
188-
* POPMUSIC, Tabu search with chain'
189-
*
190-
*/
191-
double popmusic_tabu_chain( SubPart *part );
192-
193133
/**
194134
* \brief Basic initial solution : every feature to -1
195135
*/
@@ -247,14 +187,10 @@ namespace pal
247187
*/
248188
double bbox[4];
249189

250-
double *labelPositionCost = nullptr;
251-
int *nbOlap = nullptr;
252-
253190
QList< LabelPosition * > mLabelPositions;
254191

255192
RTree<LabelPosition *, double, 2, double> *candidates = nullptr; // index all candidates
256193
RTree<LabelPosition *, double, 2, double> *candidates_sol = nullptr; // index active candidates
257-
RTree<LabelPosition *, double, 2, double> *candidates_subsol = nullptr; // idem for subparts
258194

259195
QList< LabelPosition * > mPositionsWithNoCandidates;
260196

@@ -264,20 +200,13 @@ namespace pal
264200
double *inactiveCost = nullptr; //
265201

266202
Sol *sol = nullptr; // [nbft]
267-
int nbActive = 0;
268-
269203
double nbOverlap = 0.0;
270204

271-
int *featWrap = nullptr;
272-
273-
Chain *chain( SubPart *part, int seed );
274-
275205
Chain *chain( int seed );
276206

277207
Pal *pal = nullptr;
278208

279209
void solution_cost();
280-
void check_solution();
281210
};
282211

283212
} // namespace

‎src/core/qgslabelingengine.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,6 @@ void QgsLabelingEngine::run( QgsRenderContext &context )
190190
const QgsLabelingEngineSettings &settings = mMapSettings.labelingEngineSettings();
191191

192192
pal::Pal p;
193-
pal::SearchMethod s;
194-
switch ( settings.searchMethod() )
195-
{
196-
case QgsLabelingEngineSettings::Chain:
197-
s = pal::CHAIN;
198-
break;
199-
case QgsLabelingEngineSettings::Popmusic_Tabu:
200-
s = pal::POPMUSIC_TABU;
201-
break;
202-
case QgsLabelingEngineSettings::Popmusic_Chain:
203-
s = pal::POPMUSIC_CHAIN;
204-
break;
205-
case QgsLabelingEngineSettings::Popmusic_Tabu_Chain:
206-
s = pal::POPMUSIC_TABU_CHAIN;
207-
break;
208-
case QgsLabelingEngineSettings::Falp:
209-
s = pal::FALP;
210-
break;
211-
}
212-
p.setSearch( s );
213193

214194
// set number of candidates generated per feature
215195
int candPoint, candLine, candPolygon;

‎src/core/qgslabelingenginesettings.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define QGSLABELINGENGINESETTINGS_H
1717

1818
#include "qgis_core.h"
19+
#include "qgis_sip.h"
1920
#include "qgsrendercontext.h"
2021
#include <QFlags>
2122

@@ -42,6 +43,8 @@ class CORE_EXPORT QgsLabelingEngineSettings
4243
};
4344
Q_DECLARE_FLAGS( Flags, Flag )
4445

46+
// TODO QGIS 4 - remove
47+
4548
/**
4649
* Search methods in the PAL library to remove colliding labels
4750
* (methods have different processing speed and number of labels placed)
@@ -74,10 +77,17 @@ class CORE_EXPORT QgsLabelingEngineSettings
7477
//! Sets number of candidate positions that will be generated for each label feature
7578
void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; }
7679

77-
//! Sets which search method to use for removal collisions between labels
78-
void setSearchMethod( Search s ) { mSearchMethod = s; }
79-
//! Which search method to use for removal collisions between labels
80-
Search searchMethod() const { return mSearchMethod; }
80+
/**
81+
* Used to set which search method to use for removal collisions between labels
82+
* \deprecated since QGIS 3.10 - Chain is always used.
83+
*/
84+
Q_DECL_DEPRECATED void setSearchMethod( Search s ) SIP_DEPRECATED { Q_UNUSED( s ) }
85+
86+
/**
87+
* Which search method to use for removal collisions between labels
88+
* \deprecated since QGIS 3.10 - Chain is always used.
89+
*/
90+
Q_DECL_DEPRECATED Search searchMethod() const SIP_DEPRECATED { return Chain; }
8191

8292
//! Read configuration of the labeling engine from a project
8393
void readSettingsFromProject( QgsProject *project );

‎src/ui/qgslabelengineconfigdialog.ui

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,14 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>420</width>
10-
<height>358</height>
9+
<width>437</width>
10+
<height>426</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Automated Placement Engine</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
17-
<item>
18-
<layout class="QHBoxLayout" name="horizontalLayout">
19-
<item>
20-
<widget class="QLabel" name="label">
21-
<property name="sizePolicy">
22-
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
23-
<horstretch>0</horstretch>
24-
<verstretch>0</verstretch>
25-
</sizepolicy>
26-
</property>
27-
<property name="text">
28-
<string>Search method</string>
29-
</property>
30-
</widget>
31-
</item>
32-
<item>
33-
<widget class="QComboBox" name="cboSearchMethod">
34-
<item>
35-
<property name="text">
36-
<string>Chain (fast)</string>
37-
</property>
38-
</item>
39-
<item>
40-
<property name="text">
41-
<string>Popmusic Tabu</string>
42-
</property>
43-
</item>
44-
<item>
45-
<property name="text">
46-
<string>Popmusic Chain</string>
47-
</property>
48-
</item>
49-
<item>
50-
<property name="text">
51-
<string>Popmusic Tabu Chain</string>
52-
</property>
53-
</item>
54-
<item>
55-
<property name="text">
56-
<string>FALP (fastest)</string>
57-
</property>
58-
</item>
59-
</widget>
60-
</item>
61-
</layout>
62-
</item>
6317
<item>
6418
<layout class="QHBoxLayout" name="horizontalLayout_2">
6519
<item>
@@ -328,7 +282,6 @@
328282
</customwidget>
329283
</customwidgets>
330284
<tabstops>
331-
<tabstop>cboSearchMethod</tabstop>
332285
<tabstop>spinCandPoint</tabstop>
333286
<tabstop>spinCandLine</tabstop>
334287
<tabstop>spinCandPolygon</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.