Specialized axis ticker which allows arbitrary labels at specified coordinates. More...
Public Functions | |
QCPAxisTickerText () | |
QMap< double, QString > & | ticks () |
int | subTickCount () const |
void | setTicks (const QMap< double, QString > &ticks) |
void | setTicks (const QVector< double > &positions, const QVector< QString > &labels) |
void | setSubTickCount (int subTicks) |
void | clear () |
void | addTick (double position, const QString &label) |
void | addTicks (const QMap< double, QString > &ticks) |
void | addTicks (const QVector< double > &positions, const QVector< QString > &labels) |
QMap< double, QString > & | ticks () |
int | subTickCount () const |
void | setTicks (const QMap< double, QString > &ticks) |
void | setTicks (const QVector< double > &positions, const QVector< QString > &labels) |
void | setSubTickCount (int subTicks) |
void | clear () |
void | addTick (double position, const QString &label) |
void | addTicks (const QMap< double, QString > &ticks) |
void | addTicks (const QVector< double > &positions, const QVector< QString > &labels) |
![]() | |
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) |
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 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 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 |
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 |
Additional Inherited Members | |
![]() | |
enum | TickStepStrategy |
enum | TickStepStrategy |
Specialized axis ticker which allows arbitrary labels at specified coordinates.
This QCPAxisTicker subclass generates ticks which can be directly specified by the user as coordinates and associated strings. They can be passed as a whole with setTicks or one at a time with addTick. Alternatively you can directly access the internal storage via ticks and modify the tick/label data there.
This is useful for cases where the axis represents categories rather than numerical values.
If you are updating the ticks of this ticker regularly and in a dynamic fasion (e.g. dependent on the axis range), it is a sign that you should probably create an own ticker by subclassing QCPAxisTicker, instead of using this one.
The ticker can be created and assigned to an axis like this:
QCPAxisTickerText::QCPAxisTickerText | ( | ) |
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.
|
inline |
Returns a non-const reference to the internal map which stores the tick coordinates and their labels.
You can access the map directly in order to add, remove or manipulate ticks, as an alternative to using the methods provided by QCPAxisTickerText, such as setTicks and addTick.
void QCPAxisTickerText::setTicks | ( | const QMap< double, QString > & | ticks | ) |
This is an overloaded function.
Sets the ticks that shall appear on the axis. The map key of ticks corresponds to the axis coordinate, and the map value is the string that will appear as tick label.
An alternative to manipulate ticks is to directly access the internal storage with the ticks getter.
void QCPAxisTickerText::setTicks | ( | const QVector< double > & | positions, |
const QVector< QString > & | labels | ||
) |
void QCPAxisTickerText::setSubTickCount | ( | int | subTicks | ) |
Sets the number of sub ticks that shall appear between ticks. For QCPAxisTickerText, there is no automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this method.
void QCPAxisTickerText::clear | ( | ) |
void QCPAxisTickerText::addTick | ( | double | position, |
const QString & | label | ||
) |
void QCPAxisTickerText::addTicks | ( | const QMap< double, QString > & | ticks | ) |
This is an overloaded function.
Adds the provided ticks to the ones already existing. The map key of ticks corresponds to the axis coordinate, and the map value is the string that will appear as tick label.
An alternative to manipulate ticks is to directly access the internal storage with the ticks getter.
void QCPAxisTickerText::addTicks | ( | const QVector< double > & | positions, |
const QVector< QString > & | labels | ||
) |
This is an overloaded function.
Adds the provided ticks to the ones already existing. The entries of positions correspond to the axis coordinates, and the entries of labels are the respective strings that will appear as tick labels.
An alternative to manipulate ticks is to directly access the internal storage with the ticks getter.
|
protectedvirtual |
Since the tick coordinates are provided externally, this method implementation does nothing.
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Returns the sub tick count that was configured with setSubTickCount.
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Returns the tick label which corresponds to the key tick in the internal tick storage. Since the labels are provided externally, locale, formatChar, and precision are ignored.
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
Returns the externally provided tick coordinates which are in the specified range. If available, one tick above and below the range is provided in addition, to allow possible sub tick calculation. The parameter tickStep is ignored.
For general information about this virtual method, see the base class implementation.
Reimplemented from QCPAxisTicker.
|
protectedvirtual |
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 from QCPAxisTicker.
|
protectedvirtual |
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 from QCPAxisTicker.
|
protectedvirtual |
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 from QCPAxisTicker.
|
protectedvirtual |
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 from QCPAxisTicker.