diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-10 16:26:11 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-11 10:42:53 +0300 |
commit | d93f5f3b64fdb52cc150232f6b6d80ffdb57db78 (patch) | |
tree | 4a99ecc02c2e885b56abb1082527e482967b84f8 /src/datavisualization/axis | |
parent | d315336b202ec1c1260f96945a23fde6d2c41b69 (diff) |
QBarDataProxy now has list of row and column labels
Category axes use those labels if no explicit labels are set to them.
+ Other misc fixes
Task-number: QTRD-2252
Change-Id: Idc15e0cc1cdeb08195b2e2baeead9cfef2533e04
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis')
-rw-r--r-- | src/datavisualization/axis/q3dcategoryaxis.cpp | 49 | ||||
-rw-r--r-- | src/datavisualization/axis/q3dcategoryaxis.h | 4 | ||||
-rw-r--r-- | src/datavisualization/axis/q3dcategoryaxis_p.h | 8 |
3 files changed, 55 insertions, 6 deletions
diff --git a/src/datavisualization/axis/q3dcategoryaxis.cpp b/src/datavisualization/axis/q3dcategoryaxis.cpp index 55a27f52..90a7ff45 100644 --- a/src/datavisualization/axis/q3dcategoryaxis.cpp +++ b/src/datavisualization/axis/q3dcategoryaxis.cpp @@ -18,6 +18,8 @@ #include "q3dcategoryaxis.h" #include "q3dcategoryaxis_p.h" +#include "bars3dcontroller_p.h" +#include "qbardataproxy.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -53,7 +55,12 @@ Q3DCategoryAxis::~Q3DCategoryAxis() * \property Q3DCategoryAxis::categoryLabels * * Defines labels for axis applied to categories. If there are fewer labels than categories, the - * remaining ones do not have a label. + * remaining ones do not have a label. If category labels are not explicitly defined, labels are + * generated from the data row and column labels. + * + * \note CategoryLabels actually reads/writes the Q3DAbstractAxis::labels property, + * which is read only there. Since subclass cannot have property with same name, + * this partially duplicate property is necessary. */ QStringList Q3DCategoryAxis::categoryLabels() const { @@ -62,7 +69,24 @@ QStringList Q3DCategoryAxis::categoryLabels() const void Q3DCategoryAxis::setCategoryLabels(const QStringList &labels) { - if (d_ptr->m_labels != labels) { + dptr()->m_labelsExplicitlySet = !labels.isEmpty(); + bool labelsFromData = false; + + // Get labels from data proxy if axis is attached to a bar controller and an active axis there + if (labels.isEmpty()) { + Bars3DController *controller = qobject_cast<Bars3DController *>(parent()); + if (controller) { + if (controller->axisX() == this) { + controller->handleDataRowLabelsChanged(); + labelsFromData = true; + } else if (controller->axisZ() == this) { + controller->handleDataColumnLabelsChanged(); + labelsFromData = true; + } + } + } + + if (!labelsFromData && d_ptr->m_labels != labels) { d_ptr->m_labels = labels; emit labelsChanged(); } @@ -77,7 +101,8 @@ Q3DCategoryAxisPrivate *Q3DCategoryAxis::dptr() } Q3DCategoryAxisPrivate::Q3DCategoryAxisPrivate(Q3DCategoryAxis *q) - : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory) + : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory), + m_labelsExplicitlySet(false) { } @@ -85,4 +110,22 @@ Q3DCategoryAxisPrivate::~Q3DCategoryAxisPrivate() { } +/*! + * \internal + * Controller uses this function to set labels from data proxy as category labels. + * If the labels have been explicitly set by user, data proxy labels are not used. + */ +void Q3DCategoryAxisPrivate::setDataLabels(const QStringList &labels) +{ + if (!m_labelsExplicitlySet && m_labels != labels) { + m_labels = labels; + emit qptr()->labelsChanged(); + } +} + +Q3DCategoryAxis *Q3DCategoryAxisPrivate::qptr() +{ + return static_cast<Q3DCategoryAxis *>(q_ptr); +} + QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/axis/q3dcategoryaxis.h b/src/datavisualization/axis/q3dcategoryaxis.h index 8b7f966c..bf5e66fd 100644 --- a/src/datavisualization/axis/q3dcategoryaxis.h +++ b/src/datavisualization/axis/q3dcategoryaxis.h @@ -28,9 +28,6 @@ class Q3DCategoryAxisPrivate; class QT_DATAVISUALIZATION_EXPORT Q3DCategoryAxis : public Q3DAbstractAxis { Q_OBJECT - // Note: categoryLabels actually reads/writes the labels property in abstract axis, - // which is read only there. Since subclass cannot have property with same name, - // this partially duplicate property is necessary. Q_PROPERTY(QStringList categoryLabels READ categoryLabels WRITE setCategoryLabels) public: @@ -47,6 +44,7 @@ protected: private: Q_DISABLE_COPY(Q3DCategoryAxis) + friend class Bars3DController; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/axis/q3dcategoryaxis_p.h b/src/datavisualization/axis/q3dcategoryaxis_p.h index f7fa7b35..9b66e48a 100644 --- a/src/datavisualization/axis/q3dcategoryaxis_p.h +++ b/src/datavisualization/axis/q3dcategoryaxis_p.h @@ -42,6 +42,14 @@ class Q3DCategoryAxisPrivate : public Q3DAbstractAxisPrivate public: Q3DCategoryAxisPrivate(Q3DCategoryAxis *q); virtual ~Q3DCategoryAxisPrivate(); + + void setDataLabels(const QStringList &labels); + +private: + Q3DCategoryAxis *qptr(); + + bool m_labelsExplicitlySet; + friend class Q3DCategoryAxis; }; QT_DATAVISUALIZATION_END_NAMESPACE |