Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
1211 | werner | 2 | /******************************************************************************************** |
3 | ** iLand - an individual based forest landscape and disturbance model |
||
4 | ** http://iland.boku.ac.at |
||
5 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
6 | ** |
||
7 | ** This program is free software: you can redistribute it and/or modify |
||
8 | ** it under the terms of the GNU General Public License as published by |
||
9 | ** the Free Software Foundation, either version 3 of the License, or |
||
10 | ** (at your option) any later version. |
||
11 | ** |
||
12 | ** This program is distributed in the hope that it will be useful, |
||
13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | ** GNU General Public License for more details. |
||
16 | ** |
||
17 | ** You should have received a copy of the GNU General Public License |
||
18 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | ********************************************************************************************/ |
||
877 | werner | 20 | #ifndef COLORS_H |
21 | #define COLORS_H |
||
879 | werner | 22 | #include <QObject> |
877 | werner | 23 | #include <QColor> |
24 | #include "grid.h" |
||
25 | /** Colors: helper class for managing/selecting colors |
||
26 | * |
||
27 | * */ |
||
1009 | werner | 28 | class DEM; // forward |
879 | werner | 29 | class Colors: public QObject |
877 | werner | 30 | { |
879 | werner | 31 | Q_OBJECT |
32 | Q_PROPERTY(QStringList colors READ colors NOTIFY colorsChanged) |
||
33 | Q_PROPERTY(QStringList labels READ labels NOTIFY colorsChanged) |
||
880 | werner | 34 | Q_PROPERTY(QStringList factorLabels READ factorLabels NOTIFY colorsChanged) |
879 | werner | 35 | Q_PROPERTY(int count READ colorCount NOTIFY colorsChanged) |
36 | Q_PROPERTY(double minValue READ minValue WRITE setMinValue NOTIFY colorsChanged) |
||
37 | Q_PROPERTY(double maxValue READ maxValue WRITE setMaxValue NOTIFY colorsChanged) |
||
880 | werner | 38 | Q_PROPERTY(bool autoScale READ autoScale WRITE setAutoScale NOTIFY colorsChanged) |
39 | Q_PROPERTY(bool hasFactors READ hasFactors NOTIFY colorsChanged) |
||
40 | Q_PROPERTY(QString caption READ caption NOTIFY colorsChanged) |
||
41 | Q_PROPERTY(QString description READ description NOTIFY colorsChanged) |
||
42 | Q_PROPERTY(double meterPerPixel READ meterPerPixel NOTIFY scaleChanged) |
||
879 | werner | 43 | |
880 | werner | 44 | |
45 | |||
877 | werner | 46 | public: |
879 | werner | 47 | Colors(QWidget*parent=0); |
48 | // properties |
||
49 | QStringList colors() const {return mColors; } |
||
50 | QStringList labels() const {return mLabels; } |
||
880 | werner | 51 | QStringList factorLabels() const {return mFactorLabels; } |
879 | werner | 52 | int colorCount() const { return mColors.count(); } |
53 | double minValue() const {return mMinValue; } |
||
54 | double maxValue() const {return mMaxValue; } |
||
1041 | werner | 55 | void setMinValue(double val) { if(val==mMinValue) return; |
56 | mNeedsPaletteUpdate=true; setPalette(mCurrentType, val, mMaxValue); mMinValue = val; } |
||
57 | void setMaxValue(double val) { if(val==mMaxValue) return; |
||
58 | mNeedsPaletteUpdate=true; setPalette(mCurrentType, mMinValue, val); mMaxValue = val; } |
||
880 | werner | 59 | bool hasFactors() const { return mHasFactors; } |
60 | bool autoScale() const {return mAutoScale; } |
||
1041 | werner | 61 | void setAutoScale(bool value) { if (value==mAutoScale) return; mAutoScale=value; mNeedsPaletteUpdate=true; setPalette(mCurrentType, mMinValue, mMaxValue);} |
880 | werner | 62 | QString caption() const {return mCaption; } |
63 | QString description() const {return mDescription; } |
||
879 | werner | 64 | |
65 | void setPalette(const GridViewType type, const float min_val, const float max_val); |
||
880 | werner | 66 | void setFactorLabels(QStringList labels); |
67 | void setFactorColors(QStringList colors) { mColors = colors; } |
||
1041 | werner | 68 | void setCaption(QString caption, QString description=QString()) { |
1179 | werner | 69 | if (mCaption==caption && mDescription==description) return; |
1041 | werner | 70 | mCaption = caption; mDescription=description;mNeedsPaletteUpdate=true; } |
879 | werner | 71 | |
880 | werner | 72 | // scale |
73 | double meterPerPixel() const {return mMeterPerPixel; } |
||
74 | void setScale(double meter_per_pixel) { if(mMeterPerPixel==meter_per_pixel) return; |
||
75 | mMeterPerPixel = meter_per_pixel; emit scaleChanged();} |
||
76 | |||
877 | werner | 77 | static QColor colorFromValue(const float value, const float min_value=0.f, const float max_value=1.f, const bool reverse=false, const bool black_white=false); |
78 | static QColor colorFromValue(const float value, const GridViewType view_type, const float min_value=0.f, const float max_value=1.f); |
||
79 | static QColor colorFromPalette(const int value, const GridViewType view_type); |
||
1009 | werner | 80 | static QColor shadeColor(const QColor col, const QPointF &coordinates, const DEM *dem); |
877 | werner | 81 | private: |
82 | static QVector<QColor> mBrewerDiv; |
||
83 | static QVector<QColor> mBrewerQual; |
||
84 | static QVector<QColor> mTerrainCol; |
||
879 | werner | 85 | QStringList mColors; |
86 | QStringList mLabels; |
||
880 | werner | 87 | QStringList mFactorLabels; |
879 | werner | 88 | double mMinValue; |
89 | double mMaxValue; |
||
90 | GridViewType mCurrentType; |
||
880 | werner | 91 | bool mAutoScale; |
92 | bool mHasFactors; |
||
93 | bool mNeedsPaletteUpdate; |
||
94 | QString mCaption; |
||
95 | QString mDescription; |
||
96 | double mMeterPerPixel; |
||
879 | werner | 97 | signals: |
98 | void colorsChanged(); |
||
880 | werner | 99 | void scaleChanged(); |
877 | werner | 100 | }; |
101 | |||
102 | #endif // COLORS_H |