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