|
QGIS API Documentation
master-28efcda
|
00001 /* ************************************************************************** 00002 qgscolorrampshader.h - description 00003 ------------------- 00004 begin : Fri Dec 28 2007 00005 copyright : (C) 2007 by Peter J. Ersts 00006 email : ersts@amnh.org 00007 00008 This class is based off of code that was originally written by Marco Hugentobler and 00009 originally part of the larger QgsRasterLayer class 00010 ****************************************************************************/ 00011 00012 /* ************************************************************************** 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 ***************************************************************************/ 00020 00021 #ifndef QGSCOLORRAMPSHADER_H 00022 #define QGSCOLORRAMPSHADER_H 00023 00024 #include <QColor> 00025 #include <QMap> 00026 00027 #include "qgsrastershaderfunction.h" 00028 00032 class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction 00033 { 00034 00035 public: 00036 QgsColorRampShader( double theMinimumValue = 0.0, double theMaximumValue = 255.0 ); 00037 00038 //An entry for classification based upon value. 00039 //Such a classification is typically used for 00040 //single band layers where a pixel value represents 00041 //not a color but a quantity, e.g. temperature or elevation 00042 struct ColorRampItem 00043 { 00045 ColorRampItem() {} 00047 ColorRampItem( double val, QColor col, QString lbl = QString() ) : label( lbl ), value( val ), color( col ) {} 00048 00049 QString label; 00050 double value; 00051 QColor color; 00052 00053 // compare operator for sorting 00054 bool operator<( const ColorRampItem& other ) const { return value < other.value; } 00055 }; 00056 00057 enum ColorRamp_TYPE 00058 { 00059 INTERPOLATED, 00060 DISCRETE, 00061 EXACT 00062 }; 00063 00065 QList<QgsColorRampShader::ColorRampItem> colorRampItemList() const {return mColorRampItemList;} 00066 00068 QgsColorRampShader::ColorRamp_TYPE colorRampType() const {return mColorRampType;} 00069 00071 QString colorRampTypeAsQString(); 00072 00074 int maximumColorCacheSize() { return mMaximumColorCacheSize; } 00075 00077 void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem>& theList ); //TODO: sort on set 00078 00080 void setColorRampType( QgsColorRampShader::ColorRamp_TYPE theColorRampType ); 00081 00083 void setColorRampType( QString ); 00084 00086 void setMaximumColorCacheSize( int theSize ) { mMaximumColorCacheSize = theSize; } 00087 00089 bool shade( double, int*, int*, int*, int* ); 00090 00092 bool shade( double, double, double, double, int*, int*, int*, int* ); 00093 00094 void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const; 00095 00096 void setClip( bool clip ) { mClip = clip; } 00097 bool clip() const { return mClip; } 00098 00099 private: 00101 int mCurrentColorRampItemIndex; 00102 00103 //TODO: Consider pulling this out as a separate class and internally storing as a QMap rather than a QList 00109 QList<QgsColorRampShader::ColorRampItem> mColorRampItemList; 00110 00112 QgsColorRampShader::ColorRamp_TYPE mColorRampType; 00113 00115 QMap<double, QColor> mColorCache; 00116 00119 int mMaximumColorCacheSize; 00120 00124 bool discreteColor( double, int*, int*, int*, int* ); 00125 00129 bool exactColor( double, int*, int*, int*, int* ); 00130 00134 bool interpolatedColor( double, int*, int*, int*, int* ); 00135 00137 bool mClip; 00138 }; 00139 00140 #endif