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

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtgraphs/src/graphs3d/axis/qcategory3daxis.cpp