Classes | Public Types | Public Member Functions

QwtLinearColorMap Class Reference

QwtLinearColorMap builds a color map from color stops. More...

#include <qwt_color_map.h>

Inheritance diagram for QwtLinearColorMap:
Inheritance graph
[legend]
Collaboration diagram for QwtLinearColorMap:
Collaboration graph
[legend]

List of all members.

Classes

class  ColorStops
class  PrivateData

Public Types

enum  Mode { FixedColors, ScaledColors }

Public Member Functions

 QwtLinearColorMap (QwtColorMap::Format=QwtColorMap::RGB)
 QwtLinearColorMap (const QColor &from, const QColor &to, QwtColorMap::Format=QwtColorMap::RGB)
 QwtLinearColorMap (const QwtLinearColorMap &)
 Copy constructor.
virtual ~QwtLinearColorMap ()
 Destructor.
QwtLinearColorMapoperator= (const QwtLinearColorMap &)
 Assignment operator.
virtual QwtColorMapcopy () const
 Clone the color map.
void setMode (Mode)
 Set the mode of the color map.
Mode mode () const
void setColorInterval (const QColor &color1, const QColor &color2)
void addColorStop (double value, const QColor &)
QMemArray< double > colorStops () const
QColor color1 () const
QColor color2 () const
virtual QRgb rgb (const QwtDoubleInterval &, double value) const
virtual unsigned char colorIndex (const QwtDoubleInterval &, double value) const

Detailed Description

QwtLinearColorMap builds a color map from color stops.

A color stop is a color at a specific position. The valid range for the positions is [0.0, 1.0]. When mapping a value into a color it is translated into this interval. If mode() == FixedColors the color is calculated from the next lower color stop. If mode() == ScaledColors the color is calculated by interpolating the colors of the adjacent stops.

Definition at line 111 of file qwt_color_map.h.


Member Enumeration Documentation

Mode of color map

See also:
setMode(), mode()
Enumerator:
FixedColors 
ScaledColors 

Definition at line 118 of file qwt_color_map.h.


Constructor & Destructor Documentation

QwtLinearColorMap::QwtLinearColorMap ( QwtColorMap::Format  format = QwtColorMap::RGB )

Build a color map with two stops at 0.0 and 1.0. The color at 0.0 is Qt::blue, at 1.0 it is Qt::yellow.

Parameters:
formatPreferred format of the color map

Definition at line 211 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::mode, ScaledColors, and setColorInterval().

Referenced by copy().

                                                            :
    QwtColorMap(format)
{
    d_data = new PrivateData;
    d_data->mode = ScaledColors;

    setColorInterval( Qt::blue, Qt::yellow);
}
QwtLinearColorMap::QwtLinearColorMap ( const QColor &  color1,
const QColor &  color2,
QwtColorMap::Format  format = QwtColorMap::RGB 
)

Build a color map with two stops at 0.0 and 1.0.

Parameters:
color1Color used for the minimum value of the value interval
color2Color used for the maximum value of the value interval
formatPreferred format of the coor map

Definition at line 235 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::mode, ScaledColors, and setColorInterval().

                                                       :
    QwtColorMap(format)
{
    d_data = new PrivateData;
    d_data->mode = ScaledColors;
    setColorInterval(color1, color2); 
}
QwtLinearColorMap::QwtLinearColorMap ( const QwtLinearColorMap other )

Copy constructor.

Definition at line 221 of file qwt_color_map.cpp.

                                                                  :
    QwtColorMap(other)
{
    d_data = new PrivateData;
    *this = other;
}
QwtLinearColorMap::~QwtLinearColorMap (  ) [virtual]

Destructor.

Definition at line 245 of file qwt_color_map.cpp.

{
    delete d_data;
}

Member Function Documentation

void QwtLinearColorMap::addColorStop ( double  value,
const QColor &  color 
)

Add a color stop

The value has to be in the range [0.0, 1.0]. F.e. a stop at position 17.0 for a range [10.0,20.0] must be passed as: (17.0 - 10.0) / (20.0 - 10.0)

Parameters:
valueValue between [0.0, 1.0]
colorColor stop

Definition at line 319 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, and QwtLinearColorMap::ColorStops::insert().

{
    if ( value >= 0.0 && value <= 1.0 )
        d_data->colorStops.insert(value, color);
}
QColor QwtLinearColorMap::color1 (  ) const
Returns:
the first color of the color range
See also:
setColorInterval()

