summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization/axis')
-rw-r--r--src/datavisualization/axis/axis.pri12
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.cpp373
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.h100
-rw-r--r--src/datavisualization/axis/q3dabstractaxis_p.h77
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.cpp152
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.h50
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis_p.h57
-rw-r--r--src/datavisualization/axis/q3dvalueaxis.cpp270
-rw-r--r--src/datavisualization/axis/q3dvalueaxis.h65
-rw-r--r--src/datavisualization/axis/q3dvalueaxis_p.h66
10 files changed, 1222 insertions, 0 deletions
diff --git a/src/datavisualization/axis/axis.pri b/src/datavisualization/axis/axis.pri
new file mode 100644
index 00000000..4e96618b
--- /dev/null
+++ b/src/datavisualization/axis/axis.pri
@@ -0,0 +1,12 @@
+HEADERS += \
+ $$PWD/q3dabstractaxis.h \
+ $$PWD/q3dabstractaxis_p.h \
+ $$PWD/q3dvalueaxis.h \
+ $$PWD/q3dvalueaxis_p.h \
+ $$PWD/q3dcategoryaxis.h \
+ $$PWD/q3dcategoryaxis_p.h
+
+SOURCES += \
+ $$PWD/q3dabstractaxis.cpp \
+ $$PWD/q3dvalueaxis.cpp \
+ $$PWD/q3dcategoryaxis.cpp
diff --git a/src/datavisualization/axis/q3dabstractaxis.cpp b/src/datavisualization/axis/q3dabstractaxis.cpp
new file mode 100644
index 00000000..07761d0c
--- /dev/null
+++ b/src/datavisualization/axis/q3dabstractaxis.cpp
@@ -0,0 +1,373 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "q3dabstractaxis.h"
+#include "q3dabstractaxis_p.h"
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+/*!
+ * \class Q3DAbstractAxis
+ * \inmodule QtDataVisualization
+ * \brief Q3DAbstractAxis is base class for axes of a graph.
+ * \since 1.0.0
+ *
+ * You should not need to use this class directly, but one of its subclasses instead.
+ *
+ * \sa Q3DCategoryAxis, Q3DValueAxis
+ */
+
+/*!
+ * \qmltype AbstractAxis3D
+ * \inqmlmodule com.digia.QtDataVisualization 1.0
+ * \since com.digia.QtDataVisualization 1.0
+ * \ingroup datavisualization_qml
+ * \instantiates Q3DAbstractAxis
+ * \brief AbstractAxis3D is base type for axes of a graph.
+ *
+ * This type is uncreatable, but contains properties that are exposed via subtypes.
+ */
+
+/*!
+ * \qmlproperty string AbstractAxis3D::title
+ * Defines the title for the axis.
+ */
+
+/*!
+ * \qmlproperty list AbstractAxis3D::labels
+ * Defines the labels for the axis.
+ */
+
+/*!
+ * \qmlproperty AbstractAxis3D.AxisOrientation AbstractAxis3D::orientation
+ * Defines the orientation of the axis.
+ */
+
+/*!
+ * \qmlproperty AbstractAxis3D.AxisType AbstractAxis3D::type
+ * Defines the type of the axis.
+ */
+
+/*!
+ * \qmlproperty real AbstractAxis3D::min
+ *
+ * Defines the minimum value on the axis.
+ * When setting this property the max is adjusted if necessary, to ensure that the range remains
+ * valid.
+ */
+
+/*!
+ * \qmlproperty real AbstractAxis3D::max
+ *
+ * Defines the maximum value on the axis.
+ * When setting this property the min is adjusted if necessary, to ensure that the range remains
+ * valid.
+ */
+
+/*!
+ * \qmlproperty bool AbstractAxis3D::autoAdjustRange
+ *
+ * If set, the axis will automatically adjust the range so that all data fits in it.
+ */
+
+
+/*!
+ * \enum Q3DAbstractAxis::AxisOrientation
+ *
+ * The orientation of the axis object.
+ *
+ * \value AxisOrientationNone
+ * \value AxisOrientationX
+ * \value AxisOrientationY
+ * \value AxisOrientationZ
+ */
+
+/*!
+ * \enum Q3DAbstractAxis::AxisType
+ *
+ * The type of the axis object.
+ *
+ * \value AxisTypeNone
+ * \value AxisTypeCategory
+ * \value AxisTypeValue
+ */
+
+/*!
+ * \internal
+ */
+Q3DAbstractAxis::Q3DAbstractAxis(Q3DAbstractAxisPrivate *d, QObject *parent) :
+ QObject(parent),
+ d_ptr(d)
+{
+}
+
+/*!
+ * Destroys Q3DAbstractAxis.
+ */
+Q3DAbstractAxis::~Q3DAbstractAxis()
+{
+}
+
+/*!
+ * \property Q3DAbstractAxis::title
+ *
+ * Defines the title for the axis.
+ */
+QString Q3DAbstractAxis::title() const
+{
+ return d_ptr->m_title;
+}
+
+/*!
+ * \property Q3DAbstractAxis::labels
+ *
+ * Defines the labels for the axis.
+ */
+QStringList Q3DAbstractAxis::labels() const
+{
+ d_ptr->updateLabels();
+ return d_ptr->m_labels;
+}
+
+/*!
+ * \property Q3DAbstractAxis::orientation
+ *
+ * Defines the orientation of the axis, one of \c Q3DAbstractAxis::AxisOrientation.
+ */
+Q3DAbstractAxis::AxisOrientation Q3DAbstractAxis::orientation() const
+{
+ return d_ptr->m_orientation;
+}
+
+/*!
+ * \property Q3DAbstractAxis::type
+ *
+ * Defines the type of the axis, one of \c Q3DAbstractAxis::AxisType.
+ */
+Q3DAbstractAxis::AxisType Q3DAbstractAxis::type() const
+{
+ return d_ptr->m_type;
+}
+
+void Q3DAbstractAxis::setTitle(QString title)
+{
+ if (d_ptr->m_title != title) {
+ d_ptr->m_title = title;
+ emit titleChanged(title);
+ }
+}
+
+/*!
+ * Sets value range of the axis from \a min to \a max.
+ * When setting the range, the max is adjusted if necessary, to ensure that the range remains valid.
+ * \note For Q3DCategoryAxis this specifies the index range of rows or columns to show.
+ */
+void Q3DAbstractAxis::setRange(qreal min, qreal max)
+{
+ d_ptr->setRange(min, max);
+ setAutoAdjustRange(false);
+}
+
+/*!
+ * \property Q3DAbstractAxis::min
+ *
+ * Defines the minimum value on the axis.
+ * When setting this property the max is adjusted if necessary, to ensure that the range remains
+ * valid.
+ * \note For Q3DCategoryAxis this specifies the index of the first row or column to show.
+ */
+void Q3DAbstractAxis::setMin(qreal min)
+{
+ d_ptr->setMin(min);
+ setAutoAdjustRange(false);
+}
+
+/*!
+ * \property Q3DAbstractAxis::max
+ *
+ * Defines the maximum value on the axis.
+ * When setting this property the min is adjusted if necessary, to ensure that the range remains
+ * valid.
+ * \note For Q3DCategoryAxis this specifies the index of the last row or column to show.
+ */
+void Q3DAbstractAxis::setMax(qreal max)
+{
+ d_ptr->setMax(max);
+ setAutoAdjustRange(false);
+}
+
+qreal Q3DAbstractAxis::min() const
+{
+ return d_ptr->m_min;
+}
+
+qreal Q3DAbstractAxis::max() const
+{
+ return d_ptr->m_max;
+}
+
+/*!
+ * \property Q3DAbstractAxis::autoAdjustRange
+ *
+ * If set, the axis will automatically adjust the range so that all data fits in it.
+ *
+ * \sa setRange(), setMin(), setMax()
+ */
+void Q3DAbstractAxis::setAutoAdjustRange(bool autoAdjust)
+{
+ if (d_ptr->m_autoAdjust != autoAdjust) {
+ d_ptr->m_autoAdjust = autoAdjust;
+ emit autoAdjustRangeChanged(autoAdjust);
+ }
+}
+
+bool Q3DAbstractAxis::isAutoAdjustRange() const
+{
+ return d_ptr->m_autoAdjust;
+}
+
+// Q3DAbstractAxisPrivate
+
+Q3DAbstractAxisPrivate::Q3DAbstractAxisPrivate(Q3DAbstractAxis *q, Q3DAbstractAxis::AxisType type)
+ : QObject(0),
+ q_ptr(q),
+ m_orientation(Q3DAbstractAxis::AxisOrientationNone),
+ m_type(type),
+ m_isDefaultAxis(false),
+ m_min(0.0),
+ m_max(10.0),
+ m_autoAdjust(true),
+ m_onlyPositiveValues(false),
+ m_allowMinMaxSame(false)
+{
+}
+
+Q3DAbstractAxisPrivate::~Q3DAbstractAxisPrivate()
+{
+}
+
+void Q3DAbstractAxisPrivate::setOrientation(Q3DAbstractAxis::AxisOrientation orientation)
+{
+ if (m_orientation == Q3DAbstractAxis::AxisOrientationNone)
+ m_orientation = orientation;
+ else
+ Q_ASSERT("Attempted to reset axis orientation.");
+}
+
+void Q3DAbstractAxisPrivate::updateLabels()
+{
+ // Default implementation does nothing
+}
+
+void Q3DAbstractAxisPrivate::setRange(qreal min, qreal max)
+{
+ bool adjusted = false;
+ if (m_onlyPositiveValues) {
+ if (min < 0.0) {
+ min = 0.0;
+ adjusted = true;
+ }
+ if (max < 0.0) {
+ max = 0.0;
+ adjusted = true;
+ }
+ }
+ // If min >= max, we adjust ranges so that
+ // m_max becomes (min + 1.0)
+ // as axes need some kind of valid range.
+ bool dirty = false;
+ if (m_min != min) {
+ m_min = min;
+ dirty = true;
+ }
+ if (m_max != max || min > max || (!m_allowMinMaxSame && min == max)) {
+ if (min > max || (!m_allowMinMaxSame && min == max)) {
+ m_max = min + 1.0;
+ adjusted = true;
+ } else {
+ m_max = max;
+ }
+ dirty = true;
+ }
+
+ if (dirty) {
+ if (adjusted) {
+ qWarning() << "Warning: Tried to set invalid range for axis."
+ " Range automatically adjusted to a valid one:"
+ << min << "-" << max << "-->" << m_min << "-" << m_max;
+ }
+ emit q_ptr->rangeChanged(m_min, m_max);
+ }
+}
+
+void Q3DAbstractAxisPrivate::setMin(qreal min)
+{
+ if (m_onlyPositiveValues) {
+ if (min < 0.0) {
+ min = 0.0;
+ qWarning() << "Warning: Tried to set negative minimum for an axis that only supports"
+ " positive values:" << min;
+ }
+ }
+
+ if (m_min != min) {
+ if (min > m_max || (!m_allowMinMaxSame && min == m_max)) {
+ qreal oldMax = m_max;
+ m_max = min + 1.0;
+ qWarning() << "Warning: Tried to set minimum to equal or larger than maximum for"
+ " value axis. Maximum automatically adjusted to a valid one:"
+ << oldMax << "-->" << m_max;
+ }
+ m_min = min;
+
+ emit q_ptr->rangeChanged(m_min, m_max);
+ }
+}
+
+void Q3DAbstractAxisPrivate::setMax(qreal max)
+{
+ if (m_onlyPositiveValues) {
+ if (max < 0.0) {
+ max = 0.0;
+ qWarning() << "Warning: Tried to set negative maximum for an axis that only supports"
+ " positive values:" << max;
+ }
+ }
+
+ if (m_max != max) {
+ if (m_min > max || (!m_allowMinMaxSame && m_min == max)) {
+ qreal oldMin = m_min;
+ m_min = max - 1.0;
+ if (m_onlyPositiveValues && m_min < 0.0) {
+ m_min = 0.0;
+ if (!m_allowMinMaxSame && max == 0.0) {
+ m_min = oldMin;
+ qWarning() << "Unable to set maximum value to zero.";
+ return;
+ }
+ }
+ qWarning() << "Warning: Tried to set maximum to equal or smaller than minimum for"
+ " value axis. Minimum automatically adjusted to a valid one:"
+ << oldMin << "-->" << m_min;
+ }
+ m_max = max;
+ emit q_ptr->rangeChanged(m_min, m_max);
+ }
+}
+
+QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/axis/q3dabstractaxis.h b/src/datavisualization/axis/q3dabstractaxis.h
new file mode 100644
index 00000000..9e5c426a
--- /dev/null
+++ b/src/datavisualization/axis/q3dabstractaxis.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#ifndef Q3DABSTRACTAXIS_H
+#define Q3DABSTRACTAXIS_H
+
+#include <QtDataVisualization/qdatavisualizationenums.h>
+#include <QObject>
+#include <QScopedPointer>
+#include <QVector>
+#include <QStringList>
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DAbstractAxisPrivate;
+
+class QT_DATAVISUALIZATION_EXPORT Q3DAbstractAxis : public QObject
+{
+ Q_OBJECT
+ Q_ENUMS(AxisOrientation)
+ Q_ENUMS(AxisType)
+ Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
+ Q_PROPERTY(QStringList labels READ labels NOTIFY labelsChanged)
+ Q_PROPERTY(AxisOrientation orientation READ orientation)
+ Q_PROPERTY(AxisType type READ type)
+ Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY rangeChanged)
+ Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY rangeChanged)
+ Q_PROPERTY(bool autoAdjustRange READ isAutoAdjustRange WRITE setAutoAdjustRange NOTIFY autoAdjustRangeChanged)
+
+public:
+ enum AxisOrientation {
+ AxisOrientationNone = 0,
+ AxisOrientationX = 1,
+ AxisOrientationY = 2,
+ AxisOrientationZ = 4
+ };
+
+ enum AxisType {
+ AxisTypeNone = 0,
+ AxisTypeCategory = 1,
+ AxisTypeValue = 2
+ //AxisTypeLogValue = 6 // inherits valueaxis (4 + 2) // TODO
+ };
+
+protected:
+ explicit Q3DAbstractAxis(Q3DAbstractAxisPrivate *d, QObject *parent = 0);
+
+public:
+ virtual ~Q3DAbstractAxis();
+
+ QString title() const;
+ QStringList labels() const;
+
+ AxisOrientation orientation() const;
+ AxisType type() const;
+
+ qreal min() const;
+ qreal max() const;
+ bool isAutoAdjustRange() const;
+
+ void setTitle(QString title);
+ void setRange(qreal min, qreal max);
+ void setMin(qreal min);
+ void setMax(qreal max);
+ void setAutoAdjustRange(bool autoAdjust);
+
+signals:
+ void titleChanged(QString newTitle);
+ void labelsChanged();
+ void rangeChanged(qreal min, qreal max);
+ void autoAdjustRangeChanged(bool autoAdjust);
+
+protected:
+ QScopedPointer<Q3DAbstractAxisPrivate> d_ptr;
+
+private:
+ Q_DISABLE_COPY(Q3DAbstractAxis)
+
+ friend class Abstract3DController;
+ friend class Bars3DController;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QABSTRACTAXIS_H
diff --git a/src/datavisualization/axis/q3dabstractaxis_p.h b/src/datavisualization/axis/q3dabstractaxis_p.h
new file mode 100644
index 00000000..902f65be
--- /dev/null
+++ b/src/datavisualization/axis/q3dabstractaxis_p.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVisualization API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#include "datavisualizationglobal_p.h"
+#include "q3dabstractaxis.h"
+#include "abstract3dcontroller_p.h"
+
+#ifndef Q3DABSTRACTAXIS_P_H
+#define Q3DABSTRACTAXIS_P_H
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DAbstractAxisPrivate : public QObject
+{
+ Q_OBJECT
+public:
+ Q3DAbstractAxisPrivate(Q3DAbstractAxis *q, Q3DAbstractAxis::AxisType type);
+ virtual ~Q3DAbstractAxisPrivate();
+
+ void setOrientation(Q3DAbstractAxis::AxisOrientation orientation);
+
+ inline bool isDefaultAxis() { return m_isDefaultAxis; }
+ inline void setDefaultAxis(bool isDefault) { m_isDefaultAxis = isDefault; }
+
+ virtual void setRange(qreal min, qreal max);
+ virtual void setMin(qreal min);
+ virtual void setMax (qreal max);
+
+protected:
+ virtual void updateLabels();
+
+ Q3DAbstractAxis *q_ptr;
+
+ QString m_title;
+ QStringList m_labels;
+ Q3DAbstractAxis::AxisOrientation m_orientation;
+ Q3DAbstractAxis::AxisType m_type;
+ bool m_isDefaultAxis;
+ qreal m_min;
+ qreal m_max;
+ bool m_autoAdjust;
+ bool m_onlyPositiveValues;
+ bool m_allowMinMaxSame;
+
+ friend class Q3DAbstractAxis;
+ friend class Q3DValueAxis;
+ friend class Q3DCategoryAxis;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QABSTRACTAXIS_P_H
diff --git a/src/datavisualization/axis/q3dcategoryaxis.cpp b/src/datavisualization/axis/q3dcategoryaxis.cpp
new file mode 100644
index 00000000..05f52cdc
--- /dev/null
+++ b/src/datavisualization/axis/q3dcategoryaxis.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "q3dcategoryaxis.h"
+#include "q3dcategoryaxis_p.h"
+#include "bars3dcontroller_p.h"
+#include "qbardataproxy.h"
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+/*!
+ * \class Q3DCategoryAxis
+ * \inmodule QtDataVisualization
+ * \brief The Q3DCategoryAxis class is used for manipulating an axis of a graph.
+ * \since 1.0.0
+ *
+ * Q3DCategoryAxis provides an axis that can be given labels. The axis is divided into equal-sized
+ * categories based on the data window size defined by setting the axis range.
+ *
+ * Grid lines are drawn between categories, if visible. Labels are drawn to positions of categories
+ * if provided.
+ */
+
+/*!
+ * \qmltype CategoryAxis3D
+ * \inqmlmodule com.digia.QtDataVisualization 1.0
+ * \since com.digia.QtDataVisualization 1.0
+ * \ingroup datavisualization_qml
+ * \instantiates Q3DCategoryAxis
+ * \inherits AbstractAxis3D
+ * \brief The CategoryAxis3D type is used for manipulating an axis of a graph.
+ *
+ * This type provides an axis that can be given labels.
+ */
+
+/*!
+ * \qmlproperty list CategoryAxis3D::categoryLabels
+ * Defines labels for axis applied to categories. If there are fewer labels than categories, the
+ * remaining ones do not have a label. If category labels are not explicitly defined, labels are
+ * generated from the data row and column labels.
+ */
+
+/*!
+ * Constructs Q3DCategoryAxis with \a parent.
+ */
+Q3DCategoryAxis::Q3DCategoryAxis(QObject *parent) :
+ Q3DAbstractAxis(new Q3DCategoryAxisPrivate(this), parent)
+{
+}
+
+/*!
+ * Destroys Q3DCategoryAxis.
+ */
+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. 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
+{
+ return labels();
+}
+
+void Q3DCategoryAxis::setCategoryLabels(const QStringList &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();
+ }
+}
+
+/*!
+ * \internal
+ */
+Q3DCategoryAxisPrivate *Q3DCategoryAxis::dptr()
+{
+ return static_cast<Q3DCategoryAxisPrivate *>(d_ptr.data());
+}
+
+Q3DCategoryAxisPrivate::Q3DCategoryAxisPrivate(Q3DCategoryAxis *q)
+ : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory),
+ m_labelsExplicitlySet(false)
+{
+ m_onlyPositiveValues = true;
+ m_allowMinMaxSame = true;
+}
+
+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
new file mode 100644
index 00000000..ef545950
--- /dev/null
+++ b/src/datavisualization/axis/q3dcategoryaxis.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#ifndef Q3DCATEGORYAXIS_H
+#define Q3DCATEGORYAXIS_H
+
+#include <QtDataVisualization/q3dabstractaxis.h>
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DCategoryAxisPrivate;
+
+class QT_DATAVISUALIZATION_EXPORT Q3DCategoryAxis : public Q3DAbstractAxis
+{
+ Q_OBJECT
+ Q_PROPERTY(QStringList categoryLabels READ categoryLabels WRITE setCategoryLabels)
+
+public:
+ explicit Q3DCategoryAxis(QObject *parent = 0);
+ virtual ~Q3DCategoryAxis();
+
+ QStringList categoryLabels() const;
+ void setCategoryLabels(const QStringList &labels);
+
+protected:
+ Q3DCategoryAxisPrivate *dptr();
+
+private:
+ Q_DISABLE_COPY(Q3DCategoryAxis)
+ friend class Bars3DController;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QCATEGORYAXIS_H
diff --git a/src/datavisualization/axis/q3dcategoryaxis_p.h b/src/datavisualization/axis/q3dcategoryaxis_p.h
new file mode 100644
index 00000000..9b66e48a
--- /dev/null
+++ b/src/datavisualization/axis/q3dcategoryaxis_p.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVisualization API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#include "q3dcategoryaxis.h"
+#include "q3dabstractaxis_p.h"
+#include "qbardataitem.h"
+
+#ifndef QCATEGORYAXIS_P_H
+#define QCATEGORYAXIS_P_H
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DCategoryAxisPrivate : public Q3DAbstractAxisPrivate
+{
+ Q_OBJECT
+
+public:
+ Q3DCategoryAxisPrivate(Q3DCategoryAxis *q);
+ virtual ~Q3DCategoryAxisPrivate();
+
+ void setDataLabels(const QStringList &labels);
+
+private:
+ Q3DCategoryAxis *qptr();
+
+ bool m_labelsExplicitlySet;
+ friend class Q3DCategoryAxis;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QCATEGORYAXIS_P_H
diff --git a/src/datavisualization/axis/q3dvalueaxis.cpp b/src/datavisualization/axis/q3dvalueaxis.cpp
new file mode 100644
index 00000000..5e38e4ca
--- /dev/null
+++ b/src/datavisualization/axis/q3dvalueaxis.cpp
@@ -0,0 +1,270 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#include "q3dvalueaxis.h"
+#include "q3dvalueaxis_p.h"
+#include "utils_p.h"
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+/*!
+ * \class Q3DValueAxis
+ * \inmodule QtDataVisualization
+ * \brief The Q3DValueAxis class is used for manipulating an axis of a graph.
+ * \since 1.0.0
+ *
+ * Q3DValueAxis provides an axis that can be given a range of values and segment and subsegment
+ * counts to divide the range into.
+ *
+ * Labels are drawn between each segment. Grid lines are drawn between each segment and each
+ * subsegment. \note If visible, there will always be at least two grid lines and labels indicating
+ * the minimum and the maximum values of the range, as there is always at least one segment.
+ */
+
+/*!
+ * \qmltype ValueAxis3D
+ * \inqmlmodule com.digia.QtDataVisualization 1.0
+ * \since com.digia.QtDataVisualization 1.0
+ * \ingroup datavisualization_qml
+ * \instantiates Q3DValueAxis
+ * \inherits AbstractAxis3D
+ * \brief The ValueAxis3D type is used for manipulating an axis of a graph.
+ *
+ * This type provides an axis that can be given a range of values and segment and subsegment
+ * counts to divide the range into.
+ */
+
+
+/*!
+ * \qmlproperty int ValueAxis3D::segmentCount
+ *
+ * Defines the number of segments on the axis. This indicates how many labels are drawn. The number
+ * of grid lines to be drawn is calculated with formula: \c {segments * subsegments + 1}.
+ * The preset default is \c 5, and it can not be below \c 1.
+ */
+
+/*!
+ * \qmlproperty int ValueAxis3D::subSegmentCount
+ *
+ * Defines the number of subsegments inside each segment on the axis. Grid lines are drawn between
+ * each subsegment, in addition to each segment.
+ * The preset default is \c 1, and it can not be below \c 1.
+ */
+
+/*!
+ * \qmlproperty string ValueAxis3D::labelFormat
+ *
+ * Defines the label format to be used for the labels on this axis. Supported specifiers are:
+ * \c {d, i, o, x, X, f, F, e, E, g, G, c}. See QString::sprintf() for additional details.
+ */
+
+/*!
+ * Constructs Q3DValueAxis with the given \a parent.
+ */
+Q3DValueAxis::Q3DValueAxis(QObject *parent) :
+ Q3DAbstractAxis(new Q3DValueAxisPrivate(this), parent)
+{
+}
+
+/*!
+ * Destroys Q3DValueAxis.
+ */
+Q3DValueAxis::~Q3DValueAxis()
+{
+}
+
+
+/*!
+ * \property Q3DValueAxis::segmentCount
+ *
+ * Defines the number of segments on the axis. This indicates how many labels are drawn. The number
+ * of grid lines to be drawn is calculated with formula: \c {segments * subsegments + 1}.
+ * The preset default is \c 5, and it can not be below \c 1.
+ *
+ * \sa setSubSegmentCount()
+ */
+void Q3DValueAxis::setSegmentCount(int count)
+{
+ if (count <= 0) {
+ qWarning() << "Warning: Illegal segment count automatically adjusted to a legal one:"
+ << count << "-> 1";
+ count = 1;
+ }
+ if (dptr()->m_segmentCount != count){
+ dptr()->m_segmentCount = count;
+ dptr()->emitLabelsChanged();
+ emit segmentCountChanged(count);
+ }
+}
+
+int Q3DValueAxis::segmentCount() const
+{
+ return dptrc()->m_segmentCount;
+}
+
+/*!
+ * \property Q3DValueAxis::subSegmentCount
+ *
+ * Defines the number of subsegments inside each segment on the axis. Grid lines are drawn between
+ * each subsegment, in addition to each segment.
+ * The preset default is \c 1, and it can not be below \c 1.
+ *
+ * \sa setSegmentCount()
+ */
+void Q3DValueAxis::setSubSegmentCount(int count)
+{
+ if (count <= 0) {
+ qWarning() << "Warning: Illegal subsegment count automatically adjusted to a legal one:"
+ << count << "-> 1";
+ count = 1;
+ }
+ if (dptr()->m_subSegmentCount != count) {
+ dptr()->m_subSegmentCount = count;
+ emit subSegmentCountChanged(count);
+ }
+}
+
+int Q3DValueAxis::subSegmentCount() const
+{
+ return dptrc()->m_subSegmentCount;
+}
+
+/*!
+ * \property Q3DValueAxis::labelFormat
+ *
+ * Defines the label format to be used for the labels on this axis. Supported specifiers are:
+ * \c {d, i, o, x, X, f, F, e, E, g, G, c}. See QString::sprintf() for additional details.
+ *
+ * Usage example:
+ *
+ * \c {axis->setLabelFormat("%.2f mm");}
+ */
+void Q3DValueAxis::setLabelFormat(const QString &format)
+{
+ if (dptr()->m_labelFormat != format) {
+ dptr()->m_labelFormat = format;
+ dptr()->emitLabelsChanged();
+ emit labelFormatChanged(format);
+ }
+}
+
+QString Q3DValueAxis::labelFormat() const
+{
+ return dptrc()->m_labelFormat;
+}
+
+/*!
+ * \internal
+ */
+Q3DValueAxisPrivate *Q3DValueAxis::dptr()
+{
+ return static_cast<Q3DValueAxisPrivate *>(d_ptr.data());
+}
+
+/*!
+ * \internal
+ */
+const Q3DValueAxisPrivate *Q3DValueAxis::dptrc() const
+{
+ return static_cast<const Q3DValueAxisPrivate *>(d_ptr.data());
+}
+
+Q3DValueAxisPrivate::Q3DValueAxisPrivate(Q3DValueAxis *q)
+ : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeValue),
+ m_segmentCount(5),
+ m_subSegmentCount(1),
+ m_labelFormat(Utils::defaultLabelFormat()),
+ m_labelsDirty(true)
+{
+}
+
+Q3DValueAxisPrivate::~Q3DValueAxisPrivate()
+{
+}
+
+void Q3DValueAxisPrivate::setRange(qreal min, qreal max)
+{
+ bool dirty = (min != m_min || max != m_max);
+
+ Q3DAbstractAxisPrivate::setRange(min, max);
+
+ if (dirty)
+ emitLabelsChanged();
+}
+
+void Q3DValueAxisPrivate::setMin(qreal min)
+{
+ bool dirty = (min != m_min);
+
+ Q3DAbstractAxisPrivate::setMin(min);
+
+ if (dirty)
+ emitLabelsChanged();
+}
+
+void Q3DValueAxisPrivate::setMax(qreal max)
+{
+ bool dirty = (max != m_max);
+
+ Q3DAbstractAxisPrivate::setMax(max);
+
+ if (dirty)
+ emitLabelsChanged();
+}
+
+void Q3DValueAxisPrivate::emitLabelsChanged()
+{
+ m_labelsDirty = true;
+ emit q_ptr->labelsChanged();
+}
+
+void Q3DValueAxisPrivate::updateLabels()
+{
+ if (!m_labelsDirty)
+ return;
+
+ m_labelsDirty = false;
+
+ QStringList newLabels;
+ newLabels.reserve(m_segmentCount + 1);
+
+ // First label is at axis min, which is an extra segment
+ qreal segmentStep = (m_max - m_min) / m_segmentCount;
+
+ QString formatString(m_labelFormat);
+ Utils::ParamType paramType = Utils::findFormatParamType(formatString);
+ QByteArray formatArray = formatString.toUtf8();
+
+ for (int i = 0; i < m_segmentCount; i++) {
+ qreal value = m_min + (segmentStep * i);
+ newLabels.append(Utils::formatLabel(formatArray, paramType, value));
+ }
+
+ // Ensure max label doesn't suffer from any rounding errors
+ newLabels.append(Utils::formatLabel(formatArray, paramType, m_max));
+
+ if (m_labels != newLabels)
+ m_labels = newLabels;
+}
+
+Q3DValueAxis *Q3DValueAxisPrivate::qptr()
+{
+ return static_cast<Q3DValueAxis *>(q_ptr);
+}
+
+QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/axis/q3dvalueaxis.h b/src/datavisualization/axis/q3dvalueaxis.h
new file mode 100644
index 00000000..f1280e25
--- /dev/null
+++ b/src/datavisualization/axis/q3dvalueaxis.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+#ifndef QVALUEAXIS_H
+#define QVALUEAXIS_H
+
+#include <QtDataVisualization/q3dabstractaxis.h>
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DValueAxisPrivate;
+
+class QT_DATAVISUALIZATION_EXPORT Q3DValueAxis : public Q3DAbstractAxis
+{
+ Q_OBJECT
+ Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
+ Q_PROPERTY(int subSegmentCount READ subSegmentCount WRITE setSubSegmentCount NOTIFY subSegmentCountChanged)
+ Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged)
+
+public:
+ explicit Q3DValueAxis(QObject *parent = 0);
+ virtual ~Q3DValueAxis();
+
+ int segmentCount() const;
+ int subSegmentCount() const;
+ QString labelFormat() const;
+
+ void setSegmentCount(int count);
+ void setSubSegmentCount(int count);
+ void setLabelFormat(const QString &format);
+
+signals:
+ void segmentCountChanged(int count);
+ void subSegmentCountChanged(int count);
+ void labelFormatChanged(QString format);
+
+protected:
+ Q3DValueAxisPrivate *dptr();
+ const Q3DValueAxisPrivate *dptrc() const;
+
+private:
+ Q_DISABLE_COPY(Q3DValueAxis)
+ friend class Bars3DController;
+ friend class Scatter3DController;
+ friend class Surface3DController;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QVALUEAXIS_H
diff --git a/src/datavisualization/axis/q3dvalueaxis_p.h b/src/datavisualization/axis/q3dvalueaxis_p.h
new file mode 100644
index 00000000..5d0084e6
--- /dev/null
+++ b/src/datavisualization/axis/q3dvalueaxis_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use contact form at http://qt.digia.com
+**
+** This file is part of the QtDataVisualization module.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** contact form at http://qt.digia.com
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVisualization API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#include "q3dvalueaxis.h"
+#include "q3dabstractaxis_p.h"
+
+#ifndef QVALUEAXIS_P_H
+#define QVALUEAXIS_P_H
+
+QT_DATAVISUALIZATION_BEGIN_NAMESPACE
+
+class Q3DValueAxisPrivate : public Q3DAbstractAxisPrivate
+{
+ Q_OBJECT
+
+public:
+ Q3DValueAxisPrivate(Q3DValueAxis *q);
+ virtual ~Q3DValueAxisPrivate();
+
+ virtual void setRange(qreal min, qreal max);
+ virtual void setMin(qreal min);
+ virtual void setMax (qreal max);
+
+protected:
+ void emitLabelsChanged();
+ virtual void updateLabels();
+
+ int m_segmentCount;
+ int m_subSegmentCount;
+ QString m_labelFormat;
+ bool m_labelsDirty;
+
+private:
+ Q3DValueAxis *qptr();
+
+ friend class Q3DValueAxis;
+};
+
+QT_DATAVISUALIZATION_END_NAMESPACE
+
+#endif // QVALUEAXIS_P_H