KDChart::Palette Class Reference

#include <KDChartPalette.h>

Inheritance diagram for KDChart::Palette:

Inheritance graph
[legend]
Collaboration diagram for KDChart::Palette:

Collaboration graph
[legend]

List of all members.


Detailed Description

A Palette is a set of brushes (or colors) to be used for painting data sets.

The palette class encapsulates a colletion of brushes, which in the simplest case are colors, to be used for painting a series of data sets. When asked for the m-th color, a palette of size n will wrap around and thus cycle through the available colors.

Three builtin palettes are provided for convenience, one with a default set of colors, one with a subdued color selection, one with rainbow colors.

When a palette changes, it emits a changed() signal. Hook up to it, if you want to repaint when the color selection changes.

Definition at line 55 of file KDChartPalette.h.


Signals

void changed ()
 Emitted whenever the palette changes.

Public Member Functions

void addBrush (const QBrush &brush, int position=-1)
 Adds brush to the palette.
QBrush getBrush (int position) const
 Query the palette for a brush at the specified position.
bool isValid () const
 
Returns:
whether this represents a valid palette.

Paletteoperator= (const Palette &)
 Palette (const Palette &)
 Palette (QObject *parent=0)
void removeBrush (int position)
 Remove the brush at position position, if there is one.
int size () const
 
Returns:
the number of brushed in the palette.

 ~Palette ()

Static Public Member Functions

static const PalettedefaultPalette ()
 Provide access to the three builtin palettes, one with standard bright colors, one with more subdued colors, and one with rainbow colors.
static const PaletterainbowPalette ()
static const PalettesubduedPalette ()

Constructor & Destructor Documentation

Palette::Palette ( QObject parent = 0  )  [explicit]

Definition at line 132 of file KDChartPalette.cpp.

00133   : QObject( parent ), _d( new Private )
00134 {
00135 
00136 }

Palette::Palette ( const Palette r  ) 

Definition at line 145 of file KDChartPalette.cpp.

00146     : QObject(), _d( new Private( *r.d ) )
00147 {
00148 }

Palette::~Palette (  ) 

Definition at line 138 of file KDChartPalette.cpp.

00139 {
00140     delete _d; _d = 0;
00141 }


Member Function Documentation

void Palette::addBrush ( const QBrush &  brush,
int  position = -1 
)

Adds brush to the palette.

If no position is specified, the brush is appended.

Definition at line 169 of file KDChartPalette.cpp.

References changed(), d, and size().

Referenced by makeDefaultPalette(), makeRainbowPalette(), and makeSubduedPalette().

00170 {
00171   if ( position < 0 || position >= size() ) {
00172     d->brushes.append( brush );
00173   } else {
00174     d->brushes.insert( position, brush );
00175   }
00176   emit changed();
00177 }

void KDChart::Palette::changed (  )  [signal]

Emitted whenever the palette changes.

Views listen to this and repaing.

Referenced by addBrush(), and removeBrush().

const Palette & Palette::defaultPalette (  )  [static]

Provide access to the three builtin palettes, one with standard bright colors, one with more subdued colors, and one with rainbow colors.

Definition at line 114 of file KDChartPalette.cpp.

References makeDefaultPalette().

Referenced by KDChart::AttributesModel::headerData().

00115 {
00116     static const Palette palette = makeDefaultPalette();
00117     return palette;
00118 }

QBrush Palette::getBrush ( int  position  )  const

Query the palette for a brush at the specified position.

If the position exceeds the size of the palette, it wraps around.

Definition at line 179 of file KDChartPalette.cpp.

References d, isValid(), and size().

Referenced by KDChart::AttributesModel::headerData(), and makeRainbowPalette().

00180 {
00181   if ( !isValid() ) return QBrush();
00182   return d->brushes.at( position % size() );
00183 }

bool Palette::isValid (  )  const

Returns:
whether this represents a valid palette.

For a palette to be valid it needs to have at least one brush associated.

Definition at line 159 of file KDChartPalette.cpp.

References d.

Referenced by getBrush().

00160 {
00161   return d->brushes.size() >= 1;
00162 }

Palette & Palette::operator= ( const Palette r  ) 

Definition at line 150 of file KDChartPalette.cpp.

00151 {
00152     Palette copy( r );
00153     copy.swap( *this );
00154 
00155     // emit changed() ?
00156     return *this;
00157 }

const Palette & Palette::rainbowPalette (  )  [static]

Definition at line 126 of file KDChartPalette.cpp.

References makeRainbowPalette().

Referenced by KDChart::AttributesModel::headerData().

00127 {
00128     static const Palette palette = makeRainbowPalette();
00129     return palette;
00130 }

void Palette::removeBrush ( int  position  ) 

Remove the brush at position position, if there is one.

Definition at line 185 of file KDChartPalette.cpp.

References changed(), d, and size().

00186 {
00187   if ( position < 0 || position >= size() ) return;
00188   d->brushes.remove( position );
00189   emit changed();
00190 }

int Palette::size (  )  const

Returns:
the number of brushed in the palette.

Definition at line 164 of file KDChartPalette.cpp.

References d.

Referenced by addBrush(), getBrush(), and removeBrush().

00165 {
00166   return d->brushes.size();
00167 }

const Palette & Palette::subduedPalette (  )  [static]

Definition at line 120 of file KDChartPalette.cpp.

References makeSubduedPalette().

Referenced by KDChart::AttributesModel::headerData().

00121 {
00122     static const Palette palette = makeSubduedPalette();
00123     return palette;
00124 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:26:18 2010 for KD Chart 2 by  doxygen 1.5.4