Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgsrendererv2.h 00003 --------------------- 00004 begin : November 2009 00005 copyright : (C) 2009 by Martin Dobias 00006 email : wonder.sk at gmail.com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #ifndef QGSRENDERERV2_H 00017 #define QGSRENDERERV2_H 00018 00019 #include "qgis.h" 00020 00021 #include <QList> 00022 #include <QString> 00023 #include <QVariant> 00024 #include <QPair> 00025 #include <QPixmap> 00026 #include <QDomDocument> 00027 #include <QDomElement> 00028 00029 class QgsSymbolV2; 00030 class QgsRenderContext; 00031 class QgsFeature; 00032 class QgsVectorLayer; 00033 00034 typedef QMap<QString, QString> QgsStringMap; 00035 00036 typedef QList<QgsSymbolV2*> QgsSymbolV2List; 00037 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map; 00038 00039 typedef QList< QPair<QString, QPixmap> > QgsLegendSymbologyList; 00040 typedef QList< QPair<QString, QgsSymbolV2*> > QgsLegendSymbolList; 00041 00042 #define RENDERER_TAG_NAME "renderer-v2" 00043 00045 // symbol levels 00046 00047 class CORE_EXPORT QgsSymbolV2LevelItem 00048 { 00049 public: 00050 QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer ) : mSymbol( symbol ), mLayer( layer ) {} 00051 QgsSymbolV2* symbol() { return mSymbol; } 00052 int layer() { return mLayer; } 00053 protected: 00054 QgsSymbolV2* mSymbol; 00055 int mLayer; 00056 }; 00057 00058 // every level has list of items: symbol + symbol layer num 00059 typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level; 00060 00061 // this is a list of levels 00062 typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder; 00063 00064 00066 // renderers 00067 00068 class CORE_EXPORT QgsFeatureRendererV2 00069 { 00070 public: 00071 // renderer takes ownership of its symbols! 00072 00074 static QgsFeatureRendererV2* defaultRenderer( QGis::GeometryType geomType ); 00075 00076 QString type() const { return mType; } 00077 00078 // to be overridden 00079 virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0; 00080 00081 virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ) = 0; 00082 00083 virtual void stopRender( QgsRenderContext& context ) = 0; 00084 00085 virtual QList<QString> usedAttributes() = 0; 00086 00087 virtual ~QgsFeatureRendererV2() {} 00088 00089 virtual QgsFeatureRendererV2* clone() = 0; 00090 00091 virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ); 00092 00094 virtual QString dump(); 00095 00096 enum Capabilities 00097 { 00098 SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature()) 00099 RotationField = 1 << 1, // rotate symbols by attribute value 00100 MoreSymbolsPerFeature = 1 << 2 // may use more than one symbol to render a feature: symbolsForFeature() will return them 00101 }; 00102 00105 virtual int capabilities() { return 0; } 00106 00108 virtual QgsSymbolV2List symbols() = 0; 00109 00110 bool usingSymbolLevels() const { return mUsingSymbolLevels; } 00111 void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; } 00112 00114 static QgsFeatureRendererV2* load( QDomElement& symbologyElem ); 00115 00117 virtual QDomElement save( QDomDocument& doc ); 00118 00121 virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const; 00122 00134 static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage ); 00135 00138 virtual void toSld( QDomDocument& doc, QDomElement &element ) const 00139 { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); } 00140 00142 virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize ); 00143 00146 virtual QgsLegendSymbolList legendSymbolItems(); 00147 00149 void setVertexMarkerAppearance( int type, int size ); 00150 00153 virtual QString rotationField() const { return ""; } 00156 virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); } 00157 00162 virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; } 00163 00168 virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat ); 00169 00170 protected: 00171 QgsFeatureRendererV2( QString type ); 00172 00173 void renderFeatureWithSymbol( QgsFeature& feature, 00174 QgsSymbolV2* symbol, 00175 QgsRenderContext& context, 00176 int layer, 00177 bool selected, 00178 bool drawVertexMarker ); 00179 00181 void renderVertexMarker( QPointF& pt, QgsRenderContext& context ); 00183 void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context ); 00185 void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context ); 00186 00187 static unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, unsigned char* wkb ); 00188 static unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, unsigned char* wkb ); 00189 static unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb ); 00190 00191 QString mType; 00192 00193 bool mUsingSymbolLevels; 00194 00196 int mCurrentVertexMarkerType; 00198 int mCurrentVertexMarkerSize; 00199 }; 00200 00201 00202 #endif // QGSRENDERERV2_H