Quantum GIS API Documentation  1.8
src/core/symbology-ng/qgssymbolv2.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgssymbolv2.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 QGSSYMBOLV2_H
00017 #define QGSSYMBOLV2_H
00018 
00019 #include "qgis.h"
00020 #include <QList>
00021 #include <QMap>
00022 
00023 class QColor;
00024 class QImage;
00025 class QPainter;
00026 class QSize;
00027 class QPointF;
00028 class QPolygonF;
00029 
00030 class QDomDocument;
00031 class QDomElement;
00032 //class
00033 
00034 class QgsFeature;
00035 class QgsSymbolLayerV2;
00036 class QgsRenderContext;
00037 class QgsVectorLayer;
00038 
00039 typedef QMap<QString, QString> QgsStringMap;
00040 typedef QList<QgsSymbolLayerV2*> QgsSymbolLayerV2List;
00041 
00042 class CORE_EXPORT QgsSymbolV2
00043 {
00044   public:
00045 
00046     enum OutputUnit
00047     {
00048       MM,
00049       MapUnit
00050     };
00051 
00052     enum SymbolType
00053     {
00054       Marker,
00055       Line,
00056       Fill
00057     };
00058 
00060     enum RenderHint
00061     {
00062       DataDefinedSizeScale = 1,
00063       DataDefinedRotation = 2
00064     };
00065 
00066     virtual ~QgsSymbolV2();
00067 
00069     static QgsSymbolV2* defaultSymbol( QGis::GeometryType geomType );
00070 
00071     SymbolType type() const { return mType; }
00072 
00073     // symbol layers handling
00074 
00075     QgsSymbolLayerV2* symbolLayer( int layer );
00076 
00077     int symbolLayerCount() { return mLayers.count(); }
00078 
00080     bool insertSymbolLayer( int index, QgsSymbolLayerV2* layer );
00081 
00083     bool appendSymbolLayer( QgsSymbolLayerV2* layer );
00084 
00086     bool deleteSymbolLayer( int index );
00087 
00089     QgsSymbolLayerV2* takeSymbolLayer( int index );
00090 
00092     bool changeSymbolLayer( int index, QgsSymbolLayerV2* layer );
00093 
00094 
00095     void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 );
00096     void stopRender( QgsRenderContext& context );
00097 
00098     void setColor( const QColor& color );
00099     QColor color();
00100 
00101     void drawPreviewIcon( QPainter* painter, QSize size );
00102 
00103     QImage bigSymbolPreviewImage();
00104 
00105     QString dump();
00106 
00107     virtual QgsSymbolV2* clone() const = 0;
00108 
00109     void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
00110 
00111     OutputUnit outputUnit() const { return mOutputUnit; }
00112     void setOutputUnit( OutputUnit u ) { mOutputUnit = u; }
00113 
00115     qreal alpha() const { return mAlpha; }
00117     void setAlpha( qreal alpha ) { mAlpha = alpha; }
00118 
00120     void setRenderHints( int hints ) { mRenderHints = hints; }
00122     int renderHints() const { return mRenderHints; }
00123 
00124     QSet<QString> usedAttributes() const;
00125 
00126   protected:
00127     QgsSymbolV2( SymbolType type, QgsSymbolLayerV2List layers ); // can't be instantiated
00128 
00129     QgsSymbolLayerV2List cloneLayers() const;
00130 
00134     bool isSymbolLayerCompatible( SymbolType t );
00135 
00136     SymbolType mType;
00137     QgsSymbolLayerV2List mLayers;
00138 
00139     OutputUnit mOutputUnit;
00140 
00142     qreal mAlpha;
00143 
00144     int mRenderHints;
00145 };
00146 
00148 
00149 class CORE_EXPORT QgsSymbolV2RenderContext
00150 {
00151   public:
00152     QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u , qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0 );
00153     ~QgsSymbolV2RenderContext();
00154 
00155     QgsRenderContext& renderContext() { return mRenderContext; }
00156     //void setRenderContext( QgsRenderContext& c ) { mRenderContext = c;}
00157 
00158     QgsSymbolV2::OutputUnit outputUnit() const { return mOutputUnit; }
00159     void setOutputUnit( QgsSymbolV2::OutputUnit u ) { mOutputUnit = u; }
00160 
00162     qreal alpha() const { return mAlpha; }
00164     void setAlpha( qreal alpha ) { mAlpha = alpha; }
00165 
00166     bool selected() const { return mSelected; }
00167     void setSelected( bool selected ) { mSelected = selected; }
00168 
00170     int renderHints() const { return mRenderHints; }
00172     void setRenderHints( int hints ) { mRenderHints = hints; }
00173 
00174     void setFeature( const QgsFeature* f ) { mFeature = f; }
00175     const QgsFeature* feature() const { return mFeature; }
00176 
00177     void setLayer( const QgsVectorLayer* layer ) { mLayer = layer; }
00178     const QgsVectorLayer* layer() const { return mLayer; }
00179 
00180     // Color used for selections
00181     static QColor selectionColor();
00182 
00183     double outputLineWidth( double width ) const;
00184     double outputPixelSize( double size ) const;
00185 
00186     // workaround for sip 4.7. Don't use assignment - will fail with assertion error
00187     QgsSymbolV2RenderContext& operator=( const QgsSymbolV2RenderContext& );
00188 
00189   private:
00190     QgsRenderContext& mRenderContext;
00191     QgsSymbolV2::OutputUnit mOutputUnit;
00192     qreal mAlpha;
00193     bool mSelected;
00194     int mRenderHints;
00195     const QgsFeature* mFeature; //current feature
00196     const QgsVectorLayer* mLayer; //current vectorlayer
00197 };
00198 
00199 
00200 
00202 
00203 
00204 
00205 class CORE_EXPORT QgsMarkerSymbolV2 : public QgsSymbolV2
00206 {
00207   public:
00212     static QgsMarkerSymbolV2* createSimple( const QgsStringMap& properties );
00213 
00214     QgsMarkerSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
00215 
00216     void setAngle( double angle );
00217     double angle();
00218 
00219     void setSize( double size );
00220     double size();
00221 
00222     void renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
00223 
00224     virtual QgsSymbolV2* clone() const;
00225 };
00226 
00227 
00228 
00229 class CORE_EXPORT QgsLineSymbolV2 : public QgsSymbolV2
00230 {
00231   public:
00236     static QgsLineSymbolV2* createSimple( const QgsStringMap& properties );
00237 
00238     QgsLineSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
00239 
00240     void setWidth( double width );
00241     double width();
00242 
00243     void renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
00244 
00245     virtual QgsSymbolV2* clone() const;
00246 };
00247 
00248 
00249 
00250 class CORE_EXPORT QgsFillSymbolV2 : public QgsSymbolV2
00251 {
00252   public:
00257     static QgsFillSymbolV2* createSimple( const QgsStringMap& properties );
00258 
00259     QgsFillSymbolV2( QgsSymbolLayerV2List layers = QgsSymbolLayerV2List() );
00260     void setAngle( double angle );
00261     void renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer = -1, bool selected = false );
00262 
00263     virtual QgsSymbolV2* clone() const;
00264 };
00265 
00266 #endif
00267 
00268 
00269 /*
00270 
00271 QgsSymbolV2* ps = new QgsPointSymbol();
00272 
00273 // ----
00274 
00275 sl = QgsSymbolLayerV2Registry::instance()->createSymbolLayer("SimpleLine", { "color", "..." })
00276 
00277 // (or)
00278 
00279 sl = QgsSymbolLayerV2Registry::defaultSymbolLayer(QgsSymbolV2::Line)
00280 
00281 // (or)
00282 
00283 QgsSymbolLayerV2* sl = new QgsSimpleLineSymbolLayer(x,y,z);
00284 QgsLineSymbol* s = new LineSymbol( [ sl ] );
00285 
00286 // ----
00287 
00288 rend = QgsSingleSymbolRenderer( new LineSymbol() );
00289 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines