SimCenterCommon
Common functionality used within different SimCenter projects
QCPAxisTicker Class Reference

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

#include <qcustomplot.h>

Inheritance diagram for QCPAxisTicker:

Public Types

enum  TickStepStrategy { tssReadability, tssMeetTickCount }
 

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

TickStepStrategy mTickStepStrategy
 
int mTickCount
 
double mTickOrigin
 

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:

QCPAxisTickerFixed
axisticker-fixed.png
QCPAxisTickerLog
axisticker-log.png
QCPAxisTickerPi
axisticker-pi.png
QCPAxisTickerText
axisticker-text.png
QCPAxisTickerDateTime
axisticker-datetime.png
QCPAxisTickerTime
axisticker-time.png
axisticker-time2.png

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 1511 of file qcustomplot.h.

Member Enumeration Documentation

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

See also
setTickStepStrategy
Enumerator
tssReadability 

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

tssMeetTickCount 

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

Definition at line 1520 of file qcustomplot.h.

Constructor & Destructor Documentation

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 5372 of file qcustomplot.cpp.

QCPAxisTicker::~QCPAxisTicker ( )
virtual

Definition at line 5379 of file qcustomplot.cpp.

Member Function Documentation

double QCPAxisTicker::cleanMantissa ( double  input) const
protected

Definition at line 5705 of file qcustomplot.cpp.

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

Definition at line 5614 of file qcustomplot.cpp.

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

Definition at line 5560 of file qcustomplot.cpp.

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

Reimplemented in QCPAxisTickerLog, QCPAxisTickerText, and QCPAxisTickerDateTime.

Definition at line 5591 of file qcustomplot.cpp.

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

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 0 if not needed) and are respectively filled with sub tick coordinates, and tick label strings belonging to ticks by index.

Definition at line 5435 of file qcustomplot.cpp.

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

Definition at line 5692 of file qcustomplot.cpp.

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

Reimplemented in QCPAxisTickerPi, QCPAxisTickerText, QCPAxisTickerTime, and QCPAxisTickerDateTime.

Definition at line 5546 of file qcustomplot.cpp.

double QCPAxisTicker::getTickStep ( const QCPRange range)
protectedvirtual
double QCPAxisTicker::pickClosest ( double  target,
const QVector< double > &  candidates 
) const
protected

Definition at line 5672 of file qcustomplot.cpp.

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 5401 of file qcustomplot.cpp.

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 5417 of file qcustomplot.cpp.

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 5388 of file qcustomplot.cpp.

int QCPAxisTicker::tickCount ( ) const
inline

Definition at line 1532 of file qcustomplot.h.

double QCPAxisTicker::tickOrigin ( ) const
inline

Definition at line 1533 of file qcustomplot.h.

TickStepStrategy QCPAxisTicker::tickStepStrategy ( ) const
inline

Definition at line 1531 of file qcustomplot.h.

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

Definition at line 5630 of file qcustomplot.cpp.

Member Data Documentation

int QCPAxisTicker::mTickCount
protected

Definition at line 1546 of file qcustomplot.h.

double QCPAxisTicker::mTickOrigin
protected

Definition at line 1547 of file qcustomplot.h.

TickStepStrategy QCPAxisTicker::mTickStepStrategy
protected

Definition at line 1545 of file qcustomplot.h.


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