Class AxisEqualizer

Inheritance Relationships

Base Type

  • public QObject

Class Documentation

class AxisEqualizer : public QObject

Helper QML element to ensure that axes of a plot have equal scaling.

AxisEqualizer has properties that inform on the bounding box of the data series in a plot area. It is useful in connection with QtChart plots, to automatically resize axes ranges to enforce equal scaling of axes.

Public Functions

explicit AxisEqualizer(QObject *parent = nullptr)

Constructor.

Connects signals boundingBoxChanged() and plotAreaChanged() to slot calculateEqualAxes().

Parameters

parent[in] QObject pointer.

virtual ~AxisEqualizer()

Destructor.

QPointF bboxX() const

Property accessor for data bounding box x-axis range.

QPointF bboxY() const

Property accessor for data bounding box y-axis range.

QPointF equalAxisX() const

Property accessor for equal x-axis range.

QPointF equalAxisY() const

Property accessor for equal y-axis range.

QRectF plotArea() const

Property accessor for plot area.

Public Slots

void registerBox(const QString &seriesName, const QPointF &xR, const QPointF &yR)

Register x and y ranges for a data series.

This function registers a data series’ x-range and y-range. These ranges signifies the bounding box of a data series. All registered ranges are used when updating the global bounding box. This function is typically called when the range of a data series changes, and the plotting region potentially needs to be updated.

Parameters
  • seriesName[in] Name of the data series to register or update.

  • xR[in] x-axis value range.

  • yR[in] y-axis value range.

void calculateEqualAxes()

Calculates axes scaling to get an equal scaling of axis for the plot area.

Given the bounding box and plot area, this function calculates axes ranges to ensure that the scaling of each axis is the same.

void evaluateBoundingBox()

Evaluate bounding box ranges bboxX bboxY.

Iterates over all data series that are registered wit registerBox() and finds the bounding box that contains all the data series. Conditionally emits bondingBoxChanged().

void setPlotArea(QRectF plotArea)

Sets the plot area member variable.

Parameters

plotArea[in] Given as a QRectF.

Signals

void boundingBoxChanged(QPointF bboxX, QPointF bboxY)

Signal triggered when the bounding box has changed.

The bounds are ranges for a given axis as a QPointF, which x() being minimum, and y() maximum.

Parameters
  • bboxX[out] Range of x-axis.

  • bboxY[out] Range of y-axis.

void equalAxisChanged(QPointF axisX, QPointF axisY)

Signal triggered when on of the equal axes ranges have changed.

The bounds are ranges for a given axis as a QPointF, which x() being minimum, and y() maximum.

Parameters
  • axisX[out] Range of x-axis.

  • axisY[out] Range of y-axis.

void plotAreaChanged(QRectF plotArea)

Signal triggered when the plot area has changed.

The plot area is given as a QRectF. It is typically connected to a chart’s plotArea, such as ChartView::plotArea.

Parameters

plotArea[out] Region within which chart is drawn.

Properties

QPointF bboxX

Value range of the data points along the x-axis.

QPointF bboxY

Value range of the data points along the y-axis.

QPointF equalAxisX

Value range for an equal axis scaling, x-axis.

QPointF equalAxisY

Value range for an equal axis scaling, y-axis.

QRectF plotArea

Plot area is a QRectF specifying a drawable region on screen.

Protected Attributes

std::map<QString, std::pair<QPointF, QPointF>> m_ranges

Data structure to hold value ranges for two axes of a named data series. Set with registerBox().

std::pair<QPointF, QPointF> m_bbox

Global bounding box ranges.

std::pair<QPointF, QPointF> m_equalAxes

Equal axes ranges.

QRectF m_plotArea

Plot area.