QGIS API Documentation  master-3f58142
src/core/symbology-ng/qgsmarkersymbollayerv2.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsmarkersymbollayerv2.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 QGSMARKERSYMBOLLAYERV2_H
00017 #define QGSMARKERSYMBOLLAYERV2_H
00018 
00019 #include "qgssymbollayerv2.h"
00020 #include "qgsvectorlayer.h"
00021 
00022 #define DEFAULT_SIMPLEMARKER_NAME         "circle"
00023 #define DEFAULT_SIMPLEMARKER_COLOR        QColor(255,0,0)
00024 #define DEFAULT_SIMPLEMARKER_BORDERCOLOR  QColor(0,0,0)
00025 #define DEFAULT_SIMPLEMARKER_SIZE         DEFAULT_POINT_SIZE
00026 #define DEFAULT_SIMPLEMARKER_ANGLE        0
00027 #define DEFAULT_SCALE_METHOD              QgsSymbolV2::ScaleArea
00028 
00029 #include <QPen>
00030 #include <QBrush>
00031 #include <QPicture>
00032 #include <QPolygonF>
00033 #include <QFont>
00034 
00035 class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
00036 {
00037   public:
00038     QgsSimpleMarkerSymbolLayerV2( QString name = DEFAULT_SIMPLEMARKER_NAME,
00039                                   QColor color = DEFAULT_SIMPLEMARKER_COLOR,
00040                                   QColor borderColor = DEFAULT_SIMPLEMARKER_BORDERCOLOR,
00041                                   double size = DEFAULT_SIMPLEMARKER_SIZE,
00042                                   double angle = DEFAULT_SIMPLEMARKER_ANGLE,
00043                                   QgsSymbolV2::ScaleMethod scaleMethod = DEFAULT_SCALE_METHOD );
00044 
00045     // static stuff
00046 
00047     static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
00048     static QgsSymbolLayerV2* createFromSld( QDomElement &element );
00049 
00050     // implemented from base classes
00051 
00052     QString layerType() const;
00053 
00054     void startRender( QgsSymbolV2RenderContext& context );
00055 
00056     void stopRender( QgsSymbolV2RenderContext& context );
00057 
00058     void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
00059 
00060     QgsStringMap properties() const;
00061 
00062     QgsSymbolLayerV2* clone() const;
00063 
00064     void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
00065 
00066     QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
00067 
00068     QString name() const { return mName; }
00069     void setName( QString name ) { mName = name; }
00070 
00071     QColor borderColor() const { return mBorderColor; }
00072     void setBorderColor( QColor color ) { mBorderColor = color; }
00073 
00074     double outlineWidth() const { return mOutlineWidth; }
00075     void setOutlineWidth( double w ) { mOutlineWidth = w; }
00076 
00077     QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
00078     void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
00079 
00080   protected:
00081 
00082     void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
00083 
00084     bool prepareShape( QString name = QString() );
00085     bool preparePath( QString name = QString() );
00086 
00087     void prepareCache( QgsSymbolV2RenderContext& context );
00088 
00089     QColor mBorderColor;
00090     double mOutlineWidth;
00091     QgsSymbolV2::OutputUnit mOutlineWidthUnit;
00092     QPen mPen;
00093     QBrush mBrush;
00094     QPolygonF mPolygon;
00095     QPainterPath mPath;
00096     QString mName;
00097     QImage mCache;
00098     QPen mSelPen;
00099     QBrush mSelBrush;
00100     QImage mSelCache;
00101     bool mUsingCache;
00102 };
00103 
00105 
00106 #define DEFAULT_SVGMARKER_NAME         "/crosses/Star1.svg"
00107 #define DEFAULT_SVGMARKER_SIZE         2*DEFAULT_POINT_SIZE
00108 #define DEFAULT_SVGMARKER_ANGLE        0
00109 
00110 class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
00111 {
00112   public:
00113     QgsSvgMarkerSymbolLayerV2( QString name = DEFAULT_SVGMARKER_NAME,
00114                                double size = DEFAULT_SVGMARKER_SIZE,
00115                                double angle = DEFAULT_SVGMARKER_ANGLE );
00116 
00117     // static stuff
00118 
00119     static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
00120     static QgsSymbolLayerV2* createFromSld( QDomElement &element );
00121 
00122     // implemented from base classes
00123 
00124     QString layerType() const;
00125 
00126     void startRender( QgsSymbolV2RenderContext& context );
00127 
00128     void stopRender( QgsSymbolV2RenderContext& context );
00129 
00130     void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
00131 
00132     QgsStringMap properties() const;
00133 
00134     QgsSymbolLayerV2* clone() const;
00135 
00136     void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
00137 
00138     QString path() const { return mPath; }
00139     void setPath( QString path );
00140 
00141     QColor fillColor() const { return mFillColor; }
00142     void setFillColor( const QColor& c ) { mFillColor = c; }
00143 
00144     QColor outlineColor() const { return mOutlineColor; }
00145     void setOutlineColor( const QColor& c ) { mOutlineColor = c; }
00146 
00147     double outlineWidth() const { return mOutlineWidth; }
00148     void setOutlineWidth( double w ) { mOutlineWidth = w; }
00149 
00150     void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
00151     QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
00152 
00153     void setOutputUnit( QgsSymbolV2::OutputUnit unit );
00154     QgsSymbolV2::OutputUnit outputUnit() const;
00155 
00156   protected:
00157     QString mPath;
00158 
00159     //param(fill), param(outline), param(outline-width) are going
00160     //to be replaced in memory
00161     QColor mFillColor;
00162     QColor mOutlineColor;
00163     double mOutlineWidth;
00164     QgsSymbolV2::OutputUnit mOutlineWidthUnit;
00165     double mOrigSize;
00166 };
00167 
00168 
00170 
00171 #define POINT2MM(x) ( (x) * 25.4 / 72 ) // point is 1/72 of inch
00172 #define MM2POINT(x) ( (x) * 72 / 25.4 )
00173 
00174 #define DEFAULT_FONTMARKER_FONT   "Dingbats"
00175 #define DEFAULT_FONTMARKER_CHR    QChar('A')
00176 #define DEFAULT_FONTMARKER_SIZE   POINT2MM(12)
00177 #define DEFAULT_FONTMARKER_COLOR  QColor(Qt::black)
00178 #define DEFAULT_FONTMARKER_ANGLE  0
00179 
00180 class CORE_EXPORT QgsFontMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
00181 {
00182   public:
00183     QgsFontMarkerSymbolLayerV2( QString fontFamily = DEFAULT_FONTMARKER_FONT,
00184                                 QChar chr = DEFAULT_FONTMARKER_CHR,
00185                                 double pointSize = DEFAULT_FONTMARKER_SIZE,
00186                                 QColor color = DEFAULT_FONTMARKER_COLOR,
00187                                 double angle = DEFAULT_FONTMARKER_ANGLE );
00188 
00189     // static stuff
00190 
00191     static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() );
00192     static QgsSymbolLayerV2* createFromSld( QDomElement &element );
00193 
00194     // implemented from base classes
00195 
00196     QString layerType() const;
00197 
00198     void startRender( QgsSymbolV2RenderContext& context );
00199 
00200     void stopRender( QgsSymbolV2RenderContext& context );
00201 
00202     void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context );
00203 
00204     QgsStringMap properties() const;
00205 
00206     QgsSymbolLayerV2* clone() const;
00207 
00208     void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
00209 
00210     // new methods
00211 
00212     QString fontFamily() const { return mFontFamily; }
00213     void setFontFamily( QString family ) { mFontFamily = family; }
00214 
00215     QChar character() const { return mChr; }
00216     void setCharacter( QChar ch ) { mChr = ch; }
00217 
00218   protected:
00219 
00220     QString mFontFamily;
00221     QChar mChr;
00222 
00223     QPointF mChrOffset;
00224     QFont mFont;
00225     double mOrigSize;
00226 };
00227 
00228 
00229 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines