Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
17 #ifndef QGSLABEL_H
18 #define QGSLABEL_H
19 
20 #include <vector>
21 
22 #include <QColor>
23 #include <QList>
24 #include <QMap>
25 
26 #include "qgspoint.h"
27 
28 class QDomNode;
29 class QDomDocument;
30 class QDomElement;
31 class QString;
32 class QPainter;
33 class QPaintDevice;
34 
35 class QgsFeature;
36 class QgsField;
38 
39 #include "qgsfield.h"
40 #include "qgsrectangle.h"
41 #include "qgsrendercontext.h"
42 
43 typedef QList<int> QgsAttributeList;
44 
45 typedef QMap<int, QgsField> QgsFieldMap;
46 
52 class CORE_EXPORT QgsLabel
53 {
54  public:
55  QgsLabel( const QgsFieldMap & 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 
106  Q_DECL_DEPRECATED void renderLabel( QPainter* painter, const QgsRectangle& viewExtent,
107  QgsCoordinateTransform* coordinateTransform,
108  const QgsMapToPixel *transform,
109  QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0,
110  double sizeScale = 1., double rasterScaleFactor = 1.0 )
111  {
113  r.setExtent( viewExtent );
114  r.setCoordinateTransform( new QgsCoordinateTransform( coordinateTransform->sourceCrs(), coordinateTransform->destCRS() ) );
115  r.setMapToPixel( *transform );
116  r.setPainter( painter );
117  r.setScaleFactor( sizeScale );
118  r.setRasterScaleFactor( rasterScaleFactor );
119  renderLabel( r, feature, selected, classAttributes );
120  }
121 
129  void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0 );
130 
134  void readXML( const QDomNode& node );
135 
137  void writeXML( QDomNode & label_node, QDomDocument & document ) const;
138 
140  void addRequiredFields( QgsAttributeList& fields ) const;
141 
143  void setFields( const QgsFieldMap & fields );
144 
146  QgsFieldMap & fields( void );
147 
151  Q_DECL_DEPRECATED QgsLabelAttributes *layerAttributes( void );
152 
157  QgsLabelAttributes *labelAttributes( void );
158 
160  void setLabelField( int attr, int fieldIndex );
161 
163  bool setLabelFieldName( int attr, QString name );
164 
166  QString labelField( int attr ) const;
167 
173  QString fieldValue( int attr, QgsFeature& feature );
174 
176  void setMinScale( float theMinScale );
177  float minScale() const;
178 
180  void setMaxScale( float theMaxScale );
181  float maxScale() const;
182 
184  void setScaleBasedVisibility( bool theVisibilityFlag );
185  bool scaleBasedVisibility() const;
186 
187  private:
191  void renderLabel( QgsRenderContext &renderContext, QgsPoint point,
192  QString text, QFont font, QPen pen,
193  int dx, int dy,
194  double xoffset, double yoffset,
195  double ang,
196  int width, int height, int alignment );
197 
198  bool readLabelField( QDomElement &el, int attr, QString prefix );
199 
201  void labelPoint( std::vector<labelpoint>&, QgsFeature &feature );
202 
204  unsigned char* labelPoint( labelpoint& point, unsigned char* wkb, size_t wkblen );
205 
208 
211 
214 
216  std::vector<QString> mLabelField;
217 
219  std::vector<int> mLabelFieldIdx;
220 
222  float mMinScale;
224  float mMaxScale;
227 };
228 
229 #endif