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

A plottable representing a graph in a plot. More...

#include <qcustomplot.h>

Inherits QCPAbstractPlottable.

Public Types

enum  LineStyle {
  LSNone, LSLine, LSStepLeft, LSStepRight,
  LSStepCenter, LSImpulse
}
 
enum  ScatterStyle {
  SSNone, SSDot, SSCross, SSPlus,
  SSCircle, SSDisc, SSSquare, SSStar,
  SSTriangle, SSTriangleInverted, SSCrossSquare, SSPlusSquare,
  SSCrossCircle, SSPlusCircle, SSPeace, SSPixmap
}
 
enum  ErrorType { ETNone, ETKey, ETValue, ETBoth }
 

Public Slots

const QCPDataMapdata () const
 
LineStyle lineStyle () const
 
ScatterStyle scatterStyle () const
 
double scatterSize () const
 
const QPixmap scatterPixmap () const
 
ErrorType errorType () const
 
QPen errorPen () const
 
double errorBarSize () const
 
bool errorBarSkipSymbol () const
 
QCPGraphchannelFillGraph () const
 
void setData (QCPDataMap *data, bool copy=false)
 
void setData (const QVector< double > &key, const QVector< double > &value)
 
void setDataKeyError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &keyError)
 
void setDataKeyError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &keyErrorMinus, const QVector< double > &keyErrorPlus)
 
void setDataValueError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &valueError)
 
void setDataValueError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &valueErrorMinus, const QVector< double > &valueErrorPlus)
 
void setDataBothError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &keyError, const QVector< double > &valueError)
 
void setDataBothError (const QVector< double > &key, const QVector< double > &value, const QVector< double > &keyErrorMinus, const QVector< double > &keyErrorPlus, const QVector< double > &valueErrorMinus, const QVector< double > &valueErrorPlus)
 
void setLineStyle (int ls)
 
void setScatterStyle (int ss)
 
void setScatterSize (double size)
 
void setScatterPixmap (const QPixmap &pixmap)
 
void setErrorType (ErrorType errorType)
 
void setErrorPen (const QPen &pen)
 
void setErrorBarSize (double size)
 
void setErrorBarSkipSymbol (bool enabled)
 
void setChannelFillGraph (QCPGraph *targetGraph)
 
void addData (const QCPDataMap &dataMap)
 
void addData (const QCPData &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

 QCPGraph (QCPAxis *keyAxis, QCPAxis *valueAxis)
 
virtual ~QCPGraph ()
 
virtual void rescaleAxes (bool onlyEnlarge, bool includeErrorBars) const
 
virtual void rescaleKeyAxis (bool onlyEnlarge, bool includeErrorBars) const
 
virtual void rescaleValueAxis (bool onlyEnlarge, bool includeErrorBars) const
 
- 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 getPlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void getScatterPlotData (QVector< QCPData > *pointData) const
 
void getLinePlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void getStepLeftPlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void getStepRightPlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void getStepCenterPlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void getImpulsePlotData (QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
 
void drawFill (QPainter *painter, QVector< QPointF > *lineData) const
 
void drawScatterPlot (QPainter *painter, QVector< QCPData > *pointData) const
 
void drawLinePlot (QPainter *painter, QVector< QPointF > *lineData) const
 
void drawImpulsePlot (QPainter *painter, QVector< QPointF > *lineData) const
 
void drawScatter (QPainter *painter, double x, double y, ScatterStyle style) const
 
void drawError (QPainter *painter, double x, double y, const QCPData &data) const
 
void getVisibleDataBounds (QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
 
void addFillBasePoints (QVector< QPointF > *lineData) const
 
void removeFillBasePoints (QVector< QPointF > *lineData) const
 
QPointF lowerFillBasePoint (double lowerKey) const
 
QPointF upperFillBasePoint (double upperKey) const
 
const QPolygonF getChannelFillPolygon (const QVector< QPointF > *lineData) const
 
int findIndexBelowX (const QVector< QPointF > *data, double x) const
 
int findIndexAboveX (const QVector< QPointF > *data, double x) const
 
int findIndexBelowY (const QVector< QPointF > *data, double y) const
 
int findIndexAboveY (const QVector< QPointF > *data, double y) const
 
virtual QCPRange getKeyRange (bool &validRange, SignDomain inSignDomain=SDBoth) const
 
virtual QCPRange getValueRange (bool &validRange, SignDomain inSignDomain=SDBoth) const
 
virtual QCPRange getKeyRange (bool &validRange, SignDomain inSignDomain, bool includeErrors) const
 
virtual QCPRange getValueRange (bool &validRange, SignDomain inSignDomain, bool includeErrors) 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

QCPDataMapmData
 
QPen mErrorPen
 
LineStyle mLineStyle
 
ScatterStyle mScatterStyle
 
double mScatterSize
 
QPixmap mScatterPixmap
 
ErrorType mErrorType
 
double mErrorBarSize
 
bool mErrorBarSkipSymbol
 
QCPGraphmChannelFillGraph
 
- 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 graph in a plot.

Usually QCustomPlot creates it internally via QCustomPlot::addGraph and the resulting instance is accessed via QCustomPlot::graph.

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

Changing the appearance

The appearance of the graph is mainly determined by the line style, scatter style, brush and pen of the graph (setLineStyle, setScatterStyle, setBrush, setPen).

Filling under or between graphs

QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, just set a brush with setBrush which is neither Qt::NoBrush nor fully transparent.

By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill between this graph and another one, call setChannelFillGraph with the other graph as parameter.

See also
QCustomPlot::addGraph, QCustomPlot::graph, QCPLegend::addGraph

Definition at line 171 of file qcustomplot.h.

Member Enumeration Documentation

Defines what kind of error bars are drawn for each data point

Enumerator
ETNone 

No error bars are shown.

ETKey 

Error bars for the key dimension of the data point are shown.

ETValue 

Error bars for the value dimension of the data point are shown.

ETBoth 

Error bars for both key and value dimensions of the data point are shown.

Definition at line 216 of file qcustomplot.h.

216  {ETNone,
217  ETKey,
218  ETValue,
219  ETBoth
220  };
Error bars for the key dimension of the data point are shown.
Definition: qcustomplot.h:217
No error bars are shown.
Definition: qcustomplot.h:216
Error bars for both key and value dimensions of the data point are shown.
Definition: qcustomplot.h:219
Error bars for the value dimension of the data point are shown.
Definition: qcustomplot.h:218

Defines how the graph's line is represented visually in the plot. The line is drawn with the current pen of the graph (setPen).

See also
setLineStyle
Enumerator
LSNone 

data points are not connected with any lines (e.g. data only represented with symbols according to the scatter style, see setScatterStyle)

LSLine 

data points are connected by a straight line

LSStepLeft 

line is drawn as steps where the step height is the value of the left data point

LSStepRight 

line is drawn as steps where the step height is the value of the right data point

LSStepCenter 

line is drawn as steps where the step is in between two data points

LSImpulse 

data points are represented by a straight line parallel to the value axis, which ranges down/up to the key axis

Definition at line 180 of file qcustomplot.h.

180  {LSNone,
181  LSLine,
183  LSStepLeft,
184  LSStepRight,
185  LSStepCenter,
186  LSImpulse
187  };
line is drawn as steps where the step height is the value of the right data point ...
Definition: qcustomplot.h:184
line is drawn as steps where the step is in between two data points
Definition: qcustomplot.h:185
line is drawn as steps where the step height is the value of the left data point
Definition: qcustomplot.h:183
data points are represented by a straight line parallel to the value axis, which ranges down/up to th...
Definition: qcustomplot.h:186
data points are connected by a straight line
Definition: qcustomplot.h:182

This defines the visual appearance of the points, which are all drawn with the pen of the graph (setPen). The sizes of these visualizations (with exception of SSDot and SSPixmap) can be set with setScatterSize.

See also
setScatterStyle
Enumerator
SSNone 

no scatter symbols are drawn (e.g. data only represented with lines, see setLineStyle)

SSDot 

a single pixel, setScatterSize has no influence on its size.

SSCross 

a cross (x)

SSPlus 

a plus (+)

SSCircle 

a circle which is not filled

SSDisc 

a circle which is filled with the color of the graph's pen (not the brush!)

SSSquare 

a square which is not filled

SSStar 

a star with eight arms, i.e. a combination of cross and plus

SSTriangle 

an equilateral triangle which is not filled, standing on baseline

SSTriangleInverted 

an equilateral triangle which is not filled, standing on corner

SSCrossSquare 

a square which is not filled, with a cross inside

SSPlusSquare 

a square which is not filled, with a plus inside

SSCrossCircle 

a circle which is not filled, with a cross inside

SSPlusCircle 

a circle which is not filled, with a plus inside

SSPeace 

a circle which is not filled, with one vertical and two downward diagonal lines

SSPixmap 

a custom pixmap specified by setScatterPixmap, centered on the data point coordinates. setScatterSize has no influence on its size.

Definition at line 195 of file qcustomplot.h.

195  {SSNone,
196  SSDot,
197  SSCross,
198  SSPlus,
199  SSCircle,
200  SSDisc,
201  SSSquare,
202  SSStar,
203  SSTriangle,
205  SSCrossSquare,
206  SSPlusSquare,
207  SSCrossCircle,
208  SSPlusCircle,
209  SSPeace,
210  SSPixmap
211  };
a square which is not filled, with a plus inside
Definition: qcustomplot.h:206
a square which is not filled, with a cross inside
Definition: qcustomplot.h:205
a circle which is filled with the color of the graph&#39;s pen (not the brush!)
Definition: qcustomplot.h:200
a cross (x)
Definition: qcustomplot.h:197
an equilateral triangle which is not filled, standing on corner
Definition: qcustomplot.h:204
a circle which is not filled, with one vertical and two downward diagonal lines
Definition: qcustomplot.h:209
a circle which is not filled
Definition: qcustomplot.h:199
an equilateral triangle which is not filled, standing on baseline
Definition: qcustomplot.h:203
a square which is not filled
Definition: qcustomplot.h:201
a circle which is not filled, with a plus inside
Definition: qcustomplot.h:208
a plus (+)
Definition: qcustomplot.h:198
no scatter symbols are drawn (e.g. data only represented with lines, see setLineStyle) ...
Definition: qcustomplot.h:195
a star with eight arms, i.e. a combination of cross and plus
Definition: qcustomplot.h:202
a single pixel, setScatterSize has no influence on its size.
Definition: qcustomplot.h:196
a circle which is not filled, with a cross inside
Definition: qcustomplot.h:207
a custom pixmap specified by setScatterPixmap, centered on the data point coordinates. setScatterSize has no influence on its size.
Definition: qcustomplot.h:210

Constructor & Destructor Documentation

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

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

To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function.

Definition at line 256 of file qcustomplot.cc.

256  :
257  QCPAbstractPlottable(keyAxis, valueAxis)
258 {
259  mData = new QCPDataMap;
260  mPen.setColor(Qt::blue);
261  mPen.setStyle(Qt::SolidLine);
262  mErrorPen.setColor(Qt::black);
263  mBrush.setColor(Qt::blue);
264  mBrush.setStyle(Qt::NoBrush);
265  mLineStyle = LSLine;
267  mScatterSize = 6;
268  mErrorType = ETNone;
269  mErrorBarSize = 6;
270  mErrorBarSkipSymbol = true;
271  mChannelFillGraph = 0;
272 }
QPen mErrorPen
Definition: qcustomplot.h:279
QMap< double, QCPData > QCPDataMap
Definition: qcustomplot.h:75
QCPGraph * mChannelFillGraph
Definition: qcustomplot.h:287
double mErrorBarSize
Definition: qcustomplot.h:285
double mScatterSize
Definition: qcustomplot.h:282
No error bars are shown.
Definition: qcustomplot.h:216
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis)
bool mErrorBarSkipSymbol
Definition: qcustomplot.h:286
ErrorType mErrorType
Definition: qcustomplot.h:284
QCPDataMap * mData
Definition: qcustomplot.h:278
no scatter symbols are drawn (e.g. data only represented with lines, see setLineStyle) ...
Definition: qcustomplot.h:195
data points are connected by a straight line
Definition: qcustomplot.h:182
LineStyle mLineStyle
Definition: qcustomplot.h:280
QCPGraph::~QCPGraph ( )
virtual

Definition at line 274 of file qcustomplot.cc.

275 {
276  if (mParentPlot)
277  {
278  // if another graph has a channel fill towards this graph, set it to zero
279  for (int i=0; i<mParentPlot->graphCount(); ++i)
280  {
281  if (mParentPlot->graph(i)->channelFillGraph() == this)
283  }
284  }
285  delete mData;
286 }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
QCPDataMap * mData
Definition: qcustomplot.h:278
QCPGraph * graph(int index) const
int graphCount() const
void setChannelFillGraph(QCPGraph *targetGraph)
Definition: qcustomplot.cc:578
QCPGraph * channelFillGraph() const
Definition: qcustomplot.h:237

Member Function Documentation

void QCPGraph::addData ( const QCPDataMap dataMap)
slot

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

See also
removeData

Definition at line 602 of file qcustomplot.cc.

603 {
604  mData->unite(dataMap);
605 }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::addData ( const QCPData 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 611 of file qcustomplot.cc.

612 {
613  mData->insertMulti(data.key, data);
614 }
double key
Definition: qcustomplot.h:65
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::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 pair to the current data.

See also
removeData

Definition at line 620 of file qcustomplot.cc.

621 {
622  QCPData newData;
623  newData.key = key;
624  newData.value = value;
625  mData->insertMulti(newData.key, newData);
626 }
double key
Definition: qcustomplot.h:65
double value
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::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 pairs to the current data.

See also
removeData

Definition at line 632 of file qcustomplot.cc.

633 {
634  int n = qMin(keys.size(), values.size());
635  QCPData newData;
636  for (int i=0; i<n; ++i)
637  {
638  newData.key = keys[i];
639  newData.value = values[i];
640  mData->insertMulti(newData.key, newData);
641  }
642 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::addFillBasePoints ( QVector< QPointF > *  lineData) const
protected

Definition at line 1703 of file qcustomplot.cc.

1704 {
1705  // append points that close the polygon fill at the key axis:
1706  if (mKeyAxis->orientation() == Qt::Vertical)
1707  {
1708  *lineData << upperFillBasePoint(lineData->last().y());
1709  *lineData << lowerFillBasePoint(lineData->first().y());
1710  } else
1711  {
1712  *lineData << upperFillBasePoint(lineData->last().x());
1713  *lineData << lowerFillBasePoint(lineData->first().x());
1714  }
1715 }
QPointF upperFillBasePoint(double upperKey) const
QPointF lowerFillBasePoint(double lowerKey) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
QCPGraph* QCPGraph::channelFillGraph ( ) const
inlineslot

Definition at line 237 of file qcustomplot.h.

237 { return mChannelFillGraph; }
QCPGraph * mChannelFillGraph
Definition: qcustomplot.h:287
void QCPGraph::clearData ( )
virtualslot

Removes all data points.

See also
removeData, removeDataAfter, removeDataBefore

Definition at line 700 of file qcustomplot.cc.

701 {
702  mData->clear();
703 }
QCPDataMap * mData
Definition: qcustomplot.h:278
const QCPDataMap* QCPGraph::data ( ) const
inlineslot

Definition at line 228 of file qcustomplot.h.

228 { return mData; }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::draw ( QPainter *  painter) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 779 of file qcustomplot.cc.

780 {
781  if (!mVisible) return;
782  if (mKeyAxis->range().size() <= 0) return;
783  if (mData->isEmpty()) return;
784  if (mLineStyle == LSNone && mScatterStyle == SSNone) return;
785  painter->setClipRect(mKeyAxis->axisRect().united(mValueAxis->axisRect()));
786 
787  // allocate line and (if necessary) point vectors:
788  QVector<QPointF> *lineData = new QVector<QPointF>;
789  QVector<QCPData> *pointData = 0;
790  if (mScatterStyle != SSNone)
791  pointData = new QVector<QCPData>;
792 
793  // fill vectors with data appropriate to plot style:
794  getPlotData(lineData, pointData);
795 
796  // draw fill of graph:
797  drawFill(painter, lineData);
798 
799  // draw line:
800  if (mLineStyle == LSImpulse)
801  drawImpulsePlot(painter, lineData);
802  else if (mLineStyle != LSNone)
803  drawLinePlot(painter, lineData); // also step plots can be drawn as a line plot
804 
805  // draw scatters:
806  if (pointData)
807  drawScatterPlot(painter, pointData);
808 
809  // free allocated line and point vectors:
810  delete lineData;
811  if (pointData)
812  delete pointData;
813 }
double size() const
QRect axisRect() const
Definition: qcustomplot.h:743
const QCPRange range() const
Definition: qcustomplot.h:746
void drawFill(QPainter *painter, QVector< QPointF > *lineData) const
void drawLinePlot(QPainter *painter, QVector< QPointF > *lineData) const
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
void getPlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
Definition: qcustomplot.cc:868
data points are represented by a straight line parallel to the value axis, which ranges down/up to th...
Definition: qcustomplot.h:186
QCPDataMap * mData
Definition: qcustomplot.h:278
no scatter symbols are drawn (e.g. data only represented with lines, see setLineStyle) ...
Definition: qcustomplot.h:195
void drawScatterPlot(QPainter *painter, QVector< QCPData > *pointData) const
LineStyle mLineStyle
Definition: qcustomplot.h:280
void drawImpulsePlot(QPainter *painter, QVector< QPointF > *lineData) const
void QCPGraph::drawError ( QPainter *  painter,
double  x,
double  y,
const QCPData data 
) const
protected

Definition at line 1559 of file qcustomplot.cc.

1560 {
1561  double a, b; // positions of error bar bounds in pixels
1562  double barWidthHalf = mErrorBarSize*0.5;
1563  double skipSymbolMargin = mScatterSize*1.25; // pixels left blank per side, when mErrorBarSkipSymbol is true
1564 
1565  if (!mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEErrorBars))
1566  {
1567  x = x-0.9; // paint system correction, else, we don't get pixel exact matches (Qt problem)
1568  y = y-0.9; // paint system correction, else, we don't get pixel exact matches (Qt problem)
1569  }
1570 
1571  if (mKeyAxis->orientation() == Qt::Vertical)
1572  {
1573  // draw key error vertically and value error horizontally
1574  if (mErrorType == ETKey || mErrorType == ETBoth)
1575  {
1576  a = mKeyAxis->coordToPixel(data.key-data.keyErrorMinus);
1577  b = mKeyAxis->coordToPixel(data.key+data.keyErrorPlus);
1578  if (mKeyAxis->rangeReversed())
1579  qSwap(a,b);
1580  // draw spine:
1581  if (mErrorBarSkipSymbol)
1582  {
1583  if (a-y > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin
1584  painter->drawLine(QLineF(x, a, x, y+skipSymbolMargin));
1585  if (y-b > skipSymbolMargin)
1586  painter->drawLine(QLineF(x, y-skipSymbolMargin, x, b));
1587  } else
1588  painter->drawLine(QLineF(x, a, x, b));
1589  // draw handles:
1590  painter->drawLine(QLineF(x-barWidthHalf, a, x+barWidthHalf, a));
1591  painter->drawLine(QLineF(x-barWidthHalf, b, x+barWidthHalf, b));
1592  }
1593  if (mErrorType == ETValue || mErrorType == ETBoth)
1594  {
1595  a = mValueAxis->coordToPixel(data.value-data.valueErrorMinus);
1596  b = mValueAxis->coordToPixel(data.value+data.valueErrorPlus);
1597  if (mValueAxis->rangeReversed())
1598  qSwap(a,b);
1599  // draw spine:
1600  if (mErrorBarSkipSymbol)
1601  {
1602  if (x-a > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin
1603  painter->drawLine(QLineF(a, y, x-skipSymbolMargin, y));
1604  if (b-x > skipSymbolMargin)
1605  painter->drawLine(QLineF(x+skipSymbolMargin, y, b, y));
1606  } else
1607  painter->drawLine(QLineF(a, y, b, y));
1608  // draw handles:
1609  painter->drawLine(QLineF(a, y-barWidthHalf, a, y+barWidthHalf));
1610  painter->drawLine(QLineF(b, y-barWidthHalf, b, y+barWidthHalf));
1611  }
1612  } else
1613  {
1614  // draw value error vertically and key error horizontally
1615  if (mErrorType == ETKey || mErrorType == ETBoth)
1616  {
1617  a = mKeyAxis->coordToPixel(data.key-data.keyErrorMinus);
1618  b = mKeyAxis->coordToPixel(data.key+data.keyErrorPlus);
1619  if (mKeyAxis->rangeReversed())
1620  qSwap(a,b);
1621  // draw spine:
1622  if (mErrorBarSkipSymbol)
1623  {
1624  if (x-a > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin
1625  painter->drawLine(QLineF(a, y, x-skipSymbolMargin, y));
1626  if (b-x > skipSymbolMargin)
1627  painter->drawLine(QLineF(x+skipSymbolMargin, y, b, y));
1628  } else
1629  painter->drawLine(QLineF(a, y, b, y));
1630  // draw handles:
1631  painter->drawLine(QLineF(a, y-barWidthHalf, a, y+barWidthHalf));
1632  painter->drawLine(QLineF(b, y-barWidthHalf, b, y+barWidthHalf));
1633  }
1634  if (mErrorType == ETValue || mErrorType == ETBoth)
1635  {
1636  a = mValueAxis->coordToPixel(data.value-data.valueErrorMinus);
1637  b = mValueAxis->coordToPixel(data.value+data.valueErrorPlus);
1638  if (mValueAxis->rangeReversed())
1639  qSwap(a,b);
1640  // draw spine:
1641  if (mErrorBarSkipSymbol)
1642  {
1643  if (a-y > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin
1644  painter->drawLine(QLineF(x, a, x, y+skipSymbolMargin));
1645  if (y-b > skipSymbolMargin)
1646  painter->drawLine(QLineF(x, y-skipSymbolMargin, x, b));
1647  } else
1648  painter->drawLine(QLineF(x, a, x, b));
1649  // draw handles:
1650  painter->drawLine(QLineF(x-barWidthHalf, a, x+barWidthHalf, a));
1651  painter->drawLine(QLineF(x-barWidthHalf, b, x+barWidthHalf, b));
1652  }
1653  }
1654 }
Error bars for the key dimension of the data point are shown.
Definition: qcustomplot.h:217
double mErrorBarSize
Definition: qcustomplot.h:285
double key
Definition: qcustomplot.h:65
double value
Definition: qcustomplot.h:65
double mScatterSize
Definition: qcustomplot.h:282
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
double valueErrorPlus
Definition: qcustomplot.h:67
double valueErrorMinus
Definition: qcustomplot.h:67
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double keyErrorPlus
Definition: qcustomplot.h:66
bool rangeReversed() const
Definition: qcustomplot.h:747
bool mErrorBarSkipSymbol
Definition: qcustomplot.h:286
Error bars for both key and value dimensions of the data point are shown.
Definition: qcustomplot.h:219
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
Error bars for the value dimension of the data point are shown.
Definition: qcustomplot.h:218
ErrorType mErrorType
Definition: qcustomplot.h:284
double keyErrorMinus
Definition: qcustomplot.h:66
double coordToPixel(double value) const
void QCPGraph::drawFill ( QPainter *  painter,
QVector< QPointF > *  lineData 
) const
protected

Definition at line 1322 of file qcustomplot.cc.

1323 {
1324  if (mLineStyle == LSImpulse) return; // fill doesn't make sense for impulse plot
1325  if (mBrush.style() == Qt::NoBrush || mBrush.color().alpha() == 0) return;
1326 
1327  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEFills));
1328  if (!mChannelFillGraph)
1329  {
1330  // draw base fill under graph, fill goes all the way to the zero-value-line:
1331  addFillBasePoints(lineData);
1332  painter->setPen(Qt::NoPen);
1333  painter->setBrush(mBrush);
1334  painter->drawPolygon(QPolygonF(*lineData));
1335  removeFillBasePoints(lineData);
1336  } else
1337  {
1338  // draw channel fill between this graph and mChannelFillGraph:
1339  painter->setPen(Qt::NoPen);
1340  painter->setBrush(mBrush);
1341  painter->drawPolygon(getChannelFillPolygon(lineData));
1342  }
1343 }
QCPGraph * mChannelFillGraph
Definition: qcustomplot.h:287
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
void removeFillBasePoints(QVector< QPointF > *lineData) const
data points are represented by a straight line parallel to the value axis, which ranges down/up to th...
Definition: qcustomplot.h:186
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
void addFillBasePoints(QVector< QPointF > *lineData) const
const QPolygonF getChannelFillPolygon(const QVector< QPointF > *lineData) const
LineStyle mLineStyle
Definition: qcustomplot.h:280
void QCPGraph::drawImpulsePlot ( QPainter *  painter,
QVector< QPointF > *  lineData 
) const
protected

Definition at line 1411 of file qcustomplot.cc.

1412 {
1413  // draw impulses:
1414  if (mPen.style() != Qt::NoPen && mPen.color().alpha() != 0)
1415  {
1416  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
1417  painter->setPen(mPen);
1418  painter->setBrush(Qt::NoBrush);
1419  painter->drawLines(*lineData);
1420  }
1421 }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
void QCPGraph::drawLegendIcon ( QPainter *  painter,
const QRect &  rect 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 816 of file qcustomplot.cc.

817 {
818  // draw fill:
819  if (mBrush.style() != Qt::NoBrush)
820  {
821  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
822  painter->fillRect(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0, mBrush);
823  }
824  // draw line vertically centered:
825  if (mLineStyle != LSNone)
826  {
827  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
828  painter->setPen(mPen);
829  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
830  }
831  // draw scatter symbol:
832  if (mScatterStyle != SSNone)
833  {
834  if (mScatterStyle == SSPixmap && (mScatterPixmap.size().width() > rect.width() || mScatterPixmap.size().height() > rect.height()))
835  {
836  // handle pixmap scatters that are larger than legend icon rect separately.
837  // We resize them and draw them manually, instead of calling drawScatter:
838  QSize newSize = mScatterPixmap.size();
839  newSize.scale(rect.size(), Qt::KeepAspectRatio);
840  QRect targetRect;
841  targetRect.setSize(newSize);
842  targetRect.moveCenter(rect.center());
843  bool smoothBackup = painter->testRenderHint(QPainter::SmoothPixmapTransform);
844  painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
845  painter->drawPixmap(targetRect, mScatterPixmap);
846  painter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup);
847  } else // mScatterStyle != SSPixmap
848  {
849  painter->setPen(mPen);
850  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEScatters));
851  drawScatter(painter, rect.center().x()+1, rect.center().y()+1, mScatterStyle);
852  }
853  }
854 }
void drawScatter(QPainter *painter, double x, double y, ScatterStyle style) const
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QPixmap mScatterPixmap
Definition: qcustomplot.h:283
no scatter symbols are drawn (e.g. data only represented with lines, see setLineStyle) ...
Definition: qcustomplot.h:195
LineStyle mLineStyle
Definition: qcustomplot.h:280
a custom pixmap specified by setScatterPixmap, centered on the data point coordinates. setScatterSize has no influence on its size.
Definition: qcustomplot.h:210
void QCPGraph::drawLinePlot ( QPainter *  painter,
QVector< QPointF > *  lineData 
) const
protected

Definition at line 1393 of file qcustomplot.cc.

1394 {
1395  // draw line of graph:
1396  if (mPen.style() != Qt::NoPen && mPen.color().alpha() != 0)
1397  {
1398  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGraphs));
1399  painter->setPen(mPen);
1400  painter->setBrush(Qt::NoBrush);
1401  painter->drawPolyline(QPolygonF(*lineData));
1402  }
1403 }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
void QCPGraph::drawScatter ( QPainter *  painter,
double  x,
double  y,
ScatterStyle  style 
) const
protected

Definition at line 1431 of file qcustomplot.cc.

1432 {
1433  // If you change this correction, make sure pdf exported scatters are properly centered in error bars!
1434  // There seems to be some kind of discrepancy for different paint devices here.
1435  if (style == SSCross || style == SSPlus)
1436  {
1437  x = x-0.7; // paint system correction, else, we don't get pixel exact matches (Qt problem)
1438  y = y-0.4; // paint system correction, else, we don't get pixel exact matches (Qt problem)
1439  }
1440 
1441  double w = mScatterSize/2.0;
1442  switch (style)
1443  {
1444  case SSDot:
1445  {
1446  painter->drawPoint(QPointF(x, y));
1447  break;
1448  }
1449  case SSCross:
1450  {
1451  painter->drawLine(QLineF(x-w, y-w, x+w, y+w));
1452  painter->drawLine(QLineF(x-w, y+w, x+w, y-w));
1453  break;
1454  }
1455  case SSPlus:
1456  {
1457  painter->drawLine(QLineF(x-w, y, x+w, y));
1458  painter->drawLine(QLineF(x, y+w, x, y-w));
1459  break;
1460  }
1461  case SSCircle:
1462  {
1463  painter->setBrush(Qt::NoBrush);
1464  painter->drawEllipse(x-w,y-w,mScatterSize,mScatterSize);
1465  break;
1466  }
1467  case SSDisc:
1468  {
1469  painter->setBrush(QBrush(painter->pen().color()));
1470  painter->drawEllipse(QPointF(x,y), w, w);
1471  break;
1472  }
1473  case SSSquare:
1474  {
1475  painter->setBrush(Qt::NoBrush);
1476  painter->drawRect(x-w,y-w,mScatterSize,mScatterSize);
1477  break;
1478  }
1479  case SSStar:
1480  {
1481  painter->drawLine(QLineF(x-w, y, x+w, y));
1482  painter->drawLine(QLineF(x, y+w, x, y-w));
1483  painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707));
1484  painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707));
1485  break;
1486  }
1487  case SSTriangle:
1488  {
1489  painter->drawLine(QLineF(x-w, y+0.755*w, x+w, y+0.755*w));
1490  painter->drawLine(QLineF(x+w, y+0.755*w, x, y-0.977*w));
1491  painter->drawLine(QLineF(x, y-0.977*w, x-w, y+0.755*w));
1492  break;
1493  }
1494  case SSTriangleInverted:
1495  {
1496  painter->drawLine(QLineF(x-w, y-0.755*w, x+w, y-0.755*w));
1497  painter->drawLine(QLineF(x+w, y-0.755*w, x, y+0.977*w));
1498  painter->drawLine(QLineF(x, y+0.977*w, x-w, y-0.755*w));
1499  break;
1500  }
1501  case SSCrossSquare:
1502  {
1503  painter->setBrush(Qt::NoBrush);
1504  painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95));
1505  painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w));
1506  painter->drawRect(x-w,y-w,mScatterSize,mScatterSize);
1507  break;
1508  }
1509  case SSPlusSquare:
1510  {
1511  painter->setBrush(Qt::NoBrush);
1512  painter->drawLine(QLineF(x-w, y, x+w*0.95, y));
1513  painter->drawLine(QLineF(x, y+w, x, y-w));
1514  painter->drawRect(x-w,y-w,mScatterSize,mScatterSize);
1515  break;
1516  }
1517  case SSCrossCircle:
1518  {
1519  painter->setBrush(Qt::NoBrush);
1520  painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.67, y+w*0.67));
1521  painter->drawLine(QLineF(x-w*0.707, y+w*0.67, x+w*0.67, y-w*0.707));
1522  painter->drawEllipse(x-w,y-w,mScatterSize,mScatterSize);
1523  break;
1524  }
1525  case SSPlusCircle:
1526  {
1527  painter->setBrush(Qt::NoBrush);
1528  painter->drawLine(QLineF(x-w, y, x+w, y));
1529  painter->drawLine(QLineF(x, y+w, x, y-w));
1530  painter->drawEllipse(x-w,y-w,mScatterSize,mScatterSize);
1531  break;
1532  }
1533  case SSPeace:
1534  {
1535  painter->setBrush(Qt::NoBrush);
1536  painter->drawLine(QLineF(x, y-w, x, y+w));
1537  painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707));
1538  painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707));
1539  painter->drawEllipse(x-w,y-w,mScatterSize,mScatterSize);
1540  break;
1541  }
1542  case SSPixmap:
1543  {
1544  painter->drawPixmap(x-mScatterPixmap.width()*0.5, y-mScatterPixmap.height()*0.5, mScatterPixmap);
1545  // if something in here is changed, adapt SSPixmap scatter style case in drawLegendIcon(), too
1546  break;
1547  }
1548  default: break;
1549  }
1550 }
a square which is not filled, with a plus inside
Definition: qcustomplot.h:206
a square which is not filled, with a cross inside
Definition: qcustomplot.h:205
a circle which is filled with the color of the graph&#39;s pen (not the brush!)
Definition: qcustomplot.h:200
double mScatterSize
Definition: qcustomplot.h:282
a cross (x)
Definition: qcustomplot.h:197
an equilateral triangle which is not filled, standing on corner
Definition: qcustomplot.h:204
a circle which is not filled, with one vertical and two downward diagonal lines
Definition: qcustomplot.h:209
a circle which is not filled
Definition: qcustomplot.h:199
an equilateral triangle which is not filled, standing on baseline
Definition: qcustomplot.h:203
a square which is not filled
Definition: qcustomplot.h:201
a circle which is not filled, with a plus inside
Definition: qcustomplot.h:208
a plus (+)
Definition: qcustomplot.h:198
QPixmap mScatterPixmap
Definition: qcustomplot.h:283
a star with eight arms, i.e. a combination of cross and plus
Definition: qcustomplot.h:202
a single pixel, setScatterSize has no influence on its size.
Definition: qcustomplot.h:196
a circle which is not filled, with a cross inside
Definition: qcustomplot.h:207
a custom pixmap specified by setScatterPixmap, centered on the data point coordinates. setScatterSize has no influence on its size.
Definition: qcustomplot.h:210
void QCPGraph::drawScatterPlot ( QPainter *  painter,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 1352 of file qcustomplot.cc.

1353 {
1354  // draw error bars:
1355  if (mErrorType != ETNone)
1356  {
1357  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEErrorBars));
1358  painter->setPen(mErrorPen);
1359  if (mKeyAxis->orientation() == Qt::Vertical)
1360  {
1361  for (int i=0; i<pointData->size(); ++i)
1362  drawError(painter, mValueAxis->coordToPixel(pointData->at(i).value), mKeyAxis->coordToPixel(pointData->at(i).key), pointData->at(i));
1363  } else
1364  {
1365  for (int i=0; i<pointData->size(); ++i)
1366  drawError(painter, mKeyAxis->coordToPixel(pointData->at(i).key), mValueAxis->coordToPixel(pointData->at(i).value), pointData->at(i));
1367  }
1368  }
1369 
1370  // draw scatter point symbols:
1371  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEScatters));
1372  painter->setPen(mPen);
1373  painter->setBrush(mBrush);
1374  if (mKeyAxis->orientation() == Qt::Vertical)
1375  {
1376  for (int i=0; i<pointData->size(); ++i)
1377  drawScatter(painter, mValueAxis->coordToPixel(pointData->at(i).value), mKeyAxis->coordToPixel(pointData->at(i).key), mScatterStyle);
1378  } else
1379  {
1380  for (int i=0; i<pointData->size(); ++i)
1381  drawScatter(painter, mKeyAxis->coordToPixel(pointData->at(i).key), mValueAxis->coordToPixel(pointData->at(i).value), mScatterStyle);
1382  }
1383 }
QPen mErrorPen
Definition: qcustomplot.h:279
void drawScatter(QPainter *painter, double x, double y, ScatterStyle style) const
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
No error bars are shown.
Definition: qcustomplot.h:216
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
ErrorType mErrorType
Definition: qcustomplot.h:284
double coordToPixel(double value) const
void drawError(QPainter *painter, double x, double y, const QCPData &data) const
double QCPGraph::errorBarSize ( ) const
inlineslot

Definition at line 235 of file qcustomplot.h.

235 { return mErrorBarSize; }
double mErrorBarSize
Definition: qcustomplot.h:285
bool QCPGraph::errorBarSkipSymbol ( ) const
inlineslot

Definition at line 236 of file qcustomplot.h.

236 { return mErrorBarSkipSymbol; }
bool mErrorBarSkipSymbol
Definition: qcustomplot.h:286
QPen QCPGraph::errorPen ( ) const
inlineslot

Definition at line 234 of file qcustomplot.h.

234 { return mErrorPen; }
QPen mErrorPen
Definition: qcustomplot.h:279
ErrorType QCPGraph::errorType ( ) const
inlineslot

Definition at line 233 of file qcustomplot.h.

233 { return mErrorType; }
ErrorType mErrorType
Definition: qcustomplot.h:284
int QCPGraph::findIndexAboveX ( const QVector< QPointF > *  data,
double  x 
) const
protected

Definition at line 1990 of file qcustomplot.cc.

1991 {
1992  for (int i=data->size()-1; i>=0; --i)
1993  {
1994  if (data->at(i).x() < x)
1995  {
1996  if (i<data->size()-1)
1997  return i+1;
1998  else
1999  return data->size()-1;
2000  }
2001  }
2002  return -1;
2003 }
const QCPDataMap * data() const
Definition: qcustomplot.h:228
int QCPGraph::findIndexAboveY ( const QVector< QPointF > *  data,
double  y 
) const
protected

Definition at line 2034 of file qcustomplot.cc.

2035 {
2036  for (int i=0; i<data->size(); ++i)
2037  {
2038  if (data->at(i).y() < y)
2039  {
2040  if (i>0)
2041  return i-1;
2042  else
2043  return 0;
2044  }
2045  }
2046  return -1;
2047 }
const QCPDataMap * data() const
Definition: qcustomplot.h:228
int QCPGraph::findIndexBelowX ( const QVector< QPointF > *  data,
double  x 
) const
protected

Definition at line 2012 of file qcustomplot.cc.

2013 {
2014  for (int i=0; i<data->size(); ++i)
2015  {
2016  if (data->at(i).x() > x)
2017  {
2018  if (i>0)
2019  return i-1;
2020  else
2021  return 0;
2022  }
2023  }
2024  return -1;
2025 }
const QCPDataMap * data() const
Definition: qcustomplot.h:228
int QCPGraph::findIndexBelowY ( const QVector< QPointF > *  data,
double  y 
) const
protected

Definition at line 2056 of file qcustomplot.cc.

2057 {
2058  for (int i=data->size()-1; i>=0; --i)
2059  {
2060  if (data->at(i).y() > y)
2061  {
2062  if (i<data->size()-1)
2063  return i+1;
2064  else
2065  return data->size()-1;
2066  }
2067  }
2068  return -1;
2069 }
const QCPDataMap * data() const
Definition: qcustomplot.h:228
const QPolygonF QCPGraph::getChannelFillPolygon ( const QVector< QPointF > *  lineData) const
protected

Definition at line 1856 of file qcustomplot.cc.

1857 {
1859  return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis)
1860 
1861  if (lineData->isEmpty()) return QPolygonF();
1862  QVector<QPointF> otherData;
1863  mChannelFillGraph->getPlotData(&otherData, 0);
1864  if (otherData.isEmpty()) return QPolygonF();
1865  QVector<QPointF> thisData;
1866  thisData.reserve(lineData->size()+otherData.size()); // because we will join both vectors at end of this function
1867  for (int i=0; i<lineData->size(); ++i) // don't use the vector<<(vector), it squeezes internally, which ruins the performance tuning with reserve()
1868  thisData << lineData->at(i);
1869 
1870  // pointers to be able to swap them, depending which data range needs cropping:
1871  QVector<QPointF> *staticData = &thisData;
1872  QVector<QPointF> *croppedData = &otherData;
1873 
1874  // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType):
1875  if (mKeyAxis->orientation() == Qt::Horizontal)
1876  {
1877  // x is key
1878  // if an axis range is reversed, the data point keys will be descending. Reverse them, since following algorithm assumes ascending keys:
1879  if (staticData->first().x() > staticData->last().x())
1880  {
1881  int size = staticData->size();
1882  for (int i=0; i<size/2; ++i)
1883  qSwap((*staticData)[i], (*staticData)[size-1-i]);
1884  }
1885  if (croppedData->first().x() > croppedData->last().x())
1886  {
1887  int size = croppedData->size();
1888  for (int i=0; i<size/2; ++i)
1889  qSwap((*croppedData)[i], (*croppedData)[size-1-i]);
1890  }
1891  // crop lower bound:
1892  if (staticData->first().x() < croppedData->first().x()) // other one must be cropped
1893  qSwap(staticData, croppedData);
1894  int lowBound = findIndexBelowX(croppedData, staticData->first().x());
1895  if (lowBound == -1) return QPolygonF(); // key ranges have no overlap
1896  croppedData->remove(0, lowBound);
1897  // set lowest point of cropped data to fit exactly key position of first static data
1898  // point via linear interpolation:
1899  if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
1900  double slope;
1901  if (croppedData->at(1).x()-croppedData->at(0).x() != 0)
1902  slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x());
1903  else
1904  slope = 0;
1905  (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x()));
1906  (*croppedData)[0].setX(staticData->first().x());
1907 
1908  // crop upper bound:
1909  if (staticData->last().x() > croppedData->last().x()) // other one must be cropped
1910  qSwap(staticData, croppedData);
1911  int highBound = findIndexAboveX(croppedData, staticData->last().x());
1912  if (highBound == -1) return QPolygonF(); // key ranges have no overlap
1913  croppedData->remove(highBound+1, croppedData->size()-(highBound+1));
1914  // set highest point of cropped data to fit exactly key position of last static data
1915  // point via linear interpolation:
1916  if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
1917  int li = croppedData->size()-1; // last index
1918  if (croppedData->at(li).x()-croppedData->at(li-1).x() != 0)
1919  slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x());
1920  else
1921  slope = 0;
1922  (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x()));
1923  (*croppedData)[li].setX(staticData->last().x());
1924  } else // mKeyAxis->orientation() == Qt::Vertical
1925  {
1926  // y is key
1927  // similar to "x is key" but switched x,y. Further, lower/upper meaning is inverted compared to x,
1928  // because in pixel coordinates, y increases from top to bottom, not bottom to top like data coordinate.
1929  // if an axis range is reversed, the data point keys will be descending. Reverse them, since following algorithm assumes ascending keys:
1930  if (staticData->first().y() < staticData->last().y())
1931  {
1932  int size = staticData->size();
1933  for (int i=0; i<size/2; ++i)
1934  qSwap((*staticData)[i], (*staticData)[size-1-i]);
1935  }
1936  if (croppedData->first().y() < croppedData->last().y())
1937  {
1938  int size = croppedData->size();
1939  for (int i=0; i<size/2; ++i)
1940  qSwap((*croppedData)[i], (*croppedData)[size-1-i]);
1941  }
1942  // crop lower bound:
1943  if (staticData->first().y() > croppedData->first().y()) // other one must be cropped
1944  qSwap(staticData, croppedData);
1945  int lowBound = findIndexAboveY(croppedData, staticData->first().y());
1946  if (lowBound == -1) return QPolygonF(); // key ranges have no overlap
1947  croppedData->remove(0, lowBound);
1948  // set lowest point of cropped data to fit exactly key position of first static data
1949  // point via linear interpolation:
1950  if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
1951  double slope;
1952  if (croppedData->at(1).y()-croppedData->at(0).y() != 0) // avoid division by zero in step plots
1953  slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y());
1954  else
1955  slope = 0;
1956  (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y()));
1957  (*croppedData)[0].setY(staticData->first().y());
1958 
1959  // crop upper bound:
1960  if (staticData->last().y() < croppedData->last().y()) // other one must be cropped
1961  qSwap(staticData, croppedData);
1962  int highBound = findIndexBelowY(croppedData, staticData->last().y());
1963  if (highBound == -1) return QPolygonF(); // key ranges have no overlap
1964  croppedData->remove(highBound+1, croppedData->size()-(highBound+1));
1965  // set highest point of cropped data to fit exactly key position of last static data
1966  // point via linear interpolation:
1967  if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation
1968  int li = croppedData->size()-1; // last index
1969  if (croppedData->at(li).y()-croppedData->at(li-1).y() != 0) // avoid division by zero in step plots
1970  slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y());
1971  else
1972  slope = 0;
1973  (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y()));
1974  (*croppedData)[li].setY(staticData->last().y());
1975  }
1976 
1977  // return joined:
1978  for (int i=otherData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted
1979  thisData << otherData.at(i);
1980  return QPolygonF(thisData);
1981 }
QCPGraph * mChannelFillGraph
Definition: qcustomplot.h:287
int findIndexAboveY(const QVector< QPointF > *data, double y) const
int findIndexAboveX(const QVector< QPointF > *data, double x) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
int findIndexBelowX(const QVector< QPointF > *data, double x) const
int findIndexBelowY(const QVector< QPointF > *data, double y) const
void getPlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
Definition: qcustomplot.cc:868
void QCPGraph::getImpulsePlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 1248 of file qcustomplot.cc.

1249 {
1250  // get visible data range:
1251  QCPDataMap::const_iterator lower, upper;
1252  int dataCount;
1253  getVisibleDataBounds(lower, upper, dataCount);
1254  // prepare vectors:
1255  if (lineData)
1256  {
1257  // no need to reserve 2 extra points, because there is no fill for impulse plot
1258  lineData->resize(dataCount*2);
1259  }
1260  if (pointData)
1261  pointData->resize(dataCount);
1262 
1263  // position data points:
1264  QCPDataMap::const_iterator it = lower;
1265  QCPDataMap::const_iterator upperEnd = upper+1;
1266  int i = 0;
1267  int ipoint = 0;
1268  if (mKeyAxis->orientation() == Qt::Vertical)
1269  {
1270  double zeroPointX = mValueAxis->coordToPixel(0);
1271  double key;
1272  while (it != upperEnd)
1273  {
1274  if (pointData)
1275  {
1276  (*pointData)[ipoint] = it.value();
1277  ++ipoint;
1278  }
1279  key = mKeyAxis->coordToPixel(it.key());
1280  (*lineData)[i].setX(zeroPointX);
1281  (*lineData)[i].setY(key);
1282  ++i;
1283  (*lineData)[i].setX(mValueAxis->coordToPixel(it.value().value));
1284  (*lineData)[i].setY(key);
1285  ++i;
1286  ++it;
1287  }
1288  } else // key axis is horizontal
1289  {
1290  double zeroPointY = mValueAxis->coordToPixel(0);
1291  double key;
1292  while (it != upperEnd)
1293  {
1294  if (pointData)
1295  {
1296  (*pointData)[ipoint] = it.value();
1297  ++ipoint;
1298  }
1299  key = mKeyAxis->coordToPixel(it.key());
1300  (*lineData)[i].setX(key);
1301  (*lineData)[i].setY(zeroPointY);
1302  ++i;
1303  (*lineData)[i].setX(key);
1304  (*lineData)[i].setY(mValueAxis->coordToPixel(it.value().value));
1305  ++i;
1306  ++it;
1307  }
1308  }
1309 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
QCPRange QCPGraph::getKeyRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 2072 of file qcustomplot.cc.

2073 {
2074  // just call the specialized version which takes an additional argument whether error bars
2075  // should also be taken into consideration for range calculation. We set this to true here.
2076  return getKeyRange(validRange, inSignDomain, true);
2077 }
virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=SDBoth) const
QCPRange QCPGraph::getKeyRange ( bool &  validRange,
SignDomain  inSignDomain,
bool  includeErrors 
) const
protectedvirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Allows to specify whether the error bars should be included in the range calculation.

See also
getKeyRange(bool &validRange, SignDomain inSignDomain)

Definition at line 2092 of file qcustomplot.cc.

2093 {
2094  QCPRange range;
2095  bool haveLower = false;
2096  bool haveUpper = false;
2097 
2098  double current, currentErrorMinus, currentErrorPlus;
2099 
2100  if (inSignDomain == SDBoth) // range may be anywhere
2101  {
2102  QCPDataMap::const_iterator it = mData->constBegin();
2103  while (it != mData->constEnd())
2104  {
2105  current = it.value().key;
2106  currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0);
2107  currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0);
2108  if (current-currentErrorMinus < range.lower || !haveLower)
2109  {
2110  range.lower = current-currentErrorMinus;
2111  haveLower = true;
2112  }
2113  if (current+currentErrorPlus > range.upper || !haveUpper)
2114  {
2115  range.upper = current+currentErrorPlus;
2116  haveUpper = true;
2117  }
2118  it++;
2119  }
2120  } else if (inSignDomain == SDNegative) // range may only be in the negative sign domain
2121  {
2122  QCPDataMap::const_iterator it = mData->constBegin();
2123  while (it != mData->constEnd())
2124  {
2125  current = it.value().key;
2126  currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0);
2127  currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0);
2128  if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0)
2129  {
2130  range.lower = current-currentErrorMinus;
2131  haveLower = true;
2132  }
2133  if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0)
2134  {
2135  range.upper = current+currentErrorPlus;
2136  haveUpper = true;
2137  }
2138  if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point.
2139  {
2140  if ((current < range.lower || !haveLower) && current < 0)
2141  {
2142  range.lower = current;
2143  haveLower = true;
2144  }
2145  if ((current > range.upper || !haveUpper) && current < 0)
2146  {
2147  range.upper = current;
2148  haveUpper = true;
2149  }
2150  }
2151  it++;
2152  }
2153  } else if (inSignDomain == SDPositive) // range may only be in the positive sign domain
2154  {
2155  QCPDataMap::const_iterator it = mData->constBegin();
2156  while (it != mData->constEnd())
2157  {
2158  current = it.value().key;
2159  currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0);
2160  currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0);
2161  if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0)
2162  {
2163  range.lower = current-currentErrorMinus;
2164  haveLower = true;
2165  }
2166  if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0)
2167  {
2168  range.upper = current+currentErrorPlus;
2169  haveUpper = true;
2170  }
2171  if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point.
2172  {
2173  if ((current < range.lower || !haveLower) && current > 0)
2174  {
2175  range.lower = current;
2176  haveLower = true;
2177  }
2178  if ((current > range.upper || !haveUpper) && current > 0)
2179  {
2180  range.upper = current;
2181  haveUpper = true;
2182  }
2183  }
2184  it++;
2185  }
2186  }
2187 
2188  validRange = haveLower && haveUpper;
2189  return range;
2190 }
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
QCPDataMap * mData
Definition: qcustomplot.h:278
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 QCPGraph::getLinePlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 936 of file qcustomplot.cc.

937 {
938  // get visible data range:
939  QCPDataMap::const_iterator lower, upper;
940  int dataCount;
941  getVisibleDataBounds(lower, upper, dataCount);
942  // prepare vectors:
943  if (lineData)
944  {
945  // added 2 to reserve memory for lower/upper fill base points that might be needed for fill
946  lineData->reserve(dataCount+2);
947  lineData->resize(dataCount);
948  }
949  if (pointData)
950  pointData->resize(dataCount);
951 
952  // position data points:
953  QCPDataMap::const_iterator it = lower;
954  QCPDataMap::const_iterator upperEnd = upper+1;
955  int i = 0;
956  if (mKeyAxis->orientation() == Qt::Vertical)
957  {
958  while (it != upperEnd)
959  {
960  if (pointData)
961  (*pointData)[i] = it.value();
962  (*lineData)[i].setX(mValueAxis->coordToPixel(it.value().value));
963  (*lineData)[i].setY(mKeyAxis->coordToPixel(it.key()));
964  ++i;
965  ++it;
966  }
967  } else // key axis is horizontal
968  {
969  while (it != upperEnd)
970  {
971  if (pointData)
972  (*pointData)[i] = it.value();
973  (*lineData)[i].setX(mKeyAxis->coordToPixel(it.key()));
974  (*lineData)[i].setY(mValueAxis->coordToPixel(it.value().value));
975  ++i;
976  ++it;
977  }
978  }
979 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
void QCPGraph::getPlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 868 of file qcustomplot.cc.

869 {
870  switch(mLineStyle)
871  {
872  case LSNone: getScatterPlotData(pointData); break;
873  case LSLine: getLinePlotData(lineData, pointData); break;
874  case LSStepLeft: getStepLeftPlotData(lineData, pointData); break;
875  case LSStepRight: getStepRightPlotData(lineData, pointData); break;
876  case LSStepCenter: getStepCenterPlotData(lineData, pointData); break;
877  case LSImpulse: getImpulsePlotData(lineData, pointData); break;
878  }
879 }
line is drawn as steps where the step height is the value of the right data point ...
Definition: qcustomplot.h:184
line is drawn as steps where the step is in between two data points
Definition: qcustomplot.h:185
void getScatterPlotData(QVector< QCPData > *pointData) const
Definition: qcustomplot.cc:891
void getImpulsePlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
void getStepCenterPlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
line is drawn as steps where the step height is the value of the left data point
Definition: qcustomplot.h:183
data points are represented by a straight line parallel to the value axis, which ranges down/up to th...
Definition: qcustomplot.h:186
void getLinePlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
Definition: qcustomplot.cc:936
data points are connected by a straight line
Definition: qcustomplot.h:182
LineStyle mLineStyle
Definition: qcustomplot.h:280
void getStepRightPlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
void getStepLeftPlotData(QVector< QPointF > *lineData, QVector< QCPData > *pointData) const
Definition: qcustomplot.cc:991
void QCPGraph::getScatterPlotData ( QVector< QCPData > *  pointData) const
protected

Definition at line 891 of file qcustomplot.cc.

892 {
893  if (!pointData) return;
894 
895  // get visible data range:
896  QCPDataMap::const_iterator lower, upper;
897  int dataCount;
898  getVisibleDataBounds(lower, upper, dataCount);
899  // prepare vectors:
900  if (pointData)
901  pointData->resize(dataCount);
902 
903  // position data points:
904  QCPDataMap::const_iterator it = lower;
905  QCPDataMap::const_iterator upperEnd = upper+1;
906  int i = 0;
907  if (mKeyAxis->orientation() == Qt::Vertical)
908  {
909  while (it != upperEnd)
910  {
911  (*pointData)[i] = it.value();
912  ++i;
913  ++it;
914  }
915  } else // key axis is horizontal
916  {
917  while (it != upperEnd)
918  {
919  (*pointData)[i] = it.value();
920  ++i;
921  ++it;
922  }
923  }
924 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
void QCPGraph::getStepCenterPlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 1145 of file qcustomplot.cc.

1146 {
1147  // get visible data range:
1148  QCPDataMap::const_iterator lower, upper;
1149  int dataCount;
1150  getVisibleDataBounds(lower, upper, dataCount);
1151  // prepare vectors:
1152  if (lineData)
1153  {
1154  // added 2 to reserve memory for lower/upper fill base points that might be needed for base fill
1155  // multiplied by 2 because step plot needs two polyline points per one actual data point
1156  lineData->reserve(dataCount*2+2);
1157  lineData->resize(dataCount*2);
1158  }
1159  if (pointData)
1160  pointData->resize(dataCount);
1161 
1162  // position points:
1163  QCPDataMap::const_iterator it = lower;
1164  QCPDataMap::const_iterator upperEnd = upper+1;
1165  int i = 0;
1166  int ipoint = 0;
1167  if (mKeyAxis->orientation() == Qt::Vertical)
1168  {
1169  double lastKey = mKeyAxis->coordToPixel(it.key());
1170  double lastValue = mValueAxis->coordToPixel(it.value().value);
1171  double key;
1172  if (pointData)
1173  {
1174  (*pointData)[ipoint] = it.value();
1175  ++ipoint;
1176  }
1177  (*lineData)[i].setX(lastValue);
1178  (*lineData)[i].setY(lastKey);
1179  ++it;
1180  ++i;
1181  while (it != upperEnd)
1182  {
1183  if (pointData)
1184  {
1185  (*pointData)[ipoint] = it.value();
1186  ++ipoint;
1187  }
1188  key = (mKeyAxis->coordToPixel(it.key())-lastKey)*0.5 + lastKey;
1189  (*lineData)[i].setX(lastValue);
1190  (*lineData)[i].setY(key);
1191  ++i;
1192  lastValue = mValueAxis->coordToPixel(it.value().value);
1193  lastKey = mKeyAxis->coordToPixel(it.key());
1194  (*lineData)[i].setX(lastValue);
1195  (*lineData)[i].setY(key);
1196  ++it;
1197  ++i;
1198  }
1199  (*lineData)[i].setX(lastValue);
1200  (*lineData)[i].setY(lastKey);
1201  } else // key axis is horizontal
1202  {
1203  double lastKey = mKeyAxis->coordToPixel(it.key());
1204  double lastValue = mValueAxis->coordToPixel(it.value().value);
1205  double key;
1206  if (pointData)
1207  {
1208  (*pointData)[ipoint] = it.value();
1209  ++ipoint;
1210  }
1211  (*lineData)[i].setX(lastKey);
1212  (*lineData)[i].setY(lastValue);
1213  ++it;
1214  ++i;
1215  while (it != upperEnd)
1216  {
1217  if (pointData)
1218  {
1219  (*pointData)[ipoint] = it.value();
1220  ++ipoint;
1221  }
1222  key = (mKeyAxis->coordToPixel(it.key())-lastKey)*0.5 + lastKey;
1223  (*lineData)[i].setX(key);
1224  (*lineData)[i].setY(lastValue);
1225  ++i;
1226  lastValue = mValueAxis->coordToPixel(it.value().value);
1227  lastKey = mKeyAxis->coordToPixel(it.key());
1228  (*lineData)[i].setX(key);
1229  (*lineData)[i].setY(lastValue);
1230  ++it;
1231  ++i;
1232  }
1233  (*lineData)[i].setX(lastKey);
1234  (*lineData)[i].setY(lastValue);
1235  }
1236 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
void QCPGraph::getStepLeftPlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 991 of file qcustomplot.cc.

992 {
993  // get visible data range:
994  QCPDataMap::const_iterator lower, upper;
995  int dataCount;
996  getVisibleDataBounds(lower, upper, dataCount);
997  // prepare vectors:
998  if (lineData)
999  {
1000  // added 2 to reserve memory for lower/upper fill base points that might be needed for fill
1001  // multiplied by 2 because step plot needs two polyline points per one actual data point
1002  lineData->reserve(dataCount*2+2);
1003  lineData->resize(dataCount*2);
1004  }
1005  if (pointData)
1006  pointData->resize(dataCount);
1007 
1008  // position data points:
1009  QCPDataMap::const_iterator it = lower;
1010  QCPDataMap::const_iterator upperEnd = upper+1;
1011  int i = 0;
1012  int ipoint = 0;
1013  if (mKeyAxis->orientation() == Qt::Vertical)
1014  {
1015  double lastValue = mValueAxis->coordToPixel(it.value().value);
1016  double key;
1017  while (it != upperEnd)
1018  {
1019  if (pointData)
1020  {
1021  (*pointData)[ipoint] = it.value();
1022  ++ipoint;
1023  }
1024  key = mKeyAxis->coordToPixel(it.key());
1025  (*lineData)[i].setX(lastValue);
1026  (*lineData)[i].setY(key);
1027  ++i;
1028  lastValue = mValueAxis->coordToPixel(it.value().value);
1029  (*lineData)[i].setX(lastValue);
1030  (*lineData)[i].setY(key);
1031  ++i;
1032  ++it;
1033  }
1034  } else // key axis is horizontal
1035  {
1036  double lastValue = mValueAxis->coordToPixel(it.value().value);
1037  double key;
1038  while (it != upperEnd)
1039  {
1040  if (pointData)
1041  {
1042  (*pointData)[ipoint] = it.value();
1043  ++ipoint;
1044  }
1045  key = mKeyAxis->coordToPixel(it.key());
1046  (*lineData)[i].setX(key);
1047  (*lineData)[i].setY(lastValue);
1048  ++i;
1049  lastValue = mValueAxis->coordToPixel(it.value().value);
1050  (*lineData)[i].setX(key);
1051  (*lineData)[i].setY(lastValue);
1052  ++i;
1053  ++it;
1054  }
1055  }
1056 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
void QCPGraph::getStepRightPlotData ( QVector< QPointF > *  lineData,
QVector< QCPData > *  pointData 
) const
protected

Definition at line 1068 of file qcustomplot.cc.

1069 {
1070  // get visible data range:
1071  QCPDataMap::const_iterator lower, upper;
1072  int dataCount;
1073  getVisibleDataBounds(lower, upper, dataCount);
1074  // prepare vectors:
1075  if (lineData)
1076  {
1077  // added 2 to reserve memory for lower/upper fill base points that might be needed for fill
1078  // multiplied by 2 because step plot needs two polyline points per one actual data point
1079  lineData->reserve(dataCount*2+2);
1080  lineData->resize(dataCount*2);
1081  }
1082  if (pointData)
1083  pointData->resize(dataCount);
1084 
1085  // position points:
1086  QCPDataMap::const_iterator it = lower;
1087  QCPDataMap::const_iterator upperEnd = upper+1;
1088  int i = 0;
1089  int ipoint = 0;
1090  if (mKeyAxis->orientation() == Qt::Vertical)
1091  {
1092  double lastKey = mKeyAxis->coordToPixel(it.key());
1093  double value;
1094  while (it != upperEnd)
1095  {
1096  if (pointData)
1097  {
1098  (*pointData)[ipoint] = it.value();
1099  ++ipoint;
1100  }
1101  value = mValueAxis->coordToPixel(it.value().value);
1102  (*lineData)[i].setX(value);
1103  (*lineData)[i].setY(lastKey);
1104  ++i;
1105  lastKey = mKeyAxis->coordToPixel(it.key());
1106  (*lineData)[i].setX(value);
1107  (*lineData)[i].setY(lastKey);
1108  ++i;
1109  ++it;
1110  }
1111  } else // key axis is horizontal
1112  {
1113  double lastKey = mKeyAxis->coordToPixel(it.key());
1114  double value;
1115  while (it != upperEnd)
1116  {
1117  if (pointData)
1118  {
1119  (*pointData)[ipoint] = it.value();
1120  ++ipoint;
1121  }
1122  value = mValueAxis->coordToPixel(it.value().value);
1123  (*lineData)[i].setX(lastKey);
1124  (*lineData)[i].setY(value);
1125  ++i;
1126  lastKey = mKeyAxis->coordToPixel(it.key());
1127  (*lineData)[i].setX(lastKey);
1128  (*lineData)[i].setY(value);
1129  ++i;
1130  ++it;
1131  }
1132  }
1133 }
void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
double coordToPixel(double value) const
QCPRange QCPGraph::getValueRange ( bool &  validRange,
SignDomain  inSignDomain = SDBoth 
) const
protectedvirtual

Implements QCPAbstractPlottable.

Definition at line 2080 of file qcustomplot.cc.

2081 {
2082  // just call the specialized version which takes an additional argument whether error bars
2083  // should also be taken into consideration for range calculation. We set this to true here.
2084  return getValueRange(validRange, inSignDomain, true);
2085 }
virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=SDBoth) const
QCPRange QCPGraph::getValueRange ( bool &  validRange,
SignDomain  inSignDomain,
bool  includeErrors 
) const
protectedvirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Allows to specify whether the error bars should be included in the range calculation.

See also
getValueRange(bool &validRange, SignDomain inSignDomain)

Definition at line 2197 of file qcustomplot.cc.

2198 {
2199  QCPRange range;
2200  bool haveLower = false;
2201  bool haveUpper = false;
2202 
2203  double current, currentErrorMinus, currentErrorPlus;
2204 
2205  if (inSignDomain == SDBoth) // range may be anywhere
2206  {
2207  QCPDataMap::const_iterator it = mData->constBegin();
2208  while (it != mData->constEnd())
2209  {
2210  current = it.value().value;
2211  currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0);
2212  currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0);
2213  if (current-currentErrorMinus < range.lower || !haveLower)
2214  {
2215  range.lower = current-currentErrorMinus;
2216  haveLower = true;
2217  }
2218  if (current+currentErrorPlus > range.upper || !haveUpper)
2219  {
2220  range.upper = current+currentErrorPlus;
2221  haveUpper = true;
2222  }
2223  it++;
2224  }
2225  } else if (inSignDomain == SDNegative) // range may only be in the negative sign domain
2226  {
2227  QCPDataMap::const_iterator it = mData->constBegin();
2228  while (it != mData->constEnd())
2229  {
2230  current = it.value().value;
2231  currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0);
2232  currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0);
2233  if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0)
2234  {
2235  range.lower = current-currentErrorMinus;
2236  haveLower = true;
2237  }
2238  if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0)
2239  {
2240  range.upper = current+currentErrorPlus;
2241  haveUpper = true;
2242  }
2243  if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point.
2244  {
2245  if ((current < range.lower || !haveLower) && current < 0)
2246  {
2247  range.lower = current;
2248  haveLower = true;
2249  }
2250  if ((current > range.upper || !haveUpper) && current < 0)
2251  {
2252  range.upper = current;
2253  haveUpper = true;
2254  }
2255  }
2256  it++;
2257  }
2258  } else if (inSignDomain == SDPositive) // range may only be in the positive sign domain
2259  {
2260  QCPDataMap::const_iterator it = mData->constBegin();
2261  while (it != mData->constEnd())
2262  {
2263  current = it.value().value;
2264  currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0);
2265  currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0);
2266  if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0)
2267  {
2268  range.lower = current-currentErrorMinus;
2269  haveLower = true;
2270  }
2271  if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0)
2272  {
2273  range.upper = current+currentErrorPlus;
2274  haveUpper = true;
2275  }
2276  if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point.
2277  {
2278  if ((current < range.lower || !haveLower) && current > 0)
2279  {
2280  range.lower = current;
2281  haveLower = true;
2282  }
2283  if ((current > range.upper || !haveUpper) && current > 0)
2284  {
2285  range.upper = current;
2286  haveUpper = true;
2287  }
2288  }
2289  it++;
2290  }
2291  }
2292 
2293  validRange = haveLower && haveUpper;
2294  return range;
2295 }
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
QCPDataMap * mData
Definition: qcustomplot.h:278
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 QCPGraph::getVisibleDataBounds ( QCPDataMap::const_iterator &  lower,
QCPDataMap::const_iterator &  upper,
int &  count 
) const
protected

Definition at line 1669 of file qcustomplot.cc.

1670 {
1671  // get visible data range as QMap iterators
1672  QCPDataMap::const_iterator lbound = mData->lowerBound(mKeyAxis->range().lower);
1673  QCPDataMap::const_iterator ubound = mData->upperBound(mKeyAxis->range().upper)-1;
1674  bool lowoutlier = lbound != mData->constBegin(); // indicates whether there exist points below axis range
1675  bool highoutlier = ubound+1 != mData->constEnd(); // indicates whether there exist points above axis range
1676  lower = (lowoutlier ? lbound-1 : lbound); // data pointrange that will be actually drawn
1677  upper = (highoutlier ? ubound+1 : ubound); // data pointrange that will be actually drawn
1678 
1679  // count number of points in range lower to upper (including them), so we can allocate array for them in draw functions:
1680  QCPDataMap::const_iterator it = lower;
1681  count = 1;
1682  while (it != upper)
1683  {
1684  ++it;
1685  ++count;
1686  }
1687 }
const QCPRange range() const
Definition: qcustomplot.h:746
QCPDataMap * mData
Definition: qcustomplot.h:278
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
LineStyle QCPGraph::lineStyle ( ) const
inlineslot

Definition at line 229 of file qcustomplot.h.

229 { return mLineStyle; }
LineStyle mLineStyle
Definition: qcustomplot.h:280
QPointF QCPGraph::lowerFillBasePoint ( double  lowerKey) const
protected

Definition at line 1740 of file qcustomplot.cc.

1741 {
1742  QPointF point;
1744  {
1745  if (mKeyAxis->axisType() == QCPAxis::ATLeft)
1746  {
1747  point.setX(mValueAxis->coordToPixel(0));
1748  point.setY(lowerKey);
1749  } else if (mKeyAxis->axisType() == QCPAxis::ATRight)
1750  {
1751  point.setX(mValueAxis->coordToPixel(0));
1752  point.setY(lowerKey);
1753  } else if (mKeyAxis->axisType() == QCPAxis::ATTop)
1754  {
1755  point.setX(lowerKey);
1756  point.setY(mValueAxis->coordToPixel(0));
1757  } else if (mKeyAxis->axisType() == QCPAxis::ATBottom)
1758  {
1759  point.setX(lowerKey);
1760  point.setY(mValueAxis->coordToPixel(0));
1761  }
1762  } else // mValueAxis->mScaleType == QCPAxis::STLogarithmic
1763  {
1764  // In logarithmic scaling we can't just draw to value zero so we just fill all the way
1765  // to the axis which is in the direction towards zero
1766  if (mKeyAxis->orientation() == Qt::Vertical)
1767  {
1768  if ((mValueAxis->range().upper < 0 && !mValueAxis->rangeReversed()) ||
1769  (mValueAxis->range().upper > 0 && mValueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis
1770  point.setX(mKeyAxis->axisRect().right());
1771  else
1772  point.setX(mKeyAxis->axisRect().left());
1773  point.setY(lowerKey);
1775  {
1776  point.setX(lowerKey);
1777  if ((mValueAxis->range().upper < 0 && !mValueAxis->rangeReversed()) ||
1778  (mValueAxis->range().upper > 0 && mValueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis
1779  point.setY(mKeyAxis->axisRect().top());
1780  else
1781  point.setY(mKeyAxis->axisRect().bottom());
1782  }
1783  }
1784  return point;
1785 }
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
QRect axisRect() const
Definition: qcustomplot.h:743
const QCPRange range() const
Definition: qcustomplot.h:746
Normal linear scaling.
Definition: qcustomplot.h:731
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
bool rangeReversed() const
Definition: qcustomplot.h:747
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
double coordToPixel(double value) const
double upper
Definition: qcustomplot.h:494
ScaleType scaleType() const
Definition: qcustomplot.h:744
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711
AxisType axisType() const
Definition: qcustomplot.h:742
void QCPGraph::removeData ( double  fromKey,
double  toKey 
)
slot

Removes all data points with keys 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 674 of file qcustomplot.cc.

675 {
676  if (fromKey >= toKey || mData->isEmpty()) return;
677  QCPDataMap::iterator it = mData->upperBound(fromKey);
678  QCPDataMap::iterator itEnd = mData->upperBound(toKey);
679  while (it != itEnd)
680  it = mData->erase(it);
681 }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::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 691 of file qcustomplot.cc.

692 {
693  mData->remove(key);
694 }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::removeDataAfter ( double  key)
slot

Removes all data points with keys greater than key.

See also
addData, clearData

Definition at line 659 of file qcustomplot.cc.

660 {
661  if (mData->isEmpty()) return;
662  QCPDataMap::iterator it = mData->upperBound(key);
663  while (it != mData->end())
664  it = mData->erase(it);
665 }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::removeDataBefore ( double  key)
slot

Removes all data points with keys smaller than key.

See also
addData, clearData

Definition at line 648 of file qcustomplot.cc.

649 {
650  QCPDataMap::iterator it = mData->begin();
651  while (it != mData->end() && it.key() < key)
652  it = mData->erase(it);
653 }
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::removeFillBasePoints ( QVector< QPointF > *  lineData) const
protected

Definition at line 1722 of file qcustomplot.cc.

1723 {
1724  lineData->remove(lineData->size()-2, 2);
1725 }
void QCPGraph::rescaleAxes ( bool  onlyEnlarge,
bool  includeErrorBars 
) const
virtual

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

Allows to define whether error bars are taken into consideration when determining the new axis range.

Definition at line 710 of file qcustomplot.cc.

711 {
712  rescaleKeyAxis(onlyEnlarge, includeErrorBars);
713  rescaleValueAxis(onlyEnlarge, includeErrorBars);
714 }
virtual void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const
Definition: qcustomplot.cc:752
virtual void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const
Definition: qcustomplot.cc:721
void QCPGraph::rescaleKeyAxis ( bool  onlyEnlarge,
bool  includeErrorBars 
) const
virtual

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

Allows to define whether error bars (of kind QCPGraph::etKey) are taken into consideration when determining the new axis range.

Definition at line 721 of file qcustomplot.cc.

722 {
723  // this code is a copy of QCPAbstractPlottable::rescaleKeyAxis with the only change
724  // is that getKeyRange is passed the includeErrorBars value.
725  if (mData->isEmpty()) return;
726 
727  SignDomain signDomain = SDBoth;
729  signDomain = (mKeyAxis->range().upper < 0 ? SDNegative : SDPositive);
730 
731  bool validRange;
732  QCPRange newRange = getKeyRange(validRange, signDomain, includeErrorBars);
733 
734  if (validRange)
735  {
736  if (onlyEnlarge)
737  {
738  if (mKeyAxis->range().lower < newRange.lower)
739  newRange.lower = mKeyAxis->range().lower;
740  if (mKeyAxis->range().upper > newRange.upper)
741  newRange.upper = mKeyAxis->range().upper;
742  }
743  mKeyAxis->setRange(newRange);
744  }
745 }
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
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
QCPDataMap * mData
Definition: qcustomplot.h:278
virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=SDBoth) const
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 QCPGraph::rescaleValueAxis ( bool  onlyEnlarge,
bool  includeErrorBars 
) const
virtual

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

Allows to define whether error bars (of kind QCPGraph::ETValue) are taken into consideration when determining the new axis range.

Definition at line 752 of file qcustomplot.cc.

753 {
754  // this code is a copy of QCPAbstractPlottable::rescaleValueAxis with the only change
755  // is that getValueRange is passed the includeErrorBars value.
756  if (mData->isEmpty()) return;
757 
758  SignDomain signDomain = SDBoth;
760  signDomain = (mValueAxis->range().upper < 0 ? SDNegative : SDPositive);
761 
762  bool validRange;
763  QCPRange newRange = getValueRange(validRange, signDomain, includeErrorBars);
764 
765  if (validRange)
766  {
767  if (onlyEnlarge)
768  {
769  if (mValueAxis->range().lower < newRange.lower)
770  newRange.lower = mValueAxis->range().lower;
771  if (mValueAxis->range().upper > newRange.upper)
772  newRange.upper = mValueAxis->range().upper;
773  }
774  mValueAxis->setRange(newRange);
775  }
776 }
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
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
QCPDataMap * mData
Definition: qcustomplot.h:278
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
const QPixmap QCPGraph::scatterPixmap ( ) const
inlineslot

Definition at line 232 of file qcustomplot.h.

232 { return mScatterPixmap; }
QPixmap mScatterPixmap
Definition: qcustomplot.h:283
double QCPGraph::scatterSize ( ) const
inlineslot

Definition at line 231 of file qcustomplot.h.

231 { return mScatterSize; }
double mScatterSize
Definition: qcustomplot.h:282
ScatterStyle QCPGraph::scatterStyle ( ) const
inlineslot

Definition at line 230 of file qcustomplot.h.

230 { return mScatterStyle; }
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
void QCPGraph::setChannelFillGraph ( QCPGraph targetGraph)
slot

Sets the target graph for filling the area between this graph and targetGraph with the current brush (setBrush).

When targetGraph is set to 0, a normal graph fill will be produced. This means, when the brush is not Qt::NoBrush or fully transparent, a fill all the way to the zero-value-line parallel to the key axis of this graph will be drawn. To disable any filling, set the brush to Qt::NoBrush.

See also
setBrush

Definition at line 578 of file qcustomplot.cc.

579 {
580  // prevent setting channel target to this graph itself:
581  if (targetGraph == this)
582  {
583  qDebug() << FUNCNAME << "targetGraph is self";
584  mChannelFillGraph = 0;
585  return;
586  }
587  // prevent setting channel target to a graph not in the plot:
588  if (targetGraph && targetGraph->mParentPlot != mParentPlot)
589  {
590  qDebug() << FUNCNAME << "targetGraph not in same plot";
591  mChannelFillGraph = 0;
592  return;
593  }
594 
595  mChannelFillGraph = targetGraph;
596 }
QCPGraph * mChannelFillGraph
Definition: qcustomplot.h:287
QCustomPlot * mParentPlot
Definition: qcustomplot.h:153
#define FUNCNAME
Definition: qcustomplot.h:50
void QCPGraph::setData ( QCPDataMap 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 295 of file qcustomplot.cc.

296 {
297  if (copy)
298  {
299  *mData = *data;
300  } else
301  {
302  delete mData;
303  mData = data;
304  }
305 }
const QCPDataMap * data() const
Definition: qcustomplot.h:228
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::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 pairs. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 313 of file qcustomplot.cc.

314 {
315  mData->clear();
316  int n = key.size();
317  n = qMin(n, value.size());
318  QCPData newData;
319  for (int i=0; i<n; ++i)
320  {
321  newData.key = key[i];
322  newData.value = value[i];
323  mData->insertMulti(newData.key, newData);
324  }
325 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataBothError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  keyError,
const QVector< double > &  valueError 
)
slot

Replaces the current data with the provided points in key and value pairs. Additionally the symmetrical key and value errors of the data points are set to the values in keyError and valueError. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 436 of file qcustomplot.cc.

437 {
438  mData->clear();
439  int n = key.size();
440  n = qMin(n, value.size());
441  n = qMin(n, valueError.size());
442  n = qMin(n, keyError.size());
443  QCPData newData;
444  for (int i=0; i<n; ++i)
445  {
446  newData.key = key[i];
447  newData.value = value[i];
448  newData.keyErrorMinus = keyError[i];
449  newData.keyErrorPlus = keyError[i];
450  newData.valueErrorMinus = valueError[i];
451  newData.valueErrorPlus = valueError[i];
452  mData->insertMulti(key[i], newData);
453  }
454 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataBothError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  keyErrorMinus,
const QVector< double > &  keyErrorPlus,
const QVector< double > &  valueErrorMinus,
const QVector< double > &  valueErrorPlus 
)
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 pairs. Additionally the negative key and value errors of the data points are set to the values in keyErrorMinus and valueErrorMinus. The positive key and value errors are set to the values in keyErrorPlus valueErrorPlus. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 465 of file qcustomplot.cc.

466 {
467  mData->clear();
468  int n = key.size();
469  n = qMin(n, value.size());
470  n = qMin(n, valueErrorMinus.size());
471  n = qMin(n, valueErrorPlus.size());
472  n = qMin(n, keyErrorMinus.size());
473  n = qMin(n, keyErrorPlus.size());
474  QCPData newData;
475  for (int i=0; i<n; ++i)
476  {
477  newData.key = key[i];
478  newData.value = value[i];
479  newData.keyErrorMinus = keyErrorMinus[i];
480  newData.keyErrorPlus = keyErrorPlus[i];
481  newData.valueErrorMinus = valueErrorMinus[i];
482  newData.valueErrorPlus = valueErrorPlus[i];
483  mData->insertMulti(key[i], newData);
484  }
485 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataKeyError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  keyError 
)
slot

Replaces the current data with the provided points in key and value pairs. Additionally the symmetrical key error of the data points are set to the values in keyError. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 385 of file qcustomplot.cc.

386 {
387  mData->clear();
388  int n = key.size();
389  n = qMin(n, value.size());
390  n = qMin(n, keyError.size());
391  QCPData newData;
392  for (int i=0; i<n; ++i)
393  {
394  newData.key = key[i];
395  newData.value = value[i];
396  newData.keyErrorMinus = keyError[i];
397  newData.keyErrorPlus = keyError[i];
398  mData->insertMulti(key[i], newData);
399  }
400 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataKeyError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  keyErrorMinus,
const QVector< double > &  keyErrorPlus 
)
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 pairs. Additionally the negative key error of the data points are set to the values in keyErrorMinus, the positive key error to keyErrorPlus. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 411 of file qcustomplot.cc.

412 {
413  mData->clear();
414  int n = key.size();
415  n = qMin(n, value.size());
416  n = qMin(n, keyErrorMinus.size());
417  n = qMin(n, keyErrorPlus.size());
418  QCPData newData;
419  for (int i=0; i<n; ++i)
420  {
421  newData.key = key[i];
422  newData.value = value[i];
423  newData.keyErrorMinus = keyErrorMinus[i];
424  newData.keyErrorPlus = keyErrorPlus[i];
425  mData->insertMulti(key[i], newData);
426  }
427 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataValueError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  valueError 
)
slot

Replaces the current data with the provided points in key and value pairs. Additionally the symmetrical value error of the data points are set to the values in valueError. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 334 of file qcustomplot.cc.

335 {
336  mData->clear();
337  int n = key.size();
338  n = qMin(n, value.size());
339  n = qMin(n, valueError.size());
340  QCPData newData;
341  for (int i=0; i<n; ++i)
342  {
343  newData.key = key[i];
344  newData.value = value[i];
345  newData.valueErrorMinus = valueError[i];
346  newData.valueErrorPlus = valueError[i];
347  mData->insertMulti(key[i], newData);
348  }
349 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setDataValueError ( const QVector< double > &  key,
const QVector< double > &  value,
const QVector< double > &  valueErrorMinus,
const QVector< double > &  valueErrorPlus 
)
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 pairs. Additionally the negative value error of the data points are set to the values in valueErrorMinus, the positive value error to valueErrorPlus. For error bars to show appropriately, see setErrorType. The provided vectors should have equal length. Else, the number of added points will be the size of the smallest vector.

Definition at line 360 of file qcustomplot.cc.

361 {
362  mData->clear();
363  int n = key.size();
364  n = qMin(n, value.size());
365  n = qMin(n, valueErrorMinus.size());
366  n = qMin(n, valueErrorPlus.size());
367  QCPData newData;
368  for (int i=0; i<n; ++i)
369  {
370  newData.key = key[i];
371  newData.value = value[i];
372  newData.valueErrorMinus = valueErrorMinus[i];
373  newData.valueErrorPlus = valueErrorPlus[i];
374  mData->insertMulti(key[i], newData);
375  }
376 }
double key
Definition: qcustomplot.h:65
A class holding the data of one single data point for QCPGraph.
Definition: qcustomplot.h:61
QCPDataMap * mData
Definition: qcustomplot.h:278
void QCPGraph::setErrorBarSize ( double  size)
slot

Sets the width of the handles at both ends of an error bar in pixels.

Definition at line 550 of file qcustomplot.cc.

551 {
552  mErrorBarSize = size;
553 }
double mErrorBarSize
Definition: qcustomplot.h:285
void QCPGraph::setErrorBarSkipSymbol ( bool  enabled)
slot

If enabled is set to true, the error bar will not be drawn as a solid line under the scatter symbol but leave some free space around the symbol.

This feature uses the current scatter size (setScatterSize) to determine the size of the area to leave blank. So when drawing Pixmaps as scatter points (SSPixmap), the scatter size must be set manually to a value corresponding to the size of the Pixmap, if the error bars should leave gaps to its boundaries.

Definition at line 564 of file qcustomplot.cc.

565 {
566  mErrorBarSkipSymbol = enabled;
567 }
bool mErrorBarSkipSymbol
Definition: qcustomplot.h:286
void QCPGraph::setErrorPen ( const QPen &  pen)
slot

Sets the pen with which the error bars will be drawn.

See also
setErrorBarSize, setErrorType

Definition at line 542 of file qcustomplot.cc.

543 {
544  mErrorPen = pen;
545 }
QPen mErrorPen
Definition: qcustomplot.h:279
QPen pen() const
Definition: qcustomplot.h:124
void QCPGraph::setErrorType ( ErrorType  errorType)
slot
See also
ErrorType

Definition at line 533 of file qcustomplot.cc.

534 {
536 }
ErrorType mErrorType
Definition: qcustomplot.h:284
ErrorType errorType() const
Definition: qcustomplot.h:233
void QCPGraph::setLineStyle ( int  ls)
slot

Sets how the single data points are connected in the plot or how they are represented visually apart from the scatter symbol. For scatter-only plots, set ls to LSNone and setScatterStyle to the desired scatter style.

See also
setScatterStyle

Definition at line 494 of file qcustomplot.cc.

495 {
496  mLineStyle = (LineStyle)ls;
497 }
LineStyle mLineStyle
Definition: qcustomplot.h:280
void QCPGraph::setScatterPixmap ( const QPixmap &  pixmap)
slot

If the scatter style (setScatterStyle) is set to SSPixmap, this function defines the QPixmap that will be drawn centered on the data point coordinate.

See also
ScatterStyle

Definition at line 525 of file qcustomplot.cc.

526 {
527  mScatterPixmap = pixmap;
528 }
QPixmap mScatterPixmap
Definition: qcustomplot.h:283
void QCPGraph::setScatterSize ( double  size)
slot

This defines how big (in pixels) single scatters are drawn, if scatter style (setScatterStyle) isn't SSNone, SSDot or SSPixmap. Floating point values are allowed for fine grained control over optical appearance with antialiased painting.

See also
ScatterStyle

Definition at line 515 of file qcustomplot.cc.

516 {
517  mScatterSize = size;
518 }
double mScatterSize
Definition: qcustomplot.h:282
void QCPGraph::setScatterStyle ( int  ss)
slot

Sets the visual appearance of single data points in the plot. If set to SSNone, no scatter points are drawn (e.g. for line-only-plots with appropriate line style).

See also
ScatterStyle, setLineStyle

Definition at line 504 of file qcustomplot.cc.

505 {
507 }
ScatterStyle mScatterStyle
Definition: qcustomplot.h:281
QPointF QCPGraph::upperFillBasePoint ( double  upperKey) const
protected

Definition at line 1800 of file qcustomplot.cc.

1801 {
1802  QPointF point;
1804  {
1805  if (mKeyAxis->axisType() == QCPAxis::ATLeft)
1806  {
1807  point.setX(mValueAxis->coordToPixel(0));
1808  point.setY(upperKey);
1809  } else if (mKeyAxis->axisType() == QCPAxis::ATRight)
1810  {
1811  point.setX(mValueAxis->coordToPixel(0));
1812  point.setY(upperKey);
1813  } else if (mKeyAxis->axisType() == QCPAxis::ATTop)
1814  {
1815  point.setX(upperKey);
1816  point.setY(mValueAxis->coordToPixel(0));
1817  } else if (mKeyAxis->axisType() == QCPAxis::ATBottom)
1818  {
1819  point.setX(upperKey);
1820  point.setY(mValueAxis->coordToPixel(0));
1821  }
1822  } else // mValueAxis->mScaleType == QCPAxis::STLogarithmic
1823  {
1824  // In logarithmic scaling we can't just draw to value 0 so we just fill all the way
1825  // to the axis which is in the direction towards 0
1826  if (mKeyAxis->orientation() == Qt::Vertical)
1827  {
1828  if ((mValueAxis->range().upper < 0 && !mValueAxis->rangeReversed()) ||
1829  (mValueAxis->range().upper > 0 && mValueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis
1830  point.setX(mKeyAxis->axisRect().right());
1831  else
1832  point.setX(mKeyAxis->axisRect().left());
1833  point.setY(upperKey);
1835  {
1836  point.setX(upperKey);
1837  if ((mValueAxis->range().upper < 0 && !mValueAxis->rangeReversed()) ||
1838  (mValueAxis->range().upper > 0 && mValueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis
1839  point.setY(mKeyAxis->axisRect().top());
1840  else
1841  point.setY(mKeyAxis->axisRect().bottom());
1842  }
1843  }
1844  return point;
1845 }
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
QRect axisRect() const
Definition: qcustomplot.h:743
const QCPRange range() const
Definition: qcustomplot.h:746
Normal linear scaling.
Definition: qcustomplot.h:731
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
bool rangeReversed() const
Definition: qcustomplot.h:747
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
double coordToPixel(double value) const
double upper
Definition: qcustomplot.h:494
ScaleType scaleType() const
Definition: qcustomplot.h:744
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711
AxisType axisType() const
Definition: qcustomplot.h:742

Friends And Related Function Documentation

friend class QCPLegend
friend

Definition at line 327 of file qcustomplot.h.

friend class QCustomPlot
friend

Definition at line 326 of file qcustomplot.h.

Member Data Documentation

QCPGraph* QCPGraph::mChannelFillGraph
protected

Definition at line 287 of file qcustomplot.h.

QCPDataMap* QCPGraph::mData
protected

Definition at line 278 of file qcustomplot.h.

double QCPGraph::mErrorBarSize
protected

Definition at line 285 of file qcustomplot.h.

bool QCPGraph::mErrorBarSkipSymbol
protected

Definition at line 286 of file qcustomplot.h.

QPen QCPGraph::mErrorPen
protected

Definition at line 279 of file qcustomplot.h.

ErrorType QCPGraph::mErrorType
protected

Definition at line 284 of file qcustomplot.h.

LineStyle QCPGraph::mLineStyle
protected

Definition at line 280 of file qcustomplot.h.

QPixmap QCPGraph::mScatterPixmap
protected

Definition at line 283 of file qcustomplot.h.

double QCPGraph::mScatterSize
protected

Definition at line 282 of file qcustomplot.h.

ScatterStyle QCPGraph::mScatterStyle
protected

Definition at line 281 of file qcustomplot.h.


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