QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#define SIP_NO_FILE
34
35
36#include "qgis_core.h"
37#include "qgsgeometry.h"
38#include "qgsgeos.h"
39#include "qgssettingstree.h"
40
41#include <QList>
42#include <iostream>
43#include <ctime>
44#include <QMutex>
45#include <QStringList>
46#include <unordered_map>
47
49
50// TODO ${MAJOR} ${MINOR} etc instead of 0.2
51
55
56namespace pal
57{
58 class Layer;
59 class LabelPosition;
60 class Problem;
61 class PointSet;
62
72
82 class CORE_EXPORT Pal
83 {
84 friend class Problem;
85 friend class FeaturePart;
86 friend class Layer;
87
88 public:
89 static inline QgsSettingsTreeNode *sTreePal = QgsSettingsTree::sTreeRendering->createChildNode( QStringLiteral( "pal" ) );
90
94
95 Pal();
97
98 Pal( const Pal &other ) = delete;
99 Pal &operator=( const Pal &other ) = delete;
100
113 Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel );
114
120 void removeLayer( Layer *layer );
121
122 typedef bool ( *FnIsCanceled )( void *ctx );
123
125 void registerCancellationCallback( FnIsCanceled fnCanceled, void *context );
126
128 inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
129
148 std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context );
149
162 QList<LabelPosition *> solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<pal::LabelPosition *> *unlabeled = nullptr );
163
169 void setShowPartialLabels( bool show );
170
176 bool showPartialLabels() const;
177
183 double maximumLineCandidatesPerMapUnit() const { return mMaxLineCandidatesPerMapUnit; }
184
190 void setMaximumLineCandidatesPerMapUnit( double candidates ) { mMaxLineCandidatesPerMapUnit = candidates; }
191
197 double maximumPolygonCandidatesPerMapUnitSquared() const { return mMaxPolygonCandidatesPerMapUnitSquared; }
198
204 void setMaximumPolygonCandidatesPerMapUnitSquared( double candidates ) { mMaxPolygonCandidatesPerMapUnitSquared = candidates; }
205
211 Qgis::LabelPlacementEngineVersion placementVersion() const;
212
218 void setPlacementVersion( Qgis::LabelPlacementEngineVersion placementVersion );
219
230 int globalCandidatesLimitPoint() const { return mGlobalCandidatesLimitPoint; }
231
242 int globalCandidatesLimitLine() const { return mGlobalCandidatesLimitLine; }
243
254 int globalCandidatesLimitPolygon() const { return mGlobalCandidatesLimitPolygon; }
255
259 bool candidatesAreConflicting( const LabelPosition *lp1, const LabelPosition *lp2 ) const;
260
270 void setRules( const QList< QgsAbstractLabelingEngineRule * > &rules );
271
278 QList< QgsAbstractLabelingEngineRule * > rules() const { return mRules; }
279
280 private:
281
282 std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
283
284 QList< QgsAbstractLabelingEngineRule * > mRules;
285
286 QMutex mMutex;
287
288 /*
289 * POPMUSIC Tuning
290 */
291 int mPopmusicR = 30;
292
293 int mTabuMaxIt = 4;
294 int mTabuMinIt = 2;
295
296 int mEjChainDeg = 50;
297 int mTenure = 10;
298 double mCandListSize = 0.2;
299
300 unsigned int mNextCandidateId = 1;
301 mutable QHash< QPair< unsigned int, unsigned int >, bool > mCandidateConflicts;
302
306 bool mShowPartialLabels = true;
307
308 double mMaxLineCandidatesPerMapUnit = 0;
309 double mMaxPolygonCandidatesPerMapUnitSquared = 0;
310
311 int mGlobalCandidatesLimitPoint = 0;
312 int mGlobalCandidatesLimitLine = 0;
313 int mGlobalCandidatesLimitPolygon = 0;
314
316
318 FnIsCanceled fnIsCanceled = nullptr;
320 void *fnIsCanceledContext = nullptr;
321
326 void setPopmusicR( int r );
327
332 void setMinIt( int min_it );
333
338 void setMaxIt( int max_it );
339
344 void setTenure( int tenure );
345
350 void setEjChainDeg( int degree );
351
356 void setCandListSize( double fact );
357
358
363 int getMinIt() const;
364
369 int getMaxIt() const;
370
371 };
372
373} // end namespace pal
374
375#endif
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition qgis.h:1125
LabelPlacementEngineVersion
Labeling placement engine version.
Definition qgis.h:2733
@ Version2
Version 2 (default for new projects since QGIS 3.12)
The QgsAbstractLabelProvider class is an interface class.
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.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
static QgsSettingsTreeNode * sTreeRendering
Main class to handle feature.
Definition feature.h:65
LabelPosition is a candidate feature label position.
A set of features which influence the labeling process.
Definition layer.h:63
Main Pal labeling class.
Definition pal.h:83
double maximumLineCandidatesPerMapUnit() const
Returns the maximum number of line label candidate positions per map unit.
Definition pal.h:183
int globalCandidatesLimitPoint() const
Returns the global candidates limit for point features, or 0 if no global limit is in effect.
Definition pal.h:230
double maximumPolygonCandidatesPerMapUnitSquared() const
Returns the maximum number of polygon label candidate positions per map unit squared.
Definition pal.h:197
void setMaximumPolygonCandidatesPerMapUnitSquared(double candidates)
Sets the maximum number of polygon label candidates per map unit squared.
Definition pal.h:204
int globalCandidatesLimitLine() const
Returns the global candidates limit for line features, or 0 if no global limit is in effect.
Definition pal.h:242
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition pal.h:92
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition pal.h:91
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition pal.h:93
void setMaximumLineCandidatesPerMapUnit(double candidates)
Sets the maximum number of line label candidates per map unit.
Definition pal.h:190
bool isCanceled()
Check whether the job has been canceled.
Definition pal.h:128
Pal(const Pal &other)=delete
int globalCandidatesLimitPolygon() const
Returns the global candidates limit for polygon features, or 0 if no global limit is in effect.
Definition pal.h:254
Pal & operator=(const Pal &other)=delete
QList< QgsAbstractLabelingEngineRule * > rules() const
Returns the rules which the labeling solution must satisify.
Definition pal.h:278
Representation of a labeling problem.
Definition problem.h:73
SearchMethod
Search method to use.
Definition pal.h:65
@ FALP
Only initial solution.
Definition pal.h:70
@ POPMUSIC_TABU
Is a little bit better than CHAIN but slower.
Definition pal.h:68
@ POPMUSIC_CHAIN
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition pal.h:69
@ CHAIN
Is the worst but fastest method.
Definition pal.h:66
@ POPMUSIC_TABU_CHAIN
Is the best but slowest.
Definition pal.h:67