1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qcategory3daxis_p.h" |
5 | #include "bars3dcontroller_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | * \class QCategory3DAxis |
11 | * \inmodule QtDataVisualization |
12 | * \brief The QCategory3DAxis class manipulates an axis of a graph. |
13 | * \since QtDataVisualization 1.0 |
14 | * |
15 | * QCategory3DAxis provides an axis that can be given labels. The axis is divided into equal-sized |
16 | * categories based on the data window size defined by setting the axis range. |
17 | * |
18 | * Grid lines are drawn between categories, if visible. Labels are drawn to positions of categories |
19 | * if provided. |
20 | */ |
21 | |
22 | /*! |
23 | * \qmltype CategoryAxis3D |
24 | * \inqmlmodule QtDataVisualization |
25 | * \since QtDataVisualization 1.0 |
26 | * \ingroup datavisualization_qml |
27 | * \instantiates QCategory3DAxis |
28 | * \inherits AbstractAxis3D |
29 | * \brief Manipulates an axis of a graph. |
30 | * |
31 | * This type provides an axis that can be given labels. |
32 | */ |
33 | |
34 | /*! |
35 | * \qmlproperty list CategoryAxis3D::labels |
36 | * |
37 | * The labels for the axis applied to categories. If there are fewer labels than categories, the |
38 | * remaining ones do not have a label. If category labels are not defined explicitly, labels are |
39 | * generated from the data row (or column) labels of the primary series of the graph. |
40 | */ |
41 | |
42 | /*! |
43 | * Constructs a category 3D axis with the parent \a parent. |
44 | */ |
45 | QCategory3DAxis::QCategory3DAxis(QObject *parent) : |
46 | QAbstract3DAxis(new QCategory3DAxisPrivate(this), parent) |
47 | { |
48 | connect(sender: this, signal: &QCategory3DAxis::labelsChanged, context: this, slot: &QAbstract3DAxis::labelsChanged); |
49 | } |
50 | |
51 | /*! |
52 | * Destroys the category 3D axis. |
53 | */ |
54 | QCategory3DAxis::~QCategory3DAxis() |
55 | { |
56 | } |
57 | |
58 | /*! |
59 | * \property QCategory3DAxis::labels |
60 | * |
61 | * \brief The labels for the axis applied to categories. |
62 | * |
63 | * If there are fewer labels than categories, the |
64 | * remaining ones do not have a label. If category labels are not defined explicitly, labels are |
65 | * generated from the data row (or column) labels of the primary series of the graph. |
66 | */ |
67 | QStringList QCategory3DAxis::labels() const |
68 | { |
69 | return QAbstract3DAxis::labels(); |
70 | } |
71 | |
72 | void QCategory3DAxis::setLabels(const QStringList &labels) |
73 | { |
74 | dptr()->m_labelsExplicitlySet = !labels.isEmpty(); |
75 | bool labelsFromData = false; |
76 | |
77 | // Get labels from data proxy if axis is attached to a bar controller and an active axis there |
78 | if (labels.isEmpty()) { |
79 | Bars3DController *controller = qobject_cast<Bars3DController *>(object: parent()); |
80 | if (controller) { |
81 | if (controller->axisX() == this) { |
82 | controller->handleDataRowLabelsChanged(); |
83 | labelsFromData = true; |
84 | } else if (controller->axisZ() == this) { |
85 | controller->handleDataColumnLabelsChanged(); |
86 | labelsFromData = true; |
87 | } |
88 | } |
89 | } |
90 | |
91 | if (!labelsFromData && d_ptr->m_labels != labels) { |
92 | d_ptr->m_labels = labels; |
93 | emit labelsChanged(); |
94 | } |
95 | } |
96 | |
97 | /*! |
98 | * \internal |
99 | */ |
100 | QCategory3DAxisPrivate *QCategory3DAxis::dptr() |
101 | { |
102 | return static_cast<QCategory3DAxisPrivate *>(d_ptr.data()); |
103 | } |
104 | |
105 | QCategory3DAxisPrivate::QCategory3DAxisPrivate(QCategory3DAxis *q) |
106 | : QAbstract3DAxisPrivate(q, QAbstract3DAxis::AxisTypeCategory), |
107 | m_labelsExplicitlySet(false) |
108 | { |
109 | } |
110 | |
111 | QCategory3DAxisPrivate::~QCategory3DAxisPrivate() |
112 | { |
113 | } |
114 | |
115 | /*! |
116 | * \internal |
117 | * Controller uses this function to set labels from data proxy as category labels. |
118 | * If the labels have been set explicitly by the user, data proxy labels are not used. |
119 | */ |
120 | void QCategory3DAxisPrivate::setDataLabels(const QStringList &labels) |
121 | { |
122 | if (!m_labelsExplicitlySet && m_labels != labels) { |
123 | m_labels = labels; |
124 | emit qptr()->labelsChanged(); |
125 | } |
126 | } |
127 | |
128 | bool QCategory3DAxisPrivate::allowZero() |
129 | { |
130 | return true; |
131 | } |
132 | |
133 | bool QCategory3DAxisPrivate::allowNegatives() |
134 | { |
135 | return false; |
136 | } |
137 | |
138 | bool QCategory3DAxisPrivate::allowMinMaxSame() |
139 | { |
140 | return true; |
141 | } |
142 | |
143 | QCategory3DAxis *QCategory3DAxisPrivate::qptr() |
144 | { |
145 | return static_cast<QCategory3DAxis *>(q_ptr); |
146 | } |
147 | |
148 | QT_END_NAMESPACE |
149 | |