QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 "palgeometry.h"
35 #include <QMutex>
36 #include <QLinkedList>
37 #include <QHash>
38 #include <fstream>
39 
40 namespace pal
41 {
42 
43  template<class DATATYPE, class ELEMTYPE, int NUMDIMS, class ELEMTYPEREAL, int TMAXNODES, int TMINNODES> class RTree;
44 
45  class Feature;
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 features->size(); }
83 
86  QString name() const { return mName; }
87 
91  Arrangement arrangement() const { return mArrangement; }
92 
97  void setArrangement( Arrangement arrangement ) { mArrangement = arrangement; }
98 
102  LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }
103 
108  void setArrangementFlags( 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 
146  void setObstacle( bool obstacle ) { mObstacle = obstacle; }
147 
151  bool obstacle() const { return mObstacle; }
152 
157  ObstacleType obstacleType() const { return mObstacleType; }
158 
164  void setObstacleType( ObstacleType obstacleType ) { mObstacleType = obstacleType; }
165 
171  void setPriority( double priority );
172 
177  double priority() const { return mDefaultPriority; }
178 
183  void setLabelMode( LabelMode mode ) { mMode = mode; }
184 
188  LabelMode labelMode() const { return mMode; }
189 
194  void setMergeConnectedLines( bool merge ) { mMergeLines = merge; }
195 
199  bool mergeConnectedLines() const { return mMergeLines; }
200 
205  void setUpsidedownLabels( UpsideDownLabels ud ) { mUpsidedownLabels = ud; }
206 
210  UpsideDownLabels upsidedownLabels() const { return mUpsidedownLabels; }
211 
218  void setCentroidInside( bool forceInside ) { mCentroidInside = forceInside; }
219 
224  bool centroidInside() const { return mCentroidInside; }
225 
233  void setFitInPolygonOnly( bool fitInPolygon ) { mFitInPolygon = fitInPolygon; }
234 
239  bool fitInPolygonOnly() const { return mFitInPolygon; }
240 
263  bool registerFeature( const QString &geom_id, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
264  const QString& labelText = QString(), double labelPosX = 0.0, double labelPosY = 0.0,
265  bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
266  int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
267  bool alwaysShow = false, double repeatDistance = 0 );
268 
270  Feature* getFeature( const QString &geom_id );
271 
273  void joinConnectedFeatures();
274 
276  void chopFeaturesAtRepeatDistance();
277 
278  protected:
279  QString mName; /* unique */
280 
283 
286 
288 
290 
291  bool mObstacle;
293  bool mActive;
298 
301  LineArrangementFlags mArrangementFlags;
304 
306 
307  // indexes (spatial and id)
310 
313 
315 
329  Layer( const QString& lyrName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll = false );
330 
332  void addFeaturePart( FeaturePart* fpart, const QString &labelText = QString() );
333 
334  };
335 
336 } // end namespace pal
337 
338 #endif
void setObstacle(bool obstacle)
Sets whether features within the layer will act as obstacles for labels.
Definition: layer.h:146
UpsideDownLabels upsidedownLabels() const
Returns how upside down labels are handled within the layer.
Definition: layer.h:210
bool mMergeLines
Definition: layer.h:303
ObstacleType obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:157
bool mActive
Definition: layer.h:293
bool mLabelLayer
Definition: layer.h:294
bool active() const
Returns whether the layer is currently active.
Definition: layer.h:125
Arrangement arrangement() const
Returns the layer's arrangement policy.
Definition: layer.h:91
bool labelLayer() const
Returns whether the layer will be labeled or not.
Definition: layer.h:138
A layer of spacial entites.
Definition: layer.h:57
double mDefaultPriority
Definition: layer.h:289
void setObstacleType(ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels...
Definition: layer.h:164
Arrangement mArrangement
Optional flags used for some placement methods.
Definition: layer.h:300
Pal main class.
Definition: pal.h:109
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:177
bool centroidInside() const
Returns whether labels placed at the centroid of features within the layer are forced to be placed in...
Definition: layer.h:224
void setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
Definition: layer.h:205
QLinkedList< Feature * > * features
List of features - for deletion.
Definition: layer.h:285
bool mObstacle
Definition: layer.h:291
ObstacleType mObstacleType
Definition: layer.h:292
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:218
void setArrangement(Arrangement arrangement)
Sets the layer's arrangement policy.
Definition: layer.h:97
void setFitInPolygonOnly(bool fitInPolygon)
Sets whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:233
QString mName
Definition: layer.h:279
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
Definition: layer.h:199
bool obstacle() const
Returns whether features within the layer act as obstacles for labels.
Definition: layer.h:151
QHash< QString, QLinkedList< FeaturePart * > * > * connectedHashtable
Definition: layer.h:311
QLinkedList< FeaturePart * > * featureParts
List of feature parts.
Definition: layer.h:282
Optional additional info about label (for curved labels)
Definition: feature.h:46
int featureCount()
Returns the number of features in layer.
Definition: layer.h:82
bool mCentroidInside
Definition: layer.h:296
Main class to handle feature.
Definition: feature.h:203
bool fitInPolygonOnly() const
Returns whether labels which do not fit completely within a polygon feature are discarded.
Definition: layer.h:239
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
LineArrangementFlags mArrangementFlags
Definition: layer.h:301
bool extractFeatCallback(FeaturePart *ft_ptr, void *ctx)
Definition: pal.cpp:178
static QgsFeature getFeature(const QVariant &value, QgsExpression *parent)
Pal * pal
Definition: layer.h:287
LabelMode
Definition: layer.h:68
bool mDisplayAll
Definition: layer.h:295
Arrangement
The way to arrange labels against spatial entities.
Definition: pal.h:75
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
ObstacleType
Definition: pal.h:95
void setLabelMode(LabelMode mode)
Sets the layer's labeling mode.
Definition: layer.h:183
QMutex mMutex
Definition: layer.h:314
QLinkedList< QString > * connectedTexts
Definition: layer.h:312
LabelPosition is a candidate feature label position.
Definition: labelposition.h:48
QString name() const
Returns the layer's name.
Definition: layer.h:86
LineArrangementFlags arrangementFlags() const
Returns the layer's arrangement flags.
Definition: layer.h:102
LabelMode mMode
Definition: layer.h:302
Represent a problem.
Definition: problem.h:92
Interface that allows Pal to access user's geometries.
Definition: palgeometry.h:41
RTree< FeaturePart *, double, 2, double, 8, 4 > * rtree
Definition: layer.h:308
void setArrangementFlags(LineArrangementFlags flags)
Sets the layer's arrangement flags.
Definition: layer.h:108
QHash< QString, Feature * > * hashtable
Definition: layer.h:309
bool mFitInPolygon
Definition: layer.h:297
LabelMode labelMode() const
Returns the layer's labeling mode.
Definition: layer.h:188
UpsideDownLabels mUpsidedownLabels
Definition: layer.h:305
void setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
Definition: layer.h:194