2023-12-07 11:49:38 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
|
|
|
|
|
|
|
|
|
#ifndef AXISRENDERER_H
|
|
|
|
|
#define AXISRENDERER_H
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// W A R N I N G
|
|
|
|
|
// -------------
|
|
|
|
|
//
|
|
|
|
|
// This file is not part of the QtGraphs API. It exists purely as an
|
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
|
//
|
|
|
|
|
// We mean it.
|
|
|
|
|
|
|
|
|
|
#include <QQuickItem>
|
|
|
|
|
#include <QRectF>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QtQuick/private/qquicktext_p.h>
|
|
|
|
|
#include <private/axisgrid_p.h>
|
|
|
|
|
#include <private/axisticker_p.h>
|
|
|
|
|
#include <private/axisline_p.h>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
class QAbstractAxis;
|
|
|
|
|
class QGraphsView;
|
|
|
|
|
class QBarCategoryAxis;
|
|
|
|
|
class QValueAxis;
|
2024-01-29 09:50:10 +00:00
|
|
|
class QGraphTheme;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
class AxisRenderer : public QQuickItem
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
QML_ELEMENT
|
|
|
|
|
public:
|
|
|
|
|
AxisRenderer(QQuickItem *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void handlePolish();
|
|
|
|
|
void updateAxis();
|
|
|
|
|
void updateAxisTickers();
|
|
|
|
|
void updateAxisTickersShadow();
|
|
|
|
|
void updateAxisGrid();
|
|
|
|
|
void updateAxisGridShadow();
|
2024-03-15 06:24:27 +00:00
|
|
|
void updateAxisTitles(const QRectF &xAxisRect, const QRectF &yAxisRect);
|
2023-12-07 11:49:38 +00:00
|
|
|
void updateBarXAxisLabels(QBarCategoryAxis *axis, const QRectF &rect);
|
2024-03-22 17:30:35 +00:00
|
|
|
void updateBarYAxisLabels(QBarCategoryAxis *axis, const QRectF &rect);
|
2023-12-07 11:49:38 +00:00
|
|
|
void updateValueYAxisLabels(QValueAxis *axis, const QRectF &rect);
|
2024-01-24 15:24:58 +00:00
|
|
|
void updateValueXAxisLabels(QValueAxis *axis, const QRectF &rect);
|
2024-02-13 12:45:59 +00:00
|
|
|
void initialize();
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class QGraphsView;
|
|
|
|
|
friend class BarsRenderer;
|
|
|
|
|
friend class LinesRenderer;
|
|
|
|
|
friend class PointRenderer;
|
2024-02-27 08:49:34 +00:00
|
|
|
friend class AreaRenderer;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
2023-12-20 10:36:22 +00:00
|
|
|
double getValueStepsFromRange(double range);
|
|
|
|
|
int getValueDecimalsFromRange(double range);
|
2024-03-22 17:30:35 +00:00
|
|
|
void updateAxisLabelItems(QList<QQuickText *> &textItems, int neededSize);
|
2023-12-20 10:36:22 +00:00
|
|
|
|
2023-12-07 11:49:38 +00:00
|
|
|
QGraphsView *m_graph = nullptr;
|
2024-01-29 09:50:10 +00:00
|
|
|
QGraphTheme *theme();
|
2024-02-13 12:45:59 +00:00
|
|
|
bool m_initialized = false;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
QAbstractAxis *m_axisVertical = nullptr;
|
|
|
|
|
QAbstractAxis *m_axisHorizontal = nullptr;
|
|
|
|
|
QList<QQuickText *> m_xAxisTextItems;
|
|
|
|
|
QList<QQuickText *> m_yAxisTextItems;
|
2024-03-15 06:24:27 +00:00
|
|
|
QQuickText *m_xAxisTitle = nullptr;
|
|
|
|
|
QQuickText *m_yAxisTitle = nullptr;
|
2023-12-07 11:49:38 +00:00
|
|
|
AxisGrid *m_axisGrid = nullptr;
|
|
|
|
|
AxisTicker *m_axisTickerVertical = nullptr;
|
|
|
|
|
AxisTicker *m_axisTickerHorizontal = nullptr;
|
|
|
|
|
AxisLine *m_axisLineVertical = nullptr;
|
|
|
|
|
AxisLine *m_axisLineHorizontal = nullptr;
|
|
|
|
|
|
|
|
|
|
// Shadow
|
|
|
|
|
AxisGrid *m_axisGridShadow = nullptr;
|
|
|
|
|
AxisTicker *m_axisTickerVerticalShadow = nullptr;
|
|
|
|
|
AxisTicker *m_axisTickerHorizontalShadow = nullptr;
|
|
|
|
|
AxisLine *m_axisLineVerticalShadow = nullptr;
|
|
|
|
|
AxisLine *m_axisLineHorizontalShadow = nullptr;
|
|
|
|
|
|
2024-01-24 15:24:58 +00:00
|
|
|
// Vertical axis
|
2023-12-07 11:49:38 +00:00
|
|
|
// Max value
|
2024-01-24 15:24:58 +00:00
|
|
|
double m_axisVerticalMaxValue = 20;
|
|
|
|
|
// Min value
|
2023-12-07 11:49:38 +00:00
|
|
|
double m_axisVerticalMinValue = 0;
|
|
|
|
|
// Values range, so m_axisVerticalMaxValue - m_axisVerticalMinValue
|
|
|
|
|
double m_axisVerticalValueRange = 0;
|
2023-12-20 10:36:22 +00:00
|
|
|
// How much each major value step is
|
|
|
|
|
double m_axisVerticalValueStep = 1.0;
|
2023-12-07 11:49:38 +00:00
|
|
|
// px between major ticks
|
2023-12-20 10:36:22 +00:00
|
|
|
double m_axisVerticalStepPx = 0;
|
2023-12-07 11:49:38 +00:00
|
|
|
// Ticks movement, between -m_axisHorizontalStepPx .. m_axisHorizontalStepPx.
|
|
|
|
|
double m_axisYMovement = 0;
|
2023-12-20 10:36:22 +00:00
|
|
|
// The value of smallest label
|
|
|
|
|
double m_axisVerticalMinLabel = 0;
|
|
|
|
|
|
2024-01-24 15:24:58 +00:00
|
|
|
|
|
|
|
|
// Horizontal axis
|
|
|
|
|
// Max value
|
|
|
|
|
double m_axisHorizontalMaxValue = 20;
|
|
|
|
|
// Min value
|
2023-12-07 11:49:38 +00:00
|
|
|
double m_axisHorizontalMinValue = 0;
|
2024-01-24 15:24:58 +00:00
|
|
|
// Values range, so m_axisHorizontalMaxValue - m_axisHorizontalMinValue
|
|
|
|
|
double m_axisHorizontalValueRange = 0;
|
|
|
|
|
// How much each major value step is
|
|
|
|
|
double m_axisHorizontalValueStep = 1.0;
|
|
|
|
|
// px between major ticks
|
|
|
|
|
double m_axisHorizontalStepPx = 0;
|
|
|
|
|
// Ticks movement, between -m_axisHorizontalStepPx .. m_axisHorizontalStepPx.
|
|
|
|
|
double m_axisXMovement = 0;
|
|
|
|
|
// The value of smallest label
|
|
|
|
|
double m_axisHorizontalMinLabel = 0;
|
|
|
|
|
|
2023-12-07 11:49:38 +00:00
|
|
|
double m_axisVerticalMinorTickScale = 0.5;
|
|
|
|
|
double m_axisHorizontalMinorTickScale = 0.5;
|
|
|
|
|
bool m_gridHorizontalMajorTicksVisible = true;
|
|
|
|
|
bool m_gridVerticalMajorTicksVisible = true;
|
|
|
|
|
bool m_gridHorizontalMinorTicksVisible = false;
|
|
|
|
|
bool m_gridVerticalMinorTicksVisible = false;
|
|
|
|
|
|
|
|
|
|
// Sizes required of axis labels
|
|
|
|
|
// TODO: Should these come from QAbstactAxis?
|
|
|
|
|
qreal m_axisWidth = 40;
|
2024-01-24 15:24:58 +00:00
|
|
|
qreal m_axisHeight = 40;
|
2023-12-07 11:49:38 +00:00
|
|
|
qreal m_axisTickersWidth = 15;
|
|
|
|
|
qreal m_axisTickersHeight = 15;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
#endif // AXISRENDERER_H
|