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-04-16 13:40:26 +00:00
|
|
|
class QGraphsTheme;
|
2024-04-16 12:07:38 +00:00
|
|
|
class QDateTimeAxis;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
class AxisRenderer : public QQuickItem
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
AxisRenderer(QQuickItem *parent = nullptr);
|
2024-07-11 10:55:50 +00:00
|
|
|
~AxisRenderer() override;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
void handlePolish();
|
|
|
|
|
void updateAxis();
|
|
|
|
|
void updateAxisTickers();
|
|
|
|
|
void updateAxisTickersShadow();
|
|
|
|
|
void updateAxisGrid();
|
|
|
|
|
void updateAxisGridShadow();
|
2024-07-23 09:51:05 +00:00
|
|
|
void updateAxisTitles(const QRectF xAxisRect, const QRectF yAxisRect);
|
2024-09-18 10:03:52 +00:00
|
|
|
#ifdef USE_BARGRAPH
|
2024-07-23 09:51:05 +00:00
|
|
|
void updateBarXAxisLabels(QBarCategoryAxis *axis, const QRectF rect);
|
|
|
|
|
void updateBarYAxisLabels(QBarCategoryAxis *axis, const QRectF rect);
|
2024-09-18 10:03:52 +00:00
|
|
|
#endif
|
2024-07-23 09:51:05 +00:00
|
|
|
void updateValueYAxisLabels(QValueAxis *axis, const QRectF rect);
|
|
|
|
|
void updateValueXAxisLabels(QValueAxis *axis, const QRectF rect);
|
|
|
|
|
void updateDateTimeYAxisLabels(QDateTimeAxis *axis, const QRectF rect);
|
|
|
|
|
void updateDateTimeXAxisLabels(QDateTimeAxis *axis, const QRectF rect);
|
2024-02-13 12:45:59 +00:00
|
|
|
void initialize();
|
2023-12-07 11:49:38 +00:00
|
|
|
|
2024-12-03 09:12:30 +00:00
|
|
|
bool handleMouseMove(QMouseEvent *event);
|
|
|
|
|
bool handleMousePress(QMouseEvent *event);
|
|
|
|
|
bool handleMouseRelease(QMouseEvent *event);
|
|
|
|
|
bool handleWheel(QWheelEvent *event);
|
|
|
|
|
void handlePinchScale(qreal delta);
|
|
|
|
|
void handlePinchGrab(QPointingDevice::GrabTransition transition, QEventPoint point);
|
|
|
|
|
|
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-04-18 09:03:03 +00:00
|
|
|
void setLabelTextProperties(QQuickItem *item, const QString &text, bool xAxis,
|
|
|
|
|
QQuickText::HAlignment hAlign = QQuickText::HAlignment::AlignHCenter,
|
|
|
|
|
QQuickText::VAlignment vAlign = QQuickText::VAlignment::AlignVCenter);
|
2024-05-19 06:24:02 +00:00
|
|
|
void updateAxisLabelItems(QList<QQuickItem *> &textItems, qsizetype neededSize, QQmlComponent *component);
|
2024-12-03 09:12:30 +00:00
|
|
|
QVector2D windowToAxisCoords(QVector2D coords);
|
|
|
|
|
bool zoom(qreal delta);
|
2023-12-20 10:36:22 +00:00
|
|
|
|
2023-12-07 11:49:38 +00:00
|
|
|
QGraphsView *m_graph = nullptr;
|
2024-04-16 13:40:26 +00:00
|
|
|
QGraphsTheme *theme();
|
2024-02-13 12:45:59 +00:00
|
|
|
bool m_initialized = false;
|
2024-04-18 09:03:03 +00:00
|
|
|
bool m_wasVertical = false;
|
2024-08-01 13:26:14 +00:00
|
|
|
bool m_verticalAxisOnRight = false;
|
|
|
|
|
bool m_horizontalAxisOnTop = false;
|
2023-12-07 11:49:38 +00:00
|
|
|
|
|
|
|
|
QAbstractAxis *m_axisVertical = nullptr;
|
|
|
|
|
QAbstractAxis *m_axisHorizontal = nullptr;
|
2024-04-18 09:03:03 +00:00
|
|
|
QList<QQuickItem *> m_xAxisTextItems;
|
|
|
|
|
QList<QQuickItem *> 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.
|
2024-05-28 13:37:06 +00:00
|
|
|
double m_axisYDisplacement = 0;
|
2023-12-20 10:36:22 +00:00
|
|
|
// The value of smallest label
|
|
|
|
|
double m_axisVerticalMinLabel = 0;
|
2024-12-03 09:12:30 +00:00
|
|
|
double m_axisVerticalValueRangeZoomless = 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.
|
2024-05-28 13:37:06 +00:00
|
|
|
double m_axisXDisplacement = 0;
|
2024-01-24 15:24:58 +00:00
|
|
|
// The value of smallest label
|
|
|
|
|
double m_axisHorizontalMinLabel = 0;
|
2024-12-03 09:12:30 +00:00
|
|
|
double m_axisHorizontalValueRangeZoomless = 0;
|
2024-01-24 15:24:58 +00:00
|
|
|
|
2024-05-28 13:37:06 +00:00
|
|
|
double m_axisVerticalSubGridScale = 0.5;
|
|
|
|
|
double m_axisHorizontalSubGridScale = 0.5;
|
|
|
|
|
bool m_gridHorizontalLinesVisible = true;
|
|
|
|
|
bool m_gridVerticalLinesVisible = true;
|
|
|
|
|
bool m_gridHorizontalSubLinesVisible = false;
|
|
|
|
|
bool m_gridVerticalSubLinesVisible = false;
|
2024-12-03 09:12:30 +00:00
|
|
|
|
|
|
|
|
struct PanState
|
|
|
|
|
{
|
|
|
|
|
bool panning = false;
|
|
|
|
|
QVector2D touchPositionAtPress;
|
|
|
|
|
QVector2D panAtPress;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PanState m_panState;
|
|
|
|
|
QVector2D m_zoomBoxStart;
|
2023-12-07 11:49:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
#endif // AXISRENDERER_H
|