QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
Loading...
Searching...
No Matches
pal.h
Go to the documentation of this file.
1/*
2 * libpal - Automated Placement of Labels Library
3 *
4 * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5 * University of Applied Sciences, Western Switzerland
6 * http://www.hes-so.ch
7 *
8 * Contact:
9 * maxence.laurent <at> heig-vd <dot> ch
10 * or
11 * eric.taillard <at> heig-vd <dot> ch
12 *
13 * This file is part of libpal.
14 *
15 * libpal is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * libpal is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27 *
28 */
29
30#ifndef PAL_H
31#define PAL_H
32
33
34
35#include <ctime>
36#include <iostream>
37#include <unordered_map>
38
39#include "qgis_core.h"
40#include "qgsgeometry.h"
41#include "qgsgeos.h"
42#include "qgssettingstree.h"
43
44#include <QList>
45#include <QMutex>
46#include <QString>
47#include <QStringList>
48
49#define SIP_NO_FILE
50
51using namespace Qt::StringLiterals;
52
54
55// TODO ${MAJOR} ${MINOR} etc instead of 0.2
56
60
61namespace pal
62{
63 class Layer;
64 class LabelPosition;
65 class Problem;
66 class PointSet;
67
77
87 class CORE_EXPORT Pal
88 {
89 friend class Problem;
90 friend class FeaturePart;
91 friend class Layer;
92
93 public:
94 static inline QgsSettingsTreeNode *sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( u"pal"_s );
95
99
100 Pal();
102
103 Pal( const Pal &other ) = delete;
104 Pal &operator=( const Pal &other ) = delete;
105
118 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
119
125 void removeLayer( Layer *layer );
126
128 typedef bool ( *FnIsCanceled )( void *ctx );
129
131 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
132
134 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
135
154 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
155
168 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
169
175 void setShowPartialLabels( bool show );
176
182 bool showPartialLabels() const;
183
189 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
190
196 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
197
203 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
204
210 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
211
217 Qgis::LabelPlacementEngineVersion placementVersion() const;
218
224 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
225
236 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
237
248 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
249
260 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
261
265 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
266
276 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
277
284 QList< QgsAbstractLabelingEngineRule * > rules() const { return mRules; }
285
286 private:
287
288 std::vector< std::pair< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > > mLayers;
289
290 QList< QgsAbstractLabelingEngineRule * > mRules;
291
292 QMutex mMutex;
293
294 /*
295 * POPMUSIC Tuning
296 */
297 int mPopmusicR = 30;
298
299 int mTabuMaxIt = 4;
300 int mTabuMinIt = 2;
301
302 int mEjChainDeg = 50;
303 int mTenure = 10;
304 double mCandListSize = 0.2;
305
306 unsigned int mNextCandidateId = 1;
307 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
308
312 bool mShowPartialLabels = true;
313
314 double mMaxLineCandidatesPerMapUnit = 0;
315 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
316
317 int mGlobalCandidatesLimitPoint = 0;
318 int mGlobalCandidatesLimitLine = 0;
319 int mGlobalCandidatesLimitPolygon = 0;
320
322
324 FnIsCanceled fnIsCanceled = nullptr;
326 void *fnIsCanceledContext = nullptr;
327
332 void setPopmusicR( int r );
333
338 void setMinIt( int min_it );
339
344 void setMaxIt( int max_it );
345
350 void setTenure( int tenure );
351
356 void setEjChainDeg( int degree );
357
362 void setCandListSize( double fact );
363
364
369 int getMinIt() const;
370
375 int getMaxIt() const;
376
377 };
378
379} // end namespace pal
380
381#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1227
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2945
@ Version2
Version 2 (default for new projects since QGIS 3.12).
Definition qgis.h:2947
An abstract interface class for label providers.
Abstract base class for labeling engine rules.
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
An integer settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeRendering
LabelPosition is a candidate feature label position.
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:189
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:236
static QgsSettingsTreeNode * sTreePal
Definition pal.h:94
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:203
void removeLayer(Layer *layer)
remove a layer
Definition pal.cpp:76
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:210
friend class Layer
Definition pal.h:91
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:248
bool(* FnIsCanceled)(void *ctx)
Cancellation check callback function.
Definition pal.h:128
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition pal.h:97
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition pal.h:96
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition pal.h:98
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition pal.h:196
Pal()
Definition pal.cpp:67
friend class Problem
Definition pal.h:89
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:134
Pal(const Pal &other)=delete
friend class FeaturePart
Definition pal.h:90
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
Definition pal.cpp:655
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:260
Pal & operator=(const Pal &other)=delete
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules which the labeling solution must satisfy.
Definition pal.h:284
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
add a new layer
Definition pal.cpp:94
Representation of a labeling problem.
Definition problem.h:76
SearchMethod
Search method to use.
Definition pal.h:70
@ FALP
Only initial solution.
Definition pal.h:75
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition pal.h:73
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition pal.h:74
@ CHAIN
Is the worst but fastest method.
Definition pal.h:71
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition pal.h:72