Definition at line 337 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, QwtLinearColorMap::PrivateData::mode, and QwtLinearColorMap::ColorStops::rgb().

{
    return QColor(d_data->colorStops.rgb(d_data->mode, 0.0));
}
QColor QwtLinearColorMap::color2 (  ) const
Returns:
the second color of the color range
See also:
setColorInterval()

Definition at line 346 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, QwtLinearColorMap::PrivateData::mode, and QwtLinearColorMap::ColorStops::rgb().

{
    return QColor(d_data->colorStops.rgb(d_data->mode, 1.0));
}
unsigned char QwtLinearColorMap::colorIndex ( const QwtDoubleInterval interval,
double  value 
) const [virtual]

Map a value of a given interval into a color index, between 0 and 255

Parameters:
intervalRange for all values
valueValue to map into a color index

Implements QwtColorMap.

Definition at line 375 of file qwt_color_map.cpp.

References FixedColors, QwtDoubleInterval::maxValue(), QwtDoubleInterval::minValue(), QwtLinearColorMap::PrivateData::mode, and QwtDoubleInterval::width().

{
    const double width = interval.width();

    if ( width <= 0.0 || value <= interval.minValue() )
        return 0;

    if ( value >= interval.maxValue() )
        return (unsigned char)255;

    const double ratio = (value - interval.minValue()) / width;
    
    unsigned char index;
    if ( d_data->mode == FixedColors )
        index = (unsigned char)(ratio * 255); // always floor
    else
        index = (unsigned char)qRound(ratio * 255);

    return index;
}
QMemArray< double > QwtLinearColorMap::colorStops (  ) const

Return all positions of color stops in increasing order

Definition at line 328 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, and QwtLinearColorMap::ColorStops::stops().

{
    return d_data->colorStops.stops();
}
QwtColorMap * QwtLinearColorMap::copy (  ) const [virtual]

Clone the color map.

Implements QwtColorMap.

Definition at line 260 of file qwt_color_map.cpp.

References QwtLinearColorMap().

{
    QwtLinearColorMap* map = new QwtLinearColorMap();
    *map = *this;

    return map;
}
QwtLinearColorMap::Mode QwtLinearColorMap::mode (  ) const
Returns:
Mode of the color map
See also:
setMode()

Definition at line 286 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::mode.

Referenced by setMode().

{
    return d_data->mode;
}
QwtLinearColorMap & QwtLinearColorMap::operator= ( const QwtLinearColorMap other )

Assignment operator.

Definition at line 251 of file qwt_color_map.cpp.

{
    QwtColorMap::operator=(other);
    *d_data = *other.d_data;
    return *this;
}
QRgb QwtLinearColorMap::rgb ( const QwtDoubleInterval interval,
double  value 
) const [virtual]

Map a value of a given interval into a rgb value

Parameters:
intervalRange for all values
valueValue to map into a rgb value

Implements QwtColorMap.

Definition at line 357 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, QwtDoubleInterval::minValue(), QwtLinearColorMap::PrivateData::mode, QwtLinearColorMap::ColorStops::rgb(), and QwtDoubleInterval::width().

Referenced by QwtLinearColorMap::ColorStops::rgb().

{
    const double width = interval.width();

    double ratio = 0.0;
    if ( width > 0.0 )
        ratio = (value - interval.minValue()) / width;

    return d_data->colorStops.rgb(d_data->mode, ratio);
}
void QwtLinearColorMap::setColorInterval ( const QColor &  color1,
const QColor &  color2 
)

Set the color range

Add stops at 0.0 and 1.0.

Parameters:
color1Color used for the minimum value of the value interval
color2Color used for the maximum value of the value interval
See also:
color1(), color2()

Definition at line 301 of file qwt_color_map.cpp.

References QwtLinearColorMap::PrivateData::colorStops, and QwtLinearColorMap::ColorStops::insert().

Referenced by QwtLinearColorMap().

{
    d_data->colorStops = ColorStops();
    d_data->colorStops.insert(0.0, color1);
    d_data->colorStops.insert(1.0, color2);
}
void QwtLinearColorMap::setMode ( Mode  mode )

Set the mode of the color map.

FixedColors means the color is calculated from the next lower color stop. ScaledColors means the color is calculated by interpolating the colors of the adjacent stops.

See also:
mode()

Definition at line 277 of file qwt_color_map.cpp.

References mode(), and QwtLinearColorMap::PrivateData::mode.

{
    d_data->mode = mode;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines