rock_widget_collection  0.1
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QCPCurve Class Reference

A plottable representing a parametric curve in a plot. More...

#include <qcustomplot.h>

Inherits QCPAbstractPlottable.

Public Member Functions

 QCPCurve (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual ~QCPCurve ()
 
const QCPCurveDataMapdata () const
 
void setData (QCPCurveDataMap *data, bool copy=false)
 
void setData (const QVector< double > &t, const QVector< double > &key, const QVector< double > &value)
 
void setData (const QVector< double > &key, const QVector< double > &value)
 
void addData (const QCPCurveDataMap &dataMap)
 
void addData (const QCPCurveData &data)
 
void addData (double t, double key, double value)
 
void addData (double key, double value)
 
void addData (const QVector< double > &ts, const QVector< double > &keys, const QVector< double > &values)
 
void removeDataBefore (double t)
 
void removeDataAfter (double t)
 
void removeData (double fromt, double tot)
 
void removeData (double t)
 
virtual void clearData ()
 
- Public Member Functions inherited from QCPAbstractPlottable
 QCPAbstractPlottable (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual ~QCPAbstractPlottable ()
 

Protected Member Functions

virtual void draw (QPainter *painter) const
 
virtual void drawLegendIcon (QPainter *painter, const QRect &rect) const
 
void getCurveData (QVector< QPointF > *lineData) const
 
QPointF outsideCoordsToPixels (double key, double value, int region) const
 
virtual QCPRange getKeyRange (bool &validRange, SignDomain inSignDomain=SDBoth) const
 
virtual QCPRange getValueRange (bool &validRange, SignDomain inSignDomain=SDBoth) const
 
- Protected Member Functions inherited from QCPAbstractPlottable
void coordsToPixels (double key, double value, double &x, double &y) const
 
const QPointF coordsToPixels (double key, double value) const
 

Protected Attributes

QCPCurveDataMapmData
 
- Protected Attributes inherited from QCPAbstractPlottable
QCustomPlotmParentPlot
 
QString mName
 
bool mVisible
 
QPen mPen
 
QBrush mBrush
 
QCPAxismKeyAxis
 
QCPAxismValueAxis
 

Friends

class QCustomPlot
 
class QCPLegend
 

Additional Inherited Members

- Public Slots inherited from QCPAbstractPlottable
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 bool addToLegend () const
 
virtual bool removeFromLegend () const
 
- Protected Types inherited from QCPAbstractPlottable
enum  SignDomain { SDNegative, SDBoth, SDPositive }
 

Detailed Description

A plottable representing a parametric curve in a plot.

To plot data, assign it with the setData or addData functions.

Changing the appearance

The appearance of the curve is determined by the pen and the brush (setPen, setBrush).

Usage

Like all data representing objects in QCustomPlot, the QCPCurve is a plottable (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.)

Usually, you first create an instance:

QCPCurve *newCurve = new QCPCurve(customPlot->xAxis, customPlot->yAxis);

add it to the customPlot with QCustomPlot::addPlottable:

customPlot->addPlottable(newCurve);

and then modify the properties of the newly created plottable, e.g.:

newCurve->setName("Fermat's Spiral");
newCurve->setData(tData, xData, yData);

Definition at line 330 of file qcustomplot.h.

Constructor & Destructor Documentation

QCPCurve::QCPCurve ( QCPAxis keyAxis,
QCPAxis valueAxis 
)
explicit

Constructs a curve which uses keyAxis as its key axis ("x") and valueAxis as its value axis ("y"). keyAxis and valueAxis must both reside in the same QCustomPlot.

The constructed QCPCurve can be added to the plot with QCustomPlot::addPlottable, QCustomPlot then takes ownership of the graph.

Definition at line 6560 of file qcustomplot.cc.

6560  :
6561  QCPAbstractPlottable(keyAxis, valueAxis)
6562 {
6563  mData = new QCPCurveDataMap;
6564  mPen.setColor(Qt::blue);
6565  mPen.setStyle(Qt::SolidLine);
6566  mBrush.setColor(Qt::blue);
6567  mBrush.setStyle(Qt::NoBrush);
6568 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis)
QMap< double, QCPCurveData > QCPCurveDataMap
Definition: qcustomplot.h:92
QCPCurve::~QCPCurve ( )
virtual

Definition at line 6570 of file qcustomplot.cc.

6571 {
6572  delete mData;
6573 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358

Member Function Documentation

void QCPCurve::addData ( const QCPCurveDataMap dataMap)

Adds the provided data points in dataMap to the current data.

See Also
removeData

Definition at line 6640 of file qcustomplot.cc.

6641 {
6642  mData->unite(dataMap);
6643 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::addData ( const QCPCurveData data)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the provided single data point in data to the current data.

See Also
removeData

Definition at line 6649 of file qcustomplot.cc.

6650 {
6651  mData->insertMulti(data.t, data);
6652 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::addData ( double  t,
double  key,
double  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the provided single data point as t, key and value tuple to the current data

See Also
removeData

Definition at line 6658 of file qcustomplot.cc.

6659 {
6660  QCPCurveData newData;
6661  newData.t = t;
6662  newData.key = key;
6663  newData.value = value;
6664  mData->insertMulti(newData.t, newData);
6665 }
A class holding the data of one single data point for QCPCurve.
Definition: qcustomplot.h:79
double value
Definition: qcustomplot.h:83
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
double key
Definition: qcustomplot.h:83
void QCPCurve::addData ( double  key,
double  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Adds the provided single data point as key and value pair to the current data The t parameter of the data point is set to the t of the last data point plus 1. If there is no last data point, t will be set to 0.

See Also
removeData

Definition at line 6675 of file qcustomplot.cc.

6676 {
6677  QCPCurveData newData;
6678  if (!mData->isEmpty())
6679  newData.t = (mData->constEnd()-1).key()+1;
6680  else
6681  newData.t = 0;
6682  newData.key = key;
6683  newData.value = value;
6684  mData->insertMulti(newData.t, newData);
6685 }
A class holding the data of one single data point for QCPCurve.
Definition: qcustomplot.h:79
double value
Definition: qcustomplot.h:83
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
double key
Definition: qcustomplot.h:83
void QCPCurve::addData ( const QVector< double > &  ts,
const QVector< double > &  keys,
const QVector< double > &  values 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the provided data points as t, key and value tuples to the current data.

See Also
removeData

Definition at line 6691 of file qcustomplot.cc.

6692 {
6693  int n = ts.size();
6694  n = qMin(n, keys.size());
6695  n = qMin(n, values.size());
6696  QCPCurveData newData;
6697  for (int i=0; i<n; ++i)
6698  {
6699  newData.t = ts[i];
6700  newData.key = keys[i];
6701  newData.value = values[i];
6702  mData->insertMulti(newData.t, newData);
6703  }
6704 }
A class holding the data of one single data point for QCPCurve.
Definition: qcustomplot.h:79
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::clearData ( )
virtual

Removes all data points.

See Also
removeData, removeDataAfter, removeDataBefore

Implements QCPAbstractPlottable.

Definition at line 6763 of file qcustomplot.cc.

6764 {
6765  mData->clear();
6766 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
const QCPCurveDataMap* QCPCurve::data ( ) const
inline

Definition at line 338 of file qcustomplot.h.

338 { return mData; }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::draw ( QPainter *  painter) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 6769 of file qcustomplot.cc.

6770 {
6771  if (!mVisible) return;
6772  if (mData->isEmpty()) return;
6773  painter->setClipRect(mKeyAxis->axisRect().united(mValueAxis->axisRect()));
6774 
6775  // allocate line vector:
6776  QVector<QPointF> *lineData = new QVector<QPointF>;
6777  // fill with curve data:
6778  getCurveData(lineData);
6779  // draw curve fill:
6780  if (mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0)
6781  {
6782  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEFills));
6783  painter->setPen(Qt::NoPen);
6784  painter->setBrush(mBrush);
6785  painter->drawPolygon(QPolygonF(*lineData));
6786  }
6787  // draw curve line:
6788  if (mPen.style() != Qt::NoPen && mPen.color().alpha() != 0)
6789  {
6790  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
6791  painter->setPen(mPen);
6792  painter->setBrush(Qt::NoBrush);
6793  painter->drawPolyline(QPolygonF(*lineData));
6794  }
6795  // free allocated line data:
6796  delete lineData;
6797 }
QRect axisRect() const
Definition: qcustomplot.h:743
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void getCurveData(QVector< QPointF > *lineData) const
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
void QCPCurve::drawLegendIcon ( QPainter *  painter,
const QRect &  rect 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 6800 of file qcustomplot.cc.

6801 {
6802  // draw fill:
6803  if (mBrush.style() != Qt::NoBrush)
6804  {
6805  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
6806  painter->fillRect(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0, mBrush);
6807  }
6808  // draw line vertically centered:
6809  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
6810  painter->setPen(mPen);
6811  painter->drawLine(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0); // +5 on x2 else last segment is missing from dashed/dotted pens
6812 }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
void QCPCurve::getCurveData ( QVector< QPointF > *  lineData) const
protected

Definition at line 6819 of file qcustomplot.cc.

6820 {
6821  /* Edges of axis rect R divide outside space into 9 regions:
6822  1__|_4_|__7
6823  2__|_R_|__8
6824  3 | 6 | 9
6825  General idea: If the two points of a line segment are in the same region (that is not R), the line segment is omitted.
6826  The region inside R has index 5.
6827  */
6828  lineData->reserve(mData->size());
6829  QCPCurveDataMap::const_iterator it;
6830  int lastRegion = 5;
6831  int currentRegion = 5;
6832  double RLeft = mKeyAxis->range().lower;
6833  double RRight = mKeyAxis->range().upper;
6834  double RBottom = mValueAxis->range().lower;
6835  double RTop = mValueAxis->range().upper;
6836  double x, y; // current key/value
6837  bool addedLastAlready = true;
6838  bool firstPoint = true; // first point must always be drawn, to make sure fill works correctly
6839  for (it = mData->constBegin(); it != mData->constEnd(); ++it)
6840  {
6841  x = it.value().key;
6842  y = it.value().value;
6843  // determine current region:
6844  if (x < RLeft) // region 123
6845  {
6846  if (y > RTop)
6847  currentRegion = 1;
6848  else if (y < RBottom)
6849  currentRegion = 3;
6850  else
6851  currentRegion = 2;
6852  } else if (x > RRight) // region 789
6853  {
6854  if (y > RTop)
6855  currentRegion = 7;
6856  else if (y < RBottom)
6857  currentRegion = 9;
6858  else
6859  currentRegion = 8;
6860  } else // region 456
6861  {
6862  if (y > RTop)
6863  currentRegion = 4;
6864  else if (y < RBottom)
6865  currentRegion = 6;
6866  else
6867  currentRegion = 5;
6868  }
6869 
6870  /*
6871  Watch out, the next part is very tricky, since it modifies the curve such that it seems like
6872  the whole thing is still drawn, but actually the points outside the axisRect are simplified
6873  ("optimized") greatly. There are some subtle special cases when line segments are large and
6874  thereby each subsequent point may be in a different region or even skip some.
6875  */
6876  // determine whether to keep current point:
6877  if (currentRegion == 5 || (firstPoint && mBrush.style() != Qt::NoBrush)) // current is in R, add current and last if it wasn't added already
6878  {
6879  if (!addedLastAlready) // in case curve just entered R, make sure the last point outside R is also drawn correctly
6880  lineData->append(coordsToPixels((it-1).value().key, (it-1).value().value)); // add last point to vector
6881  else if (lastRegion != 5) // added last already. If that's the case, we probably added it at optimized position. So go back and make sure it's at original position
6882  {
6883  if (!firstPoint) // because on firstPoint, currentRegion is 5 and addedLastAlready is true, although there is no last point
6884  lineData->replace(lineData->size()-1, coordsToPixels((it-1).value().key, (it-1).value().value));
6885  }
6886  lineData->append(coordsToPixels(it.value().key, it.value().value)); // add current point to vector
6887  addedLastAlready = true; // so in next iteration, we don't add this point twice
6888  } else if (currentRegion != lastRegion) // changed region, add current and last if not added already
6889  {
6890  // using outsideCoordsToPixels instead of coorsToPixels for optimized point placement (places points just outside axisRect instead of potentially far away)
6891 
6892  // if we're coming from R or we skip diagonally over the edge regions (so line might still be visible in R), we can't place points optimized
6893  if (lastRegion == 5 || // coming from R
6894  ((lastRegion==2 && currentRegion==4) || (lastRegion==4 && currentRegion==2)) || // skip top left diagonal
6895  ((lastRegion==4 && currentRegion==8) || (lastRegion==8 && currentRegion==4)) || // skip top right diagonal
6896  ((lastRegion==8 && currentRegion==6) || (lastRegion==6 && currentRegion==8)) || // skip bottom right diagonal
6897  ((lastRegion==6 && currentRegion==2) || (lastRegion==2 && currentRegion==6)) // skip bottom left diagonal
6898  )
6899  {
6900  // always add last point if not added already, original:
6901  if (!addedLastAlready)
6902  lineData->append(coordsToPixels((it-1).value().key, (it-1).value().value));
6903  // add current point, original:
6904  lineData->append(coordsToPixels(it.value().key, it.value().value));
6905  } else // no special case that forbids optimized point placement, so do it:
6906  {
6907  // always add last point if not added already, optimized:
6908  if (!addedLastAlready)
6909  lineData->append(outsideCoordsToPixels((it-1).value().key, (it-1).value().value, currentRegion));
6910  // add current point, optimized:
6911  lineData->append(outsideCoordsToPixels(it.value().key, it.value().value, currentRegion));
6912  }
6913  addedLastAlready = true; // so that if next point enters 5, or crosses another region boundary, we don't add this point twice
6914  } else // neither in R, nor crossed a region boundary, skip current point
6915  {
6916  addedLastAlready = false;
6917  }
6918  lastRegion = currentRegion;
6919  firstPoint = false;
6920  }
6921  // If curve ends outside R, we want to add very last point so the fill looks like it should when the curve started inside R:
6922  if (lastRegion != 5 && mBrush.style() != Qt::NoBrush && !mData->isEmpty())
6923  lineData->append(coordsToPixels((mData->constEnd()-1).value().key, (mData->constEnd()-1).value().value));
6924 }
const QCPRange range() const
Definition: qcustomplot.h:746
QPointF outsideCoordsToPixels(double key, double value, int region) const
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void coordsToPixels(double key, double value, double &x, double &y) const
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange QCPCurve::getKeyRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 6960 of file qcustomplot.cc.

6961 {
6962  QCPRange range;
6963  bool haveLower = false;
6964  bool haveUpper = false;
6965 
6966  double current;
6967 
6968  QCPCurveDataMap::const_iterator it = mData->constBegin();
6969  while (it != mData->constEnd())
6970  {
6971  current = it.value().key;
6972  if (inSignDomain == SDBoth || (inSignDomain == SDNegative && current < 0) || (inSignDomain == SDPositive && current > 0))
6973  {
6974  if (current < range.lower || !haveLower)
6975  {
6976  range.lower = current;
6977  haveLower = true;
6978  }
6979  if (current > range.upper || !haveUpper)
6980  {
6981  range.upper = current;
6982  haveUpper = true;
6983  }
6984  }
6985  ++it;
6986  }
6987 
6988  validRange = haveLower && haveUpper;
6989  return range;
6990 }
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
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
QCPRange QCPCurve::getValueRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 6993 of file qcustomplot.cc.

6994 {
6995  QCPRange range;
6996  bool haveLower = false;
6997  bool haveUpper = false;
6998 
6999  double current;
7000 
7001  QCPCurveDataMap::const_iterator it = mData->constBegin();
7002  while (it != mData->constEnd())
7003  {
7004  current = it.value().value;
7005  if (inSignDomain == SDBoth || (inSignDomain == SDNegative && current < 0) || (inSignDomain == SDPositive && current > 0))
7006  {
7007  if (current < range.lower || !haveLower)
7008  {
7009  range.lower = current;
7010  haveLower = true;
7011  }
7012  if (current > range.upper || !haveUpper)
7013  {
7014  range.upper = current;
7015  haveUpper = true;
7016  }
7017  }
7018  ++it;
7019  }
7020 
7021  validRange = haveLower && haveUpper;
7022  return range;
7023 }
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
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
QPointF QCPCurve::outsideCoordsToPixels ( double  key,
double  value,
int  region 
) const
protected

Definition at line 6936 of file qcustomplot.cc.

6937 {
6938  int margin = 10;
6939  QRect axisRect = mKeyAxis->axisRect().united(mValueAxis->axisRect());
6940  QPointF result = coordsToPixels(key, value);
6941  switch (region)
6942  {
6943  case 2: result.setX(axisRect.left()-margin); break; // left
6944  case 8: result.setX(axisRect.right()+margin); break; // right
6945  case 4: result.setY(axisRect.top()-margin); break; // top
6946  case 6: result.setY(axisRect.bottom()+margin); break; // bottom
6947  case 1: result.setX(axisRect.left()-margin);
6948  result.setY(axisRect.top()-margin); break; // top left
6949  case 7: result.setX(axisRect.right()+margin);
6950  result.setY(axisRect.top()-margin); break; // top right
6951  case 9: result.setX(axisRect.right()+margin);
6952  result.setY(axisRect.bottom()+margin); break; // bottom right
6953  case 3: result.setX(axisRect.left()-margin);
6954  result.setY(axisRect.bottom()+margin); break; // bottom left
6955  }
6956  return result;
6957 }
QRect axisRect() const
Definition: qcustomplot.h:743
void coordsToPixels(double key, double value, double &x, double &y) const
void QCPCurve::removeData ( double  fromt,
double  tot 
)

Removes all data points with curve parameter t between fromt and tot. if fromt is greater or equal to tot, the function does nothing. To remove a single data point with known t, use removeData(double t).

See Also
addData, clearData

Definition at line 6736 of file qcustomplot.cc.

6737 {
6738  if (fromt >= tot || mData->isEmpty()) return;
6739  QCPCurveDataMap::iterator it = mData->upperBound(fromt);
6740  QCPCurveDataMap::iterator itEnd = mData->upperBound(tot);
6741  while (it != itEnd)
6742  it = mData->erase(it);
6743 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::removeData ( double  t)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Removes a single data point at curve parameter t. If the position is not known with absolute precision, consider using removeData(double fromt, double tot) with a small fuzziness interval around the suspected position, depeding on the precision with which the curve parameter is known.

See Also
addData, clearData

Definition at line 6754 of file qcustomplot.cc.

6755 {
6756  mData->remove(t);
6757 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::removeDataAfter ( double  t)

Removes all data points with curve parameter t greater than t.

See Also
addData, clearData

Definition at line 6721 of file qcustomplot.cc.

6722 {
6723  if (mData->isEmpty()) return;
6724  QCPCurveDataMap::iterator it = mData->upperBound(t);
6725  while (it != mData->end())
6726  it = mData->erase(it);
6727 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::removeDataBefore ( double  t)

Removes all data points with curve parameter t smaller than t.

See Also
addData, clearData

Definition at line 6710 of file qcustomplot.cc.

6711 {
6712  QCPCurveDataMap::iterator it = mData->begin();
6713  while (it != mData->end() && it.key() < t)
6714  it = mData->erase(it);
6715 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::setData ( QCPCurveDataMap data,
bool  copy = false 
)

Replaces the current data with the provided data.

If copy is set to true, data points in data will only be copied. if false, the plottable takes ownership of the passed data and replaces the internal data pointer with it. This is significantly faster than copying for large datasets.

Definition at line 6582 of file qcustomplot.cc.

6583 {
6584  if (copy)
6585  {
6586  *mData = *data;
6587  } else
6588  {
6589  delete mData;
6590  mData = data;
6591  }
6592 }
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
const QCPCurveDataMap * data() const
Definition: qcustomplot.h:338
void QCPCurve::setData ( const QVector< double > &  t,
const QVector< double > &  key,
const QVector< double > &  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Replaces the current data with the provided points in t, key and value tuples. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 6600 of file qcustomplot.cc.

6601 {
6602  mData->clear();
6603  int n = t.size();
6604  n = qMin(n, key.size());
6605  n = qMin(n, value.size());
6606  QCPCurveData newData;
6607  for (int i=0; i<n; ++i)
6608  {
6609  newData.t = t[i];
6610  newData.key = key[i];
6611  newData.value = value[i];
6612  mData->insertMulti(newData.t, newData);
6613  }
6614 }
A class holding the data of one single data point for QCPCurve.
Definition: qcustomplot.h:79
QCPCurveDataMap * mData
Definition: qcustomplot.h:358
void QCPCurve::setData ( const QVector< double > &  key,
const QVector< double > &  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Replaces the current data with the provided key and value pairs. The t parameter of each data point will be set to the integer index of the respective key/value pair.

Definition at line 6621 of file qcustomplot.cc.

6622 {
6623  mData->clear();
6624  int n = key.size();
6625  n = qMin(n, value.size());
6626  QCPCurveData newData;
6627  for (int i=0; i<n; ++i)
6628  {
6629  newData.t = i; // no t vector given, so we assign t the index of the key/value pair
6630  newData.key = key[i];
6631  newData.value = value[i];
6632  mData->insertMulti(newData.t, newData);
6633  }
6634 }
A class holding the data of one single data point for QCPCurve.
Definition: qcustomplot.h:79
QCPCurveDataMap * mData
Definition: qcustomplot.h:358

Friends And Related Function Documentation

friend class QCPLegend
friend

Definition at line 369 of file qcustomplot.h.

friend class QCustomPlot
friend

Definition at line 368 of file qcustomplot.h.

Member Data Documentation

QCPCurveDataMap* QCPCurve::mData
protected

Definition at line 358 of file qcustomplot.h.


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