Quantum GIS API Documentation  1.8
src/core/symbology/qgssymbol.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgssymbol.h  -  description
00003                              -------------------
00004     begin                : Sat Jun 22 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef QGSSYMBOL_H
00019 #define QGSSYMBOL_H
00020 
00021 #include "qgis.h"
00022 #include <QBrush>
00023 #include <QPen>
00024 #include <QImage>
00025 
00026 class QDomNode;
00027 class QDomDocument;
00028 class QDomElement;
00029 
00030 class QgsVectorLayer;
00031 
00034 class CORE_EXPORT QgsSymbol
00035 {
00036   public:
00038     QgsSymbol( QGis::GeometryType t, QString lvalue = "", QString uvalue = "", QString label = "" );
00040     QgsSymbol( QGis::GeometryType t, QString lvalue, QString uvalue, QString label, QColor c );
00041     QgsSymbol( const QgsSymbol& );
00043     QgsSymbol();
00044     QgsSymbol( QColor c );
00046     virtual void setBrush( QBrush b );
00048     virtual const QBrush& brush() const;
00050     virtual void setColor( QColor c );
00052     virtual QColor color() const;
00054     virtual QColor fillColor() const;
00056     virtual void setFillColor( QColor c );
00058     virtual double lineWidth() const;
00060     virtual void setLineWidth( double w );
00062     virtual void setPen( QPen p );
00064     virtual const QPen& pen() const;
00065 
00067     virtual void setLineStyle( Qt::PenStyle s );
00069     virtual void setFillStyle( Qt::BrushStyle s );
00070 
00072     virtual QString customTexture() const;
00074     virtual void setCustomTexture( QString path );
00075 
00076     virtual void setLowerValue( QString value );
00077     virtual QString lowerValue() const;
00078     virtual void setUpperValue( QString value );
00079     virtual QString upperValue() const;
00080     virtual void setLabel( QString label );
00081     virtual QString label() const;
00082 
00084     virtual void setNamedPointSymbol( QString name );
00086     virtual QString pointSymbolName() const;
00087 
00089     virtual void setPointSize( double s );
00091     virtual double pointSize() const;
00092 
00094     virtual void setPointSizeUnits( bool sizeInMapUnits );
00096     virtual bool pointSizeUnits() const;
00097 
00099     virtual ~QgsSymbol();
00100 
00102     virtual QImage getLineSymbolAsImage();
00103 
00105     virtual QImage getPolygonSymbolAsImage();
00106 
00109     virtual QImage getCachedPointSymbolAsImage( double widthScale = 1.0,
00110         bool selected = false,
00111         QColor selectionColor = Qt::yellow,
00112         double opacity = 1.0 );
00113 
00117     virtual QImage getPointSymbolAsImage( double widthScale = 1.0,
00118                                           bool selected = false,
00119                                           QColor selectionColor = Qt::yellow,
00120                                           double scale = 1.0,
00121                                           double rotation = 0.0,
00122                                           double rasterScaleFactor = 1.0,
00123                                           double opacity = 1.0 );
00124 
00127     virtual bool writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const;
00130     virtual bool readXML( QDomNode & symbol, const QgsVectorLayer *vl );
00132     QGis::GeometryType type() const {return mType;}
00133 
00135     int rotationClassificationField() const;
00138     void setRotationClassificationField( int field );
00139 
00141     int scaleClassificationField() const;
00144     void setScaleClassificationField( int field );
00145 
00147     int symbolField() const;
00150     void setSymbolField( int field );
00151 
00152   protected:
00153 
00155     QString mLowerValue;
00157     QString mUpperValue;
00158     QString mLabel;
00160     QGis::GeometryType mType;
00161 
00162     QPen mPen;
00163     QBrush mBrush;
00164     QString mTextureFilePath;
00165     /* Point symbol name */
00166     QString mPointSymbolName;
00167     /* size */
00168     double mSize;
00169     /* units of size */
00170     bool mSizeInMapUnits;
00171 
00172 
00173     /* TODO Because for printing we always need a symbol without oversampling but with line width scale,
00174      *      we keep also separate picture with line width scale */
00175 
00176     //
00177     //
00178     // NOTE THE LOGIC OF THESE MEMBER VARS NEED TO BE REVISITED NOW THAT
00179     // I HAVE REMOVED SVG OVERSAMPLING (NEEDED IN QT3 WITH POOR SVG SUPPORT)
00180     // Tim Sutton 2006 XXX FIXME
00181     //
00182     //
00183 
00184 
00185     /* Point symbol cache  */
00186     QImage mPointSymbolImage;
00187 
00188     /* Point symbol cache  */
00189     QImage mPointSymbolImageSelected;
00190 
00191     /* Current line width scale used by mPointSymbolVectorImage. Equals -1.0 if not set */
00192     double mWidthScale;
00193 
00194     /* Point symbol cache but with line width scale mWidthScale */
00195     QImage mPointSymbolImage2;
00196     QImage mPointSymbolImageSelected2;
00197 
00198     /* The alpha channel of the symbol */
00199     double mOpacity;
00200 
00201     /* Create point symbol mPointSymbolImage/mPointSymbolImage cache */
00202     void cache( QColor selectionColor );
00203 
00204     /* Create point symbol mPointSymbolImage2 cache */
00205     void cache2( double widthScale, QColor selectionColor, double opacity );
00206 
00207     /* mPointSymbolImage/mPointSymbolImage cache updated */
00208     bool mCacheUpToDate;
00209 
00210     /* mPointSymbolImage2 cache updated */
00211     bool mCacheUpToDate2;
00212 
00213     /* Selection color used in cache */
00214     QColor mSelectionColor;
00215     QColor mSelectionColor2;
00216 
00218     int mRotationClassificationField;
00219     int mScaleClassificationField;
00220     int mSymbolField;
00221 
00222   private:
00223     int readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl );
00224     void appendField( QDomElement &symbol, QDomDocument &document, const QgsVectorLayer &vl, QString name, int idx ) const;
00225     void appendText( QDomElement &symbol, QDomDocument &document, QString name, QString value ) const;
00226 
00227 };
00228 
00229 inline void QgsSymbol::setBrush( QBrush b )
00230 {
00231   mBrush = b;
00232 }
00233 
00234 inline const QBrush& QgsSymbol::brush() const
00235 {
00236   return mBrush;
00237 }
00238 
00239 inline void QgsSymbol::setPen( QPen p )
00240 {
00241   mPen = p;
00242 }
00243 
00244 inline const QPen& QgsSymbol::pen() const
00245 {
00246   return mPen;
00247 }
00248 
00249 inline void QgsSymbol::setLowerValue( QString value )
00250 {
00251   mLowerValue = value;
00252 }
00253 
00254 inline QString QgsSymbol::lowerValue() const
00255 {
00256   return mLowerValue;
00257 }
00258 
00259 inline void QgsSymbol::setUpperValue( QString value )
00260 {
00261   mUpperValue = value;
00262 }
00263 
00264 inline QString QgsSymbol::upperValue() const
00265 {
00266   return mUpperValue;
00267 }
00268 
00269 inline void QgsSymbol::setLabel( QString label )
00270 {
00271   mLabel = label;
00272 }
00273 
00274 inline QString QgsSymbol::label() const
00275 {
00276   return mLabel;
00277 }
00278 
00279 #endif // QGSSYMBOL_H
00280 
00281 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines