rock_widget_collection  0.1
Public Slots | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
QCPAbstractPlottable Class Referenceabstract

The abstract base class for all data representing objects in a plot. More...

#include <qcustomplot.h>

Inherits QObject.

Inherited by QCPBars, QCPCurve, QCPGraph, and QCPStatisticalBox.

Public Slots

QCustomPlotparentPlot () const
 
QString name () const
 
bool visible () const
 
QPen pen () const
 
QBrush brush () const
 
QCPAxiskeyAxis () const
 
QCPAxisvalueAxis () const
 
void setName (const QString &name)
 
void setVisible (bool visible)
 
void setPen (const QPen &pen)
 
void setBrush (const QBrush &brush)
 
void setKeyAxis (QCPAxis *axis)
 
void setValueAxis (QCPAxis *axis)
 
void rescaleAxes (bool onlyEnlarge=false) const
 
void rescaleKeyAxis (bool onlyEnlarge=false) const
 
void rescaleValueAxis (bool onlyEnlarge=false) const
 
virtual void clearData ()=0
 
virtual bool addToLegend () const
 
virtual bool removeFromLegend () const
 

Public Member Functions

 QCPAbstractPlottable (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual ~QCPAbstractPlottable ()
 

Protected Types

enum  SignDomain { SDNegative, SDBoth, SDPositive }
 

Protected Member Functions

virtual void draw (QPainter *painter) const =0
 
virtual void drawLegendIcon (QPainter *painter, const QRect &rect) const =0
 
virtual QCPRange getKeyRange (bool &validRange, SignDomain inSignDomain=SDBoth) const =0
 
virtual QCPRange getValueRange (bool &validRange, SignDomain inSignDomain=SDBoth) const =0
 
void coordsToPixels (double key, double value, double &x, double &y) const
 
const QPointF coordsToPixels (double key, double value) const
 

Protected Attributes

QCustomPlotmParentPlot
 
QString mName
 
bool mVisible
 
QPen mPen
 
QBrush mBrush
 
QCPAxismKeyAxis
 
QCPAxismValueAxis
 

Friends

class QCustomPlot
 
class QCPPlottableLegendItem
 

Detailed Description

The abstract base class for all data representing objects in a plot.

It defines a very basic interface like name, pen, brush, visibility etc. Since this class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself (see below), to create new ways of displaying data.

All further specifics are in the subclasses, for example:

Creating own plottables

To create an own plottable, you implement a subclass of QCPAbstractPlottable. These are the pure virtual functions, you must implement:

See the documentation of those functions for what they need to do.

For drawing your plot, you can use the coordsToPixels functions to translate a point in plot coordinates to pixel coordinates. This function is quite convenient, because it takes the orientation of the key and value axes into account for you (x and y are swapped when the key axis is vertical and the value axis horizontal). If you are worried about performance (i.e. you need to translate many points in a loop like QCPGraph), you can directly use QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis yourself.

From QCPAbstractPlottable you inherit the following members you may use:

Definition at line 112 of file qcustomplot.h.

Member Enumeration Documentation

Represents negative and positive sign domain for passing to getKeyRange and getValueRange.

Enumerator
SDNegative 

The negative sign domain, i.e. numbers smaller than zero.

SDBoth 

Both sign domains, including zero, i.e. all (rational) numbers.

SDPositive 

The positive sign domain, i.e. numbers greater than zero.

Definition at line 149 of file qcustomplot.h.

149  {SDNegative,
150  SDBoth,
151  SDPositive
152  };
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
The negative sign domain, i.e. numbers smaller than zero.
Definition: qcustomplot.h:149
The positive sign domain, i.e. numbers greater than zero.
Definition: qcustomplot.h:151

Constructor & Destructor Documentation

QCPAbstractPlottable::QCPAbstractPlottable ( QCPAxis keyAxis,
QCPAxis valueAxis 
)

Constructs an abstract plottable which uses keyAxis as its key axis ("x") and valueAxis as its value axis ("y"). keyAxis and valueAxis must reside in the same QCustomPlot instance.

Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables (i.e. any form of data representation inside a plot, like graphs, curves etc.), it can't be directly instantiated.

You probably want one of the subclasses like QCPGraph and QCPCurve instead.

See Also
setkeyAxis, setValueAxis

Definition at line 6092 of file qcustomplot.cc.

6092  :
6093  mParentPlot(keyAxis->parentPlot()),
6094  mName(""),
6095  mVisible(true),
6096  mPen(Qt::black),
6097  mBrush(Qt::NoBrush),
6098  mKeyAxis(keyAxis),
6099  mValueAxis(valueAxis)
6100 {
6101  if (keyAxis->parentPlot() != valueAxis->parentPlot())
6102  qDebug() << FUNCNAME << "Parent plot of keyAxis is not the same as that of valueAxis.";
6103  if (keyAxis->orientation() == valueAxis->orientation())
6104  qDebug() << FUNCNAME << "keyAxis and valueAxis must be orthogonal to each other.";
6105 }
QCustomPlot * parentPlot() const
Definition: qcustomplot.h:741
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
#define FUNCNAME
Definition: qcustomplot.h:50
virtual QCPAbstractPlottable::~QCPAbstractPlottable ( )
inlinevirtual

Definition at line 117 of file qcustomplot.h.

117 {}

Member Function Documentation

bool QCPAbstractPlottable::addToLegend ( ) const
virtualslot

Adds this plottable to the legend of the parent QCustomPlot.

Normally, a QCPPlottableLegendItem is created and inserted into the legend. If the plottable needs a more specialized representation in the plot, this function will take this into account and instead create the specialized subclass of QCPAbstractLegendItem.

Returns true on success, i.e. when a legend item associated with this plottable isn't already in the legend.

See Also
removeFromLegend, QCPLegend::addItem

Definition at line 6260 of file qcustomplot.cc.

6261 {
6263  {
6265  return true;
6266  } else
6267  return false;
6268 }
bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QCPLegend * legend
Definition: qcustomplot.h:1007
bool addItem(QCPAbstractLegendItem *item)
friend class QCPPlottableLegendItem
Definition: qcustomplot.h:168
QBrush QCPAbstractPlottable::brush ( ) const
inlineslot

Definition at line 125 of file qcustomplot.h.

125 { return mBrush; }
void QCPAbstractPlottable::clearData ( )
pure virtualslot

Clears all data in the plottable.

Implemented in QCPCurve.

void QCPAbstractPlottable::coordsToPixels ( double  key,
double  value,
double &  x,
double &  y 
) const
protected

Definition at line 6298 of file qcustomplot.cc.

6299 {
6300  if (mKeyAxis->orientation() == Qt::Horizontal)
6301  {
6302  x = mKeyAxis->coordToPixel(key);
6303  y = mValueAxis->coordToPixel(value);
6304  } else
6305  {
6306  y = mKeyAxis->coordToPixel(key);
6307  x = mValueAxis->coordToPixel(value);
6308  }
6309 }
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
const QPointF QCPAbstractPlottable::coordsToPixels ( double  key,
double  value 
) const
protected

Definition at line 6316 of file qcustomplot.cc.

6317 {
6318  if (mKeyAxis->orientation() == Qt::Horizontal)
6319  return QPointF(mKeyAxis->coordToPixel(key), mValueAxis->coordToPixel(value));
6320  else
6321  return QPointF(mValueAxis->coordToPixel(value), mKeyAxis->coordToPixel(key));
6322 }
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
void QCPAbstractPlottable::draw ( QPainter *  painter) const
protectedpure virtual

Implemented in QCPStatisticalBox, QCPBars, QCPCurve, and QCPGraph.

void QCPAbstractPlottable::drawLegendIcon ( QPainter *  painter,
const QRect &  rect 
) const
protectedpure virtual

Implemented in QCPStatisticalBox, QCPBars, QCPCurve, and QCPGraph.

QCPRange QCPAbstractPlottable::getKeyRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedpure virtual

Implemented in QCPStatisticalBox, QCPBars, QCPCurve, and QCPGraph.

QCPRange QCPAbstractPlottable::getValueRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedpure virtual

Implemented in QCPStatisticalBox, QCPBars, QCPCurve, and QCPGraph.

QCPAxis* QCPAbstractPlottable::keyAxis ( ) const
inlineslot

Definition at line 126 of file qcustomplot.h.

126 { return mKeyAxis; }
QString QCPAbstractPlottable::name ( ) const
inlineslot

Definition at line 122 of file qcustomplot.h.

122 { return mName; }
QCustomPlot* QCPAbstractPlottable::parentPlot ( ) const
inlineslot

Definition at line 121 of file qcustomplot.h.

121 { return mParentPlot; }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QPen QCPAbstractPlottable::pen ( ) const
inlineslot

Definition at line 124 of file qcustomplot.h.

124 { return mPen; }
bool QCPAbstractPlottable::removeFromLegend ( ) const
virtualslot

Removes the plottable from the legend of the parent QCustomPlot. This means the QCPAbstractLegendItem (usually a QCPPlottableLegendItem) that is associated with this plottable is removed.

Returns true on success, i.e. if a legend item associated with this plottable was found and removed from the legend.

See Also
addToLegend, QCPLegend::removeItem

Definition at line 6280 of file qcustomplot.cc.

6281 {
6283  return mParentPlot->legend->removeItem(lip);
6284  else
6285  return false;
6286 }
A legend item representing a plottable with an icon and the plottable name.
Definition: qcustomplot.h:533
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QCPLegend * legend
Definition: qcustomplot.h:1007
QCPPlottableLegendItem * itemWithPlottable(const QCPAbstractPlottable *plottable) const
bool removeItem(int index)
void QCPAbstractPlottable::rescaleAxes ( bool  onlyEnlarge = false) const
slot

Rescales the key and value axes associated with this plottable to contain all displayed data, so the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. Instead it will stay in the current sign domain and ignore all entities of the plottable that lie outside of that domain.

onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has onlyEnlarge set to false (the default), and all subsequent set to true.

Definition at line 6188 of file qcustomplot.cc.

6189 {
6190  rescaleKeyAxis(onlyEnlarge);
6191  rescaleValueAxis(onlyEnlarge);
6192 }
void rescaleKeyAxis(bool onlyEnlarge=false) const
void rescaleValueAxis(bool onlyEnlarge=false) const
void QCPAbstractPlottable::rescaleKeyAxis ( bool  onlyEnlarge = false) const
slot

Rescales the key axis of the plottable so the whole plottable is visible.

See rescaleAxes for detailed behaviour.

Definition at line 6199 of file qcustomplot.cc.

6200 {
6201  SignDomain signDomain = SDBoth;
6203  signDomain = (mKeyAxis->range().upper < 0 ? SDNegative : SDPositive);
6204 
6205  bool validRange;
6206  QCPRange newRange = getKeyRange(validRange, signDomain);
6207 
6208  if (validRange)
6209  {
6210  if (onlyEnlarge)
6211  {
6212  if (mKeyAxis->range().lower < newRange.lower)
6213  newRange.lower = mKeyAxis->range().lower;
6214  if (mKeyAxis->range().upper > newRange.upper)
6215  newRange.upper = mKeyAxis->range().upper;
6216  }
6217  mKeyAxis->setRange(newRange);
6218  }
6219 }
const QCPRange range() const
Definition: qcustomplot.h:746
void setRange(double lower, double upper)
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=SDBoth) const =0
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
The negative sign domain, i.e. numbers smaller than zero.
Definition: qcustomplot.h:149
The positive sign domain, i.e. numbers greater than zero.
Definition: qcustomplot.h:151
double upper
Definition: qcustomplot.h:494
Represents the range an axis is encompassing.
Definition: qcustomplot.h:491
double lower
Definition: qcustomplot.h:494
ScaleType scaleType() const
Definition: qcustomplot.h:744
void QCPAbstractPlottable::rescaleValueAxis ( bool  onlyEnlarge = false) const
slot

Rescales the value axis of the plottable so the whole plottable is visible.

See rescaleAxes for detailed behaviour.

Definition at line 6226 of file qcustomplot.cc.

6227 {
6228  SignDomain signDomain = SDBoth;
6230  signDomain = (mValueAxis->range().upper < 0 ? SDNegative : SDPositive);
6231 
6232  bool validRange;
6233  QCPRange newRange = getValueRange(validRange, signDomain);
6234 
6235  if (validRange)
6236  {
6237  if (onlyEnlarge)
6238  {
6239  if (mValueAxis->range().lower < newRange.lower)
6240  newRange.lower = mValueAxis->range().lower;
6241  if (mValueAxis->range().upper > newRange.upper)
6242  newRange.upper = mValueAxis->range().upper;
6243  }
6244  mValueAxis->setRange(newRange);
6245  }
6246 }
const QCPRange range() const
Definition: qcustomplot.h:746
void setRange(double lower, double upper)
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=SDBoth) const =0
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
The negative sign domain, i.e. numbers smaller than zero.
Definition: qcustomplot.h:149
The positive sign domain, i.e. numbers greater than zero.
Definition: qcustomplot.h:151
double upper
Definition: qcustomplot.h:494
Represents the range an axis is encompassing.
Definition: qcustomplot.h:491
double lower
Definition: qcustomplot.h:494
ScaleType scaleType() const
Definition: qcustomplot.h:744
void QCPAbstractPlottable::setBrush ( const QBrush &  brush)
slot

The brush is used to draw basic fills of the plottable representation in the plot. The Fill can be a color, gradient or texture, see the usage of QBrush.

For example, the QCPGraph subclass draws the fill under the graph with this brush, when it's not set to Qt::NoBrush.

See Also
setPen

Definition at line 6148 of file qcustomplot.cc.

6149 {
6150  mBrush = brush;
6151 }
QBrush brush() const
Definition: qcustomplot.h:125
void QCPAbstractPlottable::setKeyAxis ( QCPAxis axis)
slot

The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal to the plottable's value axis. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the y-axis (QCustomPlot::yAxis) as value axis.

See Also
setValueAxis

Definition at line 6160 of file qcustomplot.cc.

6161 {
6162  mKeyAxis = axis;
6163 }
void QCPAbstractPlottable::setName ( const QString &  name)
slot

The name is the textual representation of this plottable as it is displayed in the QCPLegend of the parent QCustomPlot. It may contain any utf-8 characters, including newlines.

Definition at line 6111 of file qcustomplot.cc.

6112 {
6113  mName = name;
6114 }
QString name() const
Definition: qcustomplot.h:122
void QCPAbstractPlottable::setPen ( const QPen &  pen)
slot

The pen is used to draw basic lines that make up the plottable representation in the plot.

For example, the QCPGraph subclass draws its graph lines and scatter points with this pen.

See Also
setBrush

Definition at line 6134 of file qcustomplot.cc.

6135 {
6136  mPen = pen;
6137 }
QPen pen() const
Definition: qcustomplot.h:124
void QCPAbstractPlottable::setValueAxis ( QCPAxis axis)
slot

The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal to the plottable's key axis. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the y-axis (QCustomPlot::yAxis) as value axis.

See Also
setKeyAxis

Definition at line 6172 of file qcustomplot.cc.

6173 {
6174  mValueAxis = axis;
6175 }
void QCPAbstractPlottable::setVisible ( bool  visible)
slot

If the plottable visibility is set to false, it won't be drawn to the plot surface. It will still appear in a QCPLegend that it's associated with, though.

Definition at line 6120 of file qcustomplot.cc.

6121 {
6122  mVisible = visible;
6123 }
bool visible() const
Definition: qcustomplot.h:123
QCPAxis* QCPAbstractPlottable::valueAxis ( ) const
inlineslot

Definition at line 127 of file qcustomplot.h.

127 { return mValueAxis; }
bool QCPAbstractPlottable::visible ( ) const
inlineslot

Definition at line 123 of file qcustomplot.h.

123 { return mVisible; }

Friends And Related Function Documentation

friend class QCPPlottableLegendItem
friend

Definition at line 168 of file qcustomplot.h.

friend class QCustomPlot
friend

Definition at line 167 of file qcustomplot.h.

Member Data Documentation

QBrush QCPAbstractPlottable::mBrush
protected

Definition at line 157 of file qcustomplot.h.

QCPAxis* QCPAbstractPlottable::mKeyAxis
protected

Definition at line 158 of file qcustomplot.h.

QString QCPAbstractPlottable::mName
protected

Definition at line 154 of file qcustomplot.h.

QCustomPlot* QCPAbstractPlottable::mParentPlot
protected

Definition at line 153 of file qcustomplot.h.

QPen QCPAbstractPlottable::mPen
protected

Definition at line 156 of file qcustomplot.h.

QCPAxis * QCPAbstractPlottable::mValueAxis
protected

Definition at line 158 of file qcustomplot.h.

bool QCPAbstractPlottable::mVisible
protected

Definition at line 155 of file qcustomplot.h.


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