QGIS API Documentation  2.12.0-Lyon
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 _LAYER_H_
31 #define _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 
57  class CORE_EXPORT Layer
58  {
59  friend class Pal;
60  friend class FeaturePart;
61 
62  friend class Problem;
63 
64  friend class LabelPosition;
65  friend bool extractFeatCallback( FeaturePart *ft_ptr, void *ctx );
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  Arrangement arrangement() const { return mArrangement; }
95 
100  void setArrangement( Arrangement arrangement ) { mArrangement = arrangement; }
101 
105  LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }
106 
111  void setArrangementFlags( const LineArrangementFlags& flags ) { mArrangementFlags = flags; }
112 
123  void setActive( bool active ) { mActive = active; }
124 
128  bool active() const { return mActive; }
129 
136  void setLabelLayer( bool toLabel ) { mLabelLayer = toLabel; }
137 
141  bool labelLayer() const { return mLabelLayer; }
142 
147  ObstacleType obstacleType() const { return mObstacleType; }
148 
154  void setObstacleType( ObstacleType obstacleType ) { mObstacleType = obstacleType; }
155 
161  void setPriority( double priority );
162 
167  double priority() const { return mDefaultPriority; }
168 
173  void setLabelMode( LabelMode mode ) { mMode = mode; }
174 
178  LabelMode labelMode() const { return mMode; }
179 
184  void setMergeConnectedLines( bool merge ) { mMergeLines = merge; }
185 
189  bool mergeConnectedLines() const { return mMergeLines; }
190 
195  void setUpsidedownLabels( UpsideDownLabels ud ) { mUpsidedownLabels = ud; }
196 
200  UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
201 
208  void setCentroidInside( bool forceInside ) { mCentroidInside = forceInside; }
209 
214  bool centroidInside() const { return mCentroidInside; }
215 
223  void setFitInPolygonOnly( bool fitInPolygon ) { mFitInPolygon = fitInPolygon; }
224 
229  bool fitInPolygonOnly() const { return mFitInPolygon; }
230 
239  bool registerFeature( QgsLabelFeature* label );
240 
242  void joinConnectedFeatures();
243 
245  void chopFeaturesAtRepeatDistance();
246 
247  protected:
250 
253 
255 
257 
259  bool mActive;
264 
267  LineArrangementFlags mArrangementFlags;
270 
272 
273  // indexes (spatial and id)
277 
280 
282 
296  Layer( QgsAbstractLabelProvider* provider, const QString& name, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll = false );
297 
299  void addFeaturePart( FeaturePart* fpart, const QString &labelText = QString() );
300 
301  };
302 
303 } // end namespace pal
304 
305 #endif
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
Definition: layer.h:200
bool mMergeLines
Definition: layer.h:269
ObstacleType obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:147
bool mActive
Definition: layer.h:259
bool mLabelLayer
Definition: layer.h:260
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
Definition: layer.h:252
bool active() const
Returns whether the layer is currently active.
Definition: layer.h:128
QStringList mConnectedTexts
Definition: layer.h:279
Arrangement arrangement() const
Returns the layer's arrangement policy.
Definition: layer.h:94
bool labelLayer() const
Returns whether the layer will be labeled or not.
Definition: layer.h:141
A layer of spacial entites.
Definition: layer.h:57
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
Definition: layer.h:276
double mDefaultPriority
Definition: layer.h:256
void setObstacleType(ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:154
Arrangement mArrangement
Optional flags used for some placement methods.
Definition: layer.h:266
Pal main class.
Definition: pal.h:111
UpsideDownLabels
Definition: layer.h:69
bool displayAll() const
Definition: layer.h:78
double priority() const
Returns the layer's priority, between 0 and 1.
Definition: layer.h:167
bool centroidInside() const
Returns whether labels placed at the centroid of features within the layer are forced to be placed in...
Definition: layer.h:214
void setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
Definition: layer.h:195
ObstacleType mObstacleType
Definition: layer.h:258
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:208
void setArrangement(Arrangement arrangement)
Sets the layer's arrangement policy.
Definition: layer.h:100
void setFitInPolygonOnly(bool fitInPolygon)
Sets whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:223
QString mName
Definition: layer.h:249
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
Definition: layer.h:189
Optional additional info about label (for curved labels)
Definition: feature.h:47
int featureCount()
Returns the number of features in layer.
Definition: layer.h:82
QgsAbstractLabelProvider * provider() const
Returns pointer to the associated provider.
Definition: layer.h:85
bool mCentroidInside
Definition: layer.h:262
Main class to handle feature.
Definition: feature.h:79
The QgsAbstractLabelProvider class is an interface class.
void setArrangementFlags(const LineArrangementFlags &flags)
Sets the layer's arrangement flags.
Definition: layer.h:111
bool fitInPolygonOnly() const
Returns whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:229
LineArrangementFlags mArrangementFlags
Definition: layer.h:267
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
Definition: pal.cpp:151
Pal * pal
Definition: layer.h:254
QHash< QString, QLinkedList< FeaturePart * > * > mConnectedHashtable
Definition: layer.h:278
LabelMode
Definition: layer.h:68
bool mDisplayAll
Definition: layer.h:261
Arrangement
The way to arrange labels against spatial entities.
Definition: pal.h:77
void setActive(bool active)
Sets whether the layer is currently active.
Definition: layer.h:123
void setLabelLayer(bool toLabel)
Sets whether the layer will be labeled.
Definition: layer.h:136
QgsAbstractLabelProvider * mProvider
Definition: layer.h:248
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
ObstacleType
Definition: pal.h:97
void setLabelMode(LabelMode mode)
Sets the layer's labeling mode.
Definition: layer.h:173
QMutex mMutex
Definition: layer.h:281
LabelPosition is a candidate feature label position.
Definition: labelposition.h:48
QString name() const
Returns the layer's name.
Definition: layer.h:89
LineArrangementFlags arrangementFlags() const
Returns the layer's arrangement flags.
Definition: layer.h:105
LabelMode mMode
Definition: layer.h:268
Represent a problem.
Definition: problem.h:93
RTree< FeaturePart *, double, 2, double, 8, 4 > * rtree
Definition: layer.h:274
bool mFitInPolygon
Definition: layer.h:263
LabelMode labelMode() const
Returns the layer's labeling mode.
Definition: layer.h:178
UpsideDownLabels mUpsidedownLabels
Definition: layer.h:271
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
Definition: layer.h:184