rock_widget_collection  0.1
Public Slots | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
QCPBars Class Reference

A plottable representing a bar chart in a plot. More...

#include <qcustomplot.h>

Inherits QCPAbstractPlottable.

Public Slots

double width () const
 
QCPBarsbarBelow () const
 
QCPBarsbarAbove () const
 
const QCPBarDataMapdata () const
 
void setWidth (double width)
 
void setData (QCPBarDataMap *data, bool copy=false)
 
void setData (const QVector< double > &key, const QVector< double > &value)
 
void moveBelow (QCPBars *bars)
 
void moveAbove (QCPBars *bars)
 
void addData (const QCPBarDataMap &dataMap)
 
void addData (const QCPBarData &data)
 
void addData (double key, double value)
 
void addData (const QVector< double > &keys, const QVector< double > &values)
 
void removeDataBefore (double key)
 
void removeDataAfter (double key)
 
void removeData (double fromKey, double toKey)
 
void removeData (double key)
 
virtual void clearData ()
 
- 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 void clearData ()=0
 
virtual bool addToLegend () const
 
virtual bool removeFromLegend () const
 

Public Member Functions

 QCPBars (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual ~QCPBars ()
 
- 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
 
QPolygonF getBarPolygon (double key, double value) const
 
double getBaseValue (double key, bool positive) 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
 

Static Protected Member Functions

static void connectBars (QCPBars *lower, QCPBars *upper)
 

Protected Attributes

QCPBarDataMapmData
 
double mWidth
 
QCPBarsmBarBelow
 
QCPBarsmBarAbove
 
- Protected Attributes inherited from QCPAbstractPlottable
QCustomPlotmParentPlot
 
QString mName
 
bool mVisible
 
QPen mPen
 
QBrush mBrush
 
QCPAxismKeyAxis
 
QCPAxismValueAxis
 

Friends

class QCustomPlot
 
class QCPLegend
 

Additional Inherited Members

- Protected Types inherited from QCPAbstractPlottable
enum  SignDomain { SDNegative, SDBoth, SDPositive }
 

Detailed Description

A plottable representing a bar chart in a plot.

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

Changing the appearance

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

Bar charts are stackable. This means, Two QCPBars plottables can be placed ontop of eachother (see QCPBars::moveAbove). Then, when two bars are at the same key position, they will appear stacked.

Usage

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

Usually, you first create an instance:

QCPBars *newBars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

add it to the customPlot with QCustomPlot::addPlottable:

customPlot->addPlottable(newBars);

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

newBars->setName("Country population");
newBars->setData(xData, yData);

Definition at line 372 of file qcustomplot.h.

Constructor & Destructor Documentation

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

Constructs a bar chart 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 QCPBars can be added to the plot with QCustomPlot::addPlottable, QCustomPlot then takes ownership of the bar chart.

Definition at line 7081 of file qcustomplot.cc.

7081  :
7082  QCPAbstractPlottable(keyAxis, valueAxis),
7083  mBarBelow(0),
7084  mBarAbove(0)
7085 {
7086  mData = new QCPBarDataMap;
7087  mPen.setColor(Qt::blue);
7088  mPen.setStyle(Qt::SolidLine);
7089  mBrush.setColor(QColor(40, 50, 255, 30));
7090  mBrush.setStyle(Qt::SolidPattern);
7091  mWidth = 0.75;
7092 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis)
QMap< double, QCPBarData > QCPBarDataMap
Definition: qcustomplot.h:108
QCPBars * mBarAbove
Definition: qcustomplot.h:407
QCPBarDataMap * mData
Definition: qcustomplot.h:405
double mWidth
Definition: qcustomplot.h:406
QCPBars::~QCPBars ( )
virtual

Definition at line 7094 of file qcustomplot.cc.

7095 {
7096  if (mBarBelow || mBarAbove)
7097  connectBars(mBarBelow, mBarAbove); // take this bar out of any stacking
7098  delete mData;
7099 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
static void connectBars(QCPBars *lower, QCPBars *upper)
QCPBars * mBarAbove
Definition: qcustomplot.h:407
QCPBarDataMap * mData
Definition: qcustomplot.h:405

Member Function Documentation

void QCPBars::addData ( const QCPBarDataMap dataMap)
slot

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

See also
removeData

Definition at line 7218 of file qcustomplot.cc.

7219 {
7220  mData->unite(dataMap);
7221 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::addData ( const QCPBarData data)
slot

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 7227 of file qcustomplot.cc.

7228 {
7229  mData->insertMulti(data.key, data);
7230 }
double key
Definition: qcustomplot.h:100
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::addData ( double  key,
double  value 
)
slot

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 tuple to the current data

See also
removeData

Definition at line 7236 of file qcustomplot.cc.

7237 {
7238  QCPBarData newData;
7239  newData.key = key;
7240  newData.value = value;
7241  mData->insertMulti(newData.key, newData);
7242 }
double key
Definition: qcustomplot.h:100
QCPBarDataMap * mData
Definition: qcustomplot.h:405
double value
Definition: qcustomplot.h:100
A class holding the data of one single data point (one bar) for QCPBars.
Definition: qcustomplot.h:96
void QCPBars::addData ( const QVector< double > &  keys,
const QVector< double > &  values 
)
slot

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 key and value tuples to the current data.

See also
removeData

Definition at line 7248 of file qcustomplot.cc.

7249 {
7250  int n = keys.size();
7251  n = qMin(n, values.size());
7252  QCPBarData newData;
7253  for (int i=0; i<n; ++i)
7254  {
7255  newData.key = keys[i];
7256  newData.value = values[i];
7257  mData->insertMulti(newData.key, newData);
7258  }
7259 }
double key
Definition: qcustomplot.h:100
QCPBarDataMap * mData
Definition: qcustomplot.h:405
A class holding the data of one single data point (one bar) for QCPBars.
Definition: qcustomplot.h:96
QCPBars * QCPBars::barAbove ( ) const
inlineslot

Returns the bars plottable that is directly above this bars plottable. If there is no such plottable, returns 0.

See also
barBelow, moveBelow, moveAbove

Definition at line 383 of file qcustomplot.h.

383 { return mBarAbove; }
QCPBars * mBarAbove
Definition: qcustomplot.h:407
QCPBars * QCPBars::barBelow ( ) const
inlineslot

Returns the bars plottable that is directly below this bars plottable. If there is no such plottable, returns 0.

See also
barAbove, moveBelow, moveAbove

Definition at line 382 of file qcustomplot.h.

382 { return mBarBelow; }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
void QCPBars::clearData ( )
virtualslot

Removes all data points.

See also
removeData, removeDataAfter, removeDataBefore

Definition at line 7317 of file qcustomplot.cc.

7318 {
7319  mData->clear();
7320 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::connectBars ( QCPBars lower,
QCPBars upper 
)
staticprotected

Definition at line 7419 of file qcustomplot.cc.

7420 {
7421  if (!lower && !upper) return;
7422 
7423  if (!lower) // disconnect upper at bottom
7424  {
7425  // disconnect old bar below upper:
7426  if (upper->mBarBelow && upper->mBarBelow->mBarAbove == upper)
7427  upper->mBarBelow->mBarAbove = 0;
7428  upper->mBarBelow = 0;
7429  } else if (!upper) // disconnect lower at top
7430  {
7431  // disconnect old bar above lower:
7432  if (lower->mBarAbove && lower->mBarAbove->mBarBelow == lower)
7433  lower->mBarAbove->mBarBelow = 0;
7434  lower->mBarAbove = 0;
7435  } else // connect lower and upper
7436  {
7437  // disconnect old bar above lower:
7438  if (lower->mBarAbove && lower->mBarAbove->mBarBelow == lower)
7439  lower->mBarAbove->mBarBelow = 0;
7440  // disconnect old bar below upper:
7441  if (upper->mBarBelow && upper->mBarBelow->mBarAbove == upper)
7442  upper->mBarBelow->mBarAbove = 0;
7443  lower->mBarAbove = upper;
7444  upper->mBarBelow = lower;
7445  }
7446 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
QCPBars * mBarAbove
Definition: qcustomplot.h:407
const QCPBarDataMap* QCPBars::data ( ) const
inlineslot

Definition at line 384 of file qcustomplot.h.

384 { return mData; }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::draw ( QPainter *  painter) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 7323 of file qcustomplot.cc.

7324 {
7325  if (!mVisible || mData->isEmpty()) return;
7326  painter->setClipRect(mKeyAxis->axisRect().united(mValueAxis->axisRect()));
7327 
7328  QCPBarDataMap::const_iterator it;
7329  for (it = mData->constBegin(); it != mData->constEnd(); ++it)
7330  {
7331  if (it.key()+mWidth*0.5 < mKeyAxis->range().lower || it.key()-mWidth*0.5 > mKeyAxis->range().upper)
7332  continue;
7333  QPolygonF barPolygon = getBarPolygon(it.key(), it.value().value);
7334  // draw bar fill:
7335  if (mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0)
7336  {
7337  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEFills));
7338  painter->setPen(Qt::NoPen);
7339  painter->setBrush(mBrush);
7340  painter->drawPolygon(barPolygon);
7341  }
7342  // draw bar line:
7343  if (mPen.style() != Qt::NoPen && mPen.color().alpha() != 0)
7344  {
7345  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
7346  painter->setPen(mPen);
7347  painter->setBrush(Qt::NoBrush);
7348  painter->drawPolyline(barPolygon);
7349  }
7350  }
7351 }
QRect axisRect() const
Definition: qcustomplot.h:743
const QCPRange range() const
Definition: qcustomplot.h:746
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QPolygonF getBarPolygon(double key, double value) const
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QCPBarDataMap * mData
Definition: qcustomplot.h:405
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
double mWidth
Definition: qcustomplot.h:406
void QCPBars::drawLegendIcon ( QPainter *  painter,
const QRect &  rect 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 7354 of file qcustomplot.cc.

7355 {
7356  // draw filled rect:
7357  painter->setBrush(mBrush);
7358  painter->setPen(mPen);
7359  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
7360  QRect r = QRect(0, 0, rect.width()*0.67, rect.height()*0.67);
7361  r.moveCenter(rect.center());
7362  painter->drawRect(r);
7363 }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QPolygonF QCPBars::getBarPolygon ( double  key,
double  value 
) const
protected

Definition at line 7370 of file qcustomplot.cc.

7371 {
7372  QPolygonF result;
7373  double baseValue = getBaseValue(key, value >= 0); // calculates base value dependant on stacking
7374  result << coordsToPixels(key-mWidth*0.5, baseValue);
7375  result << coordsToPixels(key-mWidth*0.5, baseValue+value);
7376  result << coordsToPixels(key+mWidth*0.5, baseValue+value);
7377  result << coordsToPixels(key+mWidth*0.5, baseValue);
7378  return result;
7379 }
double getBaseValue(double key, bool positive) const
void coordsToPixels(double key, double value, double &x, double &y) const
double mWidth
Definition: qcustomplot.h:406
double QCPBars::getBaseValue ( double  key,
bool  positive 
) const
protected

Definition at line 7390 of file qcustomplot.cc.

7391 {
7392  if (mBarBelow)
7393  {
7394  double max = 0;
7395  // find bars of mBarBelow that are approximately at key and find largest one:
7396  QCPBarDataMap::const_iterator it = mBarBelow->mData->lowerBound(key-mWidth*0.1);
7397  QCPBarDataMap::const_iterator itEnd = mBarBelow->mData->upperBound(key+mWidth*0.1);
7398  while (it != itEnd)
7399  {
7400  if ((positive && it.value().value > max) ||
7401  (!positive && it.value().value < max))
7402  max = it.value().value;
7403  ++it;
7404  }
7405  // recurse down the bar-stack to find the total height:
7406  return max + mBarBelow->getBaseValue(key, positive);
7407  } else
7408  return 0;
7409 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
double getBaseValue(double key, bool positive) const
QCPBarDataMap * mData
Definition: qcustomplot.h:405
double mWidth
Definition: qcustomplot.h:406
QCPRange QCPBars::getKeyRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 7449 of file qcustomplot.cc.

7450 {
7451  QCPRange range;
7452  bool haveLower = false;
7453  bool haveUpper = false;
7454 
7455  double current;
7456  double barWidthHalf = mWidth*0.5;
7457  QCPBarDataMap::const_iterator it = mData->constBegin();
7458  while (it != mData->constEnd())
7459  {
7460  current = it.value().key;
7461  if (inSignDomain == SDBoth || (inSignDomain == SDNegative && current+barWidthHalf < 0) || (inSignDomain == SDPositive && current-barWidthHalf > 0))
7462  {
7463  if (current-barWidthHalf < range.lower || !haveLower)
7464  {
7465  range.lower = current-barWidthHalf;
7466  haveLower = true;
7467  }
7468  if (current+barWidthHalf > range.upper || !haveUpper)
7469  {
7470  range.upper = current+barWidthHalf;
7471  haveUpper = true;
7472  }
7473  }
7474  ++it;
7475  }
7476 
7477  validRange = haveLower && haveUpper;
7478  return range;
7479 }
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
QCPBarDataMap * mData
Definition: qcustomplot.h:405
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
double mWidth
Definition: qcustomplot.h:406
QCPRange QCPBars::getValueRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 7482 of file qcustomplot.cc.

7483 {
7484  QCPRange range;
7485  bool haveLower = true; // set to true, because 0 should always be visible in bar charts
7486  bool haveUpper = true; // set to true, because 0 should always be visible in bar charts
7487 
7488  double current;
7489 
7490  QCPBarDataMap::const_iterator it = mData->constBegin();
7491  while (it != mData->constEnd())
7492  {
7493  current = it.value().value + getBaseValue(it.value().key, it.value().value >= 0);
7494  if (inSignDomain == SDBoth || (inSignDomain == SDNegative && current < 0) || (inSignDomain == SDPositive && current > 0))
7495  {
7496  if (current < range.lower || !haveLower)
7497  {
7498  range.lower = current;
7499  haveLower = true;
7500  }
7501  if (current > range.upper || !haveUpper)
7502  {
7503  range.upper = current;
7504  haveUpper = true;
7505  }
7506  }
7507  ++it;
7508  }
7509 
7510  validRange = !qFuzzyCompare(range.lower+1.0, range.upper+1.0);
7511  return range;
7512 }
Both sign domains, including zero, i.e. all (rational) numbers.
Definition: qcustomplot.h:150
double getBaseValue(double key, bool positive) const
The negative sign domain, i.e. numbers smaller than zero.
Definition: qcustomplot.h:149
QCPBarDataMap * mData
Definition: qcustomplot.h:405
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
void QCPBars::moveAbove ( QCPBars bars)
slot

Moves this bars plottable above bars. In other words, the bars of this plottable will appear above the bars of bars. The move target bars must use the same key and value axis as this plottable.

Inserting into and removing from existing bar stacking is handled gracefully. If bars already has a bars object below itself, this bars object is inserted between the two. If this bars object is already between two other bars, the two other bars will be stacked ontop of each other after the operation.

To remove this bars plottable from any stacking, set bars to 0.

See also
moveBelow, barBelow, barAbove

Definition at line 7195 of file qcustomplot.cc.

7196 {
7197  if (bars == this) return;
7198  if (bars && (bars->keyAxis() != mKeyAxis || bars->valueAxis() != mValueAxis))
7199  {
7200  qDebug() << FUNCNAME << "passed QCPBars* doesn't have same key and value axis as this QCPBars";
7201  return;
7202  }
7203  // remove from stacking:
7204  connectBars(mBarBelow, mBarAbove); // Note: also works if one (or both) of them is 0
7205  // if new bar given, insert this bar above it:
7206  if (bars)
7207  {
7208  if (bars->mBarAbove)
7209  connectBars(this, bars->mBarAbove);
7210  connectBars(bars, this);
7211  }
7212 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
QCPAxis * keyAxis() const
Definition: qcustomplot.h:126
static void connectBars(QCPBars *lower, QCPBars *upper)
QCPBars * mBarAbove
Definition: qcustomplot.h:407
QCPAxis * valueAxis() const
Definition: qcustomplot.h:127
#define FUNCNAME
Definition: qcustomplot.h:50
void QCPBars::moveBelow ( QCPBars bars)
slot

Moves this bars plottable below bars. In other words, the bars of this plottable will appear below the bars of bars. The move target bars must use the same key and value axis as this plottable.

Inserting into and removing from existing bar stacking is handled gracefully. If bars already has a bars object below itself, this bars object is inserted between the two. If this bars object is already between two other bars, the two other bars will be stacked ontop of each other after the operation.

To remove this bars plottable from any stacking, set bars to 0.

See also
moveBelow, barAbove, barBelow

Definition at line 7162 of file qcustomplot.cc.

7163 {
7164  if (bars == this) return;
7165  if (bars->keyAxis() != mKeyAxis || bars->valueAxis() != mValueAxis)
7166  {
7167  qDebug() << FUNCNAME << "passed QCPBars* doesn't have same key and value axis as this QCPBars";
7168  return;
7169  }
7170  // remove from stacking:
7171  connectBars(mBarBelow, mBarAbove); // Note: also works if one (or both) of them is 0
7172  // if new bar given, insert this bar below it:
7173  if (bars)
7174  {
7175  if (bars->mBarBelow)
7176  connectBars(bars->mBarBelow, this);
7177  connectBars(this, bars);
7178  }
7179 }
QCPBars * mBarBelow
Definition: qcustomplot.h:407
QCPAxis * keyAxis() const
Definition: qcustomplot.h:126
static void connectBars(QCPBars *lower, QCPBars *upper)
QCPBars * mBarAbove
Definition: qcustomplot.h:407
QCPAxis * valueAxis() const
Definition: qcustomplot.h:127
#define FUNCNAME
Definition: qcustomplot.h:50
void QCPBars::removeData ( double  fromKey,
double  toKey 
)
slot

Removes all data points with key between fromKey and toKey. if fromKey is greater or equal to toKey, the function does nothing. To remove a single data point with known key, use removeData(double key).

See also
addData, clearData

Definition at line 7291 of file qcustomplot.cc.

7292 {
7293  if (fromKey >= toKey || mData->isEmpty()) return;
7294  QCPBarDataMap::iterator it = mData->upperBound(fromKey);
7295  QCPBarDataMap::iterator itEnd = mData->upperBound(toKey);
7296  while (it != itEnd)
7297  it = mData->erase(it);
7298 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::removeData ( double  key)
slot

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 key. If the position is not known with absolute precision, consider using removeData(double fromKey, double toKey) with a small fuzziness interval around the suspected position, depeding on the precision with which the key is known.

See also
addData, clearData

Definition at line 7308 of file qcustomplot.cc.

7309 {
7310  mData->remove(key);
7311 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::removeDataAfter ( double  key)
slot

Removes all data points with key greater than key.

See also
addData, clearData

Definition at line 7276 of file qcustomplot.cc.

7277 {
7278  if (mData->isEmpty()) return;
7279  QCPBarDataMap::iterator it = mData->upperBound(key);
7280  while (it != mData->end())
7281  it = mData->erase(it);
7282 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::removeDataBefore ( double  key)
slot

Removes all data points with key smaller than key.

See also
addData, clearData

Definition at line 7265 of file qcustomplot.cc.

7266 {
7267  QCPBarDataMap::iterator it = mData->begin();
7268  while (it != mData->end() && it.key() < key)
7269  it = mData->erase(it);
7270 }
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::setData ( QCPBarDataMap data,
bool  copy = false 
)
slot

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 7116 of file qcustomplot.cc.

7117 {
7118  if (copy)
7119  {
7120  *mData = *data;
7121  } else
7122  {
7123  delete mData;
7124  mData = data;
7125  }
7126 }
const QCPBarDataMap * data() const
Definition: qcustomplot.h:384
QCPBarDataMap * mData
Definition: qcustomplot.h:405
void QCPBars::setData ( const QVector< double > &  key,
const QVector< double > &  value 
)
slot

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 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 7134 of file qcustomplot.cc.

7135 {
7136  mData->clear();
7137  int n = key.size();
7138  n = qMin(n, value.size());
7139  QCPBarData newData;
7140  for (int i=0; i<n; ++i)
7141  {
7142  newData.key = key[i];
7143  newData.value = value[i];
7144  mData->insertMulti(newData.key, newData);
7145  }
7146 }
double key
Definition: qcustomplot.h:100
QCPBarDataMap * mData
Definition: qcustomplot.h:405
A class holding the data of one single data point (one bar) for QCPBars.
Definition: qcustomplot.h:96
void QCPBars::setWidth ( double  width)
slot

Sets the width of the bars in plot (key) coordinates.

Definition at line 7104 of file qcustomplot.cc.

7105 {
7106  mWidth = width;
7107 }
double width() const
Definition: qcustomplot.h:381
double mWidth
Definition: qcustomplot.h:406
double QCPBars::width ( ) const
inlineslot

Definition at line 381 of file qcustomplot.h.

381 { return mWidth; }
double mWidth
Definition: qcustomplot.h:406

Friends And Related Function Documentation

friend class QCPLegend
friend

Definition at line 419 of file qcustomplot.h.

friend class QCustomPlot
friend

Definition at line 418 of file qcustomplot.h.

Member Data Documentation

QCPBars * QCPBars::mBarAbove
protected

Definition at line 407 of file qcustomplot.h.

QCPBars* QCPBars::mBarBelow
protected

Definition at line 407 of file qcustomplot.h.

QCPBarDataMap* QCPBars::mData
protected

Definition at line 405 of file qcustomplot.h.

double QCPBars::mWidth
protected

Definition at line 406 of file qcustomplot.h.


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