|
QGIS API Documentation
master-59fd5e0
|
00001 /*************************************************************************** 00002 qgslabel.h - render vector labels 00003 ------------------- 00004 begin : August 2004 00005 copyright : (C) 2004 by Radim Blazek 00006 email : blazek@itc.it 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 class QgsFields; 00046 00052 class CORE_EXPORT QgsLabel 00053 { 00054 public: 00055 QgsLabel( const QgsFields & 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 00101 void renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes = 0 ); 00102 00106 void readXML( const QDomNode& node ); 00107 00109 void writeXML( QDomNode & label_node, QDomDocument & document ) const; 00110 00112 void addRequiredFields( QgsAttributeList& fields ) const; 00113 00115 void setFields( const QgsFields & fields ); 00116 00118 QgsFields & fields(); 00119 00124 QgsLabelAttributes *labelAttributes(); 00125 00127 void setLabelField( int attr, int fieldIndex ); 00128 00130 QString labelField( int attr ) const; 00131 00137 QString fieldValue( int attr, QgsFeature& feature ); 00138 00140 void setMinScale( float theMinScale ); 00141 float minScale() const; 00142 00144 void setMaxScale( float theMaxScale ); 00145 float maxScale() const; 00146 00148 void setScaleBasedVisibility( bool theVisibilityFlag ); 00149 bool scaleBasedVisibility() const; 00150 00151 private: 00155 void renderLabel( QgsRenderContext &renderContext, QgsPoint point, 00156 QString text, QFont font, QPen pen, 00157 int dx, int dy, 00158 double xoffset, double yoffset, 00159 double ang, 00160 int width, int height, int alignment ); 00161 00162 bool readLabelField( QDomElement &el, int attr, QString prefix ); 00163 00165 void labelPoint( std::vector<labelpoint>&, QgsFeature &feature ); 00166 00168 unsigned char* labelPoint( labelpoint& point, unsigned char* wkb, size_t wkblen ); 00169 00171 QColor mSelectionColor; 00172 00174 QgsLabelAttributes *mLabelAttributes; 00175 00177 QgsFields mFields; 00178 00180 std::vector<QString> mLabelField; 00181 00183 std::vector<int> mLabelFieldIdx; 00184 00186 float mMinScale; 00188 float mMaxScale; 00190 bool mScaleBasedVisibility; 00191 }; 00192 00193 #endif