Search for usage in LXR

Inheritance diagram for QCPAxisTicker:

Public Types

enum  TickStepStrategy { tssReadability , tssMeetTickCount }

Public Member Functions

 QCPAxisTicker ()
virtual void generate (const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector< double > &ticks, QVector< double > *subTicks, QVector< QString > *tickLabels)
void setTickCount (int count)
void setTickOrigin (double origin)
void setTickStepStrategy (TickStepStrategy strategy)
int tickCount () const
double tickOrigin () const
TickStepStrategy tickStepStrategy () const

Protected Member Functions

double cleanMantissa (double input) const
virtual QVector< QStringcreateLabelVector (const QVector< double > &ticks, const QLocale &locale, QChar formatChar, int precision)
virtual QVector< double > createSubTickVector (int subTickCount, const QVector< double > &ticks)
virtual QVector< double > createTickVector (double tickStep, const QCPRange &range)
double getMantissa (double input, double *magnitude=nullptr) const
virtual int getSubTickCount (double tickStep)
virtual QString getTickLabel (double tick, const QLocale &locale, QChar formatChar, int precision)
virtual double getTickStep (const QCPRange &range)
double pickClosest (double target, const QVector< double > &candidates) const
void trimTicks (const QCPRange &range, QVector< double > &ticks, bool keepOneOutlier) const

Protected Attributes

int mTickCount
double mTickOrigin
TickStepStrategy mTickStepStrategy

Detailed Description

The base class tick generator used by QCPAxis to create tick positions and tick labels.

Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions and tick labels for the current axis range. The ticker of an axis can be set via QCPAxis::setTicker. Since that method takes a QSharedPointer<QCPAxisTicker>, multiple axes can share the same ticker instance.

This base class generates normal tick coordinates and numeric labels for linear axes. It picks a reasonable tick step (the separation between ticks) which results in readable tick labels. The number of ticks that should be approximately generated can be set via setTickCount. Depending on the current tick step strategy (setTickStepStrategy), the algorithm either sacrifices readability to better match the specified tick count (QCPAxisTicker::tssMeetTickCount) or relaxes the tick count in favor of better tick steps (QCPAxisTicker::tssReadability), which is the default.

The following more specialized axis ticker subclasses are available, see details in the respective class documentation:


Creating own axis tickers

Creating own axis tickers can be achieved very easily by sublassing QCPAxisTicker and reimplementing some or all of the available virtual methods.

In the simplest case you might wish to just generate different tick steps than the other tickers, so you only reimplement the method getTickStep. If you additionally want control over the string that will be shown as tick label, reimplement getTickLabel.

If you wish to have complete control, you can generate the tick vectors and tick label vectors yourself by reimplementing createTickVector and createLabelVector. The default implementations use the previously mentioned virtual methods getTickStep and getTickLabel, but your reimplementations don't necessarily need to do so. For example in the case of unequal tick steps, the method getTickStep loses its usefulness and can be ignored.

The sub tick count between major ticks can be controlled with getSubTickCount. Full sub tick placement control is obtained by reimplementing createSubTickVector.

See the documentation of all these virtual methods in QCPAxisTicker for detailed information about the parameters and expected return values.

Definition at line 1675 of file qcustomplot.h.

Member Enumeration Documentation

◆ TickStepStrategy

Defines the strategies that the axis ticker may follow when choosing the size of the tick step.

See also

A nicely readable tick step is prioritized over matching the requested number of ticks (see setTickCount)


Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count.

Definition at line 1684 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPAxisTicker()

QCPAxisTicker::QCPAxisTicker ( )

Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker.

Definition at line 6102 of file qcustomplot.cpp.

◆ ~QCPAxisTicker()

QCPAxisTicker::~QCPAxisTicker ( )

Definition at line 6109 of file qcustomplot.cpp.

Member Function Documentation

◆ cleanMantissa()

double QCPAxisTicker::cleanMantissa ( double input) const

Returns a number that is close to input but has a clean, easier human readable mantissa. How strongly the mantissa is altered, and thus how strong the result deviates from the original input, depends on the current tick step strategy (see setTickStepStrategy).

Definition at line 6435 of file qcustomplot.cpp.

◆ createLabelVector()

QVector< QString > QCPAxisTicker::createLabelVector ( const QVector< double > & ticks,
const QLocale & locale,
QChar formatChar,
int precision )

Returns a vector containing all tick label strings corresponding to the tick coordinates provided in ticks. The default implementation calls getTickLabel to generate the respective strings.

It is possible but uncommon for QCPAxisTicker subclasses to reimplement this method, as reimplementing getTickLabel often achieves the intended result easier.

Definition at line 6344 of file qcustomplot.cpp.

◆ createSubTickVector()

QVector< double > QCPAxisTicker::createSubTickVector ( int subTickCount,
const QVector< double > & ticks )

Returns a vector containing all coordinates of sub ticks that should be drawn. It generates subTickCount sub ticks between each tick pair given in ticks.

If a QCPAxisTicker subclass needs maximal control over the generated sub ticks, it should reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to base its result on subTickCount or ticks.

Definition at line 6290 of file qcustomplot.cpp.

◆ createTickVector()

QVector< double > QCPAxisTicker::createTickVector ( double tickStep,
const QCPRange & range )

Returns a vector containing all coordinates of ticks that should be drawn. The default implementation generates ticks with a spacing of tickStep (mathematically starting at the tick step origin, see setTickOrigin) distributed over the passed range.

In order for the axis ticker to generate proper sub ticks, it is necessary that the first and last tick coordinates returned by this method are just below/above the provided range. Otherwise the outer intervals won't contain any sub ticks.

If a QCPAxisTicker subclass needs maximal control over the generated ticks, it should reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to base its result on tickStep, e.g. when the ticks are spaced unequally like in the case of QCPAxisTickerLog.

Reimplemented in QCPAxisTickerDateTime, QCPAxisTickerText, and QCPAxisTickerLog.

Definition at line 6321 of file qcustomplot.cpp.

◆ generate()

void QCPAxisTicker::generate ( const QCPRange & range,
const QLocale & locale,
QChar formatChar,
int precision,
QVector< double > & ticks,
QVector< double > * subTicks,
QVector< QString > * tickLabels )

This is the method called by QCPAxis in order to actually generate tick coordinates (ticks), tick label strings (tickLabels) and sub tick coordinates (subTicks).

The ticks are generated for the specified range. The generated labels typically follow the specified locale, formatChar and number precision, however this might be different (or even irrelevant) for certain QCPAxisTicker subclasses.

The output parameter ticks is filled with the generated tick positions in axis coordinates. The output parameters subTicks and tickLabels are optional (set them to nullptr if not needed) and are respectively filled with sub tick coordinates, and tick label strings belonging to ticks by index.

Definition at line 6165 of file qcustomplot.cpp.

◆ getMantissa()

double QCPAxisTicker::getMantissa ( double input,
double * magnitude = nullptr ) const

Returns the decimal mantissa of input. Optionally, if magnitude is not set to zero, it also returns the magnitude of input as a power of 10.

For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100.

Definition at line 6422 of file qcustomplot.cpp.

◆ getSubTickCount()

int QCPAxisTicker::getSubTickCount ( double tickStep)

Takes the tickStep, i.e. the distance between two consecutive ticks, and returns an appropriate number of sub ticks for that specific tick step.

Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections.

Reimplemented in QCPAxisTickerDateTime, QCPAxisTickerTime, QCPAxisTickerText, QCPAxisTickerPi, and QCPAxisTickerLog.

Definition at line 6213 of file qcustomplot.cpp.

◆ getTickLabel()

QString QCPAxisTicker::getTickLabel ( double tick,
const QLocale & locale,
QChar formatChar,
int precision )

This method returns the tick label string as it should be printed under the tick coordinate. If a textual number is returned, it should respect the provided locale, formatChar and precision.

