QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
layer.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_LAYER_H_
31 #define PAL_LAYER_H_
32 
33 #include "pal.h"
34 #include <QMutex>
35 #include <QLinkedList>
36 #include <QHash>
37 #include <fstream>
38 
39 class QgsLabelFeature;
40 
41 namespace pal
42 {
43 
45  template<class DATATYPE, class ELEMTYPE, int NUMDIMS, class ELEMTYPEREAL, int TMAXNODES, int TMINNODES> class RTree;
47 
48  class FeaturePart;
49  class Pal;
50  class LabelInfo;
51 
58  class CORE_EXPORT Layer
59  {
60  friend class Pal;
61  friend class FeaturePart;
62 
63  friend class Problem;
64 
65  friend class LabelPosition;
66 
67  public:
68  enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
70  {
71  Upright, // upside-down labels (90 <= angle < 270) are shown upright
72  ShowDefined, // show upside down when rotation is layer- or data-defined
73  ShowAll // show upside down for all labels, including dynamic ones
74  };
75 
76  virtual ~Layer();
77 
78  bool displayAll() const { return mDisplayAll; }
79 
82  int featureCount() { return mHashtable.size(); }
83 
85  QgsAbstractLabelProvider* provider() const { return mProvider; }
86 
89  QString name() const { return mName; }
90 
94  QgsPalLayerSettings::Placement arrangement() const { return mArrangement; }
95 
98  bool isCurved() const { return mArrangement == QgsPalLayerSettings::Curved || mArrangement == QgsPalLayerSettings::PerimeterCurved; }
99 
104  void setArrangement( QgsPalLayerSettings::Placement arrangement ) { mArrangement = arrangement; }
105 
109  LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }
110 
115  void setArrangementFlags( const LineArrangementFlags& flags ) { mArrangementFlags = flags; }
116 
127  void setActive( bool active ) { mActive = active; }
128 
132  bool active() const { return mActive; }
133 
140  void setLabelLayer( bool toLabel ) { mLabelLayer = toLabel; }
141 
145  bool labelLayer() const { return mLabelLayer; }
146 
151  QgsPalLayerSettings::ObstacleType obstacleType() const { return mObstacleType; }
152 
158  void setObstacleType( QgsPalLayerSettings::ObstacleType obstacleType ) { mObstacleType = obstacleType; }
159 
165  void setPriority( double priority );
166 
171  double priority() const { return mDefaultPriority; }
172 
177  void setLabelMode( LabelMode mode ) { mMode = mode; }
178 
182  LabelMode labelMode() const { return mMode; }
183 
188  void setMergeConnectedLines( bool merge ) { mMergeLines = merge; }
189 
193  bool mergeConnectedLines() const { return mMergeLines; }
194 
199  void setUpsidedownLabels( UpsideDownLabels ud ) { mUpsidedownLabels = ud; }
200 
204  UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
205 
212  void setCentroidInside( bool forceInside ) { mCentroidInside = forceInside; }
213 
218  bool centroidInside() const { return mCentroidInside; }
219 
228  bool registerFeature( QgsLabelFeature* label );
229 
231  void joinConnectedFeatures();
232 
237  int connectedFeatureId( QgsFeatureId featureId ) const;
238 
240  void chopFeaturesAtRepeatDistance();
241 
242  protected:
245 
248 
251 
253 
255 
257  bool mActive;
261 
264  LineArrangementFlags mArrangementFlags;
267 
269 
270  // indexes (spatial and id)
271  RTree<FeaturePart*, double, 2, double, 8, 4> *mFeatureIndex;
274 
275  //obstacle r-tree
276  RTree<FeaturePart*, double, 2, double, 8, 4> *mObstacleIndex;
277 
281 
283 
297  Layer( QgsAbstractLabelProvider* provider, const QString& name, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll = false );
298 
300  void addFeaturePart( FeaturePart* fpart, const QString &labelText = QString() );
301 
303  void addObstaclePart( FeaturePart* fpart );
304 
305  };
306 
307 } // end namespace pal
308 
309 #endif
bool labelLayer() const
Returns whether the layer will be labeled or not.
Definition: layer.h:145
QgsAbstractLabelProvider * provider() const
Returns pointer to the associated provider.
Definition: layer.h:85
bool centroidInside() const
Returns whether labels placed at the centroid of features within the layer are forced to be placed in...
Definition: layer.h:218
QHash< QgsFeatureId, int > mConnectedFeaturesIds
Definition: layer.h:280
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
Definition: layer.h:193
bool mMergeLines
Definition: layer.h:266
bool mActive
Definition: layer.h:257
bool mLabelLayer
Definition: layer.h:258
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
Definition: layer.h:247
QStringList mConnectedTexts
Definition: layer.h:279
A set of features which influence the labelling process.
Definition: layer.h:58
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
Definition: layer.h:273
double mDefaultPriority
Definition: layer.h:254
Main Pal labelling class.
Definition: pal.h:84
UpsideDownLabels
Definition: layer.h:69
void setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
Definition: layer.h:199
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
Definition: layer.h:204
void setObstacleType(QgsPalLayerSettings::ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:158
void setCentroidInside(bool forceInside)
Sets whether labels placed at the centroid of features within the layer are forced to be placed insid...
Definition: layer.h:212
QgsPalLayerSettings::ObstacleType obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:151
QString mName
Definition: layer.h:244
bool displayAll() const
Definition: layer.h:78
double priority() const
Returns the layer&#39;s priority, between 0 and 1.
Definition: layer.h:171
void setArrangement(QgsPalLayerSettings::Placement arrangement)
Sets the layer&#39;s arrangement policy.
Definition: layer.h:104
QgsPalLayerSettings::Placement arrangement() const
Returns the layer&#39;s arrangement policy.
Definition: layer.h:94
int featureCount()
Returns the number of features in layer.
Definition: layer.h:82
bool mCentroidInside
Definition: layer.h:260
QgsPalLayerSettings::ObstacleType mObstacleType
Definition: layer.h:256
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
Definition: layer.h:250
Main class to handle feature.
Definition: feature.h:91
The QgsAbstractLabelProvider class is an interface class.
void setArrangementFlags(const LineArrangementFlags &flags)
Sets the layer&#39;s arrangement flags.
Definition: layer.h:115
LineArrangementFlags mArrangementFlags
Definition: layer.h:264
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
Definition: layer.h:276
Placement
Placement modes which determine how label candidates are generated for a feature. ...
Pal * pal
Definition: layer.h:252
QHash< QString, QLinkedList< FeaturePart * > *> mConnectedHashtable
Definition: layer.h:278
LabelMode
Definition: layer.h:68
bool mDisplayAll
Definition: layer.h:259
void setActive(bool active)
Sets whether the layer is currently active.
Definition: layer.h:127
void setLabelLayer(bool toLabel)
Sets whether the layer will be labeled.
Definition: layer.h:140
QgsAbstractLabelProvider * mProvider
Definition: layer.h:243
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
Definition: layer.h:271
void setLabelMode(LabelMode mode)
Sets the layer&#39;s labeling mode.
Definition: layer.h:177
QMutex mMutex
Definition: layer.h:282
QString name() const
Returns the layer&#39;s name.
Definition: layer.h:89
bool active() const
Returns whether the layer is currently active.
Definition: layer.h:132
LabelPosition is a candidate feature label position.
Definition: labelposition.h:51
LabelMode mMode
Definition: layer.h:265
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Representation of a labeling problem.
Definition: problem.h:101
LineArrangementFlags arrangementFlags() const
Returns the layer&#39;s arrangement flags.
Definition: layer.h:109
QgsPalLayerSettings::Placement mArrangement
Optional flags used for some placement methods.
Definition: layer.h:263
LabelMode labelMode() const
Returns the layer&#39;s labeling mode.
Definition: layer.h:182
bool isCurved() const
Returns true if the layer has curved labels.
Definition: layer.h:98
UpsideDownLabels mUpsidedownLabels
Definition: layer.h:268
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
Definition: layer.h:188
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels...