summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-12-05 06:28:02 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-12-05 06:28:56 +0200
commite57ed8602ac02ff86e3c08362ca4fbe23fe05bfb (patch)
tree8182e15307cf5853255b6d6d9d0c0b017875cc1d /src/datavisualization/axis
parent78d4deb0be21f22d74e3e01315686857ef8edf2e (diff)
Notifys added to properties
Task-number: QTRD-2671 Change-Id: If95696b01eab836c2b4d5c6a3c19d7da9b255ab3 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis')
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.cpp85
-rw-r--r--src/datavisualization/axis/q3dabstractaxis.h25
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.cpp21
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.h9
4 files changed, 91 insertions, 49 deletions
diff --git a/src/datavisualization/axis/q3dabstractaxis.cpp b/src/datavisualization/axis/q3dabstractaxis.cpp
index 82d6e775..0b284947 100644
--- a/src/datavisualization/axis/q3dabstractaxis.cpp
+++ b/src/datavisualization/axis/q3dabstractaxis.cpp
@@ -51,6 +51,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
/*!
* \qmlproperty list AbstractAxis3D::labels
* Defines the labels for the axis.
+ * \note Setting this property for ValueAxis3D does nothing, as it generates labels automatically.
*/
/*!
@@ -124,27 +125,6 @@ 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.
@@ -164,6 +144,11 @@ Q3DAbstractAxis::AxisType Q3DAbstractAxis::type() const
return d_ptr->m_type;
}
+/*!
+ * \property Q3DAbstractAxis::title
+ *
+ * Defines the title for the axis.
+ */
void Q3DAbstractAxis::setTitle(QString title)
{
if (d_ptr->m_title != title) {
@@ -172,6 +157,28 @@ void Q3DAbstractAxis::setTitle(QString title)
}
}
+QString Q3DAbstractAxis::title() const
+{
+ return d_ptr->m_title;
+}
+
+/*!
+ * \property Q3DAbstractAxis::labels
+ *
+ * Defines the labels for the axis.
+ * \note Setting this property for Q3DValueAxis does nothing, as it generates labels automatically.
+ */
+void Q3DAbstractAxis::setLabels(const QStringList &labels)
+{
+ Q_UNUSED(labels)
+}
+
+QStringList Q3DAbstractAxis::labels() const
+{
+ d_ptr->updateLabels();
+ return d_ptr->m_labels;
+}
+
/*!
* 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.
@@ -241,6 +248,12 @@ bool Q3DAbstractAxis::isAutoAdjustRange() const
return d_ptr->m_autoAdjust;
}
+/*!
+ * \fn Q3DAbstractAxis::rangeChanged(float min, float max)
+ *
+ * Emits range \a min and \a max values when range changes.
+ */
+
// Q3DAbstractAxisPrivate
Q3DAbstractAxisPrivate::Q3DAbstractAxisPrivate(Q3DAbstractAxis *q, Q3DAbstractAxis::AxisType type)
@@ -263,10 +276,12 @@ Q3DAbstractAxisPrivate::~Q3DAbstractAxisPrivate()
void Q3DAbstractAxisPrivate::setOrientation(Q3DAbstractAxis::AxisOrientation orientation)
{
- if (m_orientation == Q3DAbstractAxis::AxisOrientationNone)
+ if (m_orientation == Q3DAbstractAxis::AxisOrientationNone) {
m_orientation = orientation;
- else
+ emit q_ptr->orientationChanged(orientation);
+ } else {
Q_ASSERT("Attempted to reset axis orientation.");
+ }
}
void Q3DAbstractAxisPrivate::updateLabels()
@@ -290,10 +305,11 @@ void Q3DAbstractAxisPrivate::setRange(float min, float max)
// If min >= max, we adjust ranges so that
// m_max becomes (min + 1.0f)
// as axes need some kind of valid range.
- bool dirty = false;
+ bool minDirty = false;
+ bool maxDirty = false;
if (m_min != min) {
m_min = min;
- dirty = true;
+ minDirty = true;
}
if (m_max != max || min > max || (!m_allowMinMaxSame && min == max)) {
if (min > max || (!m_allowMinMaxSame && min == max)) {
@@ -302,10 +318,10 @@ void Q3DAbstractAxisPrivate::setRange(float min, float max)
} else {
m_max = max;
}
- dirty = true;
+ maxDirty = true;
}
- if (dirty) {
+ if (minDirty || maxDirty) {
if (adjusted) {
qWarning() << "Warning: Tried to set invalid range for axis."
" Range automatically adjusted to a valid one:"
@@ -313,6 +329,11 @@ void Q3DAbstractAxisPrivate::setRange(float min, float max)
}
emit q_ptr->rangeChanged(m_min, m_max);
}
+
+ if (minDirty)
+ emit q_ptr->minChanged(m_min);
+ if (maxDirty)
+ emit q_ptr->maxChanged(m_max);
}
void Q3DAbstractAxisPrivate::setMin(float min)
@@ -326,16 +347,21 @@ void Q3DAbstractAxisPrivate::setMin(float min)
}
if (m_min != min) {
+ bool maxChanged = false;
if (min > m_max || (!m_allowMinMaxSame && min == m_max)) {
float oldMax = m_max;
m_max = min + 1.0f;
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;
+ maxChanged = true;
}
m_min = min;
emit q_ptr->rangeChanged(m_min, m_max);
+ emit q_ptr->minChanged(m_min);
+ if (maxChanged)
+ emit q_ptr->maxChanged(m_max);
}
}
@@ -350,6 +376,7 @@ void Q3DAbstractAxisPrivate::setMax(float max)
}
if (m_max != max) {
+ bool minChanged = false;
if (m_min > max || (!m_allowMinMaxSame && m_min == max)) {
float oldMin = m_min;
m_min = max - 1.0f;
@@ -364,9 +391,13 @@ void Q3DAbstractAxisPrivate::setMax(float max)
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;
+ minChanged = true;
}
m_max = max;
emit q_ptr->rangeChanged(m_min, m_max);
+ emit q_ptr->maxChanged(m_max);
+ if (minChanged)
+ emit q_ptr->minChanged(m_min);
}
}
diff --git a/src/datavisualization/axis/q3dabstractaxis.h b/src/datavisualization/axis/q3dabstractaxis.h
index c154c3ea..825290f5 100644
--- a/src/datavisualization/axis/q3dabstractaxis.h
+++ b/src/datavisualization/axis/q3dabstractaxis.h
@@ -35,11 +35,11 @@ class QT_DATAVISUALIZATION_EXPORT Q3DAbstractAxis : public QObject
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(float min READ min WRITE setMin NOTIFY rangeChanged)
- Q_PROPERTY(float max READ max WRITE setMax NOTIFY rangeChanged)
+ Q_PROPERTY(QStringList labels READ labels WRITE setLabels NOTIFY labelsChanged)
+ Q_PROPERTY(AxisOrientation orientation READ orientation NOTIFY orientationChanged)
+ Q_PROPERTY(AxisType type READ type CONSTANT)
+ Q_PROPERTY(float min READ min WRITE setMin NOTIFY minChanged)
+ Q_PROPERTY(float max READ max WRITE setMax NOTIFY maxChanged)
Q_PROPERTY(bool autoAdjustRange READ isAutoAdjustRange WRITE setAutoAdjustRange NOTIFY autoAdjustRangeChanged)
public:
@@ -63,25 +63,32 @@ protected:
public:
virtual ~Q3DAbstractAxis();
+ void setTitle(QString title);
QString title() const;
+
+ void setLabels(const QStringList &labels);
QStringList labels() const;
AxisOrientation orientation() const;
AxisType type() const;
+ void setMin(float min);
float min() const;
+
+ void setMax(float max);
float max() const;
+
+ void setAutoAdjustRange(bool autoAdjust);
bool isAutoAdjustRange() const;
- void setTitle(QString title);
void setRange(float min, float max);
- void setMin(float min);
- void setMax(float max);
- void setAutoAdjustRange(bool autoAdjust);
signals:
void titleChanged(QString newTitle);
void labelsChanged();
+ void orientationChanged(AxisOrientation orientation);
+ void minChanged(float value);
+ void maxChanged(float value);
void rangeChanged(float min, float max);
void autoAdjustRangeChanged(bool autoAdjust);
diff --git a/src/datavisualization/axis/q3dcategoryaxis.cpp b/src/datavisualization/axis/q3dcategoryaxis.cpp
index 6d2dec3a..26a75f93 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.cpp
+++ b/src/datavisualization/axis/q3dcategoryaxis.cpp
@@ -49,10 +49,14 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
*/
/*!
- * \qmlproperty list CategoryAxis3D::categoryLabels
+ * \qmlproperty list CategoryAxis3D::labels
+ *
* 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 defined explicitly, labels are
- * generated from the data row and column labels.
+ * generated from the data row (or column) labels.
+ *
+ * \note If the graph has multiple visible series and category labels are not defined explicitly,
+ * changing the rows (or columns) on any of the attached series will regenerate the labels.
*/
/*!
@@ -61,6 +65,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
Q3DCategoryAxis::Q3DCategoryAxis(QObject *parent) :
Q3DAbstractAxis(new Q3DCategoryAxisPrivate(this), parent)
{
+ connect(this, &Q3DCategoryAxis::labelsChanged, this, &Q3DAbstractAxis::labelsChanged);
}
/*!
@@ -71,7 +76,7 @@ Q3DCategoryAxis::~Q3DCategoryAxis()
}
/*!
- * \property Q3DCategoryAxis::categoryLabels
+ * \property Q3DCategoryAxis::labels
*
* 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 defined explicitly, labels are
@@ -79,17 +84,13 @@ Q3DCategoryAxis::~Q3DCategoryAxis()
*
* \note If the graph has multiple visible series and category labels are not defined explicitly,
* changing the rows (or columns) on any of the attached series will regenerate the 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
+QStringList Q3DCategoryAxis::labels() const
{
- return labels();
+ return Q3DAbstractAxis::labels();
}
-void Q3DCategoryAxis::setCategoryLabels(const QStringList &labels)
+void Q3DCategoryAxis::setLabels(const QStringList &labels)
{
dptr()->m_labelsExplicitlySet = !labels.isEmpty();
bool labelsFromData = false;
diff --git a/src/datavisualization/axis/q3dcategoryaxis.h b/src/datavisualization/axis/q3dcategoryaxis.h
index ef545950..7b2b4744 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.h
+++ b/src/datavisualization/axis/q3dcategoryaxis.h
@@ -28,14 +28,17 @@ class Q3DCategoryAxisPrivate;
class QT_DATAVISUALIZATION_EXPORT Q3DCategoryAxis : public Q3DAbstractAxis
{
Q_OBJECT
- Q_PROPERTY(QStringList categoryLabels READ categoryLabels WRITE setCategoryLabels)
+ Q_PROPERTY(QStringList labels READ labels WRITE setLabels NOTIFY labelsChanged)
public:
explicit Q3DCategoryAxis(QObject *parent = 0);
virtual ~Q3DCategoryAxis();
- QStringList categoryLabels() const;
- void setCategoryLabels(const QStringList &labels);
+ void setLabels(const QStringList &labels);
+ QStringList labels() const;
+
+signals:
+ void labelsChanged();
protected:
Q3DCategoryAxisPrivate *dptr();