Quantum GIS API Documentation
1.8
|
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 #ifndef QGSLABEL_H 00017 #define QGSLABEL_H 00018 00019 #include <vector> 00020 00021 #include <QColor> 00022 #include <QList> 00023 #include <QMap> 00024 00025 #include "qgspoint.h" 00026 00027 class QDomNode; 00028 class QDomDocument; 00029 class QDomElement; 00030 class QString; 00031 class QPainter; 00032 class QPaintDevice; 00033 00034 class QgsFeature; 00035 class QgsField; 00036 class QgsLabelAttributes; 00037 00038 #include "qgsfield.h" 00039 #include "qgsrectangle.h" 00040 #include "qgsrendercontext.h" 00041 00042 typedef QList<int> QgsAttributeList; 00043 00044 typedef QMap<int, QgsField> QgsFieldMap; 00045 00051 class CORE_EXPORT QgsLabel 00052 { 00053 public: 00054 QgsLabel( const QgsFieldMap & fields ); 00055 00056 ~QgsLabel(); 00057 00058 /* Fields */ 00059 enum LabelField 00060 { 00061 Text = 0, 00062 Family, 00063 Size, 00064 SizeType, 00065 Bold, 00066 Italic, 00067 Underline, 00068 Color, 00069 XCoordinate, 00070 YCoordinate, 00071 XOffset, 00072 YOffset, 00073 Angle, 00074 Alignment, 00075 BufferEnabled, 00076 BufferSize, 00077 BufferColor, 00078 BufferBrush, 00079 BorderWidth, 00080 BorderColor, 00081 BorderStyle, 00082 MultilineEnabled, 00083 StrikeOut, // added in 1.5 00084 LabelFieldCount 00085 }; 00086 00087 struct labelpoint 00088 { 00089 QgsPoint p; 00090 double angle; 00091 }; 00092 00105 Q_DECL_DEPRECATED void renderLabel( QPainter* painter, const QgsRectangle& viewExtent, 00106 QgsCoordinateTransform* coordinateTransform, 00107 const QgsMapToPixel *transform, 00108 QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0, 00109 double sizeScale = 1., double rasterScaleFactor = 1.0 ) 00110 { 00111 QgsRenderContext r; 00112 r.setExtent( viewExtent ); 00113 r.setCoordinateTransform( new QgsCoordinateTransform( coordinateTransform->sourceCrs(), coordinateTransform->destCRS() ) ); 00114 r.setMapToPixel( *transform ); 00115 r.setPainter( painter ); 00116 r.setScaleFactor( sizeScale ); 00117 r.setRasterScaleFactor( rasterScaleFactor ); 00118 renderLabel( r, feature, selected, classAttributes ); 00119 } 00120 00128 void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0 ); 00129 00133 void readXML( const QDomNode& node ); 00134 00136 void writeXML( QDomNode & label_node, QDomDocument & document ) const; 00137 00139 void addRequiredFields( QgsAttributeList& fields ) const; 00140 00142 void setFields( const QgsFieldMap & fields ); 00143 00145 QgsFieldMap & fields( void ); 00146 00150 Q_DECL_DEPRECATED QgsLabelAttributes *layerAttributes( void ); 00151 00156 QgsLabelAttributes *labelAttributes( void ); 00157 00159 void setLabelField( int attr, int fieldIndex ); 00160 00162 QString labelField( int attr ) const; 00163 00169 QString fieldValue( int attr, QgsFeature& feature ); 00170 00172 void setMinScale( float theMinScale ); 00173 float minScale() const; 00174 00176 void setMaxScale( float theMaxScale ); 00177 float maxScale() const; 00178 00180 void setScaleBasedVisibility( bool theVisibilityFlag ); 00181 bool scaleBasedVisibility() const; 00182 00183 private: 00187 void renderLabel( QgsRenderContext &renderContext, QgsPoint point, 00188 QString text, QFont font, QPen pen, 00189 int dx, int dy, 00190 double xoffset, double yoffset, 00191 double ang, 00192 int width, int height, int alignment ); 00193 00194 bool readLabelField( QDomElement &el, int attr, QString prefix ); 00195 00197 void labelPoint( std::vector<labelpoint>&, QgsFeature &feature ); 00198 00200 unsigned char* labelPoint( labelpoint& point, unsigned char* wkb, size_t wkblen ); 00201 00203 QColor mSelectionColor; 00204 00206 QgsLabelAttributes *mLabelAttributes; 00207 00209 QgsFieldMap mField; 00210 00212 std::vector<QString> mLabelField; 00213 00215 std::vector<int> mLabelFieldIdx; 00216 00218 float mMinScale; 00220 float mMaxScale; 00222 bool mScaleBasedVisibility; 00223 }; 00224 00225 #endif