QGIS API Documentation  2.15.0-Master (94d88e6)
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 
44  template<class DATATYPE, class ELEMTYPE, int NUMDIMS, class ELEMTYPEREAL, int TMAXNODES, int TMINNODES> class RTree;
45 
46  class FeaturePart;
47  class Pal;
48  class LabelInfo;
49 
55  class CORE_EXPORT Layer
56  {
57  friend class Pal;
58  friend class FeaturePart;
59 
60  friend class Problem;
61 
62  friend class LabelPosition;
63 
64  public:
65  enum LabelMode { LabelPerFeature, LabelPerFeaturePart };
67  {
68  Upright, // upside-down labels (90 <= angle < 270) are shown upright
69  ShowDefined, // show upside down when rotation is layer- or data-defined
70  ShowAll // show upside down for all labels, including dynamic ones
71  };
72 
73  virtual ~Layer();
74 
75  bool displayAll() const { return mDisplayAll; }
76 
79  int featureCount() { return mHashtable.size(); }
80 
82  QgsAbstractLabelProvider* provider() const { return mProvider; }
83 
86  QString name() const { return mName; }
87 
91  QgsPalLayerSettings::Placement arrangement() const { return mArrangement; }
92 
97  void setArrangement( QgsPalLayerSettings::Placement arrangement ) { mArrangement = arrangement; }
98 
102  LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }
103 
108  void setArrangementFlags( const LineArrangementFlags& flags ) { mArrangementFlags = flags; }
109 
120  void setActive( bool active ) { mActive = active; }
121 
125  bool active() const { return mActive; }
126 
133  void setLabelLayer( bool toLabel ) { mLabelLayer = toLabel; }
134 
138  bool labelLayer() const { return mLabelLayer; }
139 
144  QgsPalLayerSettings::ObstacleType obstacleType() const { return mObstacleType; }
145 
151  void setObstacleType( QgsPalLayerSettings::ObstacleType obstacleType ) { mObstacleType = obstacleType; }
152 
158  void setPriority( double priority );
159 
164  double priority() const { return mDefaultPriority; }
165 
170  void setLabelMode( LabelMode mode ) { mMode = mode; }
171 
175  LabelMode labelMode() const { return mMode; }
176 
181  void setMergeConnectedLines( bool merge ) { mMergeLines = merge; }
182 
186  bool mergeConnectedLines() const { return mMergeLines; }
187 
192  void setUpsidedownLabels( UpsideDownLabels ud ) { mUpsidedownLabels = ud; }
193 
197  UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
198 
205  void setCentroidInside( bool forceInside ) { mCentroidInside = forceInside; }
206 
211  bool centroidInside() const { return mCentroidInside; }
212 
220  void setFitInPolygonOnly( bool fitInPolygon ) { mFitInPolygon = fitInPolygon; }
221 
226  bool fitInPolygonOnly() const { return mFitInPolygon; }
227 
236  bool registerFeature( QgsLabelFeature* label );
237 
239  void joinConnectedFeatures();
240 
245  int connectedFeatureId( QgsFeatureId featureId ) const;
246 
248  void chopFeaturesAtRepeatDistance();
249 
250  protected:
253 
256 
259 
261 
263 
265  bool mActive;
270 
273  LineArrangementFlags mArrangementFlags;
276 
278 
279  // indexes (spatial and id)
283 
284  //obstacle r-tree
286 
290 
292 
306  Layer( QgsAbstractLabelProvider* provider, const QString& name, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll = false );
307 
309  void addFeaturePart( FeaturePart* fpart, const QString &labelText = QString() );
310 
312  void addObstaclePart( FeaturePart* fpart );
313 
314  };
315 
316 } // end namespace pal
317 
318 #endif
QHash< QgsFeatureId, int > mConnectedFeaturesIds
Definition: layer.h:289
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
Definition: layer.h:197
bool mMergeLines
Definition: layer.h:275
bool mActive
Definition: layer.h:265
bool mLabelLayer
Definition: layer.h:266
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
Definition: layer.h:255
bool active() const
Returns whether the layer is currently active.
Definition: layer.h:125
QStringList mConnectedTexts
Definition: layer.h:288
bool labelLayer() const
Returns whether the layer will be labeled or not.
Definition: layer.h:138
A set of features which influence the labelling process.
Definition: layer.h:55
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
Definition: layer.h:282
double mDefaultPriority
Definition: layer.h:262
Main Pal labelling class.
Definition: pal.h:84
UpsideDownLabels
Definition: layer.h:66
bool displayAll() const
Definition: layer.h:75
double priority() const
Returns the layer&#39;s priority, between 0 and 1.
Definition: layer.h:164
bool centroidInside() const
Returns whether labels placed at the centroid of features within the layer are forced to be placed in...
Definition: layer.h:211
void setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
Definition: layer.h:192
void setObstacleType(QgsPalLayerSettings::ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:151
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:205
void setFitInPolygonOnly(bool fitInPolygon)
Sets whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:220
QString mName
Definition: layer.h:252
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
Definition: layer.h:186
QgsPalLayerSettings::Placement arrangement() const
Returns the layer&#39;s arrangement policy.
Definition: layer.h:91
QgsPalLayerSettings::ObstacleType obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:144
void setArrangement(QgsPalLayerSettings::Placement arrangement)
Sets the layer&#39;s arrangement policy.
Definition: layer.h:97
Optional additional info about label (for curved labels)
Definition: feature.h:52
int featureCount()
Returns the number of features in layer.
Definition: layer.h:79
QgsAbstractLabelProvider * provider() const
Returns pointer to the associated provider.
Definition: layer.h:82
bool mCentroidInside
Definition: layer.h:268
QgsPalLayerSettings::ObstacleType mObstacleType
Definition: layer.h:264
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
Definition: layer.h:258
Main class to handle feature.
Definition: feature.h:90
The QgsAbstractLabelProvider class is an interface class.
void setArrangementFlags(const LineArrangementFlags &flags)
Sets the layer&#39;s arrangement flags.
Definition: layer.h:108
bool fitInPolygonOnly() const
Returns whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:226
LineArrangementFlags mArrangementFlags
Definition: layer.h:273
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
Definition: layer.h:285
Placement
Placement modes which determine how label candidates are generated for a feature. ...
Pal * pal
Definition: layer.h:260
QHash< QString, QLinkedList< FeaturePart * > * > mConnectedHashtable
Definition: layer.h:287
LabelMode
Definition: layer.h:65
bool mDisplayAll
Definition: layer.h:267
void setActive(bool active)
Sets whether the layer is currently active.
Definition: layer.h:120
void setLabelLayer(bool toLabel)
Sets whether the layer will be labeled.
Definition: layer.h:133
QgsAbstractLabelProvider * mProvider
Definition: layer.h:251
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:280
void setLabelMode(LabelMode mode)
Sets the layer&#39;s labeling mode.
Definition: layer.h:170
QMutex mMutex
Definition: layer.h:291
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
QString name() const
Returns the layer&#39;s name.
Definition: layer.h:86
LineArrangementFlags arrangementFlags() const
Returns the layer&#39;s arrangement flags.
Definition: layer.h:102
LabelMode mMode
Definition: layer.h:274
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Representation of a labeling problem.
Definition: problem.h:99
QgsPalLayerSettings::Placement mArrangement
Optional flags used for some placement methods.
Definition: layer.h:272
bool mFitInPolygon
Definition: layer.h:269
LabelMode labelMode() const
Returns the layer&#39;s labeling mode.
Definition: layer.h:175
UpsideDownLabels mUpsidedownLabels
Definition: layer.h:277
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
Definition: layer.h:181
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels...