Qwt User's Guide 6.1.4

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 "qwt_global.h"
14 #include "qwt_interval.h"
15 #include <qcolor.h>
16 #include <qvector.h>
17
33 class QWT_EXPORT QwtColorMap
34 {
35 public:
41 enum Format
42 {
44 RGB,
45
50 Indexed
51 };
52
53 QwtColorMap( Format = QwtColorMap::RGB );
54 virtual ~QwtColorMap();
55
56 Format format() const;
57
65 virtual QRgb rgb( const QwtInterval &interval,
66 double value ) const = 0;
67
75 virtual unsigned char colorIndex(
76 const QwtInterval &interval, double value ) const = 0;
77
78 QColor color( const QwtInterval &, double value ) const;
79 virtual QVector<QRgb> colorTable( const QwtInterval & ) const;
80
81 private:
82 Format d_format;
83 };
84
92 class QWT_EXPORT QwtLinearColorMap: public QwtColorMap
93 {
94 public:
99 enum Mode
100 {
102 FixedColors,
103
105 ScaledColors
106 };
107
108 QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB );
109 QwtLinearColorMap( const QColor &color1, const QColor &color2,
110 QwtColorMap::Format = QwtColorMap::RGB );
111
112 virtual ~QwtLinearColorMap();
113
114 void setMode( Mode );
115 Mode mode() const;
116
117 void setColorInterval( const QColor &color1, const QColor &color2 );
118 void addColorStop( double value, const QColor& );
119 QVector<double> colorStops() const;
120
121 QColor color1() const;
122 QColor color2() const;
123
124 virtual QRgb rgb( const QwtInterval &, double value ) const;
125 virtual unsigned char colorIndex(
126 const QwtInterval &, double value ) const;
127
128 class ColorStops;
129
130 private:
131 // Disabled copy constructor and operator=
132 QwtLinearColorMap( const QwtLinearColorMap & );
133 QwtLinearColorMap &operator=( const QwtLinearColorMap & );
134
135 class PrivateData;
136 PrivateData *d_data;
137 };
138
142 class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
143 {
144 public:
145 QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) );
146 virtual ~QwtAlphaColorMap();
147
148 void setColor( const QColor & );
149 QColor color() const;
150
151 virtual QRgb rgb( const QwtInterval &, double value ) const;
152
153 private:
154 QwtAlphaColorMap( const QwtAlphaColorMap & );
155 QwtAlphaColorMap &operator=( const QwtAlphaColorMap & );
156
157 virtual unsigned char colorIndex(
158 const QwtInterval &, double value ) const;
159
160 class PrivateData;
161 PrivateData *d_data;
162 };
163
164
177 inline QColor QwtColorMap::color(
178 const QwtInterval &interval, double value ) const
179 {
180 if ( d_format == RGB )
181 {
182 return QColor::fromRgba( rgb( interval, value ) );
183 }
184 else
185 {
186 const unsigned int index = colorIndex( interval, value );
187
188 const QVector<QRgb> rgbTable = colorTable( interval );
189 return rgbTable[index]; // slow
190 }
191 }
192
197 inline QwtColorMap::Format QwtColorMap::format() const
198 {
199 return d_format;
200 }
201
202 #endif
QwtLinearColorMap
QwtLinearColorMap builds a color map from color stops.
Definition: qwt_color_map.h:92
QwtColorMap::RGB
The map is intended to map into RGB values.
Definition: qwt_color_map.h:44
QwtLinearColorMap::Mode
Mode
Definition: qwt_color_map.h:99
QwtColorMap::format
Format format() const
Definition: qwt_color_map.h:197
QwtColorMap::colorTable
virtual QVector< QRgb > colorTable(const QwtInterval &) const
Definition: qwt_color_map.cpp:219
QwtColorMap::Format
Format
Definition: qwt_color_map.h:41
QwtColorMap::color
QColor color(const QwtInterval &, double value) const
Definition: qwt_color_map.h:177
QwtLinearColorMap::FixedColors
Return the color from the next lower color stop.
Definition: qwt_color_map.h:102
QwtColorMap
QwtColorMap is used to map values into colors.
Definition: qwt_color_map.h:33
QwtColorMap::rgb
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
QwtColorMap::colorIndex
virtual unsigned char colorIndex(const QwtInterval &interval, double value) const =0
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:26
QwtAlphaColorMap
QwtAlphaColorMap varies the alpha value of a color.
Definition: qwt_color_map.h:142