QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 : blazek@itc.it
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 
42 typedef QList<int> QgsAttributeList;
43 
44 typedef QMap<int, QgsField> QgsFieldMap;
45 class QgsFields;
46 
52 class CORE_EXPORT QgsLabel
53 {
54  public:
55  QgsLabel( const QgsFields & fields );
56 
57  ~QgsLabel();
58 
59  /* Fields */
61  {
62  Text = 0,
84  StrikeOut, // added in 1.5
85  LabelFieldCount
86  };
87 
88  struct labelpoint
89  {
91  double angle;
92  };
93 
101  void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0 );
102 
106  void readXML( const QDomNode& node );
107 
109  void writeXML( QDomNode & label_node, QDomDocument & document ) const;
110 
112  void addRequiredFields( QgsAttributeList& fields ) const;
113 
115  void setFields( const QgsFields & fields );
116 
118  QgsFields & fields();
119 
124  QgsLabelAttributes *labelAttributes();
125 
127  void setLabelField( int attr, int fieldIndex );
128 
130  QString labelField( int attr ) const;
131 
137  QString fieldValue( int attr, QgsFeature& feature );
138 
140  void setMinScale( float theMinScale );
141  float minScale() const;
142 
144  void setMaxScale( float theMaxScale );
145  float maxScale() const;
146 
148  void setScaleBasedVisibility( bool theVisibilityFlag );
149  bool scaleBasedVisibility() const;
150 
151  private:
155  void renderLabel( QgsRenderContext &renderContext, QgsPoint point,
156  QString text, QFont font, QPen pen,
157  int dx, int dy,
158  double xoffset, double yoffset,
159  double ang,
160  int width, int height, int alignment );
161 
162  bool readLabelField( QDomElement &el, int attr, QString prefix );
163 
165  void labelPoint( std::vector<labelpoint>&, QgsFeature &feature );
166 
168  const unsigned char* labelPoint( labelpoint& point, const unsigned char* wkb, size_t wkblen );
169 
172 
175 
178 
180  std::vector<QString> mLabelField;
181 
183  std::vector<int> mLabelFieldIdx;
184 
186  float mMinScale;
188  float mMaxScale;
191 };
192 
193 #endif
QgsLabelAttributes * mLabelAttributes
Default layer attributes.
Definition: qgslabel.h:174
QColor mSelectionColor
Color to draw selected features.
Definition: qgslabel.h:171
QMap< int, QgsField > QgsFieldMap
Definition: qgslabel.h:44
Container of fields for a vector layer.
Definition: qgsfield.h:164
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict the label's visibility.
Definition: qgslabel.h:190
QgsFields mFields
Available layer fields.
Definition: qgslabel.h:177
QList< int > QgsAttributeList
Definition: qgslabel.h:36
float mMaxScale
Maximum scale at which this label should be displayed.
Definition: qgslabel.h:188
QList< int > QgsAttributeList
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:31
A class to represent a point geometry.
Definition: qgspoint.h:63
A class to render labels.
Definition: qgslabel.h:52
Contains information about the context of a rendering operation.
std::vector< int > mLabelFieldIdx
Label field indexes.
Definition: qgslabel.h:183
LabelField
Definition: qgslabel.h:60
std::vector< QString > mLabelField
Label fields.
Definition: qgslabel.h:180
A class to store attributes needed for label rendering.
float mMinScale
Minimum scale at which this label should be displayed.
Definition: qgslabel.h:186