Quantum GIS API Documentation  1.7.4
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 /* $Id$ */
00018 
00019 #ifndef QGSSYMBOL_H
00020 #define QGSSYMBOL_H
00021 
00022 #include "qgis.h"
00023 #include <QBrush>
00024 #include <QPen>
00025 #include <QImage>
00026 
00027 class QDomNode;
00028 class QDomDocument;
00029 class QDomElement;
00030 
00031 class QgsVectorLayer;
00032 
00035 class CORE_EXPORT QgsSymbol
00036 {
00037   public:
00039     QgsSymbol( QGis::GeometryType t, QString lvalue = "", QString uvalue = "", QString label = "" );
00041     QgsSymbol( QGis::GeometryType t, QString lvalue, QString uvalue, QString label, QColor c );
00042     QgsSymbol( const QgsSymbol& );
00044     QgsSymbol();
00045     QgsSymbol( QColor c );
00047     virtual void setBrush( QBrush b );
00049     virtual const QBrush& brush() const;
00051     virtual void setColor( QColor c );
00053     virtual QColor color() const;
00055     virtual QColor fillColor() const;
00057     virtual void setFillColor( QColor c );
00059     virtual double lineWidth() const;
00061     virtual void setLineWidth( double w );
00063     virtual void setPen( QPen p );
00065     virtual const QPen& pen() const;
00066 
00068     virtual void setLineStyle( Qt::PenStyle s );
00070     virtual void setFillStyle( Qt::BrushStyle s );
00071 
00073     virtual QString customTexture() const;
00075     virtual void setCustomTexture( QString path );
00076 
00077     virtual void setLowerValue( QString value );
00078     virtual QString lowerValue() const;
00079     virtual void setUpperValue( QString value );
00080     virtual QString upperValue() const;
00081     virtual void setLabel( QString label );
00082     virtual QString label() const;
00083 
00085     virtual void setNamedPointSymbol( QString name );
00087     virtual QString pointSymbolName() const;
00088 
00090     virtual void setPointSize( double s );
00092     virtual double pointSize() const;
00093 
00095     virtual void setPointSizeUnits( bool sizeInMapUnits );
00097     virtual bool pointSizeUnits() const;
00098 
00100     virtual ~QgsSymbol();
00101 
00103     virtual QImage getLineSymbolAsImage();
00104 
00106     virtual QImage getPolygonSymbolAsImage();
00107 
00110     virtual QImage getCachedPointSymbolAsImage( double widthScale = 1.0,
00111         bool selected = false,
00112         QColor selectionColor = Qt::yellow,
00113         double opacity = 1.0 );
00114 
00118     virtual QImage getPointSymbolAsImage( double widthScale = 1.0,
00119                                           bool selected = false,
00120                                           QColor selectionColor = Qt::yellow,
00121                                           double scale = 1.0,
00122                                           double rotation = 0.0,
00123                                           double rasterScaleFactor = 1.0,
00124                                           double opacity = 1.0 );
00125 
00128     virtual bool writeXML( QDomNode & item, QDomDocument & document, const QgsVectorLayer *vl ) const;
00131     virtual bool readXML( QDomNode & symbol, const QgsVectorLayer *vl );
00133     QGis::GeometryType type() const {return mType;}
00134 
00136     int rotationClassificationField() const;
00139     void setRotationClassificationField( int field );
00140 
00142     int scaleClassificationField() const;
00145     void setScaleClassificationField( int field );
00146 
00148     int symbolField() const;
00151     void setSymbolField( int field );
00152 
00153   protected:
00154 
00156     QString mLowerValue;
00158     QString mUpperValue;
00159     QString mLabel;
00161     QGis::GeometryType mType;
00162 
00163     QPen mPen;
00164     QBrush mBrush;
00165     QString mTextureFilePath;
00166     /* Point symbol name */
00167     QString mPointSymbolName;
00168     /* size */
00169     double mSize;
00170     /* units of size */
00171     bool mSizeInMapUnits;
00172 
00173 
00174     /* TODO Because for printing we always need a symbol without oversampling but with line width scale,
00175      *      we keep also separate picture with line width scale */
00176 
00177     //
00178     //
00179     // NOTE THE LOGIC OF THESE MEMBER VARS NEED TO BE REVISITED NOW THAT
00180     // I HAVE REMOVED SVG OVERSAMPLING (NEEDED IN QT3 WITH POOR SVG SUPPORT)
00181     // Tim Sutton 2006 XXX FIXME
00182     //
00183     //
00184 
00185 
00186     /* Point symbol cache  */
00187     QImage mPointSymbolImage;
00188 
00189     /* Point symbol cache  */
00190     QImage mPointSymbolImageSelected;
00191 
00192     /* Current line width scale used by mPointSymbolVectorImage. Equals -1.0 if not set */
00193     double mWidthScale;
00194 
00195     /* Point symbol cache but with line width scale mWidthScale */
00196     QImage mPointSymbolImage2;
00197     QImage mPointSymbolImageSelected2;
00198 
00199     /* The alpha channel of the symbol */
00200     double mOpacity;
00201 
00202     /* Create point symbol mPointSymbolImage/mPointSymbolImage cache */
00203     void cache( QColor selectionColor );
00204 
00205     /* Create point symbol mPointSymbolImage2 cache */
00206     void cache2( double widthScale, QColor selectionColor, double opacity );
00207 
00208     /* mPointSymbolImage/mPointSymbolImage cache updated */
00209     bool mCacheUpToDate;
00210 
00211     /* mPointSymbolImage2 cache updated */
00212     bool mCacheUpToDate2;
00213 
00214     /* Selection color used in cache */
00215     QColor mSelectionColor;
00216     QColor mSelectionColor2;
00217 
00219     int mRotationClassificationField;
00220     int mScaleClassificationField;
00221     int mSymbolField;
00222 
00223   private:
00224     int readFieldName( QDomNode &synode, QString name, const QgsVectorLayer &vl );
00225     void appendField( QDomElement &symbol, QDomDocument &document, const QgsVectorLayer &vl, QString name, int idx ) const;
00226     void appendText( QDomElement &symbol, QDomDocument &document, QString name, QString value ) const;
00227 
00228 };
00229 
00230 inline void QgsSymbol::setBrush( QBrush b )
00231 {
00232   mBrush = b;
00233 }
00234 
00235 inline const QBrush& QgsSymbol::brush() const
00236 {
00237   return mBrush;
00238 }
00239 
00240 inline void QgsSymbol::setPen( QPen p )
00241 {
00242   mPen = p;
00243 }
00244 
00245 inline const QPen& QgsSymbol::pen() const
00246 {
00247   return mPen;
00248 }
00249 
00250 inline void QgsSymbol::setLowerValue( QString value )
00251 {
00252   mLowerValue = value;
00253 }
00254 
00255 inline QString QgsSymbol::lowerValue() const
00256 {
00257   return mLowerValue;
00258 }
00259 
00260 inline void QgsSymbol::setUpperValue( QString value )
00261 {
00262   mUpperValue = value;
00263 }
00264 
00265 inline QString QgsSymbol::upperValue() const
00266 {
00267   return mUpperValue;
00268 }
00269 
00270 inline void QgsSymbol::setLabel( QString label )
00271 {
00272   mLabel = label;
00273 }
00274 
00275 inline QString QgsSymbol::label() const
00276 {
00277   return mLabel;
00278 }
00279 
00280 #endif // QGSSYMBOL_H
00281 
00282 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines