Qwt User's Guide: qwt_color_map.h Source File

Qwt User's Guide 5.2.3

- Main Page
- Related Pages
- Classes

qwt_color_map.h
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #ifndef QWT_COLOR_MAP_H
11 #define QWT_COLOR_MAP_H
12
13 #include <qglobal.h>
14 #include <qcolor.h>
15 #if QT_VERSION < 0x040000
16 #include <qvaluevector.h>
17 #else
18 #include <qvector.h>
19 #endif
20 #include "qwt_array.h"
21 #include "qwt_double_interval.h"
22
23 #if defined(QWT_TEMPLATEDLL)
24 // MOC_SKIP_BEGIN
25 template class QWT_EXPORT QwtArray<double>;
26 // MOC_SKIP_END
27 #endif
28
44 class QWT_EXPORT QwtColorMap
45 {
46 public:
57 enum Format
58 {
59 RGB,
60 Indexed
61 };
62
63 QwtColorMap(Format = QwtColorMap::RGB );
64 virtual ~QwtColorMap();
65
66 Format format() const;
67
69 virtual QwtColorMap *copy() const = 0;
70
77 virtual QRgb rgb(
78 const QwtDoubleInterval &interval, double value) const = 0;
79
86 virtual unsigned char colorIndex(
87 const QwtDoubleInterval &interval, double value) const = 0;
88
89 QColor color(const QwtDoubleInterval &, double value) const;
90 #if QT_VERSION < 0x040000
91 virtual QValueVector<QRgb> colorTable(const QwtDoubleInterval &) const;
92 #else
93 virtual QVector<QRgb> colorTable(const QwtDoubleInterval &) const;
94 #endif
95
96 private:
97 Format d_format;
98 };
99
100
111 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
112 {
113 public:
118 enum Mode
119 {
120 FixedColors,
121 ScaledColors
122 };
123
124 QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB);
125 QwtLinearColorMap( const QColor &from, const QColor &to,
126 QwtColorMap::Format = QwtColorMap::RGB);
127
128 QwtLinearColorMap(const QwtLinearColorMap &);
129
130 virtual ~QwtLinearColorMap();
131
132 QwtLinearColorMap &operator=(const QwtLinearColorMap &);
133
134 virtual QwtColorMap *copy() const;
135
136 void setMode(Mode);
137 Mode mode() const;
138
139 void setColorInterval(const QColor &color1, const QColor &color2);
140 void addColorStop(double value, const QColor&);
141 QwtArray<double> colorStops() const;
142
143 QColor color1() const;
144 QColor color2() const;
145
146 virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
147 virtual unsigned char colorIndex(
148 const QwtDoubleInterval &, double value) const;
149
150 class ColorStops;
151
152 private:
153 class PrivateData;
154 PrivateData *d_data;
155 };
156
160 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
161 {
162 public:
163 QwtAlphaColorMap(const QColor & = QColor(Qt::gray));
164 QwtAlphaColorMap(const QwtAlphaColorMap &);
165
166 virtual ~QwtAlphaColorMap();
167
168 QwtAlphaColorMap &operator=(const QwtAlphaColorMap &);
169
170 virtual QwtColorMap *copy() const;
171
172 void setColor(const QColor &);
173 QColor color() const;
174
175 virtual QRgb rgb(const QwtDoubleInterval &, double value) const;
176
177 private:
178 virtual unsigned char colorIndex(
179 const QwtDoubleInterval &, double value) const;
180
181 class PrivateData;
182 PrivateData *d_data;
183 };
184
185
198 inline QColor QwtColorMap::color(
199 const QwtDoubleInterval &interval, double value) const
200 {
201 if ( d_format == RGB )
202 {
203 return QColor( rgb(interval, value) );
204 }
205 else
206 {
207 const unsigned int index = colorIndex(interval, value);
208 return colorTable(interval)[index]; // slow
209 }
210 }
211
216 inline QwtColorMap::Format QwtColorMap::format() const
217 {
218 return d_format;
219 }
220
221 #endif