If the returned value contains exponentials of the form "2e5" and beautifully typeset powers is enabled in the QCPAxis number format (QCPAxis::setNumberFormat), the exponential part will be formatted accordingly using multiplication symbol and superscript during rendering of the label automatically.

Reimplemented in QCPAxisTickerDateTime, QCPAxisTickerTime, QCPAxisTickerText, and QCPAxisTickerPi.

Definition at line 6276 of file qcustomplot.cpp.

◆ getTickStep()

double QCPAxisTicker::getTickStep ( const QCPRange & range)

Takes the entire currently visible axis range and returns a sensible tick step in order to provide readable tick labels as well as a reasonable number of tick counts (see setTickCount, setTickStepStrategy).

If a QCPAxisTicker subclass only wants a different tick step behaviour than the default implementation, it should reimplement this method. See cleanMantissa for a possible helper function.

Reimplemented in QCPAxisTickerDateTime, QCPAxisTickerTime, QCPAxisTickerFixed, QCPAxisTickerText, and QCPAxisTickerPi.

Definition at line 6200 of file qcustomplot.cpp.

◆ pickClosest()

double QCPAxisTicker::pickClosest ( double target,
const QVector< double > & candidates ) const

Returns the coordinate contained in candidates which is closest to the provided target.

This method assumes candidates is not empty and sorted in ascending order.

Definition at line 6402 of file qcustomplot.cpp.

◆ setTickCount()

void QCPAxisTicker::setTickCount ( int count)

Sets how many ticks this ticker shall aim to generate across the axis range. Note that count is not guaranteed to be matched exactly, as generating readable tick intervals may conflict with the requested number of ticks.

Whether the readability has priority over meeting the requested count can be specified with setTickStepStrategy.

Definition at line 6131 of file qcustomplot.cpp.

◆ setTickOrigin()

void QCPAxisTicker::setTickOrigin ( double origin)

Sets the mathematical coordinate (or "offset") of the zeroth tick. This tick coordinate is just a concept and doesn't need to be inside the currently visible axis range.

By default origin is zero, which for example yields ticks {-5, 0, 5, 10, 15,...} when the tick step is five. If origin is now set to 1 instead, the correspondingly generated ticks would be {-4, 1, 6, 11, 16,...}.

Definition at line 6147 of file qcustomplot.cpp.

◆ setTickStepStrategy()

void QCPAxisTicker::setTickStepStrategy ( QCPAxisTicker::TickStepStrategy strategy)

Sets which strategy the axis ticker follows when choosing the size of the tick step. For the available strategies, see TickStepStrategy.

Definition at line 6118 of file qcustomplot.cpp.

◆ tickCount()

int QCPAxisTicker::tickCount ( ) const

Definition at line 1696 of file qcustomplot.h.

◆ tickOrigin()

double QCPAxisTicker::tickOrigin ( ) const

Definition at line 1697 of file qcustomplot.h.

◆ tickStepStrategy()

TickStepStrategy QCPAxisTicker::tickStepStrategy ( ) const

Definition at line 1695 of file qcustomplot.h.

◆ trimTicks()

void QCPAxisTicker::trimTicks ( const QCPRange & range,
QVector< double > & ticks,
bool keepOneOutlier ) const

Removes tick coordinates from ticks which lie outside the specified range. If keepOneOutlier is true, it preserves one tick just outside the range on both sides, if present.

The passed ticks must be sorted in ascending order.

Definition at line 6360 of file qcustomplot.cpp.

Member Data Documentation

◆ mTickCount

int QCPAxisTicker::mTickCount

Definition at line 1710 of file qcustomplot.h.

◆ mTickOrigin

double QCPAxisTicker::mTickOrigin

Definition at line 1711 of file qcustomplot.h.

◆ mTickStepStrategy

TickStepStrategy QCPAxisTicker::mTickStepStrategy

Definition at line 1709 of file qcustomplot.h.

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.