Main Page · Class Overview · Hierarchy · All Classes · Special Pages
Public Types | Public Functions | Signals | Static Public Functions | Protected Functions
QCPAxis Class Reference

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

Inheritance diagram for QCPAxis:
Inheritance graph

Public Types

enum  AxisType
 
enum  LabelSide
 
enum  ScaleType
 
enum  SelectablePart
 

Public Functions

 QCPAxis (QCPAxisRect *parent, AxisType type)
 
AxisType axisType () const
 
QCPAxisRectaxisRect () const
 
ScaleType scaleType () const
 
const QCPRange range () const
 
bool rangeReversed () const
 
QSharedPointer< QCPAxisTickerticker () const
 
bool ticks () const
 
bool tickLabels () const
 
int tickLabelPadding () const
 
QFont tickLabelFont () const
 
QColor tickLabelColor () const
 
double tickLabelRotation () const
 
LabelSide tickLabelSide () const
 
QString numberFormat () const
 
int numberPrecision () const
 
QVector< double > tickVector () const
 
QVector< QString > tickVectorLabels () const
 
int tickLengthIn () const
 
int tickLengthOut () const
 
bool subTicks () const
 
int subTickLengthIn () const
 
int subTickLengthOut () const
 
QPen basePen () const
 
QPen tickPen () const
 
QPen subTickPen () const
 
QFont labelFont () const
 
QColor labelColor () const
 
QString label () const
 
int labelPadding () const
 
int padding () const
 
int offset () const
 
SelectableParts selectedParts () const
 
SelectableParts selectableParts () const
 
QFont selectedTickLabelFont () const
 
QFont selectedLabelFont () const
 
QColor selectedTickLabelColor () const
 
QColor selectedLabelColor () const
 
QPen selectedBasePen () const
 
QPen selectedTickPen () const
 
QPen selectedSubTickPen () const
 
QCPLineEnding lowerEnding () const
 
QCPLineEnding upperEnding () const
 
QCPGridgrid () const
 
Q_SLOT void setScaleType (QCPAxis::ScaleType type)
 
Q_SLOT void setRange (const QCPRange &range)
 
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 setTicker (QSharedPointer< QCPAxisTicker > ticker)
 
void setTicks (bool show)
 
void setTickLabels (bool show)
 
void setTickLabelPadding (int padding)
 
void setTickLabelFont (const QFont &font)
 
void setTickLabelColor (const QColor &color)
 
void setTickLabelRotation (double degrees)
 
void setTickLabelSide (LabelSide side)
 
void setNumberFormat (const QString &formatCode)
 
void setNumberPrecision (int precision)
 
void setTickLength (int inside, int outside=0)
 
void setTickLengthIn (int inside)
 
void setTickLengthOut (int outside)
 
void setSubTicks (bool show)
 
void setSubTickLength (int inside, int outside=0)
 
void setSubTickLengthIn (int inside)
 
void setSubTickLengthOut (int outside)
 
void setBasePen (const QPen &pen)
 
void setTickPen (const QPen &pen)
 
void setSubTickPen (const QPen &pen)
 
void setLabelFont (const QFont &font)
 
void setLabelColor (const QColor &color)
 
void setLabel (const QString &str)
 
void setLabelPadding (int padding)
 
void setPadding (int padding)
 
void setOffset (int offset)
 
void setSelectedTickLabelFont (const QFont &font)
 
void setSelectedLabelFont (const QFont &font)
 
void setSelectedTickLabelColor (const QColor &color)
 
void setSelectedLabelColor (const QColor &color)
 
void setSelectedBasePen (const QPen &pen)
 
void setSelectedTickPen (const QPen &pen)
 
void setSelectedSubTickPen (const QPen &pen)
 
Q_SLOT void setSelectableParts (const QCPAxis::SelectableParts &selectableParts)
 
Q_SLOT void setSelectedParts (const QCPAxis::SelectableParts &selectedParts)
 
void setLowerEnding (const QCPLineEnding &ending)
 
void setUpperEnding (const QCPLineEnding &ending)
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
 
Qt::Orientation orientation () const
 
int pixelOrientation () const
 
void moveRange (double diff)
 
void scaleRange (double factor)
 
void scaleRange (double factor, double center)
 
void setScaleRatio (const QCPAxis *otherAxis, double ratio=1.0)
 
void rescale (bool onlyVisiblePlottables=false)
 
double pixelToCoord (double value) const
 
double coordToPixel (double value) const
 
SelectablePart getPartAt (const QPointF &pos) const
 
QList< QCPAbstractPlottable * > plottables () const
 
QList< QCPGraph * > graphs () const
 
QList< QCPAbstractItem * > items () const
 
- Public Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0)
 
bool visible () const
 
QCustomPlotparentPlot () const
 
QCPLayerableparentLayerable () const
 
QCPLayerlayer () const
 
bool antialiased () const
 
void setVisible (bool on)
 
Q_SLOT bool setLayer (QCPLayer *layer)
 
bool setLayer (const QString &layerName)
 
void setAntialiased (bool enabled)
 
bool realVisibility () const
 

Signals

void rangeChanged (const QCPRange &newRange)
 
void rangeChanged (const QCPRange &newRange, const QCPRange &oldRange)
 
void scaleTypeChanged (QCPAxis::ScaleType scaleType)
 
void selectionChanged (const QCPAxis::SelectableParts &parts)
 
void selectableChanged (const QCPAxis::SelectableParts &parts)
 
- Signals inherited from QCPLayerable
void layerChanged (QCPLayer *newLayer)
 

Static Public Functions

static AxisType marginSideToAxisType (QCP::MarginSide side)
 
static Qt::Orientation orientation (AxisType type)
 
static AxisType opposite (AxisType type)
 

Protected Functions

virtual int calculateMargin ()
 
virtual void applyDefaultAntialiasingHint (QCPPainter *painter) const
 
virtual void draw (QCPPainter *painter)
 
virtual QCP::Interaction selectionCategory () const
 
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
 
virtual void deselectEvent (bool *selectionStateChanged)
 
void setupTickVectors ()
 
QPen getBasePen () const
 
QPen getTickPen () const
 
QPen getSubTickPen () const
 
QFont getTickLabelFont () const
 
QFont getLabelFont () const
 
QColor getTickLabelColor () const
 
QColor getLabelColor () const
 
- Protected Functions inherited from QCPLayerable
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
 
virtual QRect clipRect () const
 
virtual void mousePressEvent (QMouseEvent *event, const QVariant &details)
 
virtual void mouseMoveEvent (QMouseEvent *event, const QPointF &startPos)
 
virtual void mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details)
 
virtual void wheelEvent (QWheelEvent *event)
 
void initializeParentPlot (QCustomPlot *parentPlot)
 
void setParentLayerable (QCPLayerable *parentLayerable)
 
bool moveToLayer (QCPLayer *layer, bool prepend)
 
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const
 

Detailed Description

Manages a single axis inside a QCustomPlot.

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

Axes are always part of an axis rect, see QCPAxisRect.

AxisNamesOverview.png
Naming convention of axis parts


AxisRectSpacingOverview.png
Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line on the left represents the QCustomPlot widget border.

Each axis holds an instance of QCPAxisTicker which is used to generate the tick coordinates and tick labels. You can access the currently installed ticker or set a new one (possibly one of the specialized subclasses, or your own subclass) via setTicker. For details, see the documentation of QCPAxisTicker.

Member Enumeration Documentation

§ AxisType

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.

Enumerator
atLeft 

0x01 Axis is vertical and on the left side of the axis rect

atRight 

0x02 Axis is vertical and on the right side of the axis rect

atTop 

0x04 Axis is horizontal and on the top side of the axis rect

atBottom 

0x08 Axis is horizontal and on the bottom side of the axis rect

§ LabelSide

Defines on which side of the axis the tick labels (numbers) shall appear.

See also
setTickLabelSide
Enumerator
lsInside 

Tick labels will be displayed inside the axis rect and clipped to the inner axis rect.

lsOutside 

Tick labels will be displayed outside the axis rect.

§ ScaleType

Defines the scale of an axis.

See also
setScaleType
Enumerator
stLinear 

Linear scaling.

stLogarithmic 

Logarithmic scaling with correspondingly transformed axis coordinates (possibly also setTicker to a QCPAxisTickerLog instance).

§ SelectablePart

Defines the selectable parts of an axis.

See also
setSelectableParts, setSelectedParts
Enumerator
spNone 

None of the selectable parts.

spAxis 

The axis backbone and tick marks.

spTickLabels 

Tick labels (numbers) of this axis (as a whole, not individually)

spAxisLabel 

The axis label.

Constructor & Destructor Documentation

§ QCPAxis()

QCPAxis::QCPAxis ( QCPAxisRect parent,
AxisType  type 
)
explicit

Constructs an Axis instance of Type type for the axis rect parent.

Usually it isn't necessary to instantiate axes directly, because you can let QCustomPlot create them for you with QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, create them manually and then inject them also via QCPAxisRect::addAxis.

Member Function Documentation

§ ticker()

QSharedPointer< QCPAxisTicker > QCPAxis::ticker ( ) const
inline

Returns a modifiable shared pointer to the currently installed axis ticker. The axis ticker is responsible for generating the tick positions and tick labels of this axis. You can access the QCPAxisTicker with this method and modify basic properties such as the approximate tick count (QCPAxisTicker::setTickCount).

You can gain more control over the axis ticks by setting a different QCPAxisTicker subclass, see the documentation there. A new axis ticker can be set with setTicker.

Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis ticker simply by passing the same shared pointer to multiple axes.

See also
setTicker

§ grid()

QCPGrid * QCPAxis::grid ( ) const
inline

Returns the QCPGrid instance belonging to this axis. Access it to set details about the way the grid is displayed.

§ setScaleType()

void QCPAxis::setScaleType ( QCPAxis::ScaleType  type)

Sets whether the axis uses a linear scale or a logarithmic scale.

Note that this method controls the coordinate transformation. You will likely also want to use a logarithmic tick spacing and labeling, which can be achieved by setting an instance of QCPAxisTickerLog via setTicker. See the documentation of QCPAxisTickerLog about the details of logarithmic axis tick creation.

setNumberPrecision

§ setRange() [1/3]

void QCPAxis::setRange ( const QCPRange range)

Sets the range of the axis.

This slot may be connected with the rangeChanged signal of another axis so this axis is always synchronized with the other axis range, when it changes.

To invert the direction of an axis, use setRangeReversed.

§ setRange() [2/3]

void QCPAxis::setRange ( double  lower,
double  upper 
)

This is an overloaded function.

Sets the lower and upper bound of the axis range.

To invert the direction of an axis, use setRangeReversed.

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

§ setRange() [3/3]

void QCPAxis::setRange ( double  position,
double  size,
Qt::AlignmentFlag  alignment 
)

This is an overloaded function.

Sets the range of the axis.

The position coordinate indicates together with the alignment parameter, where the new range will be positioned. size defines the size of the new axis range. alignment may be Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, or center of the range to be aligned with position. Any other values of alignment will default to Qt::AlignCenter.

§ setRangeLower()

void QCPAxis::setRangeLower ( double  lower)

Sets the lower bound of the axis range. The upper bound is not changed.

See also
setRange

§ setRangeUpper()

void QCPAxis::setRangeUpper ( double  upper)

Sets the upper bound of the axis range. The lower bound is not changed.

See also
setRange

§ setRangeReversed()

void QCPAxis::setRangeReversed ( bool  reversed)

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.

§ setTicker()

void QCPAxis::setTicker ( QSharedPointer< QCPAxisTicker ticker)

The axis ticker is responsible for generating the tick positions and tick labels. See the documentation of QCPAxisTicker for details on how to work with axis tickers.

You can change the tick positioning/labeling behaviour of this axis by setting a different QCPAxisTicker subclass using this method. If you only wish to modify the currently installed axis ticker, access it via ticker.

Since the ticker is stored in the axis as a shared pointer, multiple axes may share the same axis ticker simply by passing the same shared pointer to multiple axes.

See also
ticker

§ setTicks()

void QCPAxis::setTicks ( bool  show)

Sets whether tick marks are displayed.

Note that setting show to false does not imply that tick labels are invisible, too. To achieve that, see setTickLabels.

See also
setSubTicks

§ setTickLabels()

void QCPAxis::setTickLabels ( bool  show)

Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks.

§ setTickLabelPadding()

void QCPAxis::setTickLabelPadding ( int  padding)

Sets the distance between the axis base line (including any outward ticks) and the tick labels.

See also
setLabelPadding, setPadding

§ setTickLabelFont()

void QCPAxis::setTickLabelFont ( const QFont &  font)

Sets the font of the tick labels.

See also
setTickLabels, setTickLabelColor

§ setTickLabelColor()

void QCPAxis::setTickLabelColor ( const QColor &  color)

Sets the color of the tick labels.

See also
setTickLabels, setTickLabelFont

§ setTickLabelRotation()

void QCPAxis::setTickLabelRotation ( double  degrees)

Sets the rotation of the tick labels. 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.

If degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For other angles, the label is drawn with an offset such that it seems to point toward or away from the tick mark.

§ setTickLabelSide()

void QCPAxis::setTickLabelSide ( LabelSide  side)

Sets whether the tick labels (numbers) shall appear inside or outside the axis rect.

The usual and default setting is lsOutside. Very compact plots sometimes require tick labels to be inside the axis rect, to save space. If side is set to lsInside, the tick labels appear on the inside are additionally clipped to the axis rect.

§ setNumberFormat()

void QCPAxis::setNumberFormat ( const QString &  formatCode)

Sets the number format for the numbers in tick labels. 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.

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.

§ setNumberPrecision()

void QCPAxis::setNumberPrecision ( int  precision)

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

§ setTickLength()

void QCPAxis::setTickLength ( int  inside,
int  outside = 0 
)

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 and axis label will increase their distance to the axis accordingly, so they won't collide with the ticks.

See also
setSubTickLength, setTickLengthIn, setTickLengthOut

§ setTickLengthIn()

void QCPAxis::setTickLengthIn ( int  inside)

Sets the length of the inward ticks in pixels. inside is the length the ticks will reach inside the plot.

See also
setTickLengthOut, setTickLength, setSubTickLength

§ setTickLengthOut()

void QCPAxis::setTickLengthOut ( int  outside)

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

See also
setTickLengthIn, setTickLength, setSubTickLength

§ setSubTicks()

void QCPAxis::setSubTicks ( bool  show)

Sets whether sub tick marks are displayed.

Sub ticks are only potentially visible if (major) ticks are also visible (see setTicks)

See also
setTicks

§ setSubTickLength()

void QCPAxis::setSubTickLength ( int  inside,
int  outside = 0 
)

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 and axis label will increase their distance to the axis accordingly, so they won't collide with the ticks.

See also
setTickLength, setSubTickLengthIn, setSubTickLengthOut

§ setSubTickLengthIn()

void QCPAxis::setSubTickLengthIn ( int  inside)

Sets the length of the inward subticks in pixels. inside is the length the subticks will reach inside the plot.

See also
setSubTickLengthOut, setSubTickLength, setTickLength

§ setSubTickLengthOut()

void QCPAxis::setSubTickLengthOut ( int  outside)

Sets the length of the outward subticks in pixels. outside is the length the subticks 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
setSubTickLengthIn, setSubTickLength, setTickLength

§ setBasePen()

void QCPAxis::setBasePen ( const QPen &  pen)

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

See also
setTickPen, setSubTickPen

§ setTickPen()

void QCPAxis::setTickPen ( const QPen &  pen)

Sets the pen, tick marks will be drawn with.

See also
setTickLength, setBasePen

§ setSubTickPen()

void QCPAxis::setSubTickPen ( const QPen &  pen)

Sets the pen, subtick marks will be drawn with.

See also
setSubTickCount, setSubTickLength, setBasePen

§ setLabelFont()

void QCPAxis::setLabelFont ( const QFont &  font)

Sets the font of the axis label.

See also
setLabelColor

§ setLabelColor()

void QCPAxis::setLabelColor ( const QColor &  color)

Sets the color of the axis label.

See also
setLabelFont

§ setLabel()

void QCPAxis::setLabel ( const QString &  str)

Sets the text of the axis label that will be shown below/above or next to the axis, depending on its orientation. To disable axis labels, pass an empty string as str.

§ setLabelPadding()

void QCPAxis::setLabelPadding ( int  padding)

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

See also
setTickLabelPadding, setPadding

§ setPadding()

void QCPAxis::setPadding ( int  padding)

Sets the padding of the axis.

When QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, that is left blank.

The axis padding has no meaning if QCPAxisRect::setAutoMargins is disabled.

See also
setLabelPadding, setTickLabelPadding

§ setOffset()

void QCPAxis::setOffset ( int  offset)

Sets the offset the axis has to its axis rect side.

If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, only the offset of the inner most axis has meaning (even if it is set to be invisible). The offset of the other, outer axes is controlled automatically, to place them at appropriate positions.

§ setSelectedTickLabelFont()

void QCPAxis::setSelectedTickLabelFont ( const QFont &  font)

Sets the font that is used for tick labels when they are selected.

See also
setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedLabelFont()

void QCPAxis::setSelectedLabelFont ( const QFont &  font)

Sets the font that is used for the axis label when it is selected.

See also
setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedTickLabelColor()

void QCPAxis::setSelectedTickLabelColor ( const QColor &  color)

Sets the color that is used for tick labels when they are selected.

See also
setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedLabelColor()

void QCPAxis::setSelectedLabelColor ( const QColor &  color)

Sets the color that is used for the axis label when it is selected.

See also
setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedBasePen()

void QCPAxis::setSelectedBasePen ( const QPen &  pen)

Sets the pen that is used to draw the axis base line when selected.

See also
setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedTickPen()

void QCPAxis::setSelectedTickPen ( const QPen &  pen)

Sets the pen that is used to draw the (major) ticks when selected.

See also
setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectedSubTickPen()

void QCPAxis::setSelectedSubTickPen ( const QPen &  pen)

Sets the pen that is used to draw the subticks when selected.

See also
setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions

§ setSelectableParts()

void QCPAxis::setSelectableParts ( const QCPAxis::SelectableParts &  selectableParts)

Sets whether the user can (de-)select the parts in selectable by clicking on the QCustomPlot surface. (When QCustomPlot::setInteractions contains iSelectAxes.)

However, even when selectable is set to a value not allowing the selection of a specific part, it is still possible to set the selection of this part manually, by calling setSelectedParts directly.

See also
SelectablePart, setSelectedParts

§ setSelectedParts()

void QCPAxis::setSelectedParts ( const QCPAxis::SelectableParts &  selectedParts)

Sets the selected state of the respective axis parts described by SelectablePart. When a part is selected, it uses a different pen/font.

The entire selection mechanism for axes is handled automatically when QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you wish to change the selection state manually.

This function can change the selection state of a part, independent of the setSelectableParts setting.

emits the selectionChanged signal when selected is different from the previous selection state.

See also
SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor

§ setLowerEnding()

void QCPAxis::setLowerEnding ( const QCPLineEnding ending)

Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available styles.

For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. Note that this meaning does not change when the axis range is reversed with setRangeReversed.

See also
setUpperEnding

§ setUpperEnding()

void QCPAxis::setUpperEnding ( const QCPLineEnding ending)

Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available styles.

For horizontal axes, this method refers to the right ending, for vertical axes the top ending. Note that this meaning does not change when the axis range is reversed with setRangeReversed.

See also
setLowerEnding

§ selectTest()

double QCPAxis::selectTest ( const QPointF &  pos,
bool  onlySelectable,
QVariant *  details = 0 
) const
virtual

This function is used to decide whether a click hits a layerable object or not.

pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the shortest pixel distance of this point to the object. If the object is either invisible or the distance couldn't be determined, -1.0 is returned. Further, if onlySelectable is true and the object is not selectable, -1.0 is returned, too.

If the object is represented not by single lines but by an area like a QCPItemText or the bars of a QCPBars plottable, a click inside the area should also be considered a hit. In these cases this function thus returns a constant value greater zero but still below the parent plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99).

Providing a constant value for area objects allows selecting line objects even when they are obscured by such area objects, by clicking close to the lines (i.e. closer than 0.99*selectionTolerance).

The actual setting of the selection state is not done by this function. This is handled by the parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified via the selectEvent/deselectEvent methods.

details is an optional output parameter. Every layerable subclass may place any information in details. This information will be passed to selectEvent when the parent QCustomPlot decides on the basis of this selectTest call, that the object was successfully selected. The subsequent call to selectEvent will carry the details. This is useful for multi-part objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked is only done once in selectTest. The result (i.e. the actually clicked part) can then be placed in details. So in the subsequent selectEvent, the decision which part was selected doesn't have to be done a second time for a single selection operation.

You may pass 0 as details to indicate that you are not interested in those selection details.

See also
selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions

Reimplemented from QCPLayerable.

§ orientation() [1/2]

Qt::Orientation QCPAxis::orientation ( ) const
inline

Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced from the axis type (left, top, right or bottom).

See also
orientation(AxisType type), pixelOrientation

§ pixelOrientation()

int QCPAxis::pixelOrientation ( ) const
inline

Returns which direction points towards higher coordinate values/keys, in pixel space.

This method returns either 1 or -1. If it returns 1, then going in the positive direction along the orientation of the axis in pixels corresponds to going from lower to higher axis coordinates. On the other hand, if this method returns -1, going to smaller pixel values corresponds to going from lower to higher axis coordinates.

For example, this is useful to easily shift axis coordinates by a certain amount given in pixels, without having to care about reversed or vertically aligned axes:

double newKey = keyAxis->pixelToCoord(keyAxis->coordToPixel(oldKey)+10*keyAxis->pixelOrientation());

newKey will then contain a key that is ten pixels towards higher keys, starting from oldKey.

§ moveRange()

void QCPAxis::moveRange ( double  diff)

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).

§ scaleRange() [1/2]

void QCPAxis::scaleRange ( double  factor)

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

If you wish to scale around a different coordinate than the current axis range center, use the overload scaleRange(double factor, double center).

§ scaleRange() [2/2]

void QCPAxis::scaleRange ( double  factor,
double  center 
)

This is an overloaded function.

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 its position in the QCustomPlot widget (i.e. coordinates around 1.0 will have moved symmetrically closer to 1.0).

See also
scaleRange(double factor)

§ setScaleRatio()

void QCPAxis::setScaleRatio ( const QCPAxis otherAxis,
double  ratio = 1.0 
)

Scales the range of this axis to have a certain scale ratio to otherAxis. The scaling will be done around the center of the current axis range.

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 aspect 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. Note that calling this function in the constructor of the QCustomPlot's parent won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent will follow.

§ rescale()

void QCPAxis::rescale ( bool  onlyVisiblePlottables = false)

Changes the axis range such that all plottables associated with this axis are fully visible in that dimension.

See also
QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes

§ pixelToCoord()

double QCPAxis::pixelToCoord ( double  value) const

Transforms value, in pixel coordinates of the QCustomPlot widget, to axis coordinates.

§ coordToPixel()

double QCPAxis::coordToPixel ( double  value) const

Transforms value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget.

§ getPartAt()

QCPAxis::SelectablePart QCPAxis::getPartAt ( const QPointF &  pos) const

Returns the part of the axis that is hit by pos (in pixels). The return value of this function is independent of the user-selectable parts defined with setSelectableParts. Further, this function does not change the current selection state of the axis.

If the axis is not visible (setVisible), this function always returns spNone.

See also
setSelectedParts, setSelectableParts, QCustomPlot::setInteractions

§ plottables()

QList< QCPAbstractPlottable * > QCPAxis::plottables ( ) const

Returns a list of all the plottables that have this axis as key or value axis.

If you are only interested in plottables of type QCPGraph, see graphs.

See also
graphs, items

§ graphs()

QList< QCPGraph * > QCPAxis::graphs ( ) const

Returns a list of all the graphs that have this axis as key or value axis.

See also
plottables, items

§ items()

QList< QCPAbstractItem * > QCPAxis::items ( ) const

Returns a list of all the items that are associated with this axis. An item is considered associated with an axis if at least one of its positions uses the axis as key or value axis.

See also
plottables, graphs

§ marginSideToAxisType()

QCPAxis::AxisType QCPAxis::marginSideToAxisType ( QCP::MarginSide  side)
static

Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.)

§ orientation() [2/2]

static Qt::Orientation QCPAxis::orientation ( AxisType  type)
inlinestatic

Returns the orientation of the specified axis type

See also
orientation(), pixelOrientation

§ opposite()

QCPAxis::AxisType QCPAxis::opposite ( QCPAxis::AxisType  type)
static

Returns the axis type that describes the opposite axis of an axis with the specified type.

§ rangeChanged [1/2]

void QCPAxis::rangeChanged ( const QCPRange newRange)
signal

This signal is emitted when the range of this axis has changed. You can connect it to the setRange slot of another axis to communicate the new range to the other axis, in order for it to be synchronized.

You may also manipulate/correct the range with setRange in a slot connected to this signal. This is useful if for example a maximum range span shall not be exceeded, or if the lower/upper range shouldn't go beyond certain values (see QCPRange::bounded). For example, the following slot would limit the x axis to ranges between 0 and 10:

customPlot->xAxis->setRange(newRange.bounded(0, 10))

§ rangeChanged [2/2]

void QCPAxis::rangeChanged ( const QCPRange newRange,
const QCPRange oldRange 
)
signal

This is an overloaded function.

Additionally to the new range, this signal also provides the previous range held by the axis as oldRange.

§ scaleTypeChanged

void QCPAxis::scaleTypeChanged ( QCPAxis::ScaleType  scaleType)
signal

This signal is emitted when the scale type changes, by calls to setScaleType

§ selectionChanged

void QCPAxis::selectionChanged ( const QCPAxis::SelectableParts &  parts)
signal

This signal is emitted when the selection state of this axis has changed, either by user interaction or by a direct call to setSelectedParts.

§ selectableChanged

void QCPAxis::selectableChanged ( const QCPAxis::SelectableParts &  parts)
signal

This signal is emitted when the selectability changes, by calls to setSelectableParts

§ calculateMargin()

int QCPAxis::calculateMargin ( )
protectedvirtual

Returns the appropriate outward margin for this axis. It is needed if QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type atLeft will return an appropriate left margin, atBottom will return an appropriate bottom margin and so forth. For the calculation, this function goes through similar steps as draw, so changing one function likely requires the modification of the other one as well.

The margin consists of the outward tick length, tick label padding, tick label size, label padding, label size, and padding.

The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. unchanged are very fast.

§ applyDefaultAntialiasingHint()

void QCPAxis::applyDefaultAntialiasingHint ( QCPPainter painter) const
protectedvirtual

A convenience function to easily set the QPainter::Antialiased hint on the provided painter before drawing axis lines.

This is the antialiasing state the painter passed to the draw method is in by default.

This function takes into account the local setting of the antialiasing flag as well as the overrides set with QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.

For general information about this virtual method, see the base class implementation.

See also
setAntialiased

Implements QCPLayerable.

§ draw()

void QCPAxis::draw ( QCPPainter painter)
protectedvirtual

Draws the axis with the specified painter, using the internal QCPAxisPainterPrivate instance.

For general information about this virtual method, see the base class implementation.

Implements QCPLayerable.

§ selectionCategory()

QCP::Interaction QCPAxis::selectionCategory ( ) const
protectedvirtual

Returns the selection category this layerable shall belong to. The selection category is used in conjunction with QCustomPlot::setInteractions to control which objects are selectable and which aren't.

Subclasses that don't fit any of the normal QCP::Interaction values can use QCP::iSelectOther. This is what the default implementation returns.

See also
QCustomPlot::setInteractions

Reimplemented from QCPLayerable.

§ selectEvent()

void QCPAxis::selectEvent ( QMouseEvent *  event,
bool  additive,
const QVariant &  details,
bool *  selectionStateChanged 
)
protectedvirtual

This event is called when the layerable shall be selected, as a consequence of a click by the user. Subclasses should react to it by setting their selection state appropriately. The default implementation does nothing.

event is the mouse event that caused the selection. additive indicates, whether the user was holding the multi-select-modifier while performing the selection (see QCustomPlot::setMultiSelectModifier). if additive is true, the selection state must be toggled (i.e. become selected when unselected and unselected when selected).

Every selectEvent is preceded by a call to selectTest, which has returned positively (i.e. returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). The details data you output from selectTest is fed back via details here. You may use it to transport any kind of information from the selectTest to the possibly subsequent selectEvent. Usually details is used to transfer which part was clicked, if it is a layerable that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need to do the calculation again to find out which part was actually clicked.

selectionStateChanged is an output parameter. If the pointer is non-null, this function must set the value either to true or false, depending on whether the selection state of this layerable was actually changed. For layerables that only are selectable as a whole and not in parts, this is simple: if additive is true, selectionStateChanged must also be set to true, because the selection toggles. If additive is false, selectionStateChanged is only set to true, if the layerable was previously unselected and now is switched to the selected state.

See also
selectTest, deselectEvent

Reimplemented from QCPLayerable.

§ deselectEvent()

void QCPAxis::deselectEvent ( bool *  selectionStateChanged)
protectedvirtual

This event is called when the layerable shall be deselected, either as consequence of a user interaction or a call to QCustomPlot::deselectAll. Subclasses should react to it by unsetting their selection appropriately.

just as in selectEvent, the output parameter selectionStateChanged (if non-null), must return true or false when the selection state of this layerable has changed or not changed, respectively.

See also
selectTest, selectEvent

Reimplemented from QCPLayerable.

§ setupTickVectors()

void QCPAxis::setupTickVectors ( )
protected

Prepares the internal tick vector, sub tick vector and tick label vector. This is done by calling QCPAxisTicker::generate on the currently installed ticker.

If a change in the label text/count is detected, the cached axis margin is invalidated to make sure the next margin calculation recalculates the label sizes and returns an up-to-date value.

§ getBasePen()

QPen QCPAxis::getBasePen ( ) const
protected

Returns the pen that is used to draw the axis base line. Depending on the selection state, this is either mSelectedBasePen or mBasePen.

§ getTickPen()

QPen QCPAxis::getTickPen ( ) const
protected

Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this is either mSelectedTickPen or mTickPen.

§ getSubTickPen()

QPen QCPAxis::getSubTickPen ( ) const
protected

Returns the pen that is used to draw the subticks. Depending on the selection state, this is either mSelectedSubTickPen or mSubTickPen.

§ getTickLabelFont()

QFont QCPAxis::getTickLabelFont ( ) const
protected

Returns the font that is used to draw the tick labels. Depending on the selection state, this is either mSelectedTickLabelFont or mTickLabelFont.

§ getLabelFont()

QFont QCPAxis::getLabelFont ( ) const
protected

Returns the font that is used to draw the axis label. Depending on the selection state, this is either mSelectedLabelFont or mLabelFont.

§ getTickLabelColor()

QColor QCPAxis::getTickLabelColor ( ) const
protected

Returns the color that is used to draw the tick labels. Depending on the selection state, this is either mSelectedTickLabelColor or mTickLabelColor.

§ getLabelColor()

QColor QCPAxis::getLabelColor ( ) const
protected

Returns the color that is used to draw the axis label. Depending on the selection state, this is either mSelectedLabelColor or mLabelColor.


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