1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the QtDataVisualization API. It exists purely as an |
9 | // implementation detail. This header file may change from version to |
10 | // version without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | |
14 | #ifndef AXISRENDERCACHE_P_H |
15 | #define AXISRENDERCACHE_P_H |
16 | |
17 | #include "datavisualizationglobal_p.h" |
18 | #include "drawer_p.h" |
19 | #include <QtCore/QPointer> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class AxisRenderCache : public QObject |
24 | { |
25 | Q_OBJECT |
26 | public: |
27 | AxisRenderCache(); |
28 | virtual ~AxisRenderCache(); |
29 | |
30 | void setDrawer(Drawer *drawer); |
31 | |
32 | void setType(QAbstract3DAxis::AxisType type); |
33 | inline QAbstract3DAxis::AxisType type() const { return m_type; } |
34 | void setTitle(const QString &title); |
35 | inline const QString &title() const { return m_title; } |
36 | void setLabels(const QStringList &labels); |
37 | inline const QStringList &labels() const { return m_labels; } |
38 | inline void setMin(float min) { m_min = min; } |
39 | inline float min() const { return m_min; } |
40 | inline void setMax(float max) { m_max = max; } |
41 | inline float max() const { return m_max; } |
42 | inline void setSegmentCount(int count) { m_segmentCount = count; m_positionsDirty = true; } |
43 | inline int segmentCount() const { return m_segmentCount; } |
44 | inline void setSubSegmentCount(int count) { m_subSegmentCount = count; m_positionsDirty = true; } |
45 | inline int subSegmentCount() const { return m_subSegmentCount; } |
46 | inline void setLabelFormat(const QString &format) { m_labelFormat = format; } |
47 | inline const QString &labelFormat() const { return m_labelFormat; } |
48 | inline void setReversed(bool enable) { m_reversed = enable; m_positionsDirty = true; } |
49 | inline bool reversed() const { return m_reversed; } |
50 | inline void setFormatter(QValue3DAxisFormatter *formatter) |
51 | { |
52 | m_formatter = formatter; m_positionsDirty = true; |
53 | } |
54 | inline QValue3DAxisFormatter *formatter() const { return m_formatter; } |
55 | inline void setCtrlFormatter(QValue3DAxisFormatter *formatter) |
56 | { |
57 | m_ctrlFormatter = formatter; |
58 | } |
59 | inline QValue3DAxisFormatter *ctrlFormatter() const { return m_ctrlFormatter; } |
60 | |
61 | inline LabelItem &titleItem() { return m_titleItem; } |
62 | inline QList<LabelItem *> &labelItems() { return m_labelItems; } |
63 | inline float gridLinePosition(int index) { return m_adjustedGridLinePositions.at(i: index); } |
64 | inline int gridLineCount() { return m_adjustedGridLinePositions.size(); } |
65 | inline float labelPosition(int index) { return m_adjustedLabelPositions.at(i: index); } |
66 | inline int labelCount() { |
67 | // Some value axis formatters may opt to not show all labels, |
68 | // so use positions array for determining count in that case. |
69 | if (m_type == QAbstract3DAxis::AxisTypeValue) |
70 | return m_adjustedLabelPositions.size(); |
71 | else |
72 | return m_labels.size(); |
73 | } |
74 | void updateAllPositions(); |
75 | inline bool positionsDirty() const { return m_positionsDirty; } |
76 | inline void markPositionsDirty() { m_positionsDirty = true; } |
77 | inline void setTranslate(float translate) { m_translate = translate; m_positionsDirty = true; } |
78 | inline float translate() { return m_translate; } |
79 | inline void setScale(float scale) { m_scale = scale; m_positionsDirty = true; } |
80 | inline float scale() { return m_scale; } |
81 | inline float positionAt(float value) |
82 | { |
83 | if (m_reversed) |
84 | return (1.0f - m_formatter->positionAt(value)) * m_scale + m_translate; |
85 | else |
86 | return m_formatter->positionAt(value) * m_scale + m_translate; |
87 | } |
88 | inline float labelAutoRotation() const { return m_labelAutoRotation; } |
89 | inline void setLabelAutoRotation(float angle) { m_labelAutoRotation = angle; } |
90 | inline bool isTitleVisible() const { return m_titleVisible; } |
91 | inline void setTitleVisible(bool visible) { m_titleVisible = visible; } |
92 | inline bool isTitleFixed() const { return m_titleFixed; } |
93 | inline void setTitleFixed(bool fixed) { m_titleFixed = fixed; } |
94 | |
95 | void updateTextures(); |
96 | void clearLabels(); |
97 | |
98 | private: |
99 | int maxLabelWidth(const QStringList &labels) const; |
100 | |
101 | // Cached axis values |
102 | QAbstract3DAxis::AxisType m_type; |
103 | QString m_title; |
104 | QStringList m_labels; |
105 | float m_min; |
106 | float m_max; |
107 | int m_segmentCount; |
108 | int m_subSegmentCount; |
109 | QString m_labelFormat; |
110 | bool m_reversed; |
111 | QFont m_font; |
112 | QValue3DAxisFormatter *m_formatter; |
113 | QPointer<QValue3DAxisFormatter> m_ctrlFormatter; |
114 | |
115 | // Renderer items |
116 | Drawer *m_drawer; // Not owned |
117 | LabelItem m_titleItem; |
118 | QList<LabelItem *> m_labelItems; |
119 | QList<float> m_adjustedGridLinePositions; |
120 | QList<float> m_adjustedLabelPositions; |
121 | bool m_positionsDirty; |
122 | float m_translate; |
123 | float m_scale; |
124 | float m_labelAutoRotation; |
125 | bool m_titleVisible; |
126 | bool m_titleFixed; |
127 | |
128 | Q_DISABLE_COPY(AxisRenderCache) |
129 | }; |
130 | |
131 | QT_END_NAMESPACE |
132 | |
133 | #endif |
134 |