iCub-main
Signals | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QCPColorScale Class Reference

A color scale for use with color coding data such as QCPColorMap. More...

#include <qcustomplot.h>

+ Inheritance diagram for QCPColorScale:

Signals

void dataRangeChanged (QCPRange newRange)
 This signal is emitted when the data range changes. More...
 
void dataScaleTypeChanged (QCPAxis::ScaleType scaleType)
 This signal is emitted when the data scale type changes. More...
 
void gradientChanged (QCPColorGradient newGradient)
 This signal is emitted when the gradient changes. More...
 
- Signals inherited from QCPLayerable
void layerChanged (QCPLayer *newLayer)
 This signal is emitted when the layer of this layerable changes, i.e. More...
 

Public Member Functions

 QCPColorScale (QCustomPlot *parentPlot)
 Constructs a new QCPColorScale. More...
 
virtual ~QCPColorScale ()
 
QCPAxisaxis () const
 Returns the internal QCPAxis instance of this color scale. More...
 
QCPAxis::AxisType type () const
 
QCPRange dataRange () const
 
QCPAxis::ScaleType dataScaleType () const
 
QCPColorGradient gradient () const
 
QString label () const
 
int barWidth () const
 
bool rangeDrag () const
 
bool rangeZoom () const
 
void setType (QCPAxis::AxisType type)
 Sets at which side of the color scale the axis is placed, and thus also its orientation. More...
 
Q_SLOT void setDataRange (const QCPRange &dataRange)
 Sets the range spanned by the color gradient and that is shown by the axis in the color scale. More...
 
Q_SLOT void setDataScaleType (QCPAxis::ScaleType scaleType)
 Sets the scale type of the color scale, i.e. More...
 
Q_SLOT void setGradient (const QCPColorGradient &gradient)
 Sets the color gradient that will be used to represent data values. More...
 
void setLabel (const QString &str)
 Sets the axis label of the color scale. More...
 
void setBarWidth (int width)
 Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed will have. More...
 
void setRangeDrag (bool enabled)
 Sets whether the user can drag the data range (setDataRange). More...
 
void setRangeZoom (bool enabled)
 Sets whether the user can zoom the data range (setDataRange) by scrolling the mouse wheel. More...
 
QList< QCPColorMap * > colorMaps () const
 Returns a list of all the color maps associated with this color scale. More...
 
void rescaleDataRange (bool onlyVisibleMaps)
 Changes the data range such that all color maps associated with this color scale are fully mapped to the gradient in the data dimension. More...
 
virtual void update (UpdatePhase phase)
 Updates the layout element and sub-elements. More...
 
- Public Member Functions inherited from QCPLayoutElement
 QCPLayoutElement (QCustomPlot *parentPlot=0)
 Creates an instance of QCPLayoutElement and sets default values. More...
 
virtual ~QCPLayoutElement ()
 
QCPLayoutlayout () const
 Returns the parent layout of this layout element. More...
 
QRect rect () const
 Returns the inner rect of this layout element. More...
 
QRect outerRect () const
 
QMargins margins () const
 
QMargins minimumMargins () const
 
QCP::MarginSides autoMargins () const
 
QSize minimumSize () const
 
QSize maximumSize () const
 
QCPMarginGroupmarginGroup (QCP::MarginSide side) const
 
QHash< QCP::MarginSide, QCPMarginGroup * > marginGroups () const
 
void setOuterRect (const QRect &rect)
 Sets the outer rect of this layout element. More...
 
void setMargins (const QMargins &margins)
 Sets the margins of this layout element. More...
 
void setMinimumMargins (const QMargins &margins)
 If setAutoMargins is enabled on some or all margins, this function is used to provide minimum values for those margins. More...
 
void setAutoMargins (QCP::MarginSides sides)
 Sets on which sides the margin shall be calculated automatically. More...
 
void setMinimumSize (const QSize &size)
 Sets the minimum size for the inner rect of this layout element. More...
 
void setMinimumSize (int width, int height)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the minimum size for the inner rect of this layout element. More...
 
void setMaximumSize (const QSize &size)
 Sets the maximum size for the inner rect of this layout element. More...
 
void setMaximumSize (int width, int height)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the maximum size for the inner rect of this layout element. More...
 
void setMarginGroup (QCP::MarginSides sides, QCPMarginGroup *group)
 Sets the margin group of the specified margin sides. More...
 
virtual QSize minimumSizeHint () const
 Returns the minimum size this layout element (the inner rect) may be compressed to. More...
 
virtual QSize maximumSizeHint () const
 Returns the maximum size this layout element (the inner rect) may be expanded to. More...
 
virtual QList< QCPLayoutElement * > elements (bool recursive) const
 Returns a list of all child elements in this layout element. More...
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
 Layout elements are sensitive to events inside their outer rect. More...
 
- Public Member Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0)
 Creates a new QCPLayerable instance. More...
 
 ~QCPLayerable ()
 
bool visible () const
 
QCustomPlotparentPlot () const
 
QCPLayerableparentLayerable () const
 Returns the parent layerable of this layerable. More...
 
QCPLayerlayer () const
 
bool antialiased () const
 
void setVisible (bool on)
 Sets the visibility of this layerable object. More...
 
Q_SLOT bool setLayer (QCPLayer *layer)
 Sets the layer of this layerable object. More...
 
bool setLayer (const QString &layerName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the layer of this layerable object by name. More...
 
void setAntialiased (bool enabled)
 Sets whether this object will be drawn antialiased or not. More...
 
bool realVisibility () const
 Returns whether this layerable is visible, taking the visibility of the layerable parent and the visibility of the layer this layerable is on into account. More...
 

Protected Member Functions

virtual void applyDefaultAntialiasingHint (QCPPainter *painter) const
 
virtual void mousePressEvent (QMouseEvent *event)
 This event is called, if the mouse was pressed while being inside the outer rect of this layout element. More...
 
virtual void mouseMoveEvent (QMouseEvent *event)
 This event is called, if the mouse is moved inside the outer rect of this layout element. More...
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 This event is called, if the mouse was previously pressed inside the outer rect of this layout element and is now released. More...
 
virtual void wheelEvent (QWheelEvent *event)
 This event is called, if the mouse wheel is scrolled while the cursor is inside the rect of this layout element. More...
 
- Protected Member Functions inherited from QCPLayoutElement
virtual int calculateAutoMargin (QCP::MarginSide side)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 This event is called, if the mouse is double-clicked inside the outer rect of this layout element. More...
 
virtual void draw (QCPPainter *painter)
 
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
 
- Protected Member Functions inherited from QCPLayerable
virtual QCP::Interaction selectionCategory () const
 
virtual QRect clipRect () const
 
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
 
virtual void deselectEvent (bool *selectionStateChanged)
 
void initializeParentPlot (QCustomPlot *parentPlot)
 
void setParentLayerable (QCPLayerable *parentLayerable)
 
bool moveToLayer (QCPLayer *layer, bool prepend)
 
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const
 

Protected Attributes

QCPAxis::AxisType mType
 
QCPRange mDataRange
 
QCPAxis::ScaleType mDataScaleType
 
QCPColorGradient mGradient
 
int mBarWidth
 
QPointer< QCPColorScaleAxisRectPrivatemAxisRect
 
QPointer< QCPAxismColorAxis
 
- Protected Attributes inherited from QCPLayoutElement
QCPLayoutmParentLayout
 
QSize mMinimumSize
 
QSize mMaximumSize
 
QRect mRect
 
QRect mOuterRect
 
QMargins mMargins
 
QMargins mMinimumMargins
 
QCP::MarginSides mAutoMargins
 
QHash< QCP::MarginSide, QCPMarginGroup * > mMarginGroups
 
- Protected Attributes inherited from QCPLayerable
bool mVisible
 
QCustomPlotmParentPlot
 
QPointer< QCPLayerablemParentLayerable
 
QCPLayermLayer
 
bool mAntialiased
 

Friends

class QCPColorScaleAxisRectPrivate
 

Additional Inherited Members

- Public Types inherited from QCPLayoutElement
enum  UpdatePhase {
  upPreparation ,
  upMargins ,
  upLayout
}
 Defines the phases of the update process, that happens just before a replot. More...
 

Detailed Description

A color scale for use with color coding data such as QCPColorMap.

This layout element can be placed on the plot to correlate a color gradient with data values. It is usually used in combination with one or multiple QCPColorMaps.

The color scale can be either horizontal or vertical, as shown in the image above. The orientation and the side where the numbers appear is controlled with setType.

Use QCPColorMap::setColorScale to connect a color map with a color scale. Once they are connected, they share their gradient, data range and data scale type (setGradient, setDataRange, setDataScaleType). Multiple color maps may be associated with a single color scale, to make them all synchronize these properties.

To have finer control over the number display and axis behaviour, you can directly access the axis. See the documentation of QCPAxis for details about configuring axes. For example, if you want to change the number of automatically generated ticks, call

colorScale->axis()->setAutoTickCount(3);

Placing a color scale next to the main axis rect works like with any other layout element:

QCPColorScale *colorScale = new QCPColorScale(customPlot);
customPlot->plotLayout()->addElement(0, 1, colorScale);
colorScale->setLabel("Some Label Text");
A color scale for use with color coding data such as QCPColorMap.
Definition: qcustomplot.h:2363
QCPColorScale(QCustomPlot *parentPlot)
Constructs a new QCPColorScale.
void setLabel(const QString &str)
Sets the axis label of the color scale.

In this case we have placed it to the right of the default axis rect, so it wasn't necessary to call setType, since QCPAxis::atRight is already the default. The text next to the color scale can be set with setLabel.

For optimum appearance (like in the image above), it may be desirable to line up the axis rect and the borders of the color scale. Use a QCPMarginGroup to achieve this:

QCPMarginGroup *group = new QCPMarginGroup(customPlot);
customPlot->axisRect()->setMarginGroup(QCP::msTop|QCP::msBottom, group);
void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group)
Sets the margin group of the specified margin sides.
friend class QCPMarginGroup
Definition: qcustomplot.h:714
A margin group allows synchronization of margin sides if working with multiple layout elements.
Definition: qcustomplot.h:600
@ msBottom
0x08 bottom margin
Definition: qcustomplot.h:102
@ msTop
0x04 top margin
Definition: qcustomplot.h:101

Color scales are initialized with a non-zero minimum top and bottom margin (setMinimumMargins), because vertical color scales are most common and the minimum top/bottom margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a horizontal color scale by setting setType to QCPAxis::atBottom or QCPAxis::atTop, you might want to also change the minimum margins accordingly, e.g. setMinimumMargins(QMargins(6, 0, 6, 0)).

Definition at line 2362 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPColorScale()

QCPColorScale::QCPColorScale ( QCustomPlot parentPlot)
explicit

Constructs a new QCPColorScale.

Definition at line 13835 of file qcustomplot.cpp.

◆ ~QCPColorScale()

QCPColorScale::~QCPColorScale ( )
virtual

Definition at line 13847 of file qcustomplot.cpp.

Member Function Documentation

◆ applyDefaultAntialiasingHint()

void QCPColorScale::applyDefaultAntialiasingHint ( QCPPainter painter) const
protectedvirtual

Reimplemented from QCPLayoutElement.

Definition at line 14182 of file qcustomplot.cpp.

◆ axis()

QCPAxis * QCPColorScale::axis ( ) const
inline

Returns the internal QCPAxis instance of this color scale.

You can access it to alter the appearance and behaviour of the axis. QCPColorScale duplicates some properties in its interface for convenience. Those are setDataRange (QCPAxis::setRange), setDataScaleType (QCPAxis::setScaleType), and the method setLabel (QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on the QCPColorScale or on its QCPAxis.

If the type of the color scale is changed with setType, the axis returned by this method will change, too, to either the left, right, bottom or top axis, depending on which type was set.

Definition at line 2380 of file qcustomplot.h.

◆ barWidth()

int QCPColorScale::barWidth ( ) const
inline

Definition at line 2386 of file qcustomplot.h.

◆ colorMaps()

QList< QCPColorMap * > QCPColorScale::colorMaps ( ) const

Returns a list of all the color maps associated with this color scale.

Definition at line 14068 of file qcustomplot.cpp.

◆ dataRange()

QCPRange QCPColorScale::dataRange ( ) const
inline

Definition at line 2382 of file qcustomplot.h.

◆ dataRangeChanged

void QCPColorScale::dataRangeChanged ( QCPRange  newRange)
signal

This signal is emitted when the data range changes.

See also
setDataRange

◆ dataScaleType()

QCPAxis::ScaleType QCPColorScale::dataScaleType ( ) const
inline

Definition at line 2383 of file qcustomplot.h.

◆ dataScaleTypeChanged

void QCPColorScale::dataScaleTypeChanged ( QCPAxis::ScaleType  scaleType)
signal

This signal is emitted when the data scale type changes.

See also
setDataScaleType

◆ gradient()

QCPColorGradient QCPColorScale::gradient ( ) const
inline

Definition at line 2384 of file qcustomplot.h.

◆ gradientChanged

void QCPColorScale::gradientChanged ( QCPColorGradient  newGradient)
signal

This signal is emitted when the gradient changes.

See also
setGradient

◆ label()

QString QCPColorScale::label ( ) const

Definition at line 13853 of file qcustomplot.cpp.

◆ mouseMoveEvent()

void QCPColorScale::mouseMoveEvent ( QMouseEvent *  event)
protectedvirtual

This event is called, if the mouse is moved inside the outer rect of this layout element.

Reimplemented from QCPLayoutElement.

Definition at line 14199 of file qcustomplot.cpp.

◆ mousePressEvent()

void QCPColorScale::mousePressEvent ( QMouseEvent *  event)
protectedvirtual

This event is called, if the mouse was pressed while being inside the outer rect of this layout element.

Reimplemented from QCPLayoutElement.

Definition at line 14188 of file qcustomplot.cpp.

◆ mouseReleaseEvent()

void QCPColorScale::mouseReleaseEvent ( QMouseEvent *  event)
protectedvirtual

This event is called, if the mouse was previously pressed inside the outer rect of this layout element and is now released.

Reimplemented from QCPLayoutElement.

Definition at line 14210 of file qcustomplot.cpp.

◆ rangeDrag()

bool QCPColorScale::rangeDrag ( ) const

Definition at line 13865 of file qcustomplot.cpp.

◆ rangeZoom()

bool QCPColorScale::rangeZoom ( ) const

Definition at line 13879 of file qcustomplot.cpp.

◆ rescaleDataRange()

void QCPColorScale::rescaleDataRange ( bool  onlyVisibleMaps)

Changes the data range such that all color maps associated with this color scale are fully mapped to the gradient in the data dimension.

See also
setDataRange

Definition at line 14086 of file qcustomplot.cpp.

◆ setBarWidth()

void QCPColorScale::setBarWidth ( int  width)

Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed will have.

Definition at line 14020 of file qcustomplot.cpp.

◆ setDataRange()

void QCPColorScale::setDataRange ( const QCPRange dataRange)

Sets the range spanned by the color gradient and that is shown by the axis in the color scale.

It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is also equivalent to directly accessing the axis and setting its range with QCPAxis::setRange.

See also
setDataScaleType, setGradient, rescaleDataRange

Definition at line 13949 of file qcustomplot.cpp.

◆ setDataScaleType()

void QCPColorScale::setDataScaleType ( QCPAxis::ScaleType  scaleType)

Sets the scale type of the color scale, i.e.

whether values are linearly associated with colors or logarithmically.

It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is also equivalent to directly accessing the axis and setting its scale type with QCPAxis::setScaleType.

See also
setDataRange, setGradient

Definition at line 13970 of file qcustomplot.cpp.

◆ setGradient()

void QCPColorScale::setGradient ( const QCPColorGradient gradient)

Sets the color gradient that will be used to represent data values.

It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps.

See also
setDataRange, setDataScaleType

Definition at line 13990 of file qcustomplot.cpp.

◆ setLabel()

void QCPColorScale::setLabel ( const QString &  str)

Sets the axis label of the color scale.

This is equivalent to calling QCPAxis::setLabel on the internal axis.

Definition at line 14005 of file qcustomplot.cpp.

◆ setRangeDrag()

void QCPColorScale::setRangeDrag ( bool  enabled)

Sets whether the user can drag the data range (setDataRange).

Note that QCP::iRangeDrag must be in the QCustomPlot's interactions (QCustomPlot::setInteractions) to allow range dragging.

Definition at line 14031 of file qcustomplot.cpp.

◆ setRangeZoom()

void QCPColorScale::setRangeZoom ( bool  enabled)

Sets whether the user can zoom the data range (setDataRange) by scrolling the mouse wheel.

Note that QCP::iRangeZoom must be in the QCustomPlot's interactions (QCustomPlot::setInteractions) to allow range dragging.

Definition at line 14051 of file qcustomplot.cpp.

◆ setType()

void QCPColorScale::setType ( QCPAxis::AxisType  type)

Sets at which side of the color scale the axis is placed, and thus also its orientation.

Note that after setting type to a different value, the axis returned by axis() will be a different one. The new axis will adopt the following properties from the previous axis: The range, scale type, log base and label.

Definition at line 13899 of file qcustomplot.cpp.

◆ type()

QCPAxis::AxisType QCPColorScale::type ( ) const
inline

Definition at line 2381 of file qcustomplot.h.

◆ update()

void QCPColorScale::update ( UpdatePhase  phase)
virtual

Updates the layout element and sub-elements.

This function is automatically called before every replot by the parent layout element. It is called multiple times, once for every UpdatePhase. The phases are run through in the order of the enum values. For details about what happens at the different phases, see the documentation of UpdatePhase.

Layout elements that have child elements should call the update method of their child elements, and pass the current phase unchanged.

The default implementation executes the automatic margin mechanism in the upMargins phase. Subclasses should make sure to call the base class implementation.

Reimplemented from QCPLayoutElement.

Definition at line 14146 of file qcustomplot.cpp.

◆ wheelEvent()

void QCPColorScale::wheelEvent ( QWheelEvent *  event)
protectedvirtual

This event is called, if the mouse wheel is scrolled while the cursor is inside the rect of this layout element.

Reimplemented from QCPLayoutElement.

Definition at line 14221 of file qcustomplot.cpp.

Friends And Related Function Documentation

◆ QCPColorScaleAxisRectPrivate

friend class QCPColorScaleAxisRectPrivate
friend

Definition at line 2435 of file qcustomplot.h.

Member Data Documentation

◆ mAxisRect

QPointer<QCPColorScaleAxisRectPrivate> QCPColorScale::mAxisRect
protected

Definition at line 2421 of file qcustomplot.h.

◆ mBarWidth

int QCPColorScale::mBarWidth
protected

Definition at line 2418 of file qcustomplot.h.

◆ mColorAxis

QPointer<QCPAxis> QCPColorScale::mColorAxis
protected

Definition at line 2422 of file qcustomplot.h.

◆ mDataRange

QCPRange QCPColorScale::mDataRange
protected

Definition at line 2415 of file qcustomplot.h.

◆ mDataScaleType

QCPAxis::ScaleType QCPColorScale::mDataScaleType
protected

Definition at line 2416 of file qcustomplot.h.

◆ mGradient

QCPColorGradient QCPColorScale::mGradient
protected

Definition at line 2417 of file qcustomplot.h.

◆ mType

QCPAxis::AxisType QCPColorScale::mType
protected

Definition at line 2414 of file qcustomplot.h.


The documentation for this class was generated from the following files: