QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgspallabeling.h"
40 #include <QList>
41 #include <iostream>
42 #include <ctime>
43 #include <QMutex>
44 #include <QStringList>
45 
46 // TODO ${MAJOR} ${MINOR} etc instead of 0.2
47 
49 
50 namespace pal
51 {
52  class Layer;
53  class LabelPosition;
54  class PalStat;
55  class Problem;
56  class PointSet;
57 
60  {
61  CHAIN = 0,
65  FALP = 4
66  };
67 
70  {
75  };
76  Q_DECLARE_FLAGS( LineArrangementFlags, LineArrangementFlag )
77 
78 
87  class CORE_EXPORT Pal
88  {
89  friend class Problem;
90  friend class FeaturePart;
91  friend class Layer;
92 
93  public:
94 
98  Pal();
99 
100  ~Pal();
101 
103  Pal( const Pal &other ) = delete;
105  Pal &operator=( const Pal &other ) = delete;
106 
120  Layer *addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, bool displayAll = false );
121 
127  void removeLayer( Layer *layer );
128 
129  typedef bool ( *FnIsCanceled )( void *ctx );
130 
132  void registerCancelationCallback( FnIsCanceled fnCanceled, void *context );
133 
135  inline bool isCanceled() { return fnIsCanceled ? fnIsCanceled( fnIsCanceledContext ) : false; }
136 
144  std::unique_ptr< Problem > extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
145 
146  QList<LabelPosition *> solveProblem( Problem *prob, bool displayAll );
147 
153  void setShowPartial( bool show );
154 
158  bool getShowPartial();
159 
166  void setPointP( int point_p );
167 
174  void setLineP( int line_p );
175 
182  void setPolyP( int poly_p );
183 
187  int getPointP();
188 
192  int getLineP();
193 
197  int getPolyP();
198 
207  void setSearch( SearchMethod method );
208 
212  SearchMethod getSearch();
213 
214  private:
215 
216  QHash< QgsAbstractLabelProvider *, Layer * > mLayers;
217 
218  QMutex mMutex;
219 
223  int point_p;
224 
228  int line_p;
229 
233  int poly_p;
234 
235  SearchMethod searchMethod;
236 
237  /*
238  * POPMUSIC Tuning
239  */
240  int popmusic_r;
241 
242  int tabuMaxIt;
243  int tabuMinIt;
244 
245  int ejChainDeg;
246  int tenure;
247  double candListSize;
248 
252  bool showPartial;
253 
255  FnIsCanceled fnIsCanceled;
257  void *fnIsCanceledContext = nullptr;
258 
264  std::unique_ptr< Problem > extract( const QgsRectangle &extent, const QgsGeometry &mapBoundary );
265 
270  void setPopmusicR( int r );
271 
276  void setMinIt( int min_it );
277 
282  void setMaxIt( int max_it );
283 
288  void setTenure( int tenure );
289 
294  void setEjChainDeg( int degree );
295 
300  void setCandListSize( double fact );
301 
302 
307  int getMinIt();
308 
313  int getMaxIt();
314 
315  };
316 
317 } // end namespace pal
318 
319 Q_DECLARE_OPERATORS_FOR_FLAGS( pal::LineArrangementFlags )
320 
321 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Definition: pal.h:65
A set of features which influence the labeling process.
Definition: layer.h:63
Main Pal labeling class.
Definition: pal.h:87
Is slower and best than TABU, worse and faster than TABU_CHAIN.
Definition: pal.h:64
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:104
Is a little bit better than CHAIN but slower.
Definition: pal.h:63
Is the best but slowest.
Definition: pal.h:62
bool isCanceled()
Check whether the job has been canceled.
Definition: pal.h:135
Main class to handle feature.
Definition: feature.h:96
The QgsAbstractLabelProvider class is an interface class.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
Representation of a labeling problem.
Definition: problem.h:107
LineArrangementFlag
Enumeration line arrangement flags. Flags can be combined.
Definition: pal.h:69
SearchMethod
Search method to use.
Definition: pal.h:59
Is the worst but fastest method.
Definition: pal.h:61