iLand
colors.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
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********************************************************************************************/
19#ifndef COLORS_H
20#define COLORS_H
21#include <QObject>
22#include <QColor>
23#include "grid.h"
27class DEM; // forward
28class Colors: public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(QStringList colors READ colors NOTIFY colorsChanged)
32 Q_PROPERTY(QStringList labels READ labels NOTIFY colorsChanged)
33 Q_PROPERTY(QStringList factorLabels READ factorLabels NOTIFY colorsChanged)
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)
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)
42
43
44
45public:
46 Colors(QWidget*parent=0);
47 // properties
48 QStringList colors() const {return mColors; }
49 QStringList labels() const {return mLabels; }
50 QStringList factorLabels() const {return mFactorLabels; }
51 int colorCount() const { return mColors.count(); }
52 double minValue() const {return mMinValue; }
53 double maxValue() const {return mMaxValue; }
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; }
58 bool hasFactors() const { return mHasFactors; }
59 bool autoScale() const {return mAutoScale; }
60 void setAutoScale(bool value) { if (value==mAutoScale) return; mAutoScale=value; mNeedsPaletteUpdate=true; setPalette(mCurrentType, mMinValue, mMaxValue);}
61 QString caption() const {return mCaption; }
62 QString description() const {return mDescription; }
63
64 void setPalette(const GridViewType type, const float min_val, const float max_val);
65 void setFactorLabels(QStringList labels);
66 void setFactorColors(QStringList colors);
67 void setCaption(QString caption, QString description=QString()) {
68 if (mCaption==caption && mDescription==description) return;
69 mCaption = caption; mDescription=description;mNeedsPaletteUpdate=true; }
70
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
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);
79 static QColor shadeColor(const QColor col, const QPointF &coordinates, const DEM *dem);
80private:
81 void setupFixedPalettes();
82 static QVector<QColor> mBrewerDiv;
83 static QVector<QColor> mBrewerQual;
84 static QVector<QColor> mTerrainCol;
85 static QVector<QColor> mCustomColors;
86 static QVector<QColor> mTurboColors;
87 QStringList mColors;
88 QStringList mLabels;
89 QStringList mFactorLabels;
90 double mMinValue;
91 double mMaxValue;
92 GridViewType mCurrentType;
93 bool mAutoScale;
94 bool mHasFactors;
95 bool mNeedsPaletteUpdate;
96 QString mCaption;
97 QString mDescription;
98 double mMeterPerPixel;
99signals:
102};
103
104#endif // COLORS_H
Definition: colors.h:29
bool autoScale
Definition: colors.h:37
void setScale(double meter_per_pixel)
Definition: colors.h:73
double maxValue() const
Definition: colors.h:53
void colorsChanged()
QString caption
Definition: colors.h:39
double minValue() const
Definition: colors.h:52
void setMaxValue(double val)
Definition: colors.h:56
Colors(QWidget *parent=0)
Definition: colors.cpp:97
bool autoScale() const
Definition: colors.h:59
QString description() const
Definition: colors.h:62
bool hasFactors() const
Definition: colors.h:58
double maxValue
Definition: colors.h:36
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)
Definition: colors.cpp:172
double meterPerPixel
Definition: colors.h:41
void setPalette(const GridViewType type, const float min_val, const float max_val)
Definition: colors.cpp:39
void scaleChanged()
static QColor colorFromPalette(const int value, const GridViewType view_type)
Definition: colors.cpp:111
int count
Definition: colors.h:34
void setCaption(QString caption, QString description=QString())
Definition: colors.h:67
void setMinValue(double val)
Definition: colors.h:54
void setAutoScale(bool value)
Definition: colors.h:60
QStringList factorLabels
Definition: colors.h:33
double meterPerPixel() const
Definition: colors.h:72
QString description
Definition: colors.h:40
QStringList labels() const
Definition: colors.h:49
void setFactorLabels(QStringList labels)
Definition: colors.cpp:82
void setFactorColors(QStringList colors)
Definition: colors.cpp:88
QStringList factorLabels() const
Definition: colors.h:50
QString caption() const
Definition: colors.h:61
double minValue
Definition: colors.h:35
QStringList colors
Definition: colors.h:31
QStringList colors() const
Definition: colors.h:48
bool hasFactors
Definition: colors.h:38
static QColor shadeColor(const QColor col, const QPointF &coordinates, const DEM *dem)
Definition: colors.cpp:135
QStringList labels
Definition: colors.h:32
int colorCount() const
Definition: colors.h:51
DEM is a digital elevation model class.
Definition: dem.h:40
GridViewType
Definition: grid.h:193