QGIS API Documentation  2.2.0-Valmiera
 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 : [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 
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