Quantum GIS API Documentation  1.7.4
src/core/qgslabel.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                          qgslabel.h - render vector labels
00003                              -------------------
00004     begin                : August 2004
00005     copyright            : (C) 2004 by Radim Blazek
00006     email                : [email protected]
00007  ***************************************************************************/
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 /* $Id$ */
00017 #ifndef QGSLABEL_H
00018 #define QGSLABEL_H
00019 
00020 #include <vector>
00021 
00022 #include <QColor>
00023 #include <QList>
00024 #include <QMap>
00025 
00026 #include "qgspoint.h"
00027 
00028 class QDomNode;
00029 class QDomDocument;
00030 class QDomElement;
00031 class QString;
00032 class QPainter;
00033 class QPaintDevice;
00034 
00035 class QgsFeature;
00036 class QgsField;
00037 class QgsLabelAttributes;
00038 
00039 #include "qgsfield.h"
00040 #include "qgsrectangle.h"
00041 #include "qgsrendercontext.h"
00042 
00043 typedef QList<int> QgsAttributeList;
00044 
00045 typedef QMap<int, QgsField> QgsFieldMap;
00046 
00052 class CORE_EXPORT QgsLabel
00053 {
00054   public:
00055     QgsLabel( const QgsFieldMap & fields );
00056 
00057     ~QgsLabel();
00058 
00059     /* Fields */
00060     enum LabelField
00061     {
00062       Text = 0,
00063       Family,
00064       Size,
00065       SizeType,
00066       Bold,
00067       Italic,
00068       Underline,
00069       Color,
00070       XCoordinate,
00071       YCoordinate,
00072       XOffset,
00073       YOffset,
00074       Angle,
00075       Alignment,
00076       BufferEnabled,
00077       BufferSize,
00078       BufferColor,
00079       BufferBrush,
00080       BorderWidth,
00081       BorderColor,
00082       BorderStyle,
00083       MultilineEnabled,
00084       StrikeOut,     // added in 1.5
00085       LabelFieldCount
00086     };
00087 
00088     struct labelpoint
00089     {
00090       QgsPoint p;
00091       double angle;
00092     };
00093 
00106     Q_DECL_DEPRECATED void renderLabel( QPainter* painter, const QgsRectangle& viewExtent,
00107                                         QgsCoordinateTransform* coordinateTransform,
00108                                         const QgsMapToPixel *transform,
00109                                         QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0,
00110                                         double sizeScale = 1., double rasterScaleFactor = 1.0 )
00111     {
00112       QgsRenderContext r;
00113       r.setExtent( viewExtent );
00114       r.setCoordinateTransform( new QgsCoordinateTransform( coordinateTransform->sourceCrs(), coordinateTransform->destCRS() ) );
00115       r.setMapToPixel( *transform );
00116       r.setPainter( painter );
00117       r.setScaleFactor( sizeScale );
00118       r.setRasterScaleFactor( rasterScaleFactor );
00119       renderLabel( r, feature, selected, classAttributes );
00120     }
00121 
00129     void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0 );
00130 
00134     void readXML( const QDomNode& node );
00135 
00137     void writeXML( QDomNode & label_node, QDomDocument & document ) const;
00138 
00140     void addRequiredFields( QgsAttributeList& fields ) const;
00141 
00143     void setFields( const QgsFieldMap & fields );
00144 
00146     QgsFieldMap & fields( void );
00147 
00151     Q_DECL_DEPRECATED QgsLabelAttributes *layerAttributes( void );
00152 
00157     QgsLabelAttributes *labelAttributes( void );
00158 
00160     void setLabelField( int attr, int fieldIndex );
00161 
00163     bool setLabelFieldName( int attr, QString name );
00164 
00166     QString labelField( int attr ) const;
00167 
00173     QString fieldValue( int attr, QgsFeature& feature );
00174 
00176     void setMinScale( float theMinScale );
00177     float minScale() const;
00178 
00180     void setMaxScale( float theMaxScale );
00181     float maxScale() const;
00182 
00184     void setScaleBasedVisibility( bool theVisibilityFlag );
00185     bool scaleBasedVisibility() const;
00186 
00187   private:
00191     void renderLabel( QgsRenderContext &renderContext, QgsPoint point,
00192                       QString text, QFont font, QPen pen,
00193                       int dx, int dy,
00194                       double xoffset, double yoffset,
00195                       double ang,
00196                       int width, int height, int alignment );
00197 
00198     bool readLabelField( QDomElement &el, int attr, QString prefix );
00199 
00201     void labelPoint( std::vector<labelpoint>&, QgsFeature &feature );
00202 
00204     unsigned char* labelPoint( labelpoint& point, unsigned char* wkb, size_t wkblen );
00205 
00207     QColor mSelectionColor;
00208 
00210     QgsLabelAttributes *mLabelAttributes;
00211 
00213     QgsFieldMap mField;
00214 
00216     std::vector<QString> mLabelField;
00217 
00219     std::vector<int> mLabelFieldIdx;
00220 
00222     float mMinScale;
00224     float mMaxScale;
00226     bool mScaleBasedVisibility;
00227 };
00228 
00229 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines