| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | // |
| 31 | // W A R N I N G |
| 32 | // ------------- |
| 33 | // |
| 34 | // This file is not part of the QtDataVisualization API. It exists purely as an |
| 35 | // implementation detail. This header file may change from version to |
| 36 | // version without notice, or even be removed. |
| 37 | // |
| 38 | // We mean it. |
| 39 | |
| 40 | #ifndef AXISRENDERCACHE_P_H |
| 41 | #define AXISRENDERCACHE_P_H |
| 42 | |
| 43 | #include "datavisualizationglobal_p.h" |
| 44 | #include "drawer_p.h" |
| 45 | #include <QtCore/QPointer> |
| 46 | |
| 47 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
| 48 | |
| 49 | class AxisRenderCache : public QObject |
| 50 | { |
| 51 | Q_OBJECT |
| 52 | public: |
| 53 | AxisRenderCache(); |
| 54 | virtual ~AxisRenderCache(); |
| 55 | |
| 56 | void setDrawer(Drawer *drawer); |
| 57 | |
| 58 | void setType(QAbstract3DAxis::AxisType type); |
| 59 | inline QAbstract3DAxis::AxisType type() const { return m_type; } |
| 60 | void setTitle(const QString &title); |
| 61 | inline const QString &title() const { return m_title; } |
| 62 | void setLabels(const QStringList &labels); |
| 63 | inline const QStringList &labels() const { return m_labels; } |
| 64 | inline void setMin(float min) { m_min = min; } |
| 65 | inline float min() const { return m_min; } |
| 66 | inline void setMax(float max) { m_max = max; } |
| 67 | inline float max() const { return m_max; } |
| 68 | inline void setSegmentCount(int count) { m_segmentCount = count; m_positionsDirty = true; } |
| 69 | inline int segmentCount() const { return m_segmentCount; } |
| 70 | inline void setSubSegmentCount(int count) { m_subSegmentCount = count; m_positionsDirty = true; } |
| 71 | inline int subSegmentCount() const { return m_subSegmentCount; } |
| 72 | inline void setLabelFormat(const QString &format) { m_labelFormat = format; } |
| 73 | inline const QString &labelFormat() const { return m_labelFormat; } |
| 74 | inline void setReversed(bool enable) { m_reversed = enable; m_positionsDirty = true; } |
| 75 | inline bool reversed() const { return m_reversed; } |
| 76 | inline void setFormatter(QValue3DAxisFormatter *formatter) |
| 77 | { |
| 78 | m_formatter = formatter; m_positionsDirty = true; |
| 79 | } |
| 80 | inline QValue3DAxisFormatter *formatter() const { return m_formatter; } |
| 81 | inline void setCtrlFormatter(QValue3DAxisFormatter *formatter) |
| 82 | { |
| 83 | m_ctrlFormatter = formatter; |
| 84 | } |
| 85 | inline QValue3DAxisFormatter *ctrlFormatter() const { return m_ctrlFormatter; } |
| 86 | |
| 87 | inline LabelItem &titleItem() { return m_titleItem; } |
| 88 | inline QList<LabelItem *> &labelItems() { return m_labelItems; } |
| 89 | inline float gridLinePosition(int index) { return m_adjustedGridLinePositions.at(i: index); } |
| 90 | inline int gridLineCount() { return m_adjustedGridLinePositions.size(); } |
| 91 | inline float labelPosition(int index) { return m_adjustedLabelPositions.at(i: index); } |
| 92 | inline int labelCount() { |
| 93 | // Some value axis formatters may opt to not show all labels, |
| 94 | // so use positions array for determining count in that case. |
| 95 | if (m_type == QAbstract3DAxis::AxisTypeValue) |
| 96 | return m_adjustedLabelPositions.size(); |
| 97 | else |
| 98 | return m_labels.size(); |
| 99 | } |
| 100 | void updateAllPositions(); |
| 101 | inline bool positionsDirty() const { return m_positionsDirty; } |
| 102 | inline void markPositionsDirty() { m_positionsDirty = true; } |
| 103 | inline void setTranslate(float translate) { m_translate = translate; m_positionsDirty = true; } |
| 104 | inline float translate() { return m_translate; } |
| 105 | inline void setScale(float scale) { m_scale = scale; m_positionsDirty = true; } |
| 106 | inline float scale() { return m_scale; } |
| 107 | inline float positionAt(float value) |
| 108 | { |
| 109 | if (m_reversed) |
| 110 | return (1.0f - m_formatter->positionAt(value)) * m_scale + m_translate; |
| 111 | else |
| 112 | return m_formatter->positionAt(value) * m_scale + m_translate; |
| 113 | } |
| 114 | inline float labelAutoRotation() const { return m_labelAutoRotation; } |
| 115 | inline void setLabelAutoRotation(float angle) { m_labelAutoRotation = angle; } |
| 116 | inline bool isTitleVisible() const { return m_titleVisible; } |
| 117 | inline void setTitleVisible(bool visible) { m_titleVisible = visible; } |
| 118 | inline bool isTitleFixed() const { return m_titleFixed; } |
| 119 | inline void setTitleFixed(bool fixed) { m_titleFixed = fixed; } |
| 120 | |
| 121 | void updateTextures(); |
| 122 | void clearLabels(); |
| 123 | |
| 124 | private: |
| 125 | int maxLabelWidth(const QStringList &labels) const; |
| 126 | |
| 127 | // Cached axis values |
| 128 | QAbstract3DAxis::AxisType m_type; |
| 129 | QString m_title; |
| 130 | QStringList m_labels; |
| 131 | float m_min; |
| 132 | float m_max; |
| 133 | int m_segmentCount; |
| 134 | int m_subSegmentCount; |
| 135 | QString m_labelFormat; |
| 136 | bool m_reversed; |
| 137 | QFont m_font; |
| 138 | QValue3DAxisFormatter *m_formatter; |
| 139 | QPointer<QValue3DAxisFormatter> m_ctrlFormatter; |
| 140 | |
| 141 | // Renderer items |
| 142 | Drawer *m_drawer; // Not owned |
| 143 | LabelItem m_titleItem; |
| 144 | QList<LabelItem *> m_labelItems; |
| 145 | QVector<float> m_adjustedGridLinePositions; |
| 146 | QVector<float> m_adjustedLabelPositions; |
| 147 | bool m_positionsDirty; |
| 148 | float m_translate; |
| 149 | float m_scale; |
| 150 | float m_labelAutoRotation; |
| 151 | bool m_titleVisible; |
| 152 | bool m_titleFixed; |
| 153 | |
| 154 | Q_DISABLE_COPY(AxisRenderCache) |
| 155 | }; |
| 156 | |
| 157 | QT_END_NAMESPACE_DATAVISUALIZATION |
| 158 | |
| 159 | #endif |
| 160 |
