QGIS API Documentation  2.14.0-Essen
qgslabel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabel.h - render vector labels
3  -------------------
4  begin : August 2004
5  copyright : (C) 2004 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSLABEL_H
17 #define QGSLABEL_H
18 
19 #include <vector>
20 
21 #include <QColor>
22 #include <QList>
23 #include <QMap>
24 
25 #include "qgspoint.h"
26 
27 class QDomNode;
28 class QDomDocument;
29 class QDomElement;
30 class QString;
31 class QPainter;
32 class QPaintDevice;
33 
34 class QgsFeature;
35 class QgsField;
37 
38 #include "qgsfield.h"
39 #include "qgsrectangle.h"
40 #include "qgsrendercontext.h"
41 
43 
44 class QgsFields;
45 
51 class CORE_EXPORT QgsLabel
52 {
53  public:
54  QgsLabel( const QgsFields & fields );
55 
56  ~QgsLabel();
57 
58  /* Fields */
60  {
61  Text = 0,
84  LabelFieldCount
85  };
86 
87  struct labelpoint
88  {
90  double angle;
91  };
92 
99  void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = nullptr );
100 
104  void readXML( const QDomNode& node );
105 
107  void writeXML( QDomNode & label_node, QDomDocument & document ) const;
108 
110  void addRequiredFields( QgsAttributeList& fields ) const;
111 
113  void setFields( const QgsFields & fields );
114 
116  QgsFields & fields();
117 
122  QgsLabelAttributes *labelAttributes();
123 
125  void setLabelField( int attr, int fieldIndex );
126 
128  QString labelField( int attr ) const;
129 
135  QString fieldValue( int attr, QgsFeature& feature );
136 
138  void setMinScale( float theMinScale );
139  float minScale() const;
140 
142  void setMaxScale( float theMaxScale );
143  float maxScale() const;
144 
146  void setScaleBasedVisibility( bool theVisibilityFlag );
147  bool scaleBasedVisibility() const;
148 
149  private:
151  void renderLabel( QgsRenderContext &renderContext, QgsPoint point,
152  const QString& text, const QFont& font, const QPen& pen,
153  int dx, int dy,
154  double xoffset, double yoffset,
155  double ang,
156  int width, int height, int alignment );
157 
158  bool readLabelField( QDomElement &el, int attr, const QString& prefix );
159 
161  void labelPoint( std::vector<labelpoint>&, QgsFeature &feature );
162 
164  const unsigned char* labelPoint( labelpoint& point, const unsigned char* wkb, size_t wkblen );
165 
167  QColor mSelectionColor;
168 
170  QgsLabelAttributes *mLabelAttributes;
171 
173  QgsFields mFields;
174 
176  std::vector<QString> mLabelField;
177 
179  std::vector<int> mLabelFieldIdx;
180 
182  float mMinScale;
184  float mMaxScale;
186  bool mScaleBasedVisibility;
187 
188  QgsLabel( const QgsLabel& rh );
189  QgsLabel& operator=( const QgsLabel& rh );
190 };
191 
192 #endif
Container of fields for a vector layer.
Definition: qgsfield.h:187
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QList< int > QgsAttributeList
Definition: qgslabel.h:36
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
A class to represent a point.
Definition: qgspoint.h:65
A class to render labels.
Definition: qgslabel.h:51
Contains information about the context of a rendering operation.
LabelField
Definition: qgslabel.h:59
A class to store attributes needed for label rendering.