summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-17 08:30:34 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-18 08:33:52 +0300
commit4daf244e9745a28b917b0976e39a60d73776c4aa (patch)
tree0b10abd2cea115f5f05b44e753e75cbde9badfd0 /src/datavisualization/axis
parent43435c1b51e81c3ecdfec771950d861df90ebef3 (diff)
Bar graph data window controlled by category axes ranges
Task-number: QTRD-2183 Task-number: QTRD-2254 Change-Id: I09808c3980a4fa60b7584839e834ee3a734b3e9a Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis')
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.cpp195
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.h13
-rw-r--r--src/datavisualization/axis/q3dabstractaxis_p.h9
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.cpp2
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.h1
-rw-r--r--src/datavisualization/axis/q3dvalueaxis.cpp151
-rw-r--r--src/datavisualization/axis/q3dvalueaxis.h12
-rw-r--r--src/datavisualization/axis/q3dvalueaxis_p.h9
8 files changed, 237 insertions, 155 deletions
diff --git a/src/datavisualization/axis/q3dabstractaxis.cpp b/src/datavisualization/axis/q3dabstractaxis.cpp
index ce3b582f..8e1e6a35 100644
--- a/src/datavisualization/axis/q3dabstractaxis.cpp
+++ b/src/datavisualization/axis/q3dabstractaxis.cpp
@@ -60,6 +60,29 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
*/
/*!
+ * \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.
@@ -145,6 +168,75 @@ void Q3DAbstractAxis::setTitle(QString 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)
@@ -152,7 +244,12 @@ Q3DAbstractAxisPrivate::Q3DAbstractAxisPrivate(Q3DAbstractAxis *q, Q3DAbstractAx
q_ptr(q),
m_orientation(Q3DAbstractAxis::AxisOrientationNone),
m_type(type),
- m_isDefaultAxis(false)
+ m_isDefaultAxis(false),
+ m_min(0.0),
+ m_max(10.0),
+ m_autoAdjust(true),
+ m_onlyPositiveValues(false),
+ m_allowMinMaxSame(false)
{
}
@@ -173,4 +270,100 @@ 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
index 6e89723a..31b7ab55 100644
--- a/src/datavisualization/axis/q3dabstractaxis.h
+++ b/src/datavisualization/axis/q3dabstractaxis.h
@@ -38,6 +38,9 @@ class QT_DATAVISUALIZATION_EXPORT Q3DAbstractAxis : public QObject
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 {
@@ -66,12 +69,22 @@ public:
AxisOrientation orientation() const;
AxisType type() const;
+ qreal min() const;
+ qreal max() const;
+ bool isAutoAdjustRange() const;
+
public slots:
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;
diff --git a/src/datavisualization/axis/q3dabstractaxis_p.h b/src/datavisualization/axis/q3dabstractaxis_p.h
index f961e82e..902f65be 100644
--- a/src/datavisualization/axis/q3dabstractaxis_p.h
+++ b/src/datavisualization/axis/q3dabstractaxis_p.h
@@ -47,6 +47,10 @@ public:
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();
@@ -57,6 +61,11 @@ protected:
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;
diff --git a/src/datavisualization/axis/q3dcategoryaxis.cpp b/src/datavisualization/axis/q3dcategoryaxis.cpp
index 57c545c8..3f032534 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.cpp
+++ b/src/datavisualization/axis/q3dcategoryaxis.cpp
@@ -119,6 +119,8 @@ Q3DCategoryAxisPrivate::Q3DCategoryAxisPrivate(Q3DCategoryAxis *q)
: Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory),
m_labelsExplicitlySet(false)
{
+ m_onlyPositiveValues = true;
+ m_allowMinMaxSame = true;
}
Q3DCategoryAxisPrivate::~Q3DCategoryAxisPrivate()
diff --git a/src/datavisualization/axis/q3dcategoryaxis.h b/src/datavisualization/axis/q3dcategoryaxis.h
index bf5e66fd..7376760b 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.h
+++ b/src/datavisualization/axis/q3dcategoryaxis.h
@@ -36,6 +36,7 @@ public:
QStringList categoryLabels() const;
+
public slots:
void setCategoryLabels(const QStringList &labels);
diff --git a/src/datavisualization/axis/q3dvalueaxis.cpp b/src/datavisualization/axis/q3dvalueaxis.cpp
index 86b16fd9..a32a96e7 100644
--- a/src/datavisualization/axis/q3dvalueaxis.cpp
+++ b/src/datavisualization/axis/q3dvalueaxis.cpp
@@ -45,21 +45,6 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
* counts to divide the range into.
*/
-/*!
- * \qmlproperty real ValueAxis3D::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 ValueAxis3D::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 int ValueAxis3D::segmentCount
@@ -78,13 +63,6 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
*/
/*!
- * \qmlproperty bool ValueAxis3D::autoAdjustRange
- *
- * Determines if the axis is to automatically calculate the range instead of setting range or
- * adjusting min or max property.
- */
-
-/*!
* \qmlproperty string ValueAxis3D::labelFormat
*
* Defines the label format to be used for the labels on this axis. Supported specifiers are:
@@ -106,51 +84,6 @@ Q3DValueAxis::~Q3DValueAxis()
{
}
-/*!
- * 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.
- */
-void Q3DValueAxis::setRange(qreal min, qreal max)
-{
- dptr()->setRange(min, max);
- setAutoAdjustRange(false);
-}
-
-/*!
- * \property Q3DValueAxis::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.
- */
-void Q3DValueAxis::setMin(qreal min)
-{
- dptr()->setMin(min);
- setAutoAdjustRange(false);
-}
-
-/*!
- * \property Q3DValueAxis::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.
- */
-void Q3DValueAxis::setMax(qreal max)
-{
- dptr()->setMax(max);
- setAutoAdjustRange(false);
-}
-
-qreal Q3DValueAxis::min() const
-{
- return dptrc()->m_min;
-}
-
-qreal Q3DValueAxis::max() const
-{
- return dptrc()->m_max;
-}
/*!
* \property Q3DValueAxis::segmentCount
@@ -208,27 +141,6 @@ int Q3DValueAxis::subSegmentCount() const
}
/*!
- * \property Q3DValueAxis::autoAdjustRange
- *
- * Tells the axis to automatically calculate the range instead of setting range or adjusting min or
- * max property.
- *
- * \sa setRange(), setMin(), setMax()
- */
-void Q3DValueAxis::setAutoAdjustRange(bool autoAdjust)
-{
- if (dptr()->m_autoAdjust != autoAdjust) {
- dptr()->m_autoAdjust = autoAdjust;
- emit autoAdjustRangeChanged(autoAdjust);
- }
-}
-
-bool Q3DValueAxis::isAutoAdjustRange() const
-{
- return dptrc()->m_autoAdjust;
-}
-
-/*!
* \property Q3DValueAxis::labelFormat
*
* Defines the label format to be used for the labels on this axis. Supported specifiers are:
@@ -270,11 +182,8 @@ const Q3DValueAxisPrivate *Q3DValueAxis::dptrc() const
Q3DValueAxisPrivate::Q3DValueAxisPrivate(Q3DValueAxis *q)
: Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeValue),
- m_min(0.0),
- m_max(10.0),
m_segmentCount(5),
m_subSegmentCount(1),
- m_autoAdjust(true),
m_labelFormat(Utils::defaultLabelFormat()),
m_labelsDirty(true)
{
@@ -286,62 +195,32 @@ Q3DValueAxisPrivate::~Q3DValueAxisPrivate()
void Q3DValueAxisPrivate::setRange(qreal min, qreal max)
{
- // If min >= max, we adjust ranges so that
- // m_max becomes (min + 1.0)
- // as axes need some kind of valid range.
- // TODO: Make "reverse" axes work (i.e. min > max)
- bool dirty = false;
- if (m_min != min) {
- m_min = min;
- dirty = true;
- }
- if (m_max != max || min >= max) {
- if (min >= max) {
- m_max = min + 1.0;
- qWarning() << "Warning: Tried to set invalid range for value axis."
- " Range automatically adjusted to a valid one:"
- << min << "-" << max << "-->" << m_min << "-" << m_max;
- } else {
- m_max = max;
- }
- dirty = true;
- }
- if (dirty) {
+ bool dirty = (min != m_min || max != m_max);
+
+ Q3DAbstractAxisPrivate::setRange(min, max);
+
+ if (dirty)
emitLabelsChanged();
- emit qptr()->rangeChanged(min, max);
- }
}
void Q3DValueAxisPrivate::setMin(qreal min)
{
- if (m_min != min) {
- if (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;
+ bool dirty = (min != m_min);
+
+ Q3DAbstractAxisPrivate::setMin(min);
+
+ if (dirty)
emitLabelsChanged();
- emit qptr()->rangeChanged(m_min, m_max);
- }
}
void Q3DValueAxisPrivate::setMax(qreal max)
{
- if (m_max != max) {
- if (max <= m_min) {
- qreal oldMin = m_min;
- m_min = max - 1.0;
- 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;
+ bool dirty = (max != m_max);
+
+ Q3DAbstractAxisPrivate::setMax(max);
+
+ if (dirty)
emitLabelsChanged();
- emit qptr()->rangeChanged(m_min, m_max);
- }
}
void Q3DValueAxisPrivate::emitLabelsChanged()
diff --git a/src/datavisualization/axis/q3dvalueaxis.h b/src/datavisualization/axis/q3dvalueaxis.h
index eb00f27f..8ff7a531 100644
--- a/src/datavisualization/axis/q3dvalueaxis.h
+++ b/src/datavisualization/axis/q3dvalueaxis.h
@@ -28,38 +28,26 @@ class Q3DValueAxisPrivate;
class QT_DATAVISUALIZATION_EXPORT Q3DValueAxis : public Q3DAbstractAxis
{
Q_OBJECT
- Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY rangeChanged)
- Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY rangeChanged)
Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
Q_PROPERTY(int subSegmentCount READ subSegmentCount WRITE setSubSegmentCount NOTIFY subSegmentCountChanged)
- Q_PROPERTY(bool autoAdjustRange READ isAutoAdjustRange WRITE setAutoAdjustRange NOTIFY autoAdjustRangeChanged)
Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged)
public:
explicit Q3DValueAxis(QObject *parent = 0);
virtual ~Q3DValueAxis();
- qreal min() const;
- qreal max() const;
int segmentCount() const;
int subSegmentCount() const;
- bool isAutoAdjustRange() const;
QString labelFormat() const;
public slots:
- void setRange(qreal min, qreal max);
- void setMin(qreal min);
- void setMax(qreal max);
void setSegmentCount(int count);
void setSubSegmentCount(int count);
- void setAutoAdjustRange(bool autoAdjust);
void setLabelFormat(const QString &format);
signals:
- void rangeChanged(qreal min, qreal max);
void segmentCountChanged(int count);
void subSegmentCountChanged(int count);
- void autoAdjustRangeChanged(bool autoAdjust);
void labelFormatChanged(QString format);
protected:
diff --git a/src/datavisualization/axis/q3dvalueaxis_p.h b/src/datavisualization/axis/q3dvalueaxis_p.h
index 8fcf50da..5d0084e6 100644
--- a/src/datavisualization/axis/q3dvalueaxis_p.h
+++ b/src/datavisualization/axis/q3dvalueaxis_p.h
@@ -42,19 +42,16 @@ public:
Q3DValueAxisPrivate(Q3DValueAxis *q);
virtual ~Q3DValueAxisPrivate();
- void setRange(qreal min, qreal max);
- void setMin(qreal min);
- void setMax (qreal max);
+ virtual void setRange(qreal min, qreal max);
+ virtual void setMin(qreal min);
+ virtual void setMax (qreal max);
protected:
void emitLabelsChanged();
virtual void updateLabels();
- qreal m_min;
- qreal m_max;
int m_segmentCount;
int m_subSegmentCount;
- bool m_autoAdjust;
QString m_labelFormat;
bool m_labelsDirty;