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

Manages a single axis inside a QCustomPlot. More...

#include <qcustomplot.h>

Inherits QObject.

Public Types

enum  AxisType { ATLeft, ATRight, ATTop, ATBottom }
 
enum  LabelType { LTNumber, LTDateTime }
 
enum  ScaleType { STLinear, STLogarithmic }
 

Public Slots

QCustomPlotparentPlot () const
 
AxisType axisType () const
 
QRect axisRect () const
 
ScaleType scaleType () const
 
double scaleLogBase () const
 
const QCPRange range () const
 
bool rangeReversed () const
 
bool visible () const
 
bool grid () const
 
bool subGrid () const
 
bool autoTicks () const
 
int autoTickCount () const
 
bool autoTickLabels () const
 
bool autoTickStep () const
 
bool autoSubTicks () const
 
bool ticks () const
 
bool tickLabels () const
 
int tickLabelPadding () const
 
LabelType tickLabelType () const
 
QFont tickLabelFont () const
 
double tickLabelRotation () const
 
QString dateTimeFormat () const
 
QString numberFormat () const
 
int numberPrecision () const
 
double tickStep () const
 
QVector< double > * tickVector () const
 
QVector< QString > * tickVectorLabels () const
 
int tickLengthIn () const
 
int tickLengthOut () const
 
int subTickCount () const
 
int subTickLengthIn () const
 
int subTickLengthOut () const
 
QPen basePen () const
 
QPen gridPen () const
 
QPen subGridPen () const
 
QPen zeroLinePen () const
 
QPen tickPen () const
 
QPen subTickPen () const
 
QFont labelFont () const
 
QString label () const
 
int labelPadding () const
 
int padding () const
 
void setScaleType (ScaleType type)
 
void setScaleLogBase (double base)
 
void setRange (double lower, double upper)
 
void setRange (double position, double size, Qt::AlignmentFlag alignment)
 
void setRangeLower (double lower)
 
void setRangeUpper (double upper)
 
void setRangeReversed (bool reversed)
 
void setVisible (bool on)
 
void setGrid (bool show)
 
void setSubGrid (bool show)
 
void setAutoTicks (bool on)
 
void setAutoTickCount (int approximateCount)
 
void setAutoTickLabels (bool on)
 
void setAutoTickStep (bool on)
 
void setAutoSubTicks (bool on)
 
void setTicks (bool show)
 
void setTickLabels (bool show)
 
void setTickLabelPadding (int padding)
 
void setTickLabelType (LabelType type)
 
void setTickLabelFont (const QFont &font)
 
void setTickLabelRotation (double degrees)
 
void setDateTimeFormat (const QString &format)
 
void setNumberFormat (const QString &formatCode)
 
void setNumberPrecision (int precision)
 
void setTickStep (double step)
 
void setTickVector (QVector< double > *vec, bool copy=false)
 
void setTickVectorLabels (QVector< QString > *vec, bool copy=false)
 
void setTickLength (int inside, int outside=0)
 
void setSubTickCount (int count)
 
void setSubTickLength (int inside, int outside=0)
 
void setBasePen (const QPen &pen)
 
void setGridPen (const QPen &pen)
 
void setSubGridPen (const QPen &pen)
 
void setZeroLinePen (const QPen &pen)
 
void setTickPen (const QPen &pen)
 
void setSubTickPen (const QPen &pen)
 
void setLabelFont (const QFont &font)
 
void setLabel (const QString &str)
 
void setLabelPadding (int padding)
 
void setPadding (int padding)
 
Qt::Orientation orientation () const
 
void moveRange (double diff)
 
void scaleRange (double factor, double center)
 
void setScaleRatio (const QCPAxis *otherAxis, double ratio=1.0)
 
double pixelToCoord (double value) const
 
double coordToPixel (double value) const
 
void setRange (const QCPRange &range)
 

Signals

void ticksRequest ()
 
void rangeChanged (const QCPRange &newRange)
 

Public Member Functions

 QCPAxis (QCustomPlot *parentPlot, AxisType type)
 
virtual ~QCPAxis ()
 

Protected Member Functions

void setAxisType (AxisType type)
 
void setAxisRect (const QRect &rect)
 
virtual void generateTickVectors ()
 
virtual void generateAutoTicks ()
 
virtual int calculateAutoSubTickCount (double tickStep) const
 
virtual int calculateMargin () const
 
virtual void drawGrid (QPainter *painter)
 
virtual void drawSubGrid (QPainter *painter)
 
virtual void drawAxis (QPainter *painter)
 
virtual void drawTickLabel (QPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize)
 
virtual void getMaxTickLabelSize (const QFont &font, const QString &text, QSize *tickLabelsSize) const
 
void visibleTickBounds (int &lowIndex, int &highIndex) const
 
double baseLog (double value) const
 
double basePow (double value) const
 

Protected Attributes

QVector< double > * mTickVector
 
QVector< QString > * mTickVectorLabels
 
QCPRange mRange
 
QString mDateTimeFormat
 
QString mLabel
 
QRect mAxisRect
 
QPen mBasePen
 
QPen mGridPen
 
QPen mSubGridPen
 
QPen mZeroLinePen
 
QPen mTickPen
 
QPen mSubTickPen
 
QFont mTickLabelFont
 
QFont mLabelFont
 
LabelType mTickLabelType
 
ScaleType mScaleType
 
AxisType mAxisType
 
double mTickStep
 
double mScaleLogBase
 
double mScaleLogBaseLogInv
 
int mSubTickCount
 
int mTickLengthIn
 
int mTickLengthOut
 
int mSubTickLengthIn
 
int mSubTickLengthOut
 
int mAutoTickCount
 
int mTickLabelPadding
 
int mLabelPadding
 
int mPadding
 
double mTickLabelRotation
 
bool mVisible
 
bool mGrid
 
bool mSubGrid
 
bool mTicks
 
bool mTickLabels
 
bool mAutoTicks
 
bool mAutoTickLabels
 
bool mAutoTickStep
 
bool mAutoSubTicks
 
bool mRangeReversed
 
QCustomPlotmParentPlot
 
QVector< double > * mSubTickVector
 
QChar mExponentialChar
 
QChar mPositiveSignChar
 
int mNumberPrecision
 
char mNumberFormatChar
 
bool mNumberBeautifulPowers
 
bool mNumberMultiplyCross
 
Qt::Orientation mOrientation
 

Friends

class QCustomPlot
 

Detailed Description

Manages a single axis inside a QCustomPlot.

Usually doesn't need to be instantiated externally. Access QCustomPlot's axes via QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and QCustomPlot::yAxis2 (right).

Definition at line 667 of file qcustomplot.h.

Member Enumeration Documentation

Defines at which side of the axis rect the axis will appear. This also affects how the tick marks are drawn, on which side the labels are placed etc.

See also
setAxisType
Enumerator
ATLeft 

Axis is vertical and on the left side of the axis rect of the parent QCustomPlot.

ATRight 

Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.

ATTop 

Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.

ATBottom 

Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.

Definition at line 711 of file qcustomplot.h.

711  {ATLeft,
712  ATRight,
713  ATTop,
714  ATBottom
715  };
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711

When automatic tick label generation is enabled (setAutoTickLabels), defines how the numerical value (coordinate) of the tick position is translated into a string that will be drawn at the tick position.

See also
setTickLabelType
Enumerator
LTNumber 

Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat)

LTDateTime 

Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC, see QDateTime::toTime_t) and will be displayed and formatted as such. (see setDateTimeFormat)

Definition at line 723 of file qcustomplot.h.

723  {LTNumber,
724  LTDateTime
725  };
Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC, see QDateTime::toTime_t) and will be displayed and formatted as such. (see setDateTimeFormat)
Definition: qcustomplot.h:724
Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat) ...
Definition: qcustomplot.h:723

Defines the scale of an axis.

See also
setScaleType
Enumerator
STLinear 

Normal linear scaling.

STLogarithmic 

Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see setScaleLogBase).

Definition at line 731 of file qcustomplot.h.

731  {STLinear,
733  };
Normal linear scaling.
Definition: qcustomplot.h:731
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732

Constructor & Destructor Documentation

QCPAxis::QCPAxis ( QCustomPlot parentPlot,
AxisType  type 
)
explicit

Constructs an Axis instance of Type type inside parentPlot.

Definition at line 3074 of file qcustomplot.cc.

3075 {
3077  mTickVector = new QVector<double>;
3078  mSubTickVector = new QVector<double>;
3079  mTickVectorLabels = new QVector<QString>;
3080  setAxisType(type);
3081  setAxisRect(parentPlot->axisRect());
3083  setScaleLogBase(10);
3084 
3085  setVisible(true);
3086  setRange(0, 5);
3087  setRangeReversed(false);
3088 
3089  setTicks(true);
3090  setTickStep(1);
3091  setAutoTickCount(6);
3092  setAutoTicks(true);
3093  setAutoTickLabels(true);
3094  setAutoTickStep(true);
3095  setTickLabelFont(parentPlot->font());
3096  setTickLength(5);
3097  setTickPen(QPen(Qt::black));
3098  setTickLabels(true);
3101  setDateTimeFormat("hh:mm:ss\ndd.MM.yy");
3102  setNumberFormat("gbd");
3103  setNumberPrecision(6);
3104  setLabel("");
3105  setLabelFont(parentPlot->font());
3106 
3107  setAutoSubTicks(true);
3108  setSubTickCount(4);
3109  setSubTickLength(2);
3110  setSubTickPen(QPen(Qt::black));
3111 
3112  QPen gPen;
3113  gPen.setColor(QColor(200,200,200));
3114  gPen.setStyle(Qt::DotLine);
3115  setGridPen(gPen);
3116  setGrid(true);
3117  QPen subgPen;
3118  subgPen.setColor(QColor(220,220,220));
3119  subgPen.setStyle(Qt::DotLine);
3120  setSubGridPen(subgPen);
3121  setSubGrid(false);
3122  QPen zlinePen;
3123  zlinePen.setColor(QColor(200,200,200));
3124  setZeroLinePen(zlinePen);
3125  setBasePen(QPen(Qt::black));
3126 
3127  setPadding(0);
3128  if (type == ATTop)
3129  {
3131  setLabelPadding(6);
3132  } else if (type == ATRight)
3133  {
3135  setLabelPadding(12);
3136  } else if (type == ATBottom)
3137  {
3139  setLabelPadding(3);
3140  } else if (type == ATLeft)
3141  {
3143  setLabelPadding(10);
3144  }
3145 }
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
void setDateTimeFormat(const QString &format)
void setAutoTickLabels(bool on)
QVector< double > * mSubTickVector
Definition: qcustomplot.h:861
void setBasePen(const QPen &pen)
void setRangeReversed(bool reversed)
void setTickLabels(bool show)
void setVisible(bool on)
void setRange(double lower, double upper)
void setAutoTickStep(bool on)
void setSubTickCount(int count)
void setAutoTicks(bool on)
void setAutoSubTicks(bool on)
void setPadding(int padding)
QCustomPlot * parentPlot() const
Definition: qcustomplot.h:741
void setAxisRect(const QRect &rect)
void setScaleLogBase(double base)
void setTickLabelRotation(double degrees)
void setZeroLinePen(const QPen &pen)
void setGridPen(const QPen &pen)
void setAutoTickCount(int approximateCount)
void setTickLabelFont(const QFont &font)
Normal linear scaling.
Definition: qcustomplot.h:731
void setGrid(bool show)
void setTickPen(const QPen &pen)
void setAxisType(AxisType type)
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
void setSubGridPen(const QPen &pen)
void setTickLength(int inside, int outside=0)
void setScaleType(ScaleType type)
void setNumberPrecision(int precision)
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
void setTickStep(double step)
void setTickLabelType(LabelType type)
QVector< double > * mTickVector
Definition: qcustomplot.h:839
void setLabelFont(const QFont &font)
void setSubTickPen(const QPen &pen)
void setNumberFormat(const QString &formatCode)
Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat) ...
Definition: qcustomplot.h:723
void setTickLabelPadding(int padding)
void setTicks(bool show)
void setSubTickLength(int inside, int outside=0)
QRect axisRect() const
Definition: qcustomplot.h:937
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
void setLabel(const QString &str)
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
void setSubGrid(bool show)
void setLabelPadding(int padding)
QCPAxis::~QCPAxis ( )
virtual

Definition at line 3147 of file qcustomplot.cc.

3148 {
3149  delete mTickVector;
3150  delete mTickVectorLabels;
3151  delete mSubTickVector;
3152 }
QVector< double > * mSubTickVector
Definition: qcustomplot.h:861
QVector< double > * mTickVector
Definition: qcustomplot.h:839
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840

Member Function Documentation

bool QCPAxis::autoSubTicks ( ) const
inlineslot

Definition at line 755 of file qcustomplot.h.

755 { return mAutoSubTicks; }
bool mAutoSubTicks
Definition: qcustomplot.h:856
int QCPAxis::autoTickCount ( ) const
inlineslot

Definition at line 752 of file qcustomplot.h.

752 { return mAutoTickCount; }
int mAutoTickCount
Definition: qcustomplot.h:853
bool QCPAxis::autoTickLabels ( ) const
inlineslot

Definition at line 753 of file qcustomplot.h.

753 { return mAutoTickLabels; }
bool mAutoTickLabels
Definition: qcustomplot.h:856
bool QCPAxis::autoTicks ( ) const
inlineslot

Definition at line 751 of file qcustomplot.h.

751 { return mAutoTicks; }
bool mAutoTicks
Definition: qcustomplot.h:856
bool QCPAxis::autoTickStep ( ) const
inlineslot

Definition at line 754 of file qcustomplot.h.

754 { return mAutoTickStep; }
bool mAutoTickStep
Definition: qcustomplot.h:856
QRect QCPAxis::axisRect ( ) const
inlineslot

Definition at line 743 of file qcustomplot.h.

743 { return mAxisRect; }
QRect mAxisRect
Definition: qcustomplot.h:844
AxisType QCPAxis::axisType ( ) const
inlineslot

Definition at line 742 of file qcustomplot.h.

742 { return mAxisType; }
AxisType mAxisType
Definition: qcustomplot.h:849
double QCPAxis::baseLog ( double  value) const
protected

Definition at line 4752 of file qcustomplot.cc.

4753 {
4754  return log(value)*mScaleLogBaseLogInv;
4755 }
double mScaleLogBaseLogInv
Definition: qcustomplot.h:851
QPen QCPAxis::basePen ( ) const
inlineslot

Definition at line 773 of file qcustomplot.h.

773 { return mBasePen; }
QPen mBasePen
Definition: qcustomplot.h:845
double QCPAxis::basePow ( double  value) const
protected

Definition at line 4763 of file qcustomplot.cc.

4764 {
4765  return pow(mScaleLogBase, value);
4766 }
double mScaleLogBase
Definition: qcustomplot.h:851
int QCPAxis::calculateAutoSubTickCount ( double  tickStep) const
protectedvirtual

Definition at line 4147 of file qcustomplot.cc.

4148 {
4149  int result = mSubTickCount; // default to current setting, if no proper value can be found
4150 
4151  // get mantissa of tickstep:
4152  double magnitudeFactor = pow(10, (int)floor(log10(tickStep))); // get magnitude factor e.g. 0.01, 1, 10, 1000 etc.
4153  double tickStepMantissa = tickStep/magnitudeFactor;
4154 
4155  // separate integer and fractional part of mantissa:
4156  double epsilon = 0.01;
4157  double intPartf;
4158  int intPart;
4159  double fracPart = modf(tickStepMantissa, &intPartf);
4160  intPart = intPartf;
4161 
4162  // handle cases with (almost) integer mantissa:
4163  if (fracPart < epsilon || 1.0-fracPart < epsilon)
4164  {
4165  if (1.0-fracPart < epsilon)
4166  intPart++;
4167  switch (intPart)
4168  {
4169  case 1: result = 4; break; // 1.0 -> 0.2 substep
4170  case 2: result = 3; break; // 2.0 -> 0.5 substep
4171  case 3: result = 2; break; // 3.0 -> 1.0 substep
4172  case 4: result = 3; break; // 4.0 -> 1.0 substep
4173  case 5: result = 4; break; // 5.0 -> 1.0 substep
4174  case 6: result = 2; break; // 6.0 -> 2.0 substep
4175  case 7: result = 6; break; // 7.0 -> 1.0 substep
4176  case 8: result = 3; break; // 8.0 -> 2.0 substep
4177  case 9: result = 2; break; // 9.0 -> 3.0 substep
4178  }
4179  } else
4180  {
4181  // handle cases with significantly fractional mantissa:
4182  if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa
4183  {
4184  switch (intPart)
4185  {
4186  case 1: result = 2; break; // 1.5 -> 0.5 substep
4187  case 2: result = 4; break; // 2.5 -> 0.5 substep
4188  case 3: result = 4; break; // 3.5 -> 0.7 substep
4189  case 4: result = 2; break; // 4.5 -> 1.5 substep
4190  case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with autoTickStep from here on)
4191  case 6: result = 4; break; // 6.5 -> 1.3 substep
4192  case 7: result = 2; break; // 7.5 -> 2.5 substep
4193  case 8: result = 4; break; // 8.5 -> 1.7 substep
4194  case 9: result = 4; break; // 9.5 -> 1.9 substep
4195  }
4196  }
4197  // if mantissa fraction isnt 0.0 or 0.5, don't bother finding good sub tick marks, leave default
4198  }
4199 
4200  return result;
4201 }
double tickStep() const
Definition: qcustomplot.h:765
int mSubTickCount
Definition: qcustomplot.h:852
int QCPAxis::calculateMargin ( ) const
protectedvirtual

Definition at line 4781 of file qcustomplot.cc.

4782 {
4783  // run through similar steps as QCPAxis::drawAxis, and caluclate margin needed to fit axis and its labels
4784  int margin = 0;
4785 
4786  if (mVisible)
4787  {
4788  int lowTick, highTick;
4789  visibleTickBounds(lowTick, highTick);
4790 
4791  // get length of tick marks reaching outside axis rect:
4792  margin += qMax(0, qMax(mTickLengthOut, mSubTickLengthOut));
4793  // calculate size of tick labels:
4794  QSize tickLabelsSize(0, 0);
4795  if (mTickLabels)
4796  {
4797  for (int i=lowTick; i <= highTick; ++i)
4798  {
4799  getMaxTickLabelSize(mTickLabelFont, mTickVectorLabels->at(i), &tickLabelsSize);
4800  }
4801  if (orientation() == Qt::Horizontal)
4802  margin += tickLabelsSize.height() + mTickLabelPadding;
4803  else
4804  margin += tickLabelsSize.width() + mTickLabelPadding;
4805  }
4806 
4807  // calculate size of axis label (only height needed, because left/right labels are rotated by 90 degrees):
4808  if (!mLabel.isEmpty())
4809  {
4810  QFontMetrics fontMetrics(mLabelFont);
4811  QRect bounds;
4812  bounds = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, mLabel);
4813  margin += bounds.height() + mLabelPadding;
4814  }
4815  }
4816 
4817  margin += mPadding;
4818 
4819  if (margin < 15) // need a bit of margin if no axis text is shown at all (i.e. only baseline and tick lines, or no axis at all)
4820  margin = 15;
4821  return margin;
4822 }
QFont mLabelFont
Definition: qcustomplot.h:846
void visibleTickBounds(int &lowIndex, int &highIndex) const
int mLabelPadding
Definition: qcustomplot.h:854
bool mVisible
Definition: qcustomplot.h:856
int mTickLengthOut
Definition: qcustomplot.h:852
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
bool mTickLabels
Definition: qcustomplot.h:856
QString mLabel
Definition: qcustomplot.h:843
int mPadding
Definition: qcustomplot.h:854
virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const
int mTickLabelPadding
Definition: qcustomplot.h:854
QFont mTickLabelFont
Definition: qcustomplot.h:846
int mSubTickLengthOut
Definition: qcustomplot.h:852
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
double QCPAxis::coordToPixel ( double  value) const
slot

Definition at line 3927 of file qcustomplot.cc.

3928 {
3929  if (orientation() == Qt::Horizontal)
3930  {
3931  if (mScaleType == STLinear)
3932  {
3933  if (mRangeReversed)
3934  return (mRange.upper-value)/mRange.size()*mAxisRect.width()+mAxisRect.left();
3935  else
3936  return (value-mRange.lower)/mRange.size()*mAxisRect.width()+mAxisRect.left();
3937  } else // mScaleType == STLogarithmic
3938  {
3939  if (value >= 0 && mRange.upper < 0) // invalid value for logarithmic scale, just draw it outside visible range
3940  return mRangeReversed ? mAxisRect.left()-200 : mAxisRect.right()+200;
3941  else if (value <= 0 && mRange.upper > 0) // invalid value for logarithmic scale, just draw it outside visible range
3942  return mRangeReversed ? mAxisRect.right()+200 : mAxisRect.left()-200;
3943  else
3944  {
3945  if (mRangeReversed)
3946  return baseLog(mRange.upper/value)/baseLog(mRange.upper/mRange.lower)*mAxisRect.width()+mAxisRect.left();
3947  else
3948  return baseLog(value/mRange.lower)/baseLog(mRange.upper/mRange.lower)*mAxisRect.width()+mAxisRect.left();
3949  }
3950  }
3951  } else // orientation() == Qt::Vertical
3952  {
3953  if (mScaleType == STLinear)
3954  {
3955  if (mRangeReversed)
3956  return mAxisRect.bottom()-(mRange.upper-value)/mRange.size()*mAxisRect.height();
3957  else
3958  return mAxisRect.bottom()-(value-mRange.lower)/mRange.size()*mAxisRect.height();
3959  } else // mScaleType == STLogarithmic
3960  {
3961  if (value >= 0 && mRange.upper < 0) // invalid value for logarithmic scale, just draw it outside visible range
3962  return mRangeReversed ? mAxisRect.bottom()+200 : mAxisRect.top()-200;
3963  else if (value <= 0 && mRange.upper > 0) // invalid value for logarithmic scale, just draw it outside visible range
3964  return mRangeReversed ? mAxisRect.top()-200 : mAxisRect.bottom()+200;
3965  else
3966  {
3967  if (mRangeReversed)
3968  return mAxisRect.bottom()-baseLog(mRange.upper/value)/baseLog(mRange.upper/mRange.lower)*mAxisRect.height();
3969  else
3970  return mAxisRect.bottom()-baseLog(value/mRange.lower)/baseLog(mRange.upper/mRange.lower)*mAxisRect.height();
3971  }
3972  }
3973  }
3974 }
double size() const
Normal linear scaling.
Definition: qcustomplot.h:731
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
ScaleType mScaleType
Definition: qcustomplot.h:848
double baseLog(double value) const
QRect mAxisRect
Definition: qcustomplot.h:844
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
bool mRangeReversed
Definition: qcustomplot.h:857
QCPRange mRange
Definition: qcustomplot.h:841
QString QCPAxis::dateTimeFormat ( ) const
inlineslot

Definition at line 762 of file qcustomplot.h.

762 { return mDateTimeFormat; }
QString mDateTimeFormat
Definition: qcustomplot.h:842
void QCPAxis::drawAxis ( QPainter *  painter)
protectedvirtual

Definition at line 4320 of file qcustomplot.cc.

4321 {
4322  if (!mVisible) return;
4323  painter->save();
4324  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEAxes));
4325  QPoint origin;
4326  if (mAxisType == ATLeft)
4327  origin = mAxisRect.bottomLeft();
4328  else if (mAxisType == ATRight)
4329  origin = mAxisRect.bottomRight();
4330  else if (mAxisType == ATTop)
4331  origin = mAxisRect.topLeft();
4332  else if (mAxisType == ATBottom)
4333  origin = mAxisRect.bottomLeft();
4334 
4335  int xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes)
4336  if (mAxisType == ATTop)
4337  yCor = -1;
4338  else if (mAxisType == ATRight)
4339  xCor = 1;
4340 
4341  int margin = 0;
4342  int lowTick, highTick;
4343  visibleTickBounds(lowTick, highTick);
4344  int t; // helper variable, result of coordinate-to-pixel transforms
4345 
4346  /* draw axes */
4347  // baselines:
4348  painter->setPen(mBasePen);
4349  if (orientation() == Qt::Horizontal)
4350  painter->drawLine(origin+QPoint(xCor, yCor), origin+QPoint(mAxisRect.width()+xCor, yCor));
4351  else
4352  painter->drawLine(origin+QPoint(xCor, yCor), origin+QPoint(xCor, -mAxisRect.height()+yCor));
4353 
4354  // ticks:
4355  if (mTicks)
4356  {
4357  painter->setPen(mTickPen);
4358  // direction of ticks ("inward" is right for left axis and left for right axis)
4359  int tickDir = (mAxisType == ATBottom || mAxisType == ATRight) ? -1 : 1;
4360  if (orientation() == Qt::Horizontal)
4361  {
4362  for (int i=lowTick; i <= highTick; ++i)
4363  {
4364  t = coordToPixel(mTickVector->at(i)); // x
4365  painter->drawLine(t+xCor, origin.y()-mTickLengthOut*tickDir+yCor, t+xCor, origin.y()+mTickLengthIn*tickDir+yCor);
4366  }
4367  } else
4368  {
4369  for (int i=lowTick; i <= highTick; ++i)
4370  {
4371  t = coordToPixel(mTickVector->at(i)); // y
4372  painter->drawLine(origin.x()-mTickLengthOut*tickDir+xCor, t+yCor, origin.x()+mTickLengthIn*tickDir+xCor, t+yCor);
4373  }
4374  }
4375  }
4376 
4377  // subticks:
4378  if (mTicks && mSubTickCount > 0)
4379  {
4380  painter->setPen(mSubTickPen);
4381  // direction of ticks ("inward" is right for left axis and left for right axis)
4382  int tickDir = (mAxisType == ATBottom || mAxisType == ATRight) ? -1 : 1;
4383  if (orientation() == Qt::Horizontal)
4384  {
4385  for (int i=0; i<mSubTickVector->size(); ++i) // no need to check bounds because subticks are always only created inside current mRange
4386  {
4387  t = coordToPixel(mSubTickVector->at(i));
4388  painter->drawLine(t+xCor, origin.y()-mSubTickLengthOut*tickDir+yCor, t+xCor, origin.y()+mSubTickLengthIn*tickDir+yCor);
4389  }
4390  } else
4391  {
4392  for (int i=0; i<mSubTickVector->size(); ++i)
4393  {
4394  t = coordToPixel(mSubTickVector->at(i));
4395  painter->drawLine(origin.x()-mSubTickLengthOut*tickDir+xCor, t+yCor, origin.x()+mSubTickLengthIn*tickDir+xCor, t+yCor);
4396  }
4397  }
4398  }
4399  margin += qMax(0, qMax(mTickLengthOut, mSubTickLengthOut));
4400 
4401  // tick labels:
4402  QSize tickLabelsSize; // size of largest tick label, for offset calculation of axis label
4403  if (mTickLabels)
4404  {
4405  margin += mTickLabelPadding;
4406  painter->setFont(mTickLabelFont);
4407  for (int i=lowTick; i <= highTick; ++i)
4408  {
4409  t = coordToPixel(mTickVector->at(i));
4410  drawTickLabel(painter, t, margin, mTickVectorLabels->at(i), &tickLabelsSize);
4411  }
4412  }
4413  if (orientation() == Qt::Horizontal)
4414  margin += tickLabelsSize.height();
4415  else
4416  margin += tickLabelsSize.width();
4417 
4418  // axis label:
4419  if (!mLabel.isEmpty())
4420  {
4421  margin += mLabelPadding;
4422  painter->setFont(mLabelFont);
4423  QRect bounds;
4424  bounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, mLabel);
4425  if (mAxisType == ATLeft)
4426  {
4427  QTransform oldTransform = painter->transform();
4428  painter->translate((origin.x()-margin-bounds.height()), origin.y());
4429  painter->rotate(-90);
4430  painter->drawText(0, 0, mAxisRect.height(), bounds.height(), Qt::TextDontClip | Qt::AlignCenter, mLabel);
4431  painter->setTransform(oldTransform);
4432  }
4433  else if (mAxisType == ATRight)
4434  {
4435  QTransform oldTransform = painter->transform();
4436  painter->translate((origin.x()+margin+bounds.height()), origin.y()-mAxisRect.height());
4437  painter->rotate(90);
4438  painter->drawText(0, 0, mAxisRect.height(), bounds.height(), Qt::TextDontClip | Qt::AlignCenter, mLabel);
4439  painter->setTransform(oldTransform);
4440  }
4441  else if (mAxisType == ATTop)
4442  painter->drawText(origin.x(), origin.y()-margin-bounds.height(), mAxisRect.width(), bounds.height(), Qt::TextDontClip | Qt::AlignCenter, mLabel);
4443  else if (mAxisType == ATBottom)
4444  painter->drawText(origin.x(), origin.y()+margin, mAxisRect.width(), bounds.height(), Qt::TextDontClip | Qt::AlignCenter, mLabel);
4445  }
4446 
4447  painter->restore();
4448 }
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
QVector< double > * mSubTickVector
Definition: qcustomplot.h:861
QFont mLabelFont
Definition: qcustomplot.h:846
void visibleTickBounds(int &lowIndex, int &highIndex) const
int mLabelPadding
Definition: qcustomplot.h:854
QPen mSubTickPen
Definition: qcustomplot.h:845
QPen mBasePen
Definition: qcustomplot.h:845
bool mVisible
Definition: qcustomplot.h:856
int mTickLengthOut
Definition: qcustomplot.h:852
bool mTickLabels
Definition: qcustomplot.h:856
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
QString mLabel
Definition: qcustomplot.h:843
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
QPen mTickPen
Definition: qcustomplot.h:845
int mTickLabelPadding
Definition: qcustomplot.h:854
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QVector< double > * mTickVector
Definition: qcustomplot.h:839
int mSubTickLengthIn
Definition: qcustomplot.h:852
QRect mAxisRect
Definition: qcustomplot.h:844
QFont mTickLabelFont
Definition: qcustomplot.h:846
double coordToPixel(double value) const
int mSubTickLengthOut
Definition: qcustomplot.h:852
int mTickLengthIn
Definition: qcustomplot.h:852
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
AxisType mAxisType
Definition: qcustomplot.h:849
int mSubTickCount
Definition: qcustomplot.h:852
virtual void drawTickLabel(QPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize)
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
bool mTicks
Definition: qcustomplot.h:856
void QCPAxis::drawGrid ( QPainter *  painter)
protectedvirtual

Definition at line 4209 of file qcustomplot.cc.

4210 {
4211  if (!mVisible || (!mGrid && mZeroLinePen.style() == Qt::NoPen)) return;
4212  painter->save();
4213  int lowTick, highTick;
4214  visibleTickBounds(lowTick, highTick);
4215  int t; // helper variable, result of coordinate-to-pixel transforms
4216  if (orientation() == Qt::Horizontal)
4217  {
4218  // draw zeroline:
4219  int zeroLineIndex = -1;
4220  if (mZeroLinePen.style() != Qt::NoPen && mRange.lower < 0 && mRange.upper > 0)
4221  {
4222  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEZeroLine));
4223  painter->setPen(mZeroLinePen);
4224  double epsilon = mRange.size()*1E-6; // for comparing double to zero
4225  for (int i=lowTick; i <= highTick; ++i)
4226  {
4227  if (fabs(mTickVector->at(i)) < epsilon)
4228  {
4229  zeroLineIndex = i;
4230  t = coordToPixel(mTickVector->at(i)); // x
4231  painter->drawLine(t, mAxisRect.bottom(), t, mAxisRect.top());
4232  break;
4233  }
4234  }
4235  }
4236  // draw grid lines:
4237  if (mGrid)
4238  {
4239  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGrid));
4240  painter->setPen(mGridPen);
4241  for (int i=lowTick; i <= highTick; ++i)
4242  {
4243  if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline
4244  t = coordToPixel(mTickVector->at(i)); // x
4245  painter->drawLine(t, mAxisRect.bottom(), t, mAxisRect.top());
4246  }
4247  }
4248  } else
4249  {
4250  // draw zeroline:
4251  int zeroLineIndex = -1;
4252  if (mZeroLinePen.style() != Qt::NoPen && mRange.lower < 0 && mRange.upper > 0)
4253  {
4254  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEZeroLine));
4255  painter->setPen(mZeroLinePen);
4256  double epsilon = mRange.size()*1E-6; // for comparing double to zero
4257  for (int i=lowTick; i <= highTick; ++i)
4258  {
4259  if (fabs(mTickVector->at(i)) < epsilon)
4260  {
4261  zeroLineIndex = i;
4262  t = coordToPixel(mTickVector->at(i)); // y
4263  painter->drawLine(mAxisRect.left(), t, mAxisRect.right(), t);
4264  break;
4265  }
4266  }
4267  }
4268  // draw grid lines:
4269  if (mGrid)
4270  {
4271  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AEGrid));
4272  painter->setPen(mGridPen);
4273  for (int i=lowTick; i <= highTick; ++i)
4274  {
4275  if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline
4276  t = coordToPixel(mTickVector->at(i)); // y
4277  painter->drawLine(mAxisRect.left(), t, mAxisRect.right(), t);
4278  }
4279  }
4280  }
4281  painter->restore();
4282 }
double size() const
void visibleTickBounds(int &lowIndex, int &highIndex) const
bool mGrid
Definition: qcustomplot.h:856
QPen mGridPen
Definition: qcustomplot.h:845
bool mVisible
Definition: qcustomplot.h:856
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QVector< double > * mTickVector
Definition: qcustomplot.h:839
QPen mZeroLinePen
Definition: qcustomplot.h:845
QRect mAxisRect
Definition: qcustomplot.h:844
double coordToPixel(double value) const
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
void QCPAxis::drawSubGrid ( QPainter *  painter)
protectedvirtual

Definition at line 4289 of file qcustomplot.cc.

4290 {
4291  if (!mVisible || !mSubGrid || !mGrid) return;
4292  painter->save();
4293  painter->setRenderHint(QPainter::Antialiasing, mParentPlot->antialiasedElements().testFlag(QCustomPlot::AESubGrid));
4294 
4295  int t; // helper variable, result of coordinate-to-pixel transforms
4296  painter->setPen(mSubGridPen);
4297  if (orientation() == Qt::Horizontal)
4298  {
4299  for (int i=0; i<mSubTickVector->size(); ++i)
4300  {
4301  t = coordToPixel(mSubTickVector->at(i)); // x
4302  painter->drawLine(t, mAxisRect.bottom(), t, mAxisRect.top());
4303  }
4304  } else
4305  {
4306  for (int i=0; i<mSubTickVector->size(); ++i)
4307  {
4308  t = coordToPixel(mSubTickVector->at(i)); // y
4309  painter->drawLine(mAxisRect.left(), t, mAxisRect.right(), t);
4310  }
4311  }
4312  painter->restore();
4313 }
QVector< double > * mSubTickVector
Definition: qcustomplot.h:861
bool mGrid
Definition: qcustomplot.h:856
bool mSubGrid
Definition: qcustomplot.h:856
bool mVisible
Definition: qcustomplot.h:856
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
const AntialiasedElements antialiasedElements() const
Definition: qcustomplot.h:949
QRect mAxisRect
Definition: qcustomplot.h:844
QPen mSubGridPen
Definition: qcustomplot.h:845
double coordToPixel(double value) const
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
void QCPAxis::drawTickLabel ( QPainter *  painter,
double  position,
int  distanceToAxis,
const QString &  text,
QSize *  tickLabelsSize 
)
protectedvirtual

Definition at line 4468 of file qcustomplot.cc.

4469 {
4470  // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly!
4471 
4472  // determine whether beautiful decimal powers should be used
4473  bool useBeautifulPowers = false;
4474  int ePos = -1;
4476  {
4477  ePos = text.indexOf('e');
4478  if (ePos > -1)
4479  useBeautifulPowers = true;
4480  }
4481 
4482  // calculate text bounding rects and do string preparation for beautiful decimal powers:
4483  QRect bounds, baseBounds, expBounds;
4484  QString basePart, expPart;
4485  QFont expFont;
4486  if (useBeautifulPowers)
4487  {
4488  // split string parts for part of number/symbol that will be drawn normally and part that will be drawn as exponent:
4489  basePart = text.left(ePos);
4490  // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base:
4491  if (mScaleType == STLogarithmic && basePart == "1")
4492  basePart = "10";
4493  else
4494  basePart += (mNumberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + "10";
4495  expPart = text.mid(ePos+1);
4496  // clip "+" and leading zeros off expPart:
4497  while (expPart.at(1) == '0' && expPart.length() > 2) // length > 2 so we leave one zero when numberFormatChar is 'e'
4498  expPart.remove(1, 1);
4499  if (expPart.at(0) == mPositiveSignChar)
4500  expPart.remove(0, 1);
4501  // prepare smaller font for exponent:
4502  expFont = painter->font();
4503  expFont.setPointSize(expFont.pointSize()*0.75);
4504  // calculate bounding rects of base part, exponent part and total one:
4505  baseBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, basePart);
4506  QFontMetrics expFontMetrics(expFont);
4507  expBounds = expFontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, expPart);
4508  bounds = baseBounds.adjusted(0, 0, expBounds.width(), 0);
4509  } else // useBeautifulPowers == false
4510  {
4511  bounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, text);
4512  }
4513 
4514  // if using rotated tick labels, transform bounding rect, too:
4515  QRect rotatedBounds = bounds;
4516  if (!qFuzzyCompare(mTickLabelRotation+1.0, 1.0))
4517  {
4518  QTransform transform;
4519  transform.rotate(mTickLabelRotation);
4520  rotatedBounds = transform.mapRect(bounds);
4521  }
4522  // expand passed tickLabelsSize if current tick label is larger:
4523  if (rotatedBounds.width() > tickLabelsSize->width())
4524  tickLabelsSize->setWidth(rotatedBounds.width());
4525  if (rotatedBounds.height() > tickLabelsSize->height())
4526  tickLabelsSize->setHeight(rotatedBounds.height());
4527 
4528  // calculate coordinates (non-trivial, for best visual appearance):
4529  // short explanation for bottom axis: The anchor, i.e. the point in the label that is placed horizontally under the
4530  // corresponding tick is always on the label side that is closer to the axis (e.g. the left side of the text when we're
4531  // rotating clockwise). On that side, the height-edge is halved and the resulting median point is defined the anchor. This way,
4532  // a 90 degree rotated text will be centered under the tick (i.e. displaced horizontally by half its height). At the
4533  // same time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick labels.
4534  bool doRotation = !qFuzzyCompare(mTickLabelRotation+1.0, 1.0);
4535  double angle = mTickLabelRotation/180.0*M_PI;
4536  int x=0,y=0;
4537  if (mAxisType == ATLeft)
4538  {
4539  if (doRotation)
4540  {
4541  if (mTickLabelRotation > 0)
4542  {
4543  x = mAxisRect.left()-cos(angle)*bounds.width()-distanceToAxis;
4544  y = position-sin(angle)*bounds.width()-cos(angle)*bounds.height()/2.0;
4545  } else
4546  {
4547  x = mAxisRect.left()-cos(-angle)*bounds.width()-sin(-angle)*bounds.height()-distanceToAxis;
4548  y = position+sin(-angle)*bounds.width()-cos(-angle)*bounds.height()/2.0;
4549  }
4550  } else
4551  {
4552  x = mAxisRect.left()-bounds.width()-distanceToAxis;
4553  y = position-bounds.height()/2.0;
4554  }
4555  } else if (mAxisType == ATRight)
4556  {
4557  if (doRotation)
4558  {
4559  if (mTickLabelRotation > 0)
4560  {
4561  x = mAxisRect.right()+sin(angle)*bounds.height()+distanceToAxis;
4562  y = position-cos(angle)*bounds.height()/2.0;
4563  } else
4564  {
4565  x = mAxisRect.right()+distanceToAxis;
4566  y = position-cos(-angle)*bounds.height()/2.0;
4567  }
4568  } else
4569  {
4570  x = mAxisRect.right()+distanceToAxis;
4571  y = position-bounds.height()/2.0;
4572  }
4573  } else if (mAxisType == ATTop)
4574  {
4575  if (doRotation)
4576  {
4577  if (mTickLabelRotation > 0)
4578  {
4579  x = position-cos(angle)*bounds.width()+sin(angle)*bounds.height()/2.0;
4580  y = mAxisRect.top()-sin(angle)*bounds.width()-cos(angle)*bounds.height()-distanceToAxis;
4581  } else
4582  {
4583  x = position-sin(-angle)*bounds.height()/2.0;
4584  y = mAxisRect.top()-cos(-angle)*bounds.height()-distanceToAxis;
4585  }
4586  } else
4587  {
4588  x = position-bounds.width()/2.0;
4589  y = mAxisRect.top()-bounds.height()-distanceToAxis;
4590  }
4591  } else if (mAxisType == ATBottom)
4592  {
4593  if (doRotation)
4594  {
4595  if (mTickLabelRotation > 0)
4596  {
4597  x = position+sin(angle)*bounds.height()/2.0;
4598  y = mAxisRect.bottom()+distanceToAxis;
4599  } else
4600  {
4601  x = position-cos(-angle)*bounds.width()-sin(-angle)*bounds.height()/2.0;
4602  y = mAxisRect.bottom()+sin(-angle)*bounds.width()+distanceToAxis;
4603  }
4604  } else
4605  {
4606  x = position-bounds.width()/2.0;
4607  y = mAxisRect.bottom()+distanceToAxis;
4608  }
4609  }
4610 
4611  // if label would be partly clipped by widget border on sides, don't draw it:
4612  if (orientation() == Qt::Horizontal)
4613  {
4614  if (x+bounds.width() > mParentPlot->mViewport.right() ||
4615  x < mParentPlot->mViewport.left())
4616  return;
4617  } else
4618  {
4619  if (y+bounds.height() > mParentPlot->mViewport.bottom() ||
4620  y < mParentPlot->mViewport.top())
4621  return;
4622  }
4623 
4624  // transform painter to position/rotation:
4625  QTransform oldTransform = painter->transform();
4626  painter->translate(x, y);
4627  if (doRotation)
4628  painter->rotate(mTickLabelRotation);
4629  // draw text:
4630  if (useBeautifulPowers)
4631  {
4632  // draw base:
4633  painter->drawText(0, 0, 0, 0, Qt::TextDontClip, basePart);
4634  // draw exponent:
4635  painter->setFont(expFont);
4636  painter->drawText(baseBounds.width()+1, 0, expBounds.width(), expBounds.height(), Qt::TextDontClip, expPart);
4637  painter->setFont(mTickLabelFont);
4638  } else // useBeautifulPowers == false
4639  {
4640  painter->drawText(0, 0, bounds.width(), bounds.height(), Qt::TextDontClip | Qt::AlignHCenter, text);
4641  }
4642 
4643  // reset rotation/translation transform to what it was before:
4644  painter->setTransform(oldTransform);
4645 }
Axis is vertical and on the right side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:712
bool mNumberBeautifulPowers
Definition: qcustomplot.h:865
bool mNumberMultiplyCross
Definition: qcustomplot.h:865
bool mAutoTickLabels
Definition: qcustomplot.h:856
double mTickLabelRotation
Definition: qcustomplot.h:855
QChar mPositiveSignChar
Definition: qcustomplot.h:862
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
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
LabelType mTickLabelType
Definition: qcustomplot.h:847
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat) ...
Definition: qcustomplot.h:723
QRect mAxisRect
Definition: qcustomplot.h:844
QRect mViewport
Definition: qcustomplot.h:1013
QFont mTickLabelFont
Definition: qcustomplot.h:846
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
AxisType mAxisType
Definition: qcustomplot.h:849
Axis is vertical and on the left side of the axis rect of the parent QCustomPlot. ...
Definition: qcustomplot.h:711
void QCPAxis::generateAutoTicks ( )
protectedvirtual

Definition at line 4069 of file qcustomplot.cc.

4070 {
4071  if (mScaleType == STLinear)
4072  {
4073  if (mAutoTickStep)
4074  {
4075  // Generate tick positions according to linear scaling:
4076  mTickStep = mRange.size()/(double)mAutoTickCount; // mAutoTickCount ticks on average
4077  double magnitudeFactor = pow(10, (int)floor(log10(mTickStep))); // get magnitude factor e.g. 0.01, 1, 10, 1000 etc.
4078  double tickStepMantissa = mTickStep/magnitudeFactor;
4079  if (tickStepMantissa < 5)
4080  {
4081  // round digit after decimal point to 0.5
4082  mTickStep = (int)(tickStepMantissa*2)/2.0*magnitudeFactor;
4083  } else
4084  {
4085  // round to first digit in multiples of 2
4086  mTickStep = (int)((tickStepMantissa/10.0)*5)/5.0*10*magnitudeFactor;
4087  }
4088  }
4089  if (mAutoSubTicks)
4091  // Generate tick positions according to mTickStep:
4092  int firstStep = floor(mRange.lower/mTickStep);
4093  int lastStep = ceil(mRange.upper/mTickStep);
4094  int tickcount = lastStep-firstStep+1;
4095  if (tickcount < 0) tickcount = 0;
4096  mTickVector->resize(tickcount);
4097  for (int i=0; i<tickcount; ++i)
4098  {
4099  (*mTickVector)[i] = (firstStep+i)*mTickStep;
4100  }
4101  } else // mScaleType == STLogarithmic
4102  {
4103  // Generate tick positions according to logbase scaling:
4104  if (mRange.lower > 0 && mRange.upper > 0) // positive range
4105  {
4106  double lowerMag = basePow((int)floor(baseLog(mRange.lower)));
4107  double currentMag = lowerMag;
4108  mTickVector->clear();
4109  mTickVector->append(currentMag);
4110  while (currentMag < mRange.upper && currentMag > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case
4111  {
4112  currentMag *= mScaleLogBase;
4113  mTickVector->append(currentMag);
4114  }
4115  } else if (mRange.lower < 0 && mRange.upper < 0) // negative range
4116  {
4117  double lowerMag = -basePow((int)ceil(baseLog(-mRange.lower)));
4118  double currentMag = lowerMag;
4119  mTickVector->clear();
4120  mTickVector->append(currentMag);
4121  while (currentMag < mRange.upper && currentMag < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case
4122  {
4123  currentMag /= mScaleLogBase;
4124  mTickVector->append(currentMag);
4125  }
4126  } else // invalid range for logarithmic scale, because lower and upper have different sign
4127  {
4128  mTickVector->clear();
4129  qDebug() << FUNCNAME << "Invalid range for logarithmic plot: " << mRange.lower << "-" << mRange.upper;
4130  }
4131  }
4132 }
double size() const
bool mAutoTickStep
Definition: qcustomplot.h:856
virtual int calculateAutoSubTickCount(double tickStep) const
Normal linear scaling.
Definition: qcustomplot.h:731
double mScaleLogBase
Definition: qcustomplot.h:851
bool mAutoSubTicks
Definition: qcustomplot.h:856
int mAutoTickCount
Definition: qcustomplot.h:853
ScaleType mScaleType
Definition: qcustomplot.h:848
double baseLog(double value) const
QVector< double > * mTickVector
Definition: qcustomplot.h:839
double basePow(double value) const
double mTickStep
Definition: qcustomplot.h:850
#define FUNCNAME
Definition: qcustomplot.h:50
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
int mSubTickCount
Definition: qcustomplot.h:852
void QCPAxis::generateTickVectors ( )
protectedvirtual

Definition at line 3984 of file qcustomplot.cc.

3985 {
3986  if ((!mTicks && !mTickLabels && !mGrid) || mRange.size() <= 0) return;
3987 
3988  // fill tick vectors, either by auto generating or by notifying user to fill the vectors himself
3989  if (mAutoTicks)
3990  {
3992  } else
3993  {
3994  emit ticksRequest();
3995  }
3996 
3997  if (mTickVector->isEmpty())
3998  {
3999  mSubTickVector->clear();
4000  return;
4001  }
4002 
4003  // generate subticks between ticks:
4004  mSubTickVector->resize((mTickVector->size()-1)*mSubTickCount);
4005  if (mSubTickCount > 0)
4006  {
4007  double subTickStep = 0;
4008  double subTickPosition = 0;
4009  int subTickIndex = 0;
4010  bool done = false;
4011  for (int i=1; i<mTickVector->size(); ++i)
4012  {
4013  subTickStep = (mTickVector->at(i)-mTickVector->at(i-1))/(double)(mSubTickCount+1);
4014  for (int k=1; k<=mSubTickCount; ++k)
4015  {
4016  subTickPosition = mTickVector->at(i-1) + k*subTickStep;
4017  if (subTickPosition < mRange.lower)
4018  continue;
4019  if (subTickPosition > mRange.upper)
4020  {
4021  done = true;
4022  break;
4023  }
4024  (*mSubTickVector)[subTickIndex] = subTickPosition;
4025  subTickIndex++;
4026  }
4027  if (done) break;
4028  }
4029  mSubTickVector->resize(subTickIndex);
4030  }
4031 
4032  // generate tick labels according to tick positions:
4033  mExponentialChar = mParentPlot->locale().exponential(); // will be needed when drawing the numbers generated here, in drawTickLabel()
4034  mPositiveSignChar = mParentPlot->locale().positiveSign(); // will be needed when drawing the numbers generated here, in drawTickLabel()
4035  if (mAutoTickLabels)
4036  {
4037  int vecsize = mTickVector->size();
4038  mTickVectorLabels->resize(vecsize);
4039  if (mTickLabelType == LTNumber)
4040  {
4041  for (int i=0; i<vecsize; ++i)
4042  (*mTickVectorLabels)[i] = mParentPlot->locale().toString(mTickVector->at(i), mNumberFormatChar, mNumberPrecision);
4043  } else if (mTickLabelType == LTDateTime)
4044  {
4045  for (int i=0; i<vecsize; ++i)
4046  (*mTickVectorLabels)[i] = mParentPlot->locale().toString(QDateTime::fromTime_t(mTickVector->at(i)), mDateTimeFormat);
4047  }
4048  } else // mAutoTickLabels == false
4049  {
4050  if (mAutoTicks) // ticks generated automatically, but not ticklabels, so emit ticksRequest here for labels
4051  {
4052  emit ticksRequest();
4053  }
4054  // make sure provided tick label vector has correct (minimal) length:
4055  if (mTickVectorLabels->size() < mTickVector->size())
4056  mTickVectorLabels->resize(mTickVector->size());
4057  }
4058 }
double size() const
QVector< double > * mSubTickVector
Definition: qcustomplot.h:861
bool mAutoTickLabels
Definition: qcustomplot.h:856
QString mDateTimeFormat
Definition: qcustomplot.h:842
QChar mPositiveSignChar
Definition: qcustomplot.h:862
bool mGrid
Definition: qcustomplot.h:856
bool mTickLabels
Definition: qcustomplot.h:856
Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC, see QDateTime::toTime_t) and will be displayed and formatted as such. (see setDateTimeFormat)
Definition: qcustomplot.h:724
bool mAutoTicks
Definition: qcustomplot.h:856
LabelType mTickLabelType
Definition: qcustomplot.h:847
char mNumberFormatChar
Definition: qcustomplot.h:864
int mNumberPrecision
Definition: qcustomplot.h:863
QVector< double > * mTickVector
Definition: qcustomplot.h:839
Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat) ...
Definition: qcustomplot.h:723
QChar mExponentialChar
Definition: qcustomplot.h:862
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
virtual void generateAutoTicks()
void ticksRequest()
QCPRange mRange
Definition: qcustomplot.h:841
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
int mSubTickCount
Definition: qcustomplot.h:852
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
bool mTicks
Definition: qcustomplot.h:856
void QCPAxis::getMaxTickLabelSize ( const QFont &  font,
const QString &  text,
QSize *  tickLabelsSize 
) const
protectedvirtual

Definition at line 4655 of file qcustomplot.cc.

4656 {
4657  // This function does the same as drawTickLabel but omits the actual drawing
4658  // changes involve creating extra QFontMetrics instances for font, since painter->fontMetrics() isn't available
4659 
4660  // determine whether beautiful powers should be used
4661  bool useBeautifulPowers = false;
4662  int ePos=-1;
4664  {
4665  ePos = text.indexOf(mExponentialChar);
4666  if (ePos > -1)
4667  useBeautifulPowers = true;
4668  }
4669 
4670  // calculate and draw text, depending on whether beautiful powers are applicable or not:
4671  QRect bounds, baseBounds, expBounds;
4672  QString basePart, expPart;
4673  QFont expFont;
4674  if (useBeautifulPowers)
4675  {
4676  // split string parts for part of number/symbol that will be drawn normally and part that will be drawn as exponent:
4677  basePart = text.left(ePos);
4678  // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base:
4679  if (mScaleType == STLogarithmic && basePart == "1")
4680  basePart = "10";
4681  else
4682  basePart += (mNumberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + "10";
4683  expPart = text.mid(ePos+1);
4684  // clip "+" and leading zeros off expPart:
4685  while (expPart.at(1) == '0' && expPart.length() > 2) // length > 2 so we leave one zero when numberFormatChar is 'e'
4686  expPart.remove(1, 1);
4687  if (expPart.at(0) == mPositiveSignChar)
4688  expPart.remove(0, 1);
4689  // prepare smaller font for exponent:
4690  expFont = font;
4691  expFont.setPointSize(expFont.pointSize()*0.75);
4692  // calculate bounding rects of base part, exponent part and total one:
4693  QFontMetrics baseFontMetrics(font);
4694  baseBounds = baseFontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, basePart);
4695  QFontMetrics expFontMetrics(expFont);
4696  expBounds = expFontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, expPart);
4697  bounds = baseBounds.adjusted(0, 0, expBounds.width(), 0);
4698  } else // useBeautifulPowers == false
4699  {
4700  QFontMetrics fontMetrics(font);
4701  bounds = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, text);
4702  }
4703 
4704  // if rotated tick labels, transform bounding rect, too:
4705  QRect rotatedBounds = bounds;
4706  if (!qFuzzyCompare(mTickLabelRotation+1.0, 1.0))
4707  {
4708  QTransform transform;
4709  transform.rotate(mTickLabelRotation);
4710  rotatedBounds = transform.mapRect(bounds);
4711  }
4712  // expand passed tickLabelsSize if current tick label is larger:
4713  if (rotatedBounds.width() > tickLabelsSize->width())
4714  tickLabelsSize->setWidth(rotatedBounds.width());
4715  if (rotatedBounds.height() > tickLabelsSize->height())
4716  tickLabelsSize->setHeight(rotatedBounds.height());
4717 }
bool mNumberBeautifulPowers
Definition: qcustomplot.h:865
bool mNumberMultiplyCross
Definition: qcustomplot.h:865
bool mAutoTickLabels
Definition: qcustomplot.h:856
double mTickLabelRotation
Definition: qcustomplot.h:855
QChar mPositiveSignChar
Definition: qcustomplot.h:862
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
LabelType mTickLabelType
Definition: qcustomplot.h:847
Tick coordinate is regarded as normal number and will be displayed as such. (see setNumberFormat) ...
Definition: qcustomplot.h:723
QChar mExponentialChar
Definition: qcustomplot.h:862
bool QCPAxis::grid ( ) const
inlineslot

Definition at line 749 of file qcustomplot.h.

749 { return mGrid; }
bool mGrid
Definition: qcustomplot.h:856
QPen QCPAxis::gridPen ( ) const
inlineslot

Definition at line 774 of file qcustomplot.h.

774 { return mGridPen; }
QPen mGridPen
Definition: qcustomplot.h:845
QString QCPAxis::label ( ) const
inlineslot

Definition at line 780 of file qcustomplot.h.

780 { return mLabel; }
QString mLabel
Definition: qcustomplot.h:843
QFont QCPAxis::labelFont ( ) const
inlineslot

Definition at line 779 of file qcustomplot.h.

779 { return mLabelFont; }
QFont mLabelFont
Definition: qcustomplot.h:846
int QCPAxis::labelPadding ( ) const
inlineslot

Definition at line 781 of file qcustomplot.h.

781 { return mLabelPadding; }
int mLabelPadding
Definition: qcustomplot.h:854
void QCPAxis::moveRange ( double  diff)
slot

If the scale type (setScaleType) is STLinear, diff is added to the lower and upper bounds of the range. The range is simply moved by diff. If the scale type is STLogarithmic, the range bounds are multiplied by diff. This corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff).

Definition at line 3813 of file qcustomplot.cc.

3814 {
3815  if (mScaleType == STLinear)
3816  {
3817  mRange.lower += diff;
3818  mRange.upper += diff;
3819  } else // mScaleType == STLogarithmic
3820  {
3821  mRange.lower *= diff;
3822  mRange.upper *= diff;
3823  }
3824  emit rangeChanged(mRange);
3825 }
void rangeChanged(const QCPRange &newRange)
Normal linear scaling.
Definition: qcustomplot.h:731
ScaleType mScaleType
Definition: qcustomplot.h:848
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
QString QCPAxis::numberFormat ( ) const
slot

Returns the number Format.

See also
setNumberFormat

Definition at line 3158 of file qcustomplot.cc.

3159 {
3160  QString result;
3161  result.append(mNumberFormatChar);
3163  {
3164  result.append("b");
3166  result.append("c");
3167  }
3168  return result;
3169 }
bool mNumberBeautifulPowers
Definition: qcustomplot.h:865
bool mNumberMultiplyCross
Definition: qcustomplot.h:865
char mNumberFormatChar
Definition: qcustomplot.h:864
int QCPAxis::numberPrecision ( ) const
inlineslot

Definition at line 764 of file qcustomplot.h.

764 { return mNumberPrecision; }
int mNumberPrecision
Definition: qcustomplot.h:863
Qt::Orientation QCPAxis::orientation ( ) const
inlineslot

Definition at line 827 of file qcustomplot.h.

827 { return mOrientation; }
Qt::Orientation mOrientation
Definition: qcustomplot.h:866
int QCPAxis::padding ( ) const
inlineslot

Definition at line 782 of file qcustomplot.h.

782 { return mPadding; }
int mPadding
Definition: qcustomplot.h:854
QCustomPlot* QCPAxis::parentPlot ( ) const
inlineslot

Definition at line 741 of file qcustomplot.h.

741 { return mParentPlot; }
QCustomPlot * mParentPlot
Definition: qcustomplot.h:860
double QCPAxis::pixelToCoord ( double  value) const
slot

Definition at line 3888 of file qcustomplot.cc.

3889 {
3890  if (orientation() == Qt::Horizontal)
3891  {
3892  if (mScaleType == STLinear)
3893  {
3894  if (mRangeReversed)
3895  return -(value-mAxisRect.left())/(double)mAxisRect.width()*mRange.size()+mRange.upper;
3896  else
3897  return (value-mAxisRect.left())/(double)mAxisRect.width()*mRange.size()+mRange.lower;
3898  } else // mScaleType == STLogarithmic
3899  {
3900  if (mRangeReversed)
3901  return pow(mRange.upper/mRange.lower, (mAxisRect.left()-value)/(double)mAxisRect.width())*mRange.upper;
3902  else
3903  return pow(mRange.upper/mRange.lower, (value-mAxisRect.left())/(double)mAxisRect.width())*mRange.lower;
3904  }
3905  } else // orientation() == Qt::Vertical
3906  {
3907  if (mScaleType == STLinear)
3908  {
3909  if (mRangeReversed)
3910  return -(mAxisRect.bottom()-value)/(double)mAxisRect.height()*mRange.size()+mRange.upper;
3911  else
3912  return (mAxisRect.bottom()-value)/(double)mAxisRect.height()*mRange.size()+mRange.lower;
3913  } else // mScaleType == STLogarithmic
3914  {
3915  if (mRangeReversed)
3916  return pow(mRange.upper/mRange.lower, (value-mAxisRect.bottom())/(double)mAxisRect.height())*mRange.upper;
3917  else
3918  return pow(mRange.upper/mRange.lower, (mAxisRect.bottom()-value)/(double)mAxisRect.height())*mRange.lower;
3919  }
3920  }
3921 }
double size() const
Normal linear scaling.
Definition: qcustomplot.h:731
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
ScaleType mScaleType
Definition: qcustomplot.h:848
QRect mAxisRect
Definition: qcustomplot.h:844
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
bool mRangeReversed
Definition: qcustomplot.h:857
QCPRange mRange
Definition: qcustomplot.h:841
const QCPRange QCPAxis::range ( ) const
inlineslot

Definition at line 746 of file qcustomplot.h.

746 { return mRange; }
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::rangeChanged ( const QCPRange newRange)
signal
bool QCPAxis::rangeReversed ( ) const
inlineslot

Definition at line 747 of file qcustomplot.h.

747 { return mRangeReversed; }
bool mRangeReversed
Definition: qcustomplot.h:857
double QCPAxis::scaleLogBase ( ) const
inlineslot

Definition at line 745 of file qcustomplot.h.

745 { return mScaleLogBase; }
double mScaleLogBase
Definition: qcustomplot.h:851
void QCPAxis::scaleRange ( double  factor,
double  center 
)
slot

Scales the range of this axis by factor around the coordinate center. For example, if factor is 2.0, center is 1.0, then the axis range will double its size, and the point at coordinate 1.0 won't have changed it's position in the QCustomPlot widget (i.e. coordinates around 1.0 will have moved symmetrically closer to 1.0).

Definition at line 3833 of file qcustomplot.cc.

3834 {
3835 
3836  if (mScaleType == STLinear)
3837  {
3838  QCPRange newRange;
3839  newRange.lower = (mRange.lower-center)*factor + center;
3840  newRange.upper = (mRange.upper-center)*factor + center;
3841  if (QCPRange::validRange(newRange))
3842  mRange = newRange.sanitizedForLinScale();
3843  } else // mScaleType == STLogarithmic
3844  {
3845  if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range
3846  {
3847  QCPRange newRange;
3848  newRange.lower = pow(mRange.lower/center, factor)*center;
3849  newRange.upper = pow(mRange.upper/center, factor)*center;
3850  if (QCPRange::validRange(newRange))
3851  mRange = newRange.sanitizedForLogScale();
3852  } else
3853  qDebug() << FUNCNAME << "center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center;
3854  }
3855  emit rangeChanged(mRange);
3856 }
void rangeChanged(const QCPRange &newRange)
static bool validRange(double lower, double upper)
QCPRange sanitizedForLogScale() const
Normal linear scaling.
Definition: qcustomplot.h:731
ScaleType mScaleType
Definition: qcustomplot.h:848
QCPRange sanitizedForLinScale() const
#define FUNCNAME
Definition: qcustomplot.h:50
double upper
Definition: qcustomplot.h:494
Represents the range an axis is encompassing.
Definition: qcustomplot.h:491
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
ScaleType QCPAxis::scaleType ( ) const
inlineslot

Definition at line 744 of file qcustomplot.h.

744 { return mScaleType; }
ScaleType mScaleType
Definition: qcustomplot.h:848
void QCPAxis::setAutoSubTicks ( bool  on)
slot

Sets whether then number of sub ticks in one tick interval is determined automatically. This works, as long as the tick step mantissa is a multiple of 0.5 (which it is, when setAutoTickStep is enabled).
When on is set to false, you may set the sub tick count with setSubTickCount manually.

Definition at line 3428 of file qcustomplot.cc.

3429 {
3430  mAutoSubTicks = on;
3431 }
bool mAutoSubTicks
Definition: qcustomplot.h:856
void QCPAxis::setAutoTickCount ( int  approximateCount)
slot

When setAutoTickStep is true, approximateCount determines how many ticks should be generated in the visible range approximately.

Definition at line 3389 of file qcustomplot.cc.

3390 {
3391  mAutoTickCount = approximateCount;
3392 }
int mAutoTickCount
Definition: qcustomplot.h:853
void QCPAxis::setAutoTickLabels ( bool  on)
slot

Sets whether the tick labels are generated automatically depending on the tick label type (LTNumber or LTDateTime).

If on is set to false, you should provide the tick labels via setTickVectorLabels. (This is usually used in a combination with setAutoTicks set to false for complete control over tick positions and labels, e.g. when the ticks should be at multiples of pi and show n*pi as tick labels.)

Definition at line 3402 of file qcustomplot.cc.

3403 {
3404  mAutoTickLabels = on;
3405 }
bool mAutoTickLabels
Definition: qcustomplot.h:856
void QCPAxis::setAutoTicks ( bool  on)
slot

Sets whether the tick positions should be calculated automatically (either from an automatically generated tick step or a tick step provided manually via setTickStep, see setAutoTickStep).

If on is set to false, you must provide the tick positions manually via setTickVector. For these manual ticks you may let QCPAxis generate the appropriate labels automatically by setting/leaving setAutoTickLabels true. If you also wish to control the displayed labels manually, set setAutoTickLabels to false and provide the label strings with setTickVectorLabels.

Definition at line 3380 of file qcustomplot.cc.

3381 {
3382  mAutoTicks = on;
3383 }
bool mAutoTicks
Definition: qcustomplot.h:856
void QCPAxis::setAutoTickStep ( bool  on)
slot

Sets whether the tick step, i.e. the interval between two (major) ticks, is calculated automatically. If on is set to true, the axis finds a tick step that is reasonable for human readable plots. This means the tick step mantissa is chosen such that it's either a multiple of two or ends in 0.5. The number of ticks the algorithm aims for within the visible range can be set with setAutoTickCount. It's not guaranteed that this number of ticks is met exactly, but approximately within a tolerance of two or three.

If on is set to false, you may set the tick step manually with setTickStep.

Definition at line 3417 of file qcustomplot.cc.

3418 {
3419  mAutoTickStep = on;
3420 }
bool mAutoTickStep
Definition: qcustomplot.h:856
void QCPAxis::setAxisRect ( const QRect &  rect)
protected

Definition at line 3190 of file qcustomplot.cc.

3191 {
3192  mAxisRect = rect;
3193 }
QRect mAxisRect
Definition: qcustomplot.h:844
void QCPAxis::setAxisType ( AxisType  type)
protected

Definition at line 3177 of file qcustomplot.cc.

3178 {
3179  mAxisType = type;
3180  mOrientation = (type == ATBottom || type == ATTop) ? Qt::Horizontal : Qt::Vertical;
3181 }
Axis is horizontal and on the bottom side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:714
Qt::Orientation mOrientation
Definition: qcustomplot.h:866
Axis is horizontal and on the top side of the axis rect of the parent QCustomPlot.
Definition: qcustomplot.h:713
AxisType mAxisType
Definition: qcustomplot.h:849
void QCPAxis::setBasePen ( const QPen &  pen)
slot

Sets the pen, the axis base line itself is drawn with.

Definition at line 3710 of file qcustomplot.cc.

3711 {
3712  mBasePen = pen;
3713 }
QPen mBasePen
Definition: qcustomplot.h:845
void QCPAxis::setDateTimeFormat ( const QString &  format)
slot

Sets the format in which dates and times are displayed as tick labels, if setTickLabelType is LTDateTime. for details about the format string, see the documentation of QDateTime::toString(). Newlines can be inserted with "\n".

Definition at line 3497 of file qcustomplot.cc.

3498 {
3499  mDateTimeFormat = format;
3500 }
QString mDateTimeFormat
Definition: qcustomplot.h:842
void QCPAxis::setGrid ( bool  show)
slot

Sets whether the grid lines are visible.

See also
setSubGrid, setGridPen

Definition at line 3357 of file qcustomplot.cc.

3358 {
3359  mGrid = show;
3360 }
bool mGrid
Definition: qcustomplot.h:856
void QCPAxis::setGridPen ( const QPen &  pen)
slot

Sets the pen, grid lines are drawn with.

See also
setSubGridPen

Definition at line 3719 of file qcustomplot.cc.

3720 {
3721  mGridPen = pen;
3722 }
QPen mGridPen
Definition: qcustomplot.h:845
void QCPAxis::setLabel ( const QString &  str)
slot

Sets the axis label that will be shown below/above or next to the axis, depending on its orientation.

Definition at line 3775 of file qcustomplot.cc.

3776 {
3777  mLabel = str;
3778 }
QString mLabel
Definition: qcustomplot.h:843
void QCPAxis::setLabelFont ( const QFont &  font)
slot

Sets the font of the axis label.

Definition at line 3767 of file qcustomplot.cc.

3768 {
3769  mLabelFont = font;
3770 }
QFont mLabelFont
Definition: qcustomplot.h:846
void QCPAxis::setLabelPadding ( int  padding)
slot

Sets the distance between the tick labels and the axis label.

See also
setTickLabelPadding, setPadding

Definition at line 3784 of file qcustomplot.cc.

3785 {
3787 }
int padding() const
Definition: qcustomplot.h:782
int mLabelPadding
Definition: qcustomplot.h:854
void QCPAxis::setNumberFormat ( const QString &  formatCode)
slot

Sets the number format for the numbers drawn as tick labels (if tick label type is LTNumber). This formatCode is an extended version of the format code used e.g. by QString::number() and QLocale::toString(). For reference about that, see the "Argument Formats" section in the detailed description of the QString class. formatCode is a string of one, two or three characters. The first character is identical to the normal format code used by Qt. In short, this means: 'e'/'E' scientific format, 'f' fixed format, 'g'/'G' scientific or fixed, whichever is shorter.

The second and third characters are optional and specific to QCustomPlot:
If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. "5.5e9", which is ugly in a plot. So when the second char of formatCode is set to 'b' (for "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. If instead a cross should be shown (as is usual in the USA), the third char of formatCode can be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the cross and 183 (0xB7) for the dot.

If the scale type (setScaleType) is STLogarithmic and the formatCode uses the 'b' option (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10 [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]" part). To only display the decimal power, set the number precision to zero with setNumberPrecision.

Examples for formatCode:

  • g normal format code behaviour. If number is small, fixed format is used, if number is large, normal scientific format is used
  • gb If number is small, fixed format is used, if number is large, scientific format is used with beautifully typeset decimal powers and a dot as multiplication sign
  • ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as multiplication sign
  • fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal powers. Format code will be reduced to 'f'.
  • hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format code will not be changed.

Definition at line 3538 of file qcustomplot.cc.

3539 {
3540  if (formatCode.length() < 1) return;
3541 
3542  // interpret first char as number format char:
3543  QString allowedFormatChars = "eEfgG";
3544  if (allowedFormatChars.contains(formatCode.at(0)))
3545  {
3546  mNumberFormatChar = formatCode.at(0).toAscii();
3547  } else
3548  {
3549  qDebug() << FUNCNAME << "Invalid number format code (first char not in 'eEfgG'):" << formatCode;
3550  return;
3551  }
3552  if (formatCode.length() < 2)
3553  {
3554  mNumberBeautifulPowers = false;
3555  mNumberMultiplyCross = false;
3556  return;
3557  }
3558 
3559  // interpret second char as indicator for beautiful decimal powers:
3560  if (formatCode.at(1) == 'b' && (mNumberFormatChar == 'e' || mNumberFormatChar == 'g'))
3561  {
3562  mNumberBeautifulPowers = true;
3563  } else
3564  {
3565  qDebug() << FUNCNAME << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode;
3566  return;
3567  }
3568  if (formatCode.length() < 3)
3569  {
3570  mNumberMultiplyCross = false;
3571  return;
3572  }
3573 
3574  // interpret third char as indicator for dot or cross multiplication symbol:
3575  if (formatCode.at(2) == 'c')
3576  {
3577  mNumberMultiplyCross = true;
3578  } else if (formatCode.at(2) == 'd')
3579  {
3580  mNumberMultiplyCross = false;
3581  } else
3582  {
3583  qDebug() << FUNCNAME << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode;
3584  return;
3585  }
3586 }
bool mNumberBeautifulPowers
Definition: qcustomplot.h:865
bool mNumberMultiplyCross
Definition: qcustomplot.h:865
char mNumberFormatChar
Definition: qcustomplot.h:864
#define FUNCNAME
Definition: qcustomplot.h:50
void QCPAxis::setNumberPrecision ( int  precision)
slot

Sets the precision of the numbers drawn as tick labels. See QLocale::toString(double i, char f, int prec) for details. The effect of precisions are most notably for number Format starting with 'e', see setNumberFormat

If the scale type (setScaleType) is STLogarithmic and the number format (setNumberFormat) uses the 'b' format code (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10 [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]" part). To only display the decimal power, set precision to zero.

Definition at line 3599 of file qcustomplot.cc.

3600 {
3601  mNumberPrecision = precision;
3602 }
int mNumberPrecision
Definition: qcustomplot.h:863
void QCPAxis::setPadding ( int  padding)
slot

Sets the padding of the axis.

When QCustomPlot::setAutoMargin is enabled, the padding is the additional distance to the respective widget border, that is left blank. If padding is zero (default), the auto margin mechanism will find a margin that the axis label (or tick label, if no axis label is set) barely fits inside the QCustomPlot widget. To give the label closest to the border some freedom, increase padding.

The axis padding has no meaning if QCustomPlot::setAutoMargin is disabled.

See also
setLabelPadding, setTickLabelPadding

Definition at line 3802 of file qcustomplot.cc.

3803 {
3804  mPadding = padding;
3805 }
int padding() const
Definition: qcustomplot.h:782
int mPadding
Definition: qcustomplot.h:854
void QCPAxis::setRange ( double  lower,
double  upper 
)
slot

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the lower and upper bound of the axis range.

There is also a slot to set a range, see setRange(const QCPRange &range).

Definition at line 3259 of file qcustomplot.cc.

3260 {
3261  if (!QCPRange::validRange(lower, upper)) return;
3262  mRange.lower = lower;
3263  mRange.upper = upper;
3264  if (mScaleType == STLogarithmic)
3265  {
3267  } else
3268  {
3270  }
3271  emit rangeChanged(mRange);
3272 }
void rangeChanged(const QCPRange &newRange)
static bool validRange(double lower, double upper)
QCPRange sanitizedForLogScale() const
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPRange sanitizedForLinScale() const
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setRange ( double  position,
double  size,
Qt::AlignmentFlag  alignment 
)
slot

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

Parameters
positionthe position coordinate indicates together with the alignment parameter, where the new range will be positioned.
sizedefines the size (upper-lower) of the new axis range.
alignmentdetermines how position is to be interpreted.
If alignment is Qt::AlignLeft, position will be the lower bound of the range.
If alignment is Qt::AlignRight, position will be the upper bound of the range.
If alignment is Qt::AlignCenter, the new range will be centered around position.
Any other values for alignment will default to Qt::AlignCenter.

Definition at line 3287 of file qcustomplot.cc.

3288 {
3289  if (alignment == Qt::AlignLeft)
3290  setRange(position, position+size);
3291  else if (alignment == Qt::AlignRight)
3292  setRange(position-size, position);
3293  else // alignment == Qt::AlignCenter
3294  setRange(position-size/2.0, position+size/2.0);
3295 }
void setRange(double lower, double upper)
void QCPAxis::setRange ( const QCPRange range)
slot

Sets the range of the axis.

This slot may be connected with the rangeChanged signal of another axis in order for the ranges to be synchronized (in one direction).

To invert the direction of an axis range, use setRangeReversed.

Definition at line 3240 of file qcustomplot.cc.

3241 {
3242  if (!QCPRange::validRange(range)) return;
3243  if (mScaleType == STLogarithmic)
3244  {
3245  mRange = range.sanitizedForLogScale();
3246  } else
3247  {
3248  mRange = range.sanitizedForLinScale();
3249  }
3250  emit rangeChanged(mRange);
3251 }
void rangeChanged(const QCPRange &newRange)
static bool validRange(double lower, double upper)
QCPRange sanitizedForLogScale() const
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPRange sanitizedForLinScale() const
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setRangeLower ( double  lower)
slot

Sets the lower bound of the axis range, independently of the upper bound.

See also
setRange

Definition at line 3301 of file qcustomplot.cc.

3302 {
3303  mRange.lower = lower;
3304  if (mScaleType == STLogarithmic)
3305  {
3307  } else
3308  {
3310  }
3311  emit rangeChanged(mRange);
3312 }
void rangeChanged(const QCPRange &newRange)
QCPRange sanitizedForLogScale() const
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPRange sanitizedForLinScale() const
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setRangeReversed ( bool  reversed)
slot

Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal axes increase left to right, on vertical axes bottom to top. When reversed is set to true, the direction of increasing values is inverted. Note that the range and data interface stays the same for reversed axes, e.g. the lower part of the setRange interface will still reference the mathematically smaller number than the upper part.

Definition at line 3338 of file qcustomplot.cc.

3339 {
3340  mRangeReversed = reversed;
3341 }
bool mRangeReversed
Definition: qcustomplot.h:857
void QCPAxis::setRangeUpper ( double  upper)
slot

Sets the upper bound of the axis range, independently of the lower bound.

See also
setRange

Definition at line 3318 of file qcustomplot.cc.

3319 {
3320  mRange.upper = upper;
3321  if (mScaleType == STLogarithmic)
3322  {
3324  } else
3325  {
3327  }
3328  emit rangeChanged(mRange);
3329 }
void rangeChanged(const QCPRange &newRange)
QCPRange sanitizedForLogScale() const
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPRange sanitizedForLinScale() const
double upper
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setScaleLogBase ( double  base)
slot

If setScaleType is set to STLogarithmic, base will be the logarithm base of the scaling. In logarithmic axis scaling, major tick marks appear at all powers of base.

Properties like tick step (setTickStep) don't apply in logarithmic scaling. If you wish a decimal base but less major ticks, consider choosing base 100, 1000 or even higher.

Definition at line 3222 of file qcustomplot.cc.

3223 {
3224  if (base > 1)
3225  {
3226  mScaleLogBase = base;
3227  mScaleLogBaseLogInv = 1.0/log(mScaleLogBase); // buffer for faster baseLog() calculation
3228  } else
3229  qDebug() << FUNCNAME << "Invalid logarithmic scale base (must be greater 1):" << base;
3230 }
double mScaleLogBase
Definition: qcustomplot.h:851
double mScaleLogBaseLogInv
Definition: qcustomplot.h:851
#define FUNCNAME
Definition: qcustomplot.h:50
void QCPAxis::setScaleRatio ( const QCPAxis otherAxis,
double  ratio = 1.0 
)
slot

Sets the range of this axis to have a certain scale ratio to otherAxis. For example, if ratio is 1, this axis is the yAxis and otherAxis is xAxis, graphs plotted with those axes will appear in a 1:1 ratio, independent of the aspect ratio the axis rect has. This is an operation that changes the range of this axis once, it doesn't fix the scale ratio indefinitely. Consequently calling this function in the constructor won't have the desired effect, since the widget's dimensions aren't defined yet, and a resizeEvent will follow.

Definition at line 3866 of file qcustomplot.cc.

3867 {
3868  int otherPixelSize, ownPixelSize;
3869 
3870  if (otherAxis->orientation() == Qt::Horizontal)
3871  otherPixelSize = otherAxis->mAxisRect.width();
3872  else
3873  otherPixelSize = otherAxis->mAxisRect.height();
3874 
3875  if (orientation() == Qt::Horizontal)
3876  ownPixelSize = mAxisRect.width();
3877  else
3878  ownPixelSize = mAxisRect.height();
3879 
3880  double newRangeSize = ratio*otherAxis->mRange.size()*ownPixelSize/(double)otherPixelSize;
3881  setRange(range().center(), newRangeSize, Qt::AlignCenter);
3882 }
double size() const
const QCPRange range() const
Definition: qcustomplot.h:746
void setRange(double lower, double upper)
Qt::Orientation orientation() const
Definition: qcustomplot.h:827
QRect mAxisRect
Definition: qcustomplot.h:844
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setScaleType ( ScaleType  type)
slot

Sets whether the axis uses a linear scale or a logarithmic scale. If type is set to STLogarithmic, the logarithm base can be set with setScaleLogBase. In logarithmic axis scaling, major tick marks appear at all powers of the logarithm base. Properties like tick step (setTickStep) don't apply in logarithmic scaling. If you wish a decimal base but less major ticks, consider choosing a logarithm base of 100, 1000 or even higher.

If type is STLogarithmic and the number format (setNumberFormat) uses the 'b' option (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10 [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]" part). To only display the decimal power, set the number precision to zero with setNumberPrecision.

Definition at line 3208 of file qcustomplot.cc.

3209 {
3210  mScaleType = type;
3211  if (mScaleType == STLogarithmic)
3213 }
QCPRange sanitizedForLogScale() const
ScaleType mScaleType
Definition: qcustomplot.h:848
Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power...
Definition: qcustomplot.h:732
QCPRange mRange
Definition: qcustomplot.h:841
void QCPAxis::setSubGrid ( bool  show)
slot

Sets whether the sub grid lines are visible.

See also
setGrid, setSubGridPen

Definition at line 3366 of file qcustomplot.cc.

3367 {
3368  mSubGrid = show;
3369 }
bool mSubGrid
Definition: qcustomplot.h:856
void QCPAxis::setSubGridPen ( const QPen &  pen)
slot

Sets the pen, the sub grid lines are drawn with. (By default, subgrid drawing needs to be enabled first with setSubGrid.)

See also
setGridPen

Definition at line 3729 of file qcustomplot.cc.

3730 {
3731  mSubGridPen = pen;
3732 }
QPen mSubGridPen
Definition: qcustomplot.h:845
void QCPAxis::setSubTickCount ( int  count)
slot

Sets the number of sub ticks in one (major) tick step. A sub tick count of three for example, divides the tick intervals in four sub intervals.

By default, the number of sub ticks is chosen automatically in a reasonable manner as long as the mantissa of the tick step is a multiple of 0.5 (which it is, when setAutoTickStep is enabled). If you want to disable automatic sub ticks and use this function to set the count manually, see setAutoSubTicks.

Definition at line 3689 of file qcustomplot.cc.

3690 {
3691  mSubTickCount = count;
3692 }
int mSubTickCount
Definition: qcustomplot.h:852
void QCPAxis::setSubTickLength ( int  inside,
int  outside = 0 
)
slot

Sets the length of the subticks in pixels. inside is the length the subticks will reach inside the plot and outside is the length they will reach outside the plot. If outside is greater than zero, the tick labels will increase their distance to the axis accordingly, so they won't collide with the ticks.

See also
setTickLength

Definition at line 3701 of file qcustomplot.cc.

3702 {
3703  mSubTickLengthIn = inside;
3704  mSubTickLengthOut = outside;
3705 }
int mSubTickLengthIn
Definition: qcustomplot.h:852
int mSubTickLengthOut
Definition: qcustomplot.h:852
void QCPAxis::setSubTickPen ( const QPen &  pen)
slot

Sets the pen, subtick marks will be drawn with.

See also
setSubTickCount, setSubTickLength

Definition at line 3759 of file qcustomplot.cc.

3760 {
3761  mSubTickPen = pen;
3762 }
QPen mSubTickPen
Definition: qcustomplot.h:845
void QCPAxis::setTickLabelFont ( const QFont &  font)
slot

Sets the font of the tick labels, i.e. the numbers drawn next to tick marks.

Definition at line 3477 of file qcustomplot.cc.

3478 {
3479  mTickLabelFont = font;
3480 }
QFont mTickLabelFont
Definition: qcustomplot.h:846
void QCPAxis::setTickLabelPadding ( int  padding)
slot

Sets the distance between the axis base line (or any tick marks pointing outward) and the tick labels.

See also
setLabelPadding, setPadding

Definition at line 3454 of file qcustomplot.cc.

3455 {
3457 }
int padding() const
Definition: qcustomplot.h:782
int mTickLabelPadding
Definition: qcustomplot.h:854
void QCPAxis::setTickLabelRotation ( double  degrees)
slot

Sets the rotation of the tick labels, i.e. the numbers drawn next to tick marks. If degrees is zero, the labels are drawn normally. Else, the tick labels are drawn rotated by degrees clockwise. The specified angle is bound to values from -90 to 90 degrees.

Definition at line 3487 of file qcustomplot.cc.

3488 {
3489  mTickLabelRotation = qBound(-90.0, degrees, 90.0);
3490 }
double mTickLabelRotation
Definition: qcustomplot.h:855
void QCPAxis::setTickLabels ( bool  show)
slot

Sets whether tick labels are displayed.

Definition at line 3445 of file qcustomplot.cc.

3446 {
3447  mTickLabels = show;
3448 }
bool mTickLabels
Definition: qcustomplot.h:856
void QCPAxis::setTickLabelType ( LabelType  type)
slot

Sets whether the tick labels display numbers or dates/times.
If type is set to LTNumber, the format specifications of setNumberFormat apply.
If type is set to LTDateTime, the format specifications of setDateTimeFormat apply.
In QCustomPlot, date/time coordinates are double numbers representing the seconds since 1970-01-01T00:00:00 UTC. This format can be retrieved from QDateTime objects with the QDateTime::toTime_t() function. Since this only gives a resolution of one second, there is also the QDateTime::toMSecsSinceEpoch() function which returns the timespan described above in milliseconds. Divide its return value by 1000.0 to get a value with the format needed for date/time plotting, this time with a resolution of one millisecond.

Definition at line 3469 of file qcustomplot.cc.

3470 {
3471  mTickLabelType = type;
3472 }
LabelType mTickLabelType
Definition: qcustomplot.h:847
void QCPAxis::setTickLength ( int  inside,
int  outside = 0 
)
slot

Sets the length of the ticks in pixels. inside is the length the ticks will reach inside the plot and outside is the length they will reach outside the plot. If outside is greater than zero, the tick labels will increase their distance to the axis accordingly, so they won't collide with the ticks.

See also
setSubTickLength

Definition at line 3674 of file qcustomplot.cc.

3675 {
3676  mTickLengthIn = inside;
3677  mTickLengthOut = outside;
3678 }
int mTickLengthOut
Definition: qcustomplot.h:852
int mTickLengthIn
Definition: qcustomplot.h:852
void QCPAxis::setTickPen ( const QPen &  pen)
slot

Sets the pen, tick marks will be drawn with.

See also
setTickLength

Definition at line 3750 of file qcustomplot.cc.

3751 {
3752  mTickPen = pen;
3753 }
QPen mTickPen
Definition: qcustomplot.h:845
void QCPAxis::setTicks ( bool  show)
slot

Sets whether tick marks are displayed. Setting show to false does not imply, that tick labels are invisible, too. To achieve that, see setTickLabels.

Definition at line 3437 of file qcustomplot.cc.

3438 {
3439  mTicks = show;
3440 }
bool mTicks
Definition: qcustomplot.h:856
void QCPAxis::setTickStep ( double  step)
slot

If setAutoTickStep is set to false, use this function to set the tick step manually. The tick step is the interval between (major) ticks, in plot coordinates.

See also
setSubTickCount

Definition at line 3609 of file qcustomplot.cc.

3610 {
3611  mTickStep = step;
3612 }
double mTickStep
Definition: qcustomplot.h:850
void QCPAxis::setTickVector ( QVector< double > *  vec,
bool  copy = false 
)
slot

If you want full control over what ticks (and possibly labels) the axes show, this function is used to set the coordinates at which ticks will appear.setAutoTicks must be disabled, else the provided tick vector will be overwritten with automatically generated tick coordinates. The labels of the ticks can either be generated automatically when setAutoTickLabels is left enabled, or be set manually with setTickVectorLabels, when setAutoTickLabels is disabled.

Parameters
veca pointer to the vector containing the positions of the ticks
copyif this is set to true, the provided vec is copied to the internal tick vector. In this case, QCPAxis does not take ownership of vec. If it's set to false, the internal tick vector is deleted and replaced by vec, QCPAxis takes ownership of the vector memory vec points to. The latter might give slight performance benefits.
See also
setTickVectorLabels

Definition at line 3628 of file qcustomplot.cc.

3629 {
3630  if (copy)
3631  {
3632  *mTickVector = *vec;
3633  } else
3634  {
3635  delete mTickVector;
3636  mTickVector = vec;
3637  }
3638 }
QVector< double > * mTickVector
Definition: qcustomplot.h:839
void QCPAxis::setTickVectorLabels ( QVector< QString > *  vec,
bool  copy = false 
)
slot

If you want full control over what ticks and labels the axes show, this function is used to set a number of QStrings that will be displayed at the tick positions which you need to provide with setTickVector. These two vectors should have the same size. (Note that you need to disable setAutoTicks and setAutoTickLabels first.)

Parameters
veca pointer to the vector containing the labels of the ticks
copyif this is set to true, the provided vec is copied to the internal label vector. In this case QCPAxis does not take ownership of vec. If it's set to false, the internal label vector is deleted and replaced by vec, QCPAxis takes ownership of the vector memory vec points to. The latter might give slight performance benefits.
See also
setTickVector

Definition at line 3655 of file qcustomplot.cc.

3656 {
3657  if (copy)
3658  {
3659  *mTickVectorLabels = *vec;
3660  } else
3661  {
3662  delete mTickVectorLabels;
3663  mTickVectorLabels = vec;
3664  }
3665 }
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
void QCPAxis::setVisible ( bool  on)
slot

Sets whether the axis (including all its decoration, i.e. labels and grid lines) is visible. An invisible axis doesn't mean a non functional axis. Graphs attached to an invisible axis can still be plotted/moved/zoomed normally as if the axis was visible.

Definition at line 3348 of file qcustomplot.cc.

3349 {
3350  mVisible = on;
3351 }
bool mVisible
Definition: qcustomplot.h:856
void QCPAxis::setZeroLinePen ( const QPen &  pen)
slot

Sets the pen with which a single grid-like line will be drawn at value position zero. The line will be drawn instead of a grid line at that position, and not on top. To disable the drawing of a zero-line, set pen to Qt::NoPen. Then, if setGrid is enabled, a grid line will be drawn instead.

See also
setGrid, setGridPen

Definition at line 3741 of file qcustomplot.cc.

3742 {
3743  mZeroLinePen = pen;
3744 }
QPen mZeroLinePen
Definition: qcustomplot.h:845
bool QCPAxis::subGrid ( ) const
inlineslot

Definition at line 750 of file qcustomplot.h.

750 { return mSubGrid; }
bool mSubGrid
Definition: qcustomplot.h:856
QPen QCPAxis::subGridPen ( ) const
inlineslot

Definition at line 775 of file qcustomplot.h.

775 { return mSubGridPen; }
QPen mSubGridPen
Definition: qcustomplot.h:845
int QCPAxis::subTickCount ( ) const
inlineslot

Definition at line 770 of file qcustomplot.h.

770 { return mSubTickCount; }
int mSubTickCount
Definition: qcustomplot.h:852
int QCPAxis::subTickLengthIn ( ) const
inlineslot

Definition at line 771 of file qcustomplot.h.

771 { return mSubTickLengthIn; }
int mSubTickLengthIn
Definition: qcustomplot.h:852
int QCPAxis::subTickLengthOut ( ) const
inlineslot

Definition at line 772 of file qcustomplot.h.

772 { return mSubTickLengthOut; }
int mSubTickLengthOut
Definition: qcustomplot.h:852
QPen QCPAxis::subTickPen ( ) const
inlineslot

Definition at line 778 of file qcustomplot.h.

778 { return mSubTickPen; }
QPen mSubTickPen
Definition: qcustomplot.h:845
QFont QCPAxis::tickLabelFont ( ) const
inlineslot

Definition at line 760 of file qcustomplot.h.

760 { return mTickLabelFont; }
QFont mTickLabelFont
Definition: qcustomplot.h:846
int QCPAxis::tickLabelPadding ( ) const
inlineslot

Definition at line 758 of file qcustomplot.h.

758 { return mTickLabelPadding; }
int mTickLabelPadding
Definition: qcustomplot.h:854
double QCPAxis::tickLabelRotation ( ) const
inlineslot

Definition at line 761 of file qcustomplot.h.

761 { return mTickLabelRotation; }
double mTickLabelRotation
Definition: qcustomplot.h:855
bool QCPAxis::tickLabels ( ) const
inlineslot

Definition at line 757 of file qcustomplot.h.

757 { return mTickLabels; }
bool mTickLabels
Definition: qcustomplot.h:856
LabelType QCPAxis::tickLabelType ( ) const
inlineslot

Definition at line 759 of file qcustomplot.h.

759 { return mTickLabelType; }
LabelType mTickLabelType
Definition: qcustomplot.h:847
int QCPAxis::tickLengthIn ( ) const
inlineslot

Definition at line 768 of file qcustomplot.h.

768 { return mTickLengthIn; }
int mTickLengthIn
Definition: qcustomplot.h:852
int QCPAxis::tickLengthOut ( ) const
inlineslot

Definition at line 769 of file qcustomplot.h.

769 { return mTickLengthOut; }
int mTickLengthOut
Definition: qcustomplot.h:852
QPen QCPAxis::tickPen ( ) const
inlineslot

Definition at line 777 of file qcustomplot.h.

777 { return mTickPen; }
QPen mTickPen
Definition: qcustomplot.h:845
bool QCPAxis::ticks ( ) const
inlineslot

Definition at line 756 of file qcustomplot.h.

756 { return mTicks; }
bool mTicks
Definition: qcustomplot.h:856
void QCPAxis::ticksRequest ( )
signal
double QCPAxis::tickStep ( ) const
inlineslot

Definition at line 765 of file qcustomplot.h.

765 { return mTickStep; }
double mTickStep
Definition: qcustomplot.h:850
QVector<double>* QCPAxis::tickVector ( ) const
inlineslot

Definition at line 766 of file qcustomplot.h.

766 { return mTickVector; }
QVector< double > * mTickVector
Definition: qcustomplot.h:839
QVector<QString>* QCPAxis::tickVectorLabels ( ) const
inlineslot

Definition at line 767 of file qcustomplot.h.

767 { return mTickVectorLabels; }
QVector< QString > * mTickVectorLabels
Definition: qcustomplot.h:840
bool QCPAxis::visible ( ) const
inlineslot

Definition at line 748 of file qcustomplot.h.

748 { return mVisible; }
bool mVisible
Definition: qcustomplot.h:856
void QCPAxis::visibleTickBounds ( int &  lowIndex,
int &  highIndex 
) const
protected

Definition at line 4728 of file qcustomplot.cc.

4729 {
4730  lowIndex = 0;
4731  highIndex = -1;
4732  // make sure only ticks that are in visible range are returned
4733  for (int i=0; i < mTickVector->size(); ++i)
4734  {
4735  lowIndex = i;
4736  if (mTickVector->at(i) >= mRange.lower) break;
4737  }
4738  for (int i=mTickVector->size()-1; i >= 0; --i)
4739  {
4740  highIndex = i;
4741  if (mTickVector->at(i) <= mRange.upper) break;
4742  }
4743 }
QVector< double > * mTickVector
Definition: qcustomplot.h:839
double upper
Definition: qcustomplot.h:494
double lower
Definition: qcustomplot.h:494
QCPRange mRange
Definition: qcustomplot.h:841
QPen QCPAxis::zeroLinePen ( ) const
inlineslot

Definition at line 776 of file qcustomplot.h.

776 { return mZeroLinePen; }
QPen mZeroLinePen
Definition: qcustomplot.h:845

Friends And Related Function Documentation

friend class QCustomPlot
friend

Definition at line 892 of file qcustomplot.h.

Member Data Documentation

bool QCPAxis::mAutoSubTicks
protected

Definition at line 856 of file qcustomplot.h.

int QCPAxis::mAutoTickCount
protected

Definition at line 853 of file qcustomplot.h.

bool QCPAxis::mAutoTickLabels
protected

Definition at line 856 of file qcustomplot.h.

bool QCPAxis::mAutoTicks
protected

Definition at line 856 of file qcustomplot.h.

bool QCPAxis::mAutoTickStep
protected

Definition at line 856 of file qcustomplot.h.

QRect QCPAxis::mAxisRect
protected

Definition at line 844 of file qcustomplot.h.

AxisType QCPAxis::mAxisType
protected

Definition at line 849 of file qcustomplot.h.

QPen QCPAxis::mBasePen
protected

Definition at line 845 of file qcustomplot.h.

QString QCPAxis::mDateTimeFormat
protected

Definition at line 842 of file qcustomplot.h.

QChar QCPAxis::mExponentialChar
protected

Definition at line 862 of file qcustomplot.h.

bool QCPAxis::mGrid
protected

Definition at line 856 of file qcustomplot.h.

QPen QCPAxis::mGridPen
protected

Definition at line 845 of file qcustomplot.h.

QString QCPAxis::mLabel
protected

Definition at line 843 of file qcustomplot.h.

QFont QCPAxis::mLabelFont
protected

Definition at line 846 of file qcustomplot.h.

int QCPAxis::mLabelPadding
protected

Definition at line 854 of file qcustomplot.h.

bool QCPAxis::mNumberBeautifulPowers
protected

Definition at line 865 of file qcustomplot.h.

char QCPAxis::mNumberFormatChar
protected

Definition at line 864 of file qcustomplot.h.

bool QCPAxis::mNumberMultiplyCross
protected

Definition at line 865 of file qcustomplot.h.

int QCPAxis::mNumberPrecision
protected

Definition at line 863 of file qcustomplot.h.

Qt::Orientation QCPAxis::mOrientation
protected

Definition at line 866 of file qcustomplot.h.

int QCPAxis::mPadding
protected

Definition at line 854 of file qcustomplot.h.

QCustomPlot* QCPAxis::mParentPlot
protected

Definition at line 860 of file qcustomplot.h.

QChar QCPAxis::mPositiveSignChar
protected

Definition at line 862 of file qcustomplot.h.

QCPRange QCPAxis::mRange
protected

Definition at line 841 of file qcustomplot.h.

bool QCPAxis::mRangeReversed
protected

Definition at line 857 of file qcustomplot.h.

double QCPAxis::mScaleLogBase
protected

Definition at line 851 of file qcustomplot.h.

double QCPAxis::mScaleLogBaseLogInv
protected

Definition at line 851 of file qcustomplot.h.

ScaleType QCPAxis::mScaleType
protected

Definition at line 848 of file qcustomplot.h.

bool QCPAxis::mSubGrid
protected

Definition at line 856 of file qcustomplot.h.

QPen QCPAxis::mSubGridPen
protected

Definition at line 845 of file qcustomplot.h.

int QCPAxis::mSubTickCount
protected

Definition at line 852 of file qcustomplot.h.

int QCPAxis::mSubTickLengthIn
protected

Definition at line 852 of file qcustomplot.h.

int QCPAxis::mSubTickLengthOut
protected

Definition at line 852 of file qcustomplot.h.

QPen QCPAxis::mSubTickPen
protected

Definition at line 845 of file qcustomplot.h.

QVector<double>* QCPAxis::mSubTickVector
protected

Definition at line 861 of file qcustomplot.h.

QFont QCPAxis::mTickLabelFont
protected

Definition at line 846 of file qcustomplot.h.

int QCPAxis::mTickLabelPadding
protected

Definition at line 854 of file qcustomplot.h.

double QCPAxis::mTickLabelRotation
protected

Definition at line 855 of file qcustomplot.h.

bool QCPAxis::mTickLabels
protected

Definition at line 856 of file qcustomplot.h.

LabelType QCPAxis::mTickLabelType
protected

Definition at line 847 of file qcustomplot.h.

int QCPAxis::mTickLengthIn
protected

Definition at line 852 of file qcustomplot.h.

int QCPAxis::mTickLengthOut
protected

Definition at line 852 of file qcustomplot.h.

QPen QCPAxis::mTickPen
protected

Definition at line 845 of file qcustomplot.h.

bool QCPAxis::mTicks
protected

Definition at line 856 of file qcustomplot.h.

double QCPAxis::mTickStep
protected

Definition at line 850 of file qcustomplot.h.

QVector<double>* QCPAxis::mTickVector
protected

Definition at line 839 of file qcustomplot.h.

QVector<QString>* QCPAxis::mTickVectorLabels
protected

Definition at line 840 of file qcustomplot.h.

bool QCPAxis::mVisible
protected

Definition at line 856 of file qcustomplot.h.

QPen QCPAxis::mZeroLinePen
protected

Definition at line 845 of file qcustomplot.h.


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