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

The central class which is also the QWidget which displays the plot and interacts with the user. More...

#include <qcustomplot.h>

Inherits QWidget.

Inherited by Plot2d.

Public Slots

QString title () const
 
QFont titleFont () const
 
QRect axisRect () const
 
int marginLeft () const
 
int marginRight () const
 
int marginTop () const
 
int marginBottom () const
 
bool autoMargin () const
 
QColor color () const
 
Qt::Orientations rangeDrag () const
 
Qt::Orientations rangeZoom () const
 
QCPAxisrangeDragAxis (Qt::Orientation orientation)
 
QCPAxisrangeZoomAxis (Qt::Orientation orientation)
 
double rangeZoomFactor (Qt::Orientation orientation)
 
const AntialiasedElements antialiasedElements () const
 
bool autoAddPlottableToLegend () const
 
QPixmap axisBackground () const
 
bool axisBackgroundScaled () const
 
Qt::AspectRatioMode axisBackgroundScaledMode () const
 
void setTitle (const QString &title)
 
void setTitleFont (const QFont &font)
 
void setAxisRect (const QRect &arect)
 
void setMarginLeft (int margin)
 
void setMarginRight (int margin)
 
void setMarginTop (int margin)
 
void setMarginBottom (int margin)
 
void setMargin (int left, int right, int top, int bottom)
 
void setAutoMargin (bool enabled)
 
void setColor (const QColor &color)
 
void setRangeDrag (Qt::Orientations orientations)
 
void setRangeZoom (Qt::Orientations orientations)
 
void setRangeDragAxes (QCPAxis *horizontal, QCPAxis *vertical)
 
void setRangeZoomAxes (QCPAxis *horizontal, QCPAxis *vertical)
 
void setRangeZoomFactor (double horizontalFactor, double verticalFactor)
 
void setRangeZoomFactor (double factor)
 
void setAntialiasedElements (const AntialiasedElements &antialiasedElements)
 
void setAntialiasedElement (AntialiasedElement antialiasedElement, bool enabled)
 
void setAutoAddPlottableToLegend (bool on)
 
void setAxisBackground (const QPixmap &pm)
 
void setAxisBackground (const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding)
 
void setAxisBackgroundScaled (bool scaled)
 
void setAxisBackgroundScaledMode (Qt::AspectRatioMode mode)
 
QCPAbstractPlottableplottable (int index)
 
QCPAbstractPlottableplottable ()
 
bool addPlottable (QCPAbstractPlottable *plottable)
 
bool removePlottable (QCPAbstractPlottable *plottable)
 
bool removePlottable (int index)
 
int clearPlottables ()
 
int plottableCount () const
 
QCPGraphgraph (int index) const
 
QCPGraphgraph () const
 
QCPGraphaddGraph (QCPAxis *keyAxis=0, QCPAxis *valueAxis=0)
 
bool removeGraph (QCPGraph *graph)
 
bool removeGraph (int index)
 
int clearGraphs ()
 
int graphCount () const
 
void replot ()
 
void setupFullAxesBox ()
 
void rescaleAxes ()
 
void savePdf (const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0)
 
void savePng (const QString &fileName, int width=0, int height=0)
 
void savePngScaled (const QString &fileName, double scale, int width=0, int height=0)
 

Signals

void mouseDoubleClick (QMouseEvent *event)
 
void mousePress (QMouseEvent *event)
 
void mousePressOnLegendItem (QMouseEvent *event, QVariant itemIdx)
 
void mousePressOnPlotArea (QMouseEvent *event)
 
void mouseMove (QMouseEvent *event)
 
void mouseRelease (QMouseEvent *event)
 
void mouseWheel (QWheelEvent *event)
 

Public Attributes

QCPAxisxAxis
 
QCPAxisyAxis
 
QCPAxisxAxis2
 
QCPAxisyAxis2
 
QCPLegendlegend
 

Protected Member Functions

virtual void paintEvent (QPaintEvent *event)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mousePressEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
virtual void draw (QPainter *painter)
 
virtual void drawAxisBackground (QPainter *painter)
 
void updateAxisRect ()
 

Protected Attributes

QPixmap buffer
 
QString mTitle
 
QFont mTitleFont
 
QRect mViewport
 
QRect mAxisRect
 
int mMarginLeft
 
int mMarginRight
 
int mMarginTop
 
int mMarginBottom
 
bool mAutoMargin
 
bool mAutoAddPlottableToLegend
 
QColor mColor
 
QList< QCPAbstractPlottable * > mPlottables
 
QList< QCPGraph * > mGraphs
 
Qt::Orientations mRangeDrag
 
Qt::Orientations mRangeZoom
 
QCPAxismRangeDragHorzAxis
 
QCPAxismRangeDragVertAxis
 
QCPAxismRangeZoomHorzAxis
 
QCPAxismRangeZoomVertAxis
 
double mRangeZoomFactorHorz
 
double mRangeZoomFactorVert
 
bool mDragging
 
QPoint mDragStart
 
QCPRange mDragStartHorzRange
 
QCPRange mDragStartVertRange
 
QFlags< AntialiasedElement > mAntialiasedElements
 
QPixmap mAxisBackground
 
QPixmap mScaledAxisBackground
 
bool mAxisBackgroundScaled
 
Qt::AspectRatioMode mAxisBackgroundScaledMode
 

Friends

class QCPLegend
 
class QCPAxis
 

Detailed Description

The central class which is also the QWidget which displays the plot and interacts with the user.

For tutorials on how to use QCustomPlot, see the website
http://www.WorksLikeClockWork.com/index.php/components/qt-plotting-widget

Definition at line 895 of file qcustomplot.h.

Member Function Documentation

◆ addGraph

QCPGraph * QCustomPlot::addGraph ( QCPAxis keyAxis = 0,
QCPAxis valueAxis = 0 
)
slot

Creates a new graph inside the plot. If keyAxis and valueAxis are left unspecified, the bottom (xAxis) is used as key and the left (yAxis) is used as value. keyAxis and valueAxis must reside in the same QCustomPlot.

Parameters
keyAxisthe axis that will be used as key axis for the graph (typically "x")
valueAxisthe axis that will be used as value axis for the graph (typically "y")

Returns a pointer to the newly created graph.

See also
graph, graphCount, removeGraph, clearGraphs

Definition at line 5383 of file qcustomplot.cc.

5384 {
5385  if (!keyAxis) keyAxis = xAxis;
5386  if (!valueAxis) valueAxis = yAxis;
5387  QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis);
5388  if (addPlottable(newGraph))
5389  {
5390  newGraph->setName("Graph "+QString::number(mGraphs.size()));
5391  return newGraph;
5392  } else
5393  {
5394  delete newGraph;
5395  return 0;
5396  }
5397 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
void setName(const QString &name)
A plottable representing a graph in a plot.
Definition: qcustomplot.h:171
bool addPlottable(QCPAbstractPlottable *plottable)
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006

◆ addPlottable

bool QCustomPlot::addPlottable ( QCPAbstractPlottable plottable)
slot

Adds the specified plottable to the plot and, if setAutoAddPlottableToLegend is enabled, to the legend. QCustomPlot takes ownership of the plottable.

Returns true on success, i.e. when plottable wasn't already added to the plot and the parent plot of plottable is this QCustomPlot (the latter is controlled by what axes the plottable was passed in the constructor).

See also
plottable, plottableCount, removePlottable, clearPlottables

Definition at line 5248 of file qcustomplot.cc.

5249 {
5250  if (!mPlottables.contains(plottable) && plottable->parentPlot() == this)
5251  {
5252  mPlottables.append(plottable);
5253  // possibly add plottable to legend:
5255  plottable->addToLegend();
5256  // special handling for QCPGraphs to maintain the simple graph interface:
5257  if (QCPGraph *graph = dynamic_cast<QCPGraph*>(plottable))
5258  mGraphs.append(graph);
5259  return true;
5260  } else
5261  {
5262  qDebug() << FUNCNAME << "plottable either already in list or not created with this QCustomPlot as parent:" << plottable;
5263  return false;
5264  }
5265 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
QCustomPlot * parentPlot() const
Definition: qcustomplot.h:121
A plottable representing a graph in a plot.
Definition: qcustomplot.h:171
QCPAbstractPlottable * plottable()
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
QCPGraph * graph() const
bool mAutoAddPlottableToLegend
Definition: qcustomplot.h:1016
virtual bool addToLegend() const
#define FUNCNAME
Definition: qcustomplot.h:50

◆ antialiasedElements

const AntialiasedElements QCustomPlot::antialiasedElements ( ) const
inlineslot

Definition at line 949 of file qcustomplot.h.

949 { return mAntialiasedElements; }
QFlags< AntialiasedElement > mAntialiasedElements
Definition: qcustomplot.h:1026

◆ autoAddPlottableToLegend

bool QCustomPlot::autoAddPlottableToLegend ( ) const
inlineslot

Definition at line 950 of file qcustomplot.h.

950 { return mAutoAddPlottableToLegend; }
bool mAutoAddPlottableToLegend
Definition: qcustomplot.h:1016

◆ autoMargin

bool QCustomPlot::autoMargin ( ) const
inlineslot

Definition at line 942 of file qcustomplot.h.

942 { return mAutoMargin; }
bool mAutoMargin
Definition: qcustomplot.h:1016

◆ axisBackground

QPixmap QCustomPlot::axisBackground ( ) const
inlineslot

Definition at line 951 of file qcustomplot.h.

951 { return mAxisBackground; }
QPixmap mAxisBackground
Definition: qcustomplot.h:1027

◆ axisBackgroundScaled

bool QCustomPlot::axisBackgroundScaled ( ) const
inlineslot

Definition at line 952 of file qcustomplot.h.

952 { return mAxisBackgroundScaled; }
bool mAxisBackgroundScaled
Definition: qcustomplot.h:1028

◆ axisBackgroundScaledMode

Qt::AspectRatioMode QCustomPlot::axisBackgroundScaledMode ( ) const
inlineslot

Definition at line 953 of file qcustomplot.h.

953 { return mAxisBackgroundScaledMode; }
Qt::AspectRatioMode mAxisBackgroundScaledMode
Definition: qcustomplot.h:1029

◆ axisRect

QRect QCustomPlot::axisRect ( ) const
inlineslot

Definition at line 937 of file qcustomplot.h.

937 { return mAxisRect; }
QRect mAxisRect
Definition: qcustomplot.h:1014

◆ clearGraphs

int QCustomPlot::clearGraphs ( )
slot

Removes all graphs from the plot (and the legend, if necessary). Returns the number of graphs removed.

See also
removeGraph

Definition at line 5430 of file qcustomplot.cc.

5431 {
5432  int c = mGraphs.size();
5433  for (int i=c-1; i >= 0; --i)
5434  removeGraph(mGraphs[i]);
5435  return c;
5436 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
bool removeGraph(QCPGraph *graph)

◆ clearPlottables

int QCustomPlot::clearPlottables ( )
slot

Removes all graphs from the plot (and the legend, if necessary).

Returns the number of graphs removed.

See also
removePlottable

Definition at line 5317 of file qcustomplot.cc.

5318 {
5319  int c = mPlottables.size();
5320  for (int i=c-1; i >= 0; --i)
5322  return c;
5323 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
bool removePlottable(QCPAbstractPlottable *plottable)

◆ color

QColor QCustomPlot::color ( ) const
inlineslot

Definition at line 943 of file qcustomplot.h.

943 { return mColor; }
QColor mColor
Definition: qcustomplot.h:1017

◆ draw()

void QCustomPlot::draw ( QPainter *  painter)
protectedvirtual

Definition at line 5875 of file qcustomplot.cc.

5876 {
5877 
5878  // draw title:
5879  QRect titleBounds;
5880  if (!mTitle.isEmpty())
5881  {
5882  painter->setFont(mTitleFont);
5883  titleBounds = painter->fontMetrics().boundingRect(0, 0, titleBounds.width(), titleBounds.height(), Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, mTitle);
5884  painter->drawText(mViewport.left(), mViewport.top(), mViewport.width(), titleBounds.height(), Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, mTitle);
5885  }
5886 
5887  // prepare values of ticks and tick strings:
5892 
5893  // set auto margin such that tick/axis labels etc. are not clipped:
5894  if (mAutoMargin)
5895  {
5898  xAxis2->calculateMargin()+titleBounds.height(),
5899  xAxis->calculateMargin());
5900  }
5901 
5902  // draw axis background:
5903  drawAxisBackground(painter);
5904 
5905  // draw grids (and zerolines):
5906  xAxis->drawSubGrid(painter);
5907  yAxis->drawSubGrid(painter);
5908  xAxis2->drawSubGrid(painter);
5909  yAxis2->drawSubGrid(painter);
5910  xAxis->drawGrid(painter);
5911  yAxis->drawGrid(painter);
5912  xAxis2->drawGrid(painter);
5913  yAxis2->drawGrid(painter);
5914 
5915  // draw all plottables:
5916  for (int i=0; i < mPlottables.size(); ++i)
5917  {
5918  painter->save(); // since this might be user subclass, we save painter outside - just in case
5919  mPlottables.at(i)->draw(painter);
5920  painter->restore();
5921  }
5922 
5923  // draw axes, ticks and axis labels:
5924  xAxis->drawAxis(painter);
5925  yAxis->drawAxis(painter);
5926  xAxis2->drawAxis(painter);
5927  yAxis2->drawAxis(painter);
5928 
5929  // draw legend:
5930  legend->reArrange();
5931  legend->draw(painter);
5932 }
QFont mTitleFont
Definition: qcustomplot.h:1012
virtual void generateTickVectors()
QString mTitle
Definition: qcustomplot.h:1011
void reArrange()
virtual void draw(QPainter *painter)
virtual int calculateMargin() const
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
virtual void drawSubGrid(QPainter *painter)
QCPAxis * xAxis2
Definition: qcustomplot.h:1006
bool mAutoMargin
Definition: qcustomplot.h:1016
QCPLegend * legend
Definition: qcustomplot.h:1007
virtual void drawGrid(QPainter *painter)
QRect mViewport
Definition: qcustomplot.h:1013
void setMargin(int left, int right, int top, int bottom)
virtual void drawAxisBackground(QPainter *painter)
virtual void drawAxis(QPainter *painter)
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006

◆ drawAxisBackground()

void QCustomPlot::drawAxisBackground ( QPainter *  painter)
protectedvirtual

Definition at line 5946 of file qcustomplot.cc.

5947 {
5948  if (!mAxisBackground.isNull())
5949  {
5951  {
5952  // check whether mScaledAxisBackground needs to be updated:
5953  QSize scaledSize(mAxisBackground.size());
5954  scaledSize.scale(mAxisRect.size(), mAxisBackgroundScaledMode);
5955  if (mScaledAxisBackground.size() != scaledSize)
5956  mScaledAxisBackground = mAxisBackground.scaled(mAxisRect.size(), mAxisBackgroundScaledMode, Qt::SmoothTransformation);
5957  painter->drawPixmap(mAxisRect.topLeft(), mScaledAxisBackground, QRect(0, 0, mAxisRect.width(), mAxisRect.height()) & mScaledAxisBackground.rect());
5958  } else
5959  {
5960  painter->drawPixmap(mAxisRect.topLeft(), mAxisBackground, QRect(0, 0, mAxisRect.width(), mAxisRect.height()));
5961  }
5962  }
5963 }
bool mAxisBackgroundScaled
Definition: qcustomplot.h:1028
QRect mAxisRect
Definition: qcustomplot.h:1014
Qt::AspectRatioMode mAxisBackgroundScaledMode
Definition: qcustomplot.h:1029
QPixmap mAxisBackground
Definition: qcustomplot.h:1027
QPixmap mScaledAxisBackground
Definition: qcustomplot.h:1027

◆ graph [1/2]

QCPGraph * QCustomPlot::graph ( int  index) const
slot

Returns the graph with index. If the index is invalid, returns 0.

There is an overloaded version of this function with no parameter which returns the last created graph, see QCustomPlot::graph()

See also
graphCount, addGraph

Definition at line 5343 of file qcustomplot.cc.

5344 {
5345  if (index >= 0 && index < mGraphs.size())
5346  {
5347  return mGraphs.at(index);
5348  } else
5349  {
5350  qDebug() << FUNCNAME << "index out of bounds:" << index;
5351  return 0;
5352  }
5353 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
#define FUNCNAME
Definition: qcustomplot.h:50

◆ graph [2/2]

QCPGraph * QCustomPlot::graph ( ) const
slot

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

Returns the last graph, that was created with addGraph. If there are no graphs in the plot, returns 0.

See also
graphCount, addGraph

Definition at line 5362 of file qcustomplot.cc.

5363 {
5364  if (!mGraphs.isEmpty())
5365  {
5366  return mGraphs.last();
5367  } else
5368  return 0;
5369 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019

◆ graphCount

int QCustomPlot::graphCount ( ) const
slot

Returns the number of currently existing graphs in the plot

See also
graph, addGraph

Definition at line 5443 of file qcustomplot.cc.

5444 {
5445  return mGraphs.size();
5446 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019

◆ marginBottom

int QCustomPlot::marginBottom ( ) const
inlineslot

Definition at line 941 of file qcustomplot.h.

941 { return mMarginBottom; }

◆ marginLeft

int QCustomPlot::marginLeft ( ) const
inlineslot

Definition at line 938 of file qcustomplot.h.

938 { return mMarginLeft; }

◆ marginRight

int QCustomPlot::marginRight ( ) const
inlineslot

Definition at line 939 of file qcustomplot.h.

939 { return mMarginRight; }

◆ marginTop

int QCustomPlot::marginTop ( ) const
inlineslot

Definition at line 940 of file qcustomplot.h.

940 { return mMarginTop; }

◆ mouseDoubleClick

void QCustomPlot::mouseDoubleClick ( QMouseEvent *  event)
signal

◆ mouseDoubleClickEvent()

void QCustomPlot::mouseDoubleClickEvent ( QMouseEvent *  event)
protectedvirtual

Definition at line 5735 of file qcustomplot.cc.

5736 {
5737  emit mouseDoubleClick(event);
5738 }
void mouseDoubleClick(QMouseEvent *event)

◆ mouseMove

void QCustomPlot::mouseMove ( QMouseEvent *  event)
signal

◆ mouseMoveEvent()

void QCustomPlot::mouseMoveEvent ( QMouseEvent *  event)
protectedvirtual

Reimplemented in Plot2d.

Definition at line 5784 of file qcustomplot.cc.

5785 {
5786  emit mouseMove(event);
5787  if (mDragging)
5788  {
5789  if (mRangeDrag.testFlag(Qt::Horizontal))
5790  {
5792  {
5793  double diff = mRangeDragHorzAxis->pixelToCoord(mDragStart.x()) - mRangeDragHorzAxis->pixelToCoord(event->pos().x());
5796  {
5797  double diff = mRangeDragHorzAxis->pixelToCoord(mDragStart.x()) / mRangeDragHorzAxis->pixelToCoord(event->pos().x());
5799  }
5800  }
5801  if (mRangeDrag.testFlag(Qt::Vertical))
5802  {
5804  {
5805  double diff = mRangeDragVertAxis->pixelToCoord(mDragStart.y()) - mRangeDragVertAxis->pixelToCoord(event->pos().y());
5808  {
5809  double diff = mRangeDragVertAxis->pixelToCoord(mDragStart.y()) / mRangeDragVertAxis->pixelToCoord(event->pos().y());
5811  }
5812  }
5813  if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot
5814  replot();
5815  }
5816 }
double pixelToCoord(double value) const
QPoint mDragStart
Definition: qcustomplot.h:1024
void mouseMove(QMouseEvent *event)
Qt::Orientations mRangeDrag
Definition: qcustomplot.h:1020
void setRange(double lower, double upper)
QCPAxis * mRangeDragHorzAxis
Definition: qcustomplot.h:1021
Normal linear scaling.
Definition: qcustomplot.h:731
QCPRange mDragStartVertRange
Definition: qcustomplot.h:1025
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPAxis * mRangeDragVertAxis
Definition: qcustomplot.h:1021
QCPRange mDragStartHorzRange
Definition: qcustomplot.h:1025
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494

◆ mousePress

void QCustomPlot::mousePress ( QMouseEvent *  event)
signal

◆ mousePressEvent()

void QCustomPlot::mousePressEvent ( QMouseEvent *  event)
protectedvirtual

Definition at line 5750 of file qcustomplot.cc.

5751 {
5752  if (event->buttons() & Qt::LeftButton)
5753  {
5754  mDragging = true;
5755  mDragStart = event->pos();
5758  } else
5759  {
5760  mDragging = false;
5761  }
5762 
5763  // check if mouse press was on a legend item
5764  int itemIdx = legend->getItemIndex(&event->pos());
5765 
5766  if (itemIdx >= 0)
5767  {
5768  emit mousePressOnLegendItem(event, QVariant(itemIdx));
5769  } else
5770  {
5771  emit mousePressOnPlotArea(event);
5772  }
5773 
5774  emit mousePress(event);
5775 }
QPoint mDragStart
Definition: qcustomplot.h:1024
void mousePressOnLegendItem(QMouseEvent *event, QVariant itemIdx)
int getItemIndex(const QPoint *point)
QCPAxis * mRangeDragHorzAxis
Definition: qcustomplot.h:1021
void mousePressOnPlotArea(QMouseEvent *event)
QCPRange mDragStartVertRange
Definition: qcustomplot.h:1025
void mousePress(QMouseEvent *event)
QCPAxis * mRangeDragVertAxis
Definition: qcustomplot.h:1021
QCPLegend * legend
Definition: qcustomplot.h:1007
QCPRange mDragStartHorzRange
Definition: qcustomplot.h:1025
const QCPRange range() const
Definition: qcustomplot.h:746

◆ mousePressOnLegendItem

void QCustomPlot::mousePressOnLegendItem ( QMouseEvent *  event,
QVariant  itemIdx 
)
signal

◆ mousePressOnPlotArea

void QCustomPlot::mousePressOnPlotArea ( QMouseEvent *  event)
signal

◆ mouseRelease

void QCustomPlot::mouseRelease ( QMouseEvent *  event)
signal

◆ mouseReleaseEvent()

void QCustomPlot::mouseReleaseEvent ( QMouseEvent *  event)
protectedvirtual

Definition at line 5826 of file qcustomplot.cc.

5827 {
5828  mDragging = false;
5829  emit mouseRelease(event);
5830 }
void mouseRelease(QMouseEvent *event)

◆ mouseWheel

void QCustomPlot::mouseWheel ( QWheelEvent *  event)
signal

◆ paintEvent()

void QCustomPlot::paintEvent ( QPaintEvent *  event)
protectedvirtual

Definition at line 5708 of file qcustomplot.cc.

5709 {
5710  Q_UNUSED(event);
5711  QPainter painter(this);
5712  painter.drawPixmap(0, 0, buffer);
5713 }
QPixmap buffer
Definition: qcustomplot.h:1010

◆ plottable [1/2]

QCPAbstractPlottable * QCustomPlot::plottable ( int  index)
slot

Returns the plottable with index. If the index is invalid, returns 0.

There is an overloaded version of this function with no parameter which returns the last created plottable, see QCustomPlot::plottable()

See also
plottableCount, addPlottable

Definition at line 5210 of file qcustomplot.cc.

5211 {
5212  if (index >= 0 && index < mPlottables.size())
5213  {
5214  return mPlottables.at(index);
5215  } else
5216  {
5217  qDebug() << FUNCNAME << "index out of bounds:" << index;
5218  return 0;
5219  }
5220 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
#define FUNCNAME
Definition: qcustomplot.h:50

◆ plottable [2/2]

QCPAbstractPlottable * QCustomPlot::plottable ( )
slot

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

Returns the last plottable, that was created with addPlottable. If there are no plottables in the plot, returns 0.

See also
plottableCount, addPlottable

Definition at line 5229 of file qcustomplot.cc.

5230 {
5231  if (!mPlottables.isEmpty())
5232  {
5233  return mPlottables.last();
5234  } else
5235  return 0;
5236 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018

◆ plottableCount

int QCustomPlot::plottableCount ( ) const
slot

Returns the number of currently existing plottables in the plot

See also
plottable, addPlottable

Definition at line 5330 of file qcustomplot.cc.

5331 {
5332  return mPlottables.size();
5333 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018

◆ rangeDrag

Qt::Orientations QCustomPlot::rangeDrag ( ) const
inlineslot

Definition at line 944 of file qcustomplot.h.

944 { return mRangeDrag; }
Qt::Orientations mRangeDrag
Definition: qcustomplot.h:1020

◆ rangeDragAxis

QCPAxis * QCustomPlot::rangeDragAxis ( Qt::Orientation  orientation)
slot

Returns the range drag axis of the orientation provided

See also
setRangeDragAxes

Definition at line 4902 of file qcustomplot.cc.

4903 {
4904  return (orientation == Qt::Horizontal ? mRangeDragHorzAxis : mRangeDragVertAxis);
4905 }
QCPAxis * mRangeDragHorzAxis
Definition: qcustomplot.h:1021
QCPAxis * mRangeDragVertAxis
Definition: qcustomplot.h:1021

◆ rangeZoom

Qt::Orientations QCustomPlot::rangeZoom ( ) const
inlineslot

Definition at line 945 of file qcustomplot.h.

945 { return mRangeZoom; }
Qt::Orientations mRangeZoom
Definition: qcustomplot.h:1020

◆ rangeZoomAxis

QCPAxis * QCustomPlot::rangeZoomAxis ( Qt::Orientation  orientation)
slot

Returns the range zoom axis of the orientation provided

See also
setRangeZoomAxes

Definition at line 4911 of file qcustomplot.cc.

4912 {
4913  return (orientation == Qt::Horizontal ? mRangeZoomHorzAxis : mRangeZoomVertAxis);
4914 }
QCPAxis * mRangeZoomHorzAxis
Definition: qcustomplot.h:1021
QCPAxis * mRangeZoomVertAxis
Definition: qcustomplot.h:1021

◆ rangeZoomFactor

double QCustomPlot::rangeZoomFactor ( Qt::Orientation  orientation)
slot

Returns the range zoom factor of the orientation provided

See also
setRangeZoomFactor

Definition at line 4920 of file qcustomplot.cc.

4921 {
4922  return (orientation == Qt::Horizontal ? mRangeZoomFactorHorz : mRangeZoomFactorVert);
4923 }
double mRangeZoomFactorHorz
Definition: qcustomplot.h:1022
double mRangeZoomFactorVert
Definition: qcustomplot.h:1022

◆ removeGraph [1/2]

bool QCustomPlot::removeGraph ( QCPGraph graph)
slot

Removes the specified graph from the plot and, if necessary, from the legend. If any other graphs in the plot have a channel fill set towards the removed graph, the channel fill property of those graphs is reset to zero (no channel fill).

Returns true on success.

See also
clearGraphs

Definition at line 5408 of file qcustomplot.cc.

5409 {
5410  return removePlottable(graph);
5411 }
bool removePlottable(QCPAbstractPlottable *plottable)

◆ removeGraph [2/2]

bool QCustomPlot::removeGraph ( int  index)
slot

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

Removes the graph by its index.

Definition at line 5417 of file qcustomplot.cc.

5418 {
5419  if (index >= 0 && index < mGraphs.size())
5420  return removeGraph(mGraphs[index]);
5421  else
5422  return false;
5423 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
bool removeGraph(QCPGraph *graph)

◆ removePlottable [1/2]

bool QCustomPlot::removePlottable ( QCPAbstractPlottable plottable)
slot

Removes the specified plottable from the plot and, if necessary, from the legend.

Returns true on success.

See also
addPlottable, clearPlottables

Definition at line 5274 of file qcustomplot.cc.

5275 {
5276  if (mPlottables.contains(plottable))
5277  {
5278  // remove plottable from legend:
5279  plottable->removeFromLegend();
5280  // special handling for QCPGraphs to maintain the simple graph interface:
5281  if (QCPGraph *graph = dynamic_cast<QCPGraph*>(plottable))
5282  mGraphs.removeOne(graph);
5283  // remove plottable:
5284  delete plottable;
5285  mPlottables.removeOne(plottable);
5286  return true;
5287  } else
5288  {
5289  qDebug() << FUNCNAME << "plottable not in list:" << plottable;
5290  return false;
5291  }
5292 }
QList< QCPGraph * > mGraphs
Definition: qcustomplot.h:1019
virtual bool removeFromLegend() const
A plottable representing a graph in a plot.
Definition: qcustomplot.h:171
QCPAbstractPlottable * plottable()
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
QCPGraph * graph() const
#define FUNCNAME
Definition: qcustomplot.h:50

◆ removePlottable [2/2]

bool QCustomPlot::removePlottable ( int  index)
slot

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

Removes the plottable by its index.

Definition at line 5298 of file qcustomplot.cc.

5299 {
5300  if (index >= 0 && index < mPlottables.size())
5301  return removePlottable(mPlottables[index]);
5302  else
5303  {
5304 
5305  qDebug() << FUNCNAME << "index out of bounds:" << index;
5306  return false;
5307  }
5308 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018
#define FUNCNAME
Definition: qcustomplot.h:50
bool removePlottable(QCPAbstractPlottable *plottable)

◆ replot

void QCustomPlot::replot ( )
slot

Causes a complete replot (axes, labels, graphs, etc.) into the internal buffer QPixmap. Finally, update() is called, to redraw the buffer on the QCustomPlot widget surface.

Definition at line 5452 of file qcustomplot.cc.

5453 {
5454  QPainter painter(&buffer);
5455  if (!painter.isActive()) // might happen if QCustomPlot has width or height zero
5456  {
5457  qDebug() << FUNCNAME << "Couldn't activate painter on buffer";
5458  return;
5459  }
5460  painter.fillRect(rect(), mColor);
5461  draw(&painter);
5462  update();
5463 }
QPixmap buffer
Definition: qcustomplot.h:1010
QColor mColor
Definition: qcustomplot.h:1017
#define FUNCNAME
Definition: qcustomplot.h:50
virtual void draw(QPainter *painter)

◆ rescaleAxes

void QCustomPlot::rescaleAxes ( )
slot

Rescales the axes such that all plottables (e.g. graphs) in the plot are fully visible. It does this by calling QCPAbstractPlottable::rescaleAxes on all plottables.

See also
QCPAbstractPlottable::rescaleAxes

Definition at line 5530 of file qcustomplot.cc.

5531 {
5532  if (mPlottables.isEmpty()) return;
5533 
5534  mPlottables.at(0)->rescaleAxes(false); // onlyEnlarge disabled on first plottable
5535  for (int i=1; i<mPlottables.size(); ++i)
5536  mPlottables.at(i)->rescaleAxes(true); // onlyEnlarge enabled on all other plottables
5537 }
QList< QCPAbstractPlottable * > mPlottables
Definition: qcustomplot.h:1018

◆ resizeEvent()

void QCustomPlot::resizeEvent ( QResizeEvent *  event)
protectedvirtual

Definition at line 5722 of file qcustomplot.cc.

5723 {
5724  // resize and repaint the buffer:
5725  buffer = QPixmap(event->size());
5726  mViewport = rect();
5727  updateAxisRect();
5728  replot();
5729 }
QPixmap buffer
Definition: qcustomplot.h:1010
void updateAxisRect()
QRect mViewport
Definition: qcustomplot.h:1013

◆ savePdf

void QCustomPlot::savePdf ( const QString &  fileName,
bool  noCosmeticPen = false,
int  width = 0,
int  height = 0 
)
slot

Saves a PDF with the vectorized plot to the file fileName. The axis ratio as well as the scale of texts and lines will be derived from the specified width and height. This means, the output will look like the normal on-screen output of a QCustomPlot widget with the corresponding pixel width and height. If either width or height is zero, the exported image will have the same dimensions as the QCustomPlot widget currently has.

noCosmeticPen disables the use of cosmetic pens when drawing to the PDF file. Cosmetic pens are pens with numerical width 0, which are always drawn as a one pixel wide line, no matter what zoom factor is set in the PDF-Viewer. For more information about cosmetic pens, see QPainter and QPen documentation.

Warning
  • If you plan on editing the exported PDF file with a vector graphics editor like Inkscape, it is advised to set noCosmeticPen to true to avoid losing those cosmetic lines (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks).
  • If calling this function inside the constructor of the parent of the QCustomPlot widget (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide explicit non-zero widths and heights. If you leave width or height as 0 (default), this function uses the current width and height of the QCustomPlot widget. However, in Qt, these aren't defined yet inside the constructor, so you would get an image that has strange widths/heights.
See also
savePng

Definition at line 5564 of file qcustomplot.cc.

5565 {
5566  int newWidth, newHeight;
5567  if (width == 0 || height == 0)
5568  {
5569  newWidth = this->width();
5570  newHeight = this->height();
5571  } else
5572  {
5573  newWidth = width;
5574  newHeight = height;
5575  }
5576 
5577  QPrinter printer(QPrinter::ScreenResolution);
5578  printer.setOutputFileName(fileName);
5579  printer.setFullPage(true);
5580  QRect oldViewport = mViewport;
5581  mViewport = QRect(0, 0, newWidth, newHeight);
5582  updateAxisRect();
5583  printer.setPaperSize(mViewport.size(), QPrinter::DevicePixel);
5584  QPainter printpainter(&printer);
5585  printpainter.setWindow(mViewport);
5586  printpainter.setRenderHint(QPainter::NonCosmeticDefaultPen, noCosmeticPen);
5587  draw(&printpainter);
5588  mViewport = oldViewport;
5589  updateAxisRect();
5590 }
void updateAxisRect()
QRect mViewport
Definition: qcustomplot.h:1013
virtual void draw(QPainter *painter)

◆ savePng

void QCustomPlot::savePng ( const QString &  fileName,
int  width = 0,
int  height = 0 
)
slot

Saves a PNG image file to fileName on disc. The output plot will have the dimensions width and height in pixels. If either width or height is zero, the exported image will have the same dimensions as the QCustomPlot widget currently has. Line widths and texts etc. are not scaled up when larger widths/heights are used. If you want that effect, consider the scaled version of this function.

Warning
If calling this function inside the constructor of the parent of the QCustomPlot widget (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide explicit non-zero widths and heights. If you leave width or height as 0 (default), this function uses the current width and height of the QCustomPlot widget. However, in Qt, these aren't defined yet inside the constructor, so you would get an image that has strange widths/heights.
See also
savePngScaled

Definition at line 5625 of file qcustomplot.cc.

5626 {
5627  int newWidth, newHeight;
5628  if (width == 0 || height == 0)
5629  {
5630  newWidth = this->width();
5631  newHeight = this->height();
5632  } else
5633  {
5634  newWidth = width;
5635  newHeight = height;
5636  }
5637 
5638  QPixmap pngBuffer(newWidth, newHeight);
5639  QPainter painter(&pngBuffer);
5640  painter.fillRect(pngBuffer.rect(), mColor);
5641  QRect oldViewport = mViewport;
5642  mViewport = QRect(0, 0, newWidth, newHeight);
5643  updateAxisRect();
5644  draw(&painter);
5645  mViewport = oldViewport;
5646  updateAxisRect();
5647  pngBuffer.save(fileName);
5648 }
void updateAxisRect()
QRect mViewport
Definition: qcustomplot.h:1013
QColor mColor
Definition: qcustomplot.h:1017
virtual void draw(QPainter *painter)

◆ savePngScaled

void QCustomPlot::savePngScaled ( const QString &  fileName,
double  scale,
int  width = 0,
int  height = 0 
)
slot

Saves a PNG image file to fileName on disc. The output plot will have a base width and height which is then scaled by factor scale. If you for example set both width and height to 100 and scale to 2, you will end up with a PNG file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, texts, etc.). This scaling is done not by stretching a 100*100 image but by actually scaling the painter, so the result will have full 200*200 pixel resolution.

Warning
  • If calling this function inside the constructor of the parent of the QCustomPlot widget (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide explicit non-zero widths and heights. If you leave width or height as 0 (default), this function uses the current width and height of the QCustomPlot widget. However, in Qt, these aren't defined yet inside the constructor, so you would get an image that has strange widths/heights.
  • When using the raster graphicssystem: There currently is a bug in the Qt painting system that prevents proper scaling of pen widths when using the raster graphicssystem. So if you use this function and need properly scaled pens widths, consider using a different graphicssystem than raster (or apply a non-zero pen width to all pens, since the bug only occurs for cosmetic pens).
See also
savePng

Definition at line 5672 of file qcustomplot.cc.

5673 {
5674  int newWidth, newHeight;
5675  if (width == 0 || height == 0)
5676  {
5677  newWidth = this->width();
5678  newHeight = this->height();
5679  } else
5680  {
5681  newWidth = width;
5682  newHeight = height;
5683  }
5684 
5685  int scaledWidth = scale*newWidth;
5686  int scaledHeight = scale*newHeight;
5687 
5688  QPixmap pngBuffer(scaledWidth, scaledHeight);
5689  QPainter painter(&pngBuffer);
5690  painter.setRenderHint(QPainter::NonCosmeticDefaultPen);
5691  painter.fillRect(pngBuffer.rect(), mColor);
5692  QRect oldViewport = mViewport;
5693  mViewport = QRect(0, 0, newWidth, newHeight);
5694  updateAxisRect();
5695  painter.scale(scale, scale);
5696  draw(&painter);
5697  mViewport = oldViewport;
5698  updateAxisRect();
5699  pngBuffer.save(fileName);
5700 }
void updateAxisRect()
QRect mViewport
Definition: qcustomplot.h:1013
QColor mColor
Definition: qcustomplot.h:1017
virtual void draw(QPainter *painter)

◆ setAntialiasedElement

void QCustomPlot::setAntialiasedElement ( AntialiasedElement  antialiasedElement,
bool  enabled 
)
slot

Sets whether the specified antialiasedElement is drawn antialiased.

Definition at line 5130 of file qcustomplot.cc.

5131 {
5132  if (!enabled && mAntialiasedElements.testFlag(antialiasedElement))
5133  mAntialiasedElements &= ~antialiasedElement;
5134  else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement))
5135  mAntialiasedElements |= antialiasedElement;
5136 }
QFlags< AntialiasedElement > mAntialiasedElements
Definition: qcustomplot.h:1026

◆ setAntialiasedElements

void QCustomPlot::setAntialiasedElements ( const AntialiasedElements &  antialiasedElements)
slot

Sets which elements are drawn antialiased as an or combination of AntialiasedElement.

Definition at line 5122 of file qcustomplot.cc.

5123 {
5125 }
QFlags< AntialiasedElement > mAntialiasedElements
Definition: qcustomplot.h:1026
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949

◆ setAutoAddPlottableToLegend

void QCustomPlot::setAutoAddPlottableToLegend ( bool  on)
slot

If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the newly created plottable to the legend.

See also
addPlottable, addGraph, QCPLegend::addItem

Definition at line 5144 of file qcustomplot.cc.

5145 {
5147 }
bool mAutoAddPlottableToLegend
Definition: qcustomplot.h:1016

◆ setAutoMargin

void QCustomPlot::setAutoMargin ( bool  enabled)
slot

Sets whether the margins are calculated automatically depeding on the sizes of the tick labels, axis labels, paddings etc. If disabled, the margins must be set manually with the setMargin functions.

See also
setMargin, QCPAxis::setLabelPadding, QCPAxis::setTickLabelPadding

Definition at line 5026 of file qcustomplot.cc.

5027 {
5028  mAutoMargin = enabled;
5029 }
bool mAutoMargin
Definition: qcustomplot.h:1016

◆ setAxisBackground [1/2]

void QCustomPlot::setAxisBackground ( const QPixmap &  pm)
slot

Sets pm as the axis background pixmap. The axis background pixmap will be drawn inside the current axis rect, before anything else (e.g. the axes themselves, grids, graphs, etc.) is drawn. If the provided pixmap doesn't have the same size as the axis rect, scaling can be enabled with setAxisBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio is preserved) can be set with setAxisBackgroundScaledMode. To set all these options in one call, consider using the overloaded version of this function.

See also
setAxisBackgroundScaled, setAxisBackgroundScaledMode

Definition at line 5157 of file qcustomplot.cc.

5158 {
5159  mAxisBackground = pm;
5160  mScaledAxisBackground = QPixmap();
5161 }
QPixmap mAxisBackground
Definition: qcustomplot.h:1027
QPixmap mScaledAxisBackground
Definition: qcustomplot.h:1027

◆ setAxisBackground [2/2]

void QCustomPlot::setAxisBackground ( const QPixmap &  pm,
bool  scaled,
Qt::AspectRatioMode  mode = Qt::KeepAspectRatioByExpanding 
)
slot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Allows setting the background pixmap, whether it shall be scaled and how it shall be scaled in one call.

See also
setAxisBackground(const QPixmap &pm), setAxisBackgroundScaled, setAxisBackgroundScaledMode

Definition at line 5168 of file qcustomplot.cc.

5169 {
5170  mAxisBackground = pm;
5171  mScaledAxisBackground = QPixmap();
5172  mAxisBackgroundScaled = scaled;
5174 }
bool mAxisBackgroundScaled
Definition: qcustomplot.h:1028
Qt::AspectRatioMode mAxisBackgroundScaledMode
Definition: qcustomplot.h:1029
QPixmap mAxisBackground
Definition: qcustomplot.h:1027
QPixmap mScaledAxisBackground
Definition: qcustomplot.h:1027

◆ setAxisBackgroundScaled

void QCustomPlot::setAxisBackgroundScaled ( bool  scaled)
slot

Sets whether the axis background pixmap shall be scaled to fit the current axis rect or not. If scaled is set to true, you may control whether and how the aspect ratio of the original pixmap is preserved with setAxisBackgroundScaledMode.

Note that the scaled version of the original pixmap is buffered, so there is no performance penalty on replots, when enabling the scaling. (Except of course, the axis rect is continuously changed, but that's not very likely.)

See also
setAxisBackground, setAxisBackgroundScaledMode

Definition at line 5187 of file qcustomplot.cc.

5188 {
5189  mAxisBackgroundScaled = scaled;
5190 }
bool mAxisBackgroundScaled
Definition: qcustomplot.h:1028

◆ setAxisBackgroundScaledMode

void QCustomPlot::setAxisBackgroundScaledMode ( Qt::AspectRatioMode  mode)
slot

If scaling of the axis background pixmap is enabled (setAxisBackgroundScaled), use this function to define whether and how the aspect ratio of the original pixmap passed to setAxisBackground is preserved.

See also
setAxisBackground, setAxisBackgroundScaled

Definition at line 5197 of file qcustomplot.cc.

5198 {
5200 }
Qt::AspectRatioMode mAxisBackgroundScaledMode
Definition: qcustomplot.h:1029

◆ setAxisRect

void QCustomPlot::setAxisRect ( const QRect &  arect)
slot

An alternative way to set the margins, by directly setting the wanted axis rect. The rect will be translated into appropriate margin values.

Warning
setting the axis rect with this function does not guarantee that the axis rect will stay like this indefinitely. In QCustomPlot, margins are the fixed values (if setAutoMargin is false). Consequently, the axis rect is automatically changed when the widget size changes, but the margins (distances between axis rect edges and widget/viewport rect edges) stay the same.
See also
setMargin

Definition at line 4955 of file qcustomplot.cc.

4956 {
4957  mMarginLeft = arect.left()-mViewport.left();
4958  mMarginRight = mViewport.right()-arect.right();
4959  mMarginTop = arect.top()-mViewport.top();
4960  mMarginBottom = mViewport.bottom()-arect.bottom();
4961  updateAxisRect();
4962 }
void updateAxisRect()
QRect mViewport
Definition: qcustomplot.h:1013

◆ setColor

void QCustomPlot::setColor ( const QColor &  color)
slot

Sets the background color of the QCustomPlot widget.

Definition at line 5034 of file qcustomplot.cc.

5035 {
5036  mColor = color;
5037 }
QColor color() const
Definition: qcustomplot.h:943
QColor mColor
Definition: qcustomplot.h:1017

◆ setMargin

void QCustomPlot::setMargin ( int  left,
int  right,
int  top,
int  bottom 
)
slot

Sets the margins manually. Will only have effect, if setAutoMargin is set to false. The margins are the distances in pixels between the axes box and the viewport box. The viewport box normally is the entire QCustomPlot widget or the entire image, if using one of the export functions. Positive margin values always mean the axes box is shrinked, going inward from the sides of the viewport box.

Definition at line 5011 of file qcustomplot.cc.

5012 {
5013  mMarginLeft = left;
5014  mMarginRight = right;
5015  mMarginTop = top;
5016  mMarginBottom = bottom;
5017  updateAxisRect();
5018 }
void updateAxisRect()

◆ setMarginBottom

void QCustomPlot::setMarginBottom ( int  margin)
slot

Sets the bottom margin manually. Will only have effect, if setAutoMargin is set to false. see setMargin for an explanation of what margins mean in QCustomPlot.

Definition at line 4998 of file qcustomplot.cc.

4999 {
5000  mMarginBottom = margin;
5001  updateAxisRect();
5002 }
void updateAxisRect()

◆ setMarginLeft

void QCustomPlot::setMarginLeft ( int  margin)
slot

Sets the left margin manually. Will only have effect, if setAutoMargin is set to false. see setMargin for an explanation of what margins mean in QCustomPlot.

Definition at line 4968 of file qcustomplot.cc.

4969 {
4970  mMarginLeft = margin;
4971  updateAxisRect();
4972 }
void updateAxisRect()

◆ setMarginRight

void QCustomPlot::setMarginRight ( int  margin)
slot

Sets the right margin manually. Will only have effect, if setAutoMargin is set to false. see setMargin for an explanation of what margins mean in QCustomPlot.

Definition at line 4978 of file qcustomplot.cc.

4979 {
4980  mMarginRight = margin;
4981  updateAxisRect();
4982 }
void updateAxisRect()

◆ setMarginTop

void QCustomPlot::setMarginTop ( int  margin)
slot

Sets the top margin manually. Will only have effect, if setAutoMargin is set to false. see setMargin for an explanation of what margins mean in QCustomPlot.

Definition at line 4988 of file qcustomplot.cc.

4989 {
4990  mMarginTop = margin;
4991  updateAxisRect();
4992 }
void updateAxisRect()

◆ setRangeDrag

void QCustomPlot::setRangeDrag ( Qt::Orientations  orientations)
slot

Sets which axis orientation may be range dragged by the user with mouse interaction. What orientation corresponds to which specific axis can be set with setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical axis is the left axis (yAxis). To disable range dragging entirely, pass 0 as orientations. To enable range dragging for both directions, pass Qt::Horizontal | Qt::Vertical as orientations.

Definition at line 5048 of file qcustomplot.cc.

5049 {
5050  mRangeDrag = orientations;
5051 }
Qt::Orientations mRangeDrag
Definition: qcustomplot.h:1020

◆ setRangeDragAxes

void QCustomPlot::setRangeDragAxes ( QCPAxis horizontal,
QCPAxis vertical 
)
slot

Sets the axes whose range will be dragged when setRangeDrag enables mouse range dragging on the QCustomPlot widget.

Definition at line 5071 of file qcustomplot.cc.

5072 {
5073  if (horizontal)
5074  mRangeDragHorzAxis = horizontal;
5075  if (vertical)
5076  mRangeDragVertAxis = vertical;
5077 }
QCPAxis * mRangeDragHorzAxis
Definition: qcustomplot.h:1021
QCPAxis * mRangeDragVertAxis
Definition: qcustomplot.h:1021

◆ setRangeZoom

void QCustomPlot::setRangeZoom ( Qt::Orientations  orientations)
slot

Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation corresponds to which specific axis can be set with setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical axis is the left axis (yAxis). To disable range zooming entirely, pass 0 as orientations. To enable range zooming for both directions, pass Qt::Horizontal | Qt::Vertical as orientations.

Definition at line 5062 of file qcustomplot.cc.

5063 {
5064  mRangeZoom = orientations;
5065 }
Qt::Orientations mRangeZoom
Definition: qcustomplot.h:1020

◆ setRangeZoomAxes

void QCustomPlot::setRangeZoomAxes ( QCPAxis horizontal,
QCPAxis vertical 
)
slot

Sets the axes whose range will be zoomed when setRangeZoom enables mouse wheel zooming on the QCustomPlot widget. The two axes can be zoomed with different strengths, when different factors are passed to setRangeZoomFactor(double horizontalFactor, double verticalFactor).

Definition at line 5084 of file qcustomplot.cc.

5085 {
5086  if (horizontal)
5087  mRangeZoomHorzAxis = horizontal;
5088  if (vertical)
5089  mRangeZoomVertAxis = vertical;
5090 }
QCPAxis * mRangeZoomHorzAxis
Definition: qcustomplot.h:1021
QCPAxis * mRangeZoomVertAxis
Definition: qcustomplot.h:1021

◆ setRangeZoomFactor [1/2]

void QCustomPlot::setRangeZoomFactor ( double  horizontalFactor,
double  verticalFactor 
)
slot

Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with setRangeZoom. The two parameters horizontalFactor and verticalFactor provide a way to let the horizontal axis zoom at different rates as the vertical axis. Which axis is horizontal and which is vertical, can be set with setRangeZoomAxes. When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) will zoom in. For zoom factors smaller than one, scrolling the mouse wheel forwards zooms in.

Definition at line 5100 of file qcustomplot.cc.

5101 {
5102  mRangeZoomFactorHorz = horizontalFactor;
5103  mRangeZoomFactorVert = verticalFactor;
5104 }
double mRangeZoomFactorHorz
Definition: qcustomplot.h:1022
double mRangeZoomFactorVert
Definition: qcustomplot.h:1022

◆ setRangeZoomFactor [2/2]

void QCustomPlot::setRangeZoomFactor ( double  factor)
slot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with setRangeZoom. The zoom factor is applied to both horizontal and vertical range zooming. When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) will zoom in. For zoom factors smaller than one, scrolling the mouse wheel forwards zooms in.

Definition at line 5113 of file qcustomplot.cc.

5114 {
5115  mRangeZoomFactorHorz = factor;
5116  mRangeZoomFactorVert = factor;
5117 }
double mRangeZoomFactorHorz
Definition: qcustomplot.h:1022
double mRangeZoomFactorVert
Definition: qcustomplot.h:1022

◆ setTitle

void QCustomPlot::setTitle ( const QString &  title)
slot

Sets the plot title which will be drawn centered at the top of the widget. The title position is not dependant on the actual position of the axes. However, if setAutoMargin is set to true, the top margin will be adjusted appropriately, so the top axis labels/tick labels will not overlap with the title.

Definition at line 4931 of file qcustomplot.cc.

4932 {
4933  mTitle = title;
4934 }
QString mTitle
Definition: qcustomplot.h:1011
QString title() const
Definition: qcustomplot.h:935

◆ setTitleFont

void QCustomPlot::setTitleFont ( const QFont &  font)
slot

Sets the font of the plot title

See also
setTitle

Definition at line 4940 of file qcustomplot.cc.

4941 {
4942  mTitleFont = font;
4943 }
QFont mTitleFont
Definition: qcustomplot.h:1012

◆ setupFullAxesBox

void QCustomPlot::setupFullAxesBox ( )
slot

Convenience function to make the top and right axes visible and assign them the following properties from their corresponding bottom/left axes:

Tick labels (QCPAxis::setTickLabels) however, is always set to false.

This function does not connect the rangeChanged signals of the bottom and left axes to the QCPAxis::setRange slots of the top and right axes in order to synchronize the ranges permanently.

Definition at line 5485 of file qcustomplot.cc.

5486 {
5487  xAxis2->setVisible(true);
5488  yAxis2->setVisible(true);
5489 
5490  xAxis2->setTickLabels(false);
5491  yAxis2->setTickLabels(false);
5492 
5495 
5498 
5501 
5504 
5507 
5508  xAxis2->setTicks(xAxis->ticks());
5509  yAxis2->setTicks(yAxis->ticks());
5510 
5513 
5516 
5517  xAxis2->setRange(xAxis->range());
5518  yAxis2->setRange(yAxis->range());
5519 
5522 }
bool autoSubTicks() const
Definition: qcustomplot.h:755
double tickStep() const
Definition: qcustomplot.h:765
bool ticks() const
Definition: qcustomplot.h:756
void setRangeReversed(bool reversed)
double scaleLogBase() const
Definition: qcustomplot.h:745
void setTickLabels(bool show)
void setVisible(bool on)
void setRange(double lower, double upper)
void setAutoTickStep(bool on)
void setSubTickCount(int count)
void setAutoSubTicks(bool on)
void setScaleLogBase(double base)
void setAutoTickCount(int approximateCount)
bool rangeReversed() const
Definition: qcustomplot.h:747
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
QCPAxis * xAxis2
Definition: qcustomplot.h:1006
void setScaleType(ScaleType type)
int subTickCount() const
Definition: qcustomplot.h:770
void setTickStep(double step)
ScaleType scaleType() const
Definition: qcustomplot.h:744
void setTicks(bool show)
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006
bool autoTickStep() const
Definition: qcustomplot.h:754
const QCPRange range() const
Definition: qcustomplot.h:746
int autoTickCount() const
Definition: qcustomplot.h:752

◆ title

QString QCustomPlot::title ( ) const
inlineslot

Definition at line 935 of file qcustomplot.h.

935 { return mTitle; }
QString mTitle
Definition: qcustomplot.h:1011

◆ titleFont

QFont QCustomPlot::titleFont ( ) const
inlineslot

Definition at line 936 of file qcustomplot.h.

936 { return mTitleFont; }
QFont mTitleFont
Definition: qcustomplot.h:1012

◆ updateAxisRect()

void QCustomPlot::updateAxisRect ( )
protected

Definition at line 5972 of file qcustomplot.cc.

5973 {
5979 }
void setAxisRect(const QRect &rect)
QRect mAxisRect
Definition: qcustomplot.h:1014
QCPAxis * yAxis2
Definition: qcustomplot.h:1006
QCPAxis * xAxis2
Definition: qcustomplot.h:1006
QRect mViewport
Definition: qcustomplot.h:1013
QCPAxis * xAxis
Definition: qcustomplot.h:1006
QCPAxis * yAxis
Definition: qcustomplot.h:1006

◆ wheelEvent()

void QCustomPlot::wheelEvent ( QWheelEvent *  event)
protectedvirtual

Definition at line 5848 of file qcustomplot.cc.

5849 {
5850  emit mouseWheel(event);
5851  if (mRangeZoom != 0)
5852  {
5853  double factor;
5854  double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
5855  if (mRangeZoom.testFlag(Qt::Horizontal))
5856  {
5857  factor = pow(mRangeZoomFactorHorz, wheelSteps);
5858  mRangeZoomHorzAxis->scaleRange(factor, mRangeZoomHorzAxis->pixelToCoord(event->pos().x()));
5859  }
5860  if (mRangeZoom.testFlag(Qt::Vertical))
5861  {
5862  factor = pow(mRangeZoomFactorVert, wheelSteps);
5863  mRangeZoomVertAxis->scaleRange(factor, mRangeZoomVertAxis->pixelToCoord(event->pos().y()));
5864  }
5865  replot();
5866  }
5867 }
double pixelToCoord(double value) const
QCPAxis * mRangeZoomHorzAxis
Definition: qcustomplot.h:1021
double mRangeZoomFactorHorz
Definition: qcustomplot.h:1022
void scaleRange(double factor, double center)
Qt::Orientations mRangeZoom
Definition: qcustomplot.h:1020
void mouseWheel(QWheelEvent *event)
double mRangeZoomFactorVert
Definition: qcustomplot.h:1022
QCPAxis * mRangeZoomVertAxis
Definition: qcustomplot.h:1021

Friends And Related Function Documentation

◆ QCPAxis

friend class QCPAxis
friend

Definition at line 1059 of file qcustomplot.h.

◆ QCPLegend

friend class QCPLegend
friend

Definition at line 1058 of file qcustomplot.h.

Member Data Documentation

◆ buffer

QPixmap QCustomPlot::buffer
protected

Definition at line 1010 of file qcustomplot.h.

◆ legend

QCPLegend* QCustomPlot::legend

Definition at line 1007 of file qcustomplot.h.

◆ mAntialiasedElements

QFlags<AntialiasedElement> QCustomPlot::mAntialiasedElements
protected

Definition at line 1026 of file qcustomplot.h.

◆ mAutoAddPlottableToLegend

bool QCustomPlot::mAutoAddPlottableToLegend
protected

Definition at line 1016 of file qcustomplot.h.

◆ mAutoMargin

bool QCustomPlot::mAutoMargin
protected

Definition at line 1016 of file qcustomplot.h.

◆ mAxisBackground

QPixmap QCustomPlot::mAxisBackground
protected

Definition at line 1027 of file qcustomplot.h.

◆ mAxisBackgroundScaled

bool QCustomPlot::mAxisBackgroundScaled
protected

Definition at line 1028 of file qcustomplot.h.

◆ mAxisBackgroundScaledMode

Qt::AspectRatioMode QCustomPlot::mAxisBackgroundScaledMode
protected

Definition at line 1029 of file qcustomplot.h.

◆ mAxisRect

QRect QCustomPlot::mAxisRect
protected

Definition at line 1014 of file qcustomplot.h.

◆ mColor

QColor QCustomPlot::mColor
protected

Definition at line 1017 of file qcustomplot.h.

◆ mDragging

bool QCustomPlot::mDragging
protected

Definition at line 1023 of file qcustomplot.h.

◆ mDragStart

QPoint QCustomPlot::mDragStart
protected

Definition at line 1024 of file qcustomplot.h.

◆ mDragStartHorzRange

QCPRange QCustomPlot::mDragStartHorzRange
protected

Definition at line 1025 of file qcustomplot.h.

◆ mDragStartVertRange

QCPRange QCustomPlot::mDragStartVertRange
protected

Definition at line 1025 of file qcustomplot.h.

◆ mGraphs

QList<QCPGraph*> QCustomPlot::mGraphs
protected

Definition at line 1019 of file qcustomplot.h.

◆ mMarginBottom

int QCustomPlot::mMarginBottom
protected

Definition at line 1015 of file qcustomplot.h.

◆ mMarginLeft

int QCustomPlot::mMarginLeft
protected

Definition at line 1015 of file qcustomplot.h.

◆ mMarginRight

int QCustomPlot::mMarginRight
protected

Definition at line 1015 of file qcustomplot.h.

◆ mMarginTop

int QCustomPlot::mMarginTop
protected

Definition at line 1015 of file qcustomplot.h.

◆ mPlottables

QList<QCPAbstractPlottable*> QCustomPlot::mPlottables
protected

Definition at line 1018 of file qcustomplot.h.

◆ mRangeDrag

Qt::Orientations QCustomPlot::mRangeDrag
protected

Definition at line 1020 of file qcustomplot.h.

◆ mRangeDragHorzAxis

QCPAxis* QCustomPlot::mRangeDragHorzAxis
protected

Definition at line 1021 of file qcustomplot.h.

◆ mRangeDragVertAxis

QCPAxis * QCustomPlot::mRangeDragVertAxis
protected

Definition at line 1021 of file qcustomplot.h.

◆ mRangeZoom

Qt::Orientations QCustomPlot::mRangeZoom
protected

Definition at line 1020 of file qcustomplot.h.

◆ mRangeZoomFactorHorz

double QCustomPlot::mRangeZoomFactorHorz
protected

Definition at line 1022 of file qcustomplot.h.

◆ mRangeZoomFactorVert

double QCustomPlot::mRangeZoomFactorVert
protected

Definition at line 1022 of file qcustomplot.h.

◆ mRangeZoomHorzAxis

QCPAxis * QCustomPlot::mRangeZoomHorzAxis
protected

Definition at line 1021 of file qcustomplot.h.

◆ mRangeZoomVertAxis

QCPAxis * QCustomPlot::mRangeZoomVertAxis
protected

Definition at line 1021 of file qcustomplot.h.

◆ mScaledAxisBackground

QPixmap QCustomPlot::mScaledAxisBackground
protected

Definition at line 1027 of file qcustomplot.h.

◆ mTitle

QString QCustomPlot::mTitle
protected

Definition at line 1011 of file qcustomplot.h.

◆ mTitleFont

QFont QCustomPlot::mTitleFont
protected

Definition at line 1012 of file qcustomplot.h.

◆ mViewport

QRect QCustomPlot::mViewport
protected

Definition at line 1013 of file qcustomplot.h.

◆ xAxis

QCPAxis* QCustomPlot::xAxis

Definition at line 1006 of file qcustomplot.h.

◆ xAxis2

QCPAxis * QCustomPlot::xAxis2

Definition at line 1006 of file qcustomplot.h.

◆ yAxis

QCPAxis * QCustomPlot::yAxis

Definition at line 1006 of file qcustomplot.h.

◆ yAxis2

QCPAxis * QCustomPlot::yAxis2

Definition at line 1006 of file qcustomplot.h.


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