| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 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 | #include "qcategory3daxis_p.h" |
| 31 | #include "bars3dcontroller_p.h" |
| 32 | |
| 33 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
| 34 | |
| 35 | /*! |
| 36 | * \class QCategory3DAxis |
| 37 | * \inmodule QtDataVisualization |
| 38 | * \brief The QCategory3DAxis class manipulates an axis of a graph. |
| 39 | * \since QtDataVisualization 1.0 |
| 40 | * |
| 41 | * QCategory3DAxis provides an axis that can be given labels. The axis is divided into equal-sized |
| 42 | * categories based on the data window size defined by setting the axis range. |
| 43 | * |
| 44 | * Grid lines are drawn between categories, if visible. Labels are drawn to positions of categories |
| 45 | * if provided. |
| 46 | */ |
| 47 | |
| 48 | /*! |
| 49 | * \qmltype CategoryAxis3D |
| 50 | * \inqmlmodule QtDataVisualization |
| 51 | * \since QtDataVisualization 1.0 |
| 52 | * \ingroup datavisualization_qml |
| 53 | * \instantiates QCategory3DAxis |
| 54 | * \inherits AbstractAxis3D |
| 55 | * \brief Manipulates an axis of a graph. |
| 56 | * |
| 57 | * This type provides an axis that can be given labels. |
| 58 | */ |
| 59 | |
| 60 | /*! |
| 61 | * \qmlproperty list CategoryAxis3D::labels |
| 62 | * |
| 63 | * The labels for the axis applied to categories. 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 | |
| 68 | /*! |
| 69 | * Constructs a category 3D axis with the parent \a parent. |
| 70 | */ |
| 71 | QCategory3DAxis::QCategory3DAxis(QObject *parent) : |
| 72 | QAbstract3DAxis(new QCategory3DAxisPrivate(this), parent) |
| 73 | { |
| 74 | connect(sender: this, signal: &QCategory3DAxis::labelsChanged, receiver: this, slot: &QAbstract3DAxis::labelsChanged); |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | * Destroys the category 3D axis. |
| 79 | */ |
| 80 | QCategory3DAxis::~QCategory3DAxis() |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | * \property QCategory3DAxis::labels |
| 86 | * |
| 87 | * \brief The labels for the axis applied to categories. |
| 88 | * |
| 89 | * If there are fewer labels than categories, the |
| 90 | * remaining ones do not have a label. If category labels are not defined explicitly, labels are |
| 91 | * generated from the data row (or column) labels of the primary series of the graph. |
| 92 | */ |
| 93 | QStringList QCategory3DAxis::labels() const |
| 94 | { |
| 95 | return QAbstract3DAxis::labels(); |
| 96 | } |
| 97 | |
| 98 | void QCategory3DAxis::setLabels(const QStringList &labels) |
| 99 | { |
| 100 | dptr()->m_labelsExplicitlySet = !labels.isEmpty(); |
| 101 | bool labelsFromData = false; |
| 102 | |
| 103 | // Get labels from data proxy if axis is attached to a bar controller and an active axis there |
| 104 | if (labels.isEmpty()) { |
| 105 | Bars3DController *controller = qobject_cast<Bars3DController *>(object: parent()); |
| 106 | if (controller) { |
| 107 | if (controller->axisX() == this) { |
| 108 | controller->handleDataRowLabelsChanged(); |
| 109 | labelsFromData = true; |
| 110 | } else if (controller->axisZ() == this) { |
| 111 | controller->handleDataColumnLabelsChanged(); |
| 112 | labelsFromData = true; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if (!labelsFromData && d_ptr->m_labels != labels) { |
| 118 | d_ptr->m_labels = labels; |
| 119 | emit labelsChanged(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /*! |
| 124 | * \internal |
| 125 | */ |
| 126 | QCategory3DAxisPrivate *QCategory3DAxis::dptr() |
| 127 | { |
| 128 | return static_cast<QCategory3DAxisPrivate *>(d_ptr.data()); |
| 129 | } |
| 130 | |
| 131 | QCategory3DAxisPrivate::QCategory3DAxisPrivate(QCategory3DAxis *q) |
| 132 | : QAbstract3DAxisPrivate(q, QAbstract3DAxis::AxisTypeCategory), |
| 133 | m_labelsExplicitlySet(false) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | QCategory3DAxisPrivate::~QCategory3DAxisPrivate() |
| 138 | { |
| 139 | } |
| 140 | |
| 141 | /*! |
| 142 | * \internal |
| 143 | * Controller uses this function to set labels from data proxy as category labels. |
| 144 | * If the labels have been set explicitly by the user, data proxy labels are not used. |
| 145 | */ |
| 146 | void QCategory3DAxisPrivate::setDataLabels(const QStringList &labels) |
| 147 | { |
| 148 | if (!m_labelsExplicitlySet && m_labels != labels) { |
| 149 | m_labels = labels; |
| 150 | emit qptr()->labelsChanged(); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | bool QCategory3DAxisPrivate::allowZero() |
| 155 | { |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | bool QCategory3DAxisPrivate::allowNegatives() |
| 160 | { |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | bool QCategory3DAxisPrivate::allowMinMaxSame() |
| 165 | { |
| 166 | return true; |
| 167 | } |
| 168 | |
| 169 | QCategory3DAxis *QCategory3DAxisPrivate::qptr() |
| 170 | { |
| 171 | return static_cast<QCategory3DAxis *>(q_ptr); |
| 172 | } |
| 173 | |
| 174 | QT_END_NAMESPACE_DATAVISUALIZATION |
| 175 | |