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