QGIS API Documentation  master-6227475
src/core/symbology-ng/qgsrendererv2.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsrendererv2.h
00003     ---------------------
00004     begin                : November 2009
00005     copyright            : (C) 2009 by Martin Dobias
00006     email                : wonder dot sk at gmail dot 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 
00082     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
00083 
00084     virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ) = 0;
00085 
00086     virtual void stopRender( QgsRenderContext& context ) = 0;
00087 
00088     virtual QList<QString> usedAttributes() = 0;
00089 
00090     virtual ~QgsFeatureRendererV2() {}
00091 
00092     virtual QgsFeatureRendererV2* clone() = 0;
00093 
00094     virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
00095 
00097     virtual QString dump();
00098 
00099     enum Capabilities
00100     {
00101       SymbolLevels = 1,     // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
00102       RotationField = 1 <<  1,    // rotate symbols by attribute value
00103       MoreSymbolsPerFeature = 1 << 2,  // may use more than one symbol to render a feature: symbolsForFeature() will return them
00104       Filter         = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
00105       ScaleDependent = 1 << 4 // dependends on scale if feature will be rendered (rule based )
00106     };
00107 
00110     virtual int capabilities() { return 0; }
00111 
00113     virtual QgsSymbolV2List symbols() = 0;
00114 
00115     bool usingSymbolLevels() const { return mUsingSymbolLevels; }
00116     void setUsingSymbolLevels( bool usingSymbolLevels ) { mUsingSymbolLevels = usingSymbolLevels; }
00117 
00119     static QgsFeatureRendererV2* load( QDomElement& symbologyElem );
00120 
00122     virtual QDomElement save( QDomDocument& doc );
00123 
00126     virtual QDomElement writeSld( QDomDocument& doc, const QgsVectorLayer &layer ) const;
00127 
00139     static QgsFeatureRendererV2* loadSld( const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage );
00140 
00143     virtual void toSld( QDomDocument& doc, QDomElement &element ) const
00144     { element.appendChild( doc.createComment( QString( "FeatureRendererV2 %1 not implemented yet" ).arg( type() ) ) ); }
00145 
00147     virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00148 
00152     virtual QgsLegendSymbolList legendSymbolItems();
00153 
00155     void setVertexMarkerAppearance( int type, int size );
00156 
00159     virtual QString rotationField() const { return ""; }
00162     virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }
00163 
00168     virtual bool willRenderFeature( QgsFeature& feat ) { return symbolForFeature( feat ) != NULL; }
00169 
00174     virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat );
00175 
00176   protected:
00177     QgsFeatureRendererV2( QString type );
00178 
00179     void renderFeatureWithSymbol( QgsFeature& feature,
00180                                   QgsSymbolV2* symbol,
00181                                   QgsRenderContext& context,
00182                                   int layer,
00183                                   bool selected,
00184                                   bool drawVertexMarker );
00185 
00187     void renderVertexMarker( QPointF& pt, QgsRenderContext& context );
00189     void renderVertexMarkerPolyline( QPolygonF& pts, QgsRenderContext& context );
00191     void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );
00192 
00193     static unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, unsigned char* wkb );
00194     static unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, unsigned char* wkb );
00195     static unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, unsigned char* wkb );
00196 
00197     void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );
00198 
00199     QString mType;
00200 
00201     bool mUsingSymbolLevels;
00202 
00204     int mCurrentVertexMarkerType;
00206     int mCurrentVertexMarkerSize;
00207 };
00208 
00209 class QgsRendererV2Widget;  // why does SIP fail, when this isn't here
00210 
00211 #endif // QGSRENDERERV2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines