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); type()59 inline QAbstract3DAxis::AxisType type() const { return m_type; } 60 void setTitle(const QString &title); title()61 inline const QString &title() const { return m_title; } 62 void setLabels(const QStringList &labels); labels()63 inline const QStringList &labels() const { return m_labels; } setMin(float min)64 inline void setMin(float min) { m_min = min; } min()65 inline float min() const { return m_min; } setMax(float max)66 inline void setMax(float max) { m_max = max; } max()67 inline float max() const { return m_max; } setSegmentCount(int count)68 inline void setSegmentCount(int count) { m_segmentCount = count; m_positionsDirty = true; } segmentCount()69 inline int segmentCount() const { return m_segmentCount; } setSubSegmentCount(int count)70 inline void setSubSegmentCount(int count) { m_subSegmentCount = count; m_positionsDirty = true; } subSegmentCount()71 inline int subSegmentCount() const { return m_subSegmentCount; } setLabelFormat(const QString & format)72 inline void setLabelFormat(const QString &format) { m_labelFormat = format; } labelFormat()73 inline const QString &labelFormat() const { return m_labelFormat; } setReversed(bool enable)74 inline void setReversed(bool enable) { m_reversed = enable; m_positionsDirty = true; } reversed()75 inline bool reversed() const { return m_reversed; } setFormatter(QValue3DAxisFormatter * formatter)76 inline void setFormatter(QValue3DAxisFormatter *formatter) 77 { 78 m_formatter = formatter; m_positionsDirty = true; 79 } formatter()80 inline QValue3DAxisFormatter *formatter() const { return m_formatter; } setCtrlFormatter(QValue3DAxisFormatter * formatter)81 inline void setCtrlFormatter(QValue3DAxisFormatter *formatter) 82 { 83 m_ctrlFormatter = formatter; 84 } ctrlFormatter()85 inline QValue3DAxisFormatter *ctrlFormatter() const { return m_ctrlFormatter; } 86 titleItem()87 inline LabelItem &titleItem() { return m_titleItem; } labelItems()88 inline QList<LabelItem *> &labelItems() { return m_labelItems; } gridLinePosition(int index)89 inline float gridLinePosition(int index) { return m_adjustedGridLinePositions.at(index); } gridLineCount()90 inline int gridLineCount() { return m_adjustedGridLinePositions.size(); } labelPosition(int index)91 inline float labelPosition(int index) { return m_adjustedLabelPositions.at(index); } labelCount()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(); positionsDirty()101 inline bool positionsDirty() const { return m_positionsDirty; } markPositionsDirty()102 inline void markPositionsDirty() { m_positionsDirty = true; } setTranslate(float translate)103 inline void setTranslate(float translate) { m_translate = translate; m_positionsDirty = true; } translate()104 inline float translate() { return m_translate; } setScale(float scale)105 inline void setScale(float scale) { m_scale = scale; m_positionsDirty = true; } scale()106 inline float scale() { return m_scale; } positionAt(float value)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 } labelAutoRotation()114 inline float labelAutoRotation() const { return m_labelAutoRotation; } setLabelAutoRotation(float angle)115 inline void setLabelAutoRotation(float angle) { m_labelAutoRotation = angle; } isTitleVisible()116 inline bool isTitleVisible() const { return m_titleVisible; } setTitleVisible(bool visible)117 inline void setTitleVisible(bool visible) { m_titleVisible = visible; } isTitleFixed()118 inline bool isTitleFixed() const { return m_titleFixed; } setTitleFixed(bool fixed)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