summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-04-02 12:16:05 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-04-03 09:27:54 +0300
commitaaf51bfad10e0eac7a8ee64e36aab5f0c1119468 (patch)
treebd20d2ec028bf1acfe4dd418b3a639b17f75b591 /src/datavisualization/data
parente076fa05488bb9f58393f0e636c97d07b6fb446d (diff)
Enable querying selection label via API
Also enable suppressing drawing the label on graph. Selection label formatting was consequently moved from renderers to series. Task-number: QTRD-2896 Change-Id: Ia6a1a40298d8db0f54349de3eb27fb0b683dd302 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data')
-rw-r--r--src/datavisualization/data/qabstract3dseries.cpp101
-rw-r--r--src/datavisualization/data/qabstract3dseries.h8
-rw-r--r--src/datavisualization/data/qabstract3dseries_p.h18
-rw-r--r--src/datavisualization/data/qbar3dseries.cpp51
-rw-r--r--src/datavisualization/data/qbar3dseries_p.h1
-rw-r--r--src/datavisualization/data/qscatter3dseries.cpp45
-rw-r--r--src/datavisualization/data/qscatter3dseries_p.h1
-rw-r--r--src/datavisualization/data/qsurface3dseries.cpp45
-rw-r--r--src/datavisualization/data/qsurface3dseries_p.h1
9 files changed, 259 insertions, 12 deletions
diff --git a/src/datavisualization/data/qabstract3dseries.cpp b/src/datavisualization/data/qabstract3dseries.cpp
index 802a4e8e..934fad16 100644
--- a/src/datavisualization/data/qabstract3dseries.cpp
+++ b/src/datavisualization/data/qabstract3dseries.cpp
@@ -241,6 +241,25 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*/
/*!
+ * \qmlproperty string Abstract3DSeries::itemLabel
+ *
+ * Contains the formatted item label. If there is no selected item or the selected item is not
+ * visible, returns an empty string.
+ *
+ * \sa itemLabelFormat
+ */
+
+/*!
+ * \qmlproperty bool Abstract3DSeries::itemLabelVisible
+ *
+ * If \c true, item labels are drawn as floating labels in the graph. Otherwise item labels are not
+ * drawn. If you prefer to show the item label in an external control, set this property to
+ * \c false. Defaults to \c true.
+ *
+ * \sa itemLabelFormat, itemLabel
+ */
+
+/*!
* \qmlmethod void Abstract3DSeries::setMeshAxisAndAngle(vector3d axis, real angle)
*
* A convenience function to construct mesh rotation quaternion from axis and angle.
@@ -587,6 +606,41 @@ QString QAbstract3DSeries::name() const
return d_ptr->m_name;
}
+/*!
+ * \property QAbstract3DSeries::itemLabel
+ *
+ * Contains the formatted item label. If there is no selected item or the selected item is not
+ * visible, returns an empty string.
+ *
+ * \sa itemLabelFormat
+ */
+QString QAbstract3DSeries::itemLabel() const
+{
+ return d_ptr->itemLabel();
+}
+
+/*!
+ * \property QAbstract3DSeries::itemLabelVisible
+ *
+ * If \c true, item labels are drawn as floating labels in the graph. Otherwise item labels are not
+ * drawn. If you prefer to show the item label in an external control, set this property to
+ * \c false. Defaults to \c true.
+ *
+ * \sa itemLabelFormat, itemLabel
+ */
+void QAbstract3DSeries::setItemLabelVisible(bool visible)
+{
+ if (d_ptr->m_itemLabelVisible != visible) {
+ d_ptr->setItemLabelVisible(visible);
+ emit itemLabelVisibilityChanged(visible);
+ }
+}
+
+bool QAbstract3DSeries::isItemLabelVisible() const
+{
+ return d_ptr->m_itemLabelVisible;
+}
+
// QAbstract3DSeriesPrivate
QAbstract3DSeriesPrivate::QAbstract3DSeriesPrivate(QAbstract3DSeries *q, QAbstract3DSeries::SeriesType type)
@@ -598,7 +652,9 @@ QAbstract3DSeriesPrivate::QAbstract3DSeriesPrivate(QAbstract3DSeries *q, QAbstra
m_controller(0),
m_mesh(QAbstract3DSeries::MeshCube),
m_meshSmooth(false),
- m_colorStyle(Q3DTheme::ColorStyleUniform)
+ m_colorStyle(Q3DTheme::ColorStyleUniform),
+ m_itemLabelDirty(true),
+ m_itemLabelVisible(true)
{
}
@@ -631,21 +687,19 @@ void QAbstract3DSeriesPrivate::setController(Abstract3DController *controller)
connectControllerAndProxy(controller);
m_controller = controller;
q_ptr->setParent(controller);
+ markItemLabelDirty();
}
void QAbstract3DSeriesPrivate::setItemLabelFormat(const QString &format)
{
m_itemLabelFormat = format;
- m_changeTracker.itemLabelFormatChanged = true;
- if (m_controller)
- m_controller->markSeriesVisualsDirty();
+ markItemLabelDirty();
}
void QAbstract3DSeriesPrivate::setVisible(bool visible)
{
m_visible = visible;
- if (m_controller)
- m_controller->markSeriesVisualsDirty();
+ markItemLabelDirty();
}
void QAbstract3DSeriesPrivate::setMesh(QAbstract3DSeries::Mesh mesh)
@@ -739,9 +793,8 @@ void QAbstract3DSeriesPrivate::setMultiHighlightGradient(const QLinearGradient &
void QAbstract3DSeriesPrivate::setName(const QString &name)
{
m_name = name;
+ markItemLabelDirty();
m_changeTracker.nameChanged = true;
- if (m_controller)
- m_controller->markSeriesVisualsDirty();
}
void QAbstract3DSeriesPrivate::resetToTheme(const Q3DTheme &theme, int seriesIndex, bool force)
@@ -781,4 +834,36 @@ void QAbstract3DSeriesPrivate::resetToTheme(const Q3DTheme &theme, int seriesInd
}
}
+QString QAbstract3DSeriesPrivate::itemLabel()
+{
+ if (m_itemLabelDirty) {
+ QString oldLabel = m_itemLabel;
+ if (m_controller && m_visible)
+ createItemLabel();
+ else
+ m_itemLabel = QString();
+ m_itemLabelDirty = false;
+
+ if (oldLabel != m_itemLabel)
+ emit q_ptr->itemLabelChanged(m_itemLabel);
+ }
+
+ return m_itemLabel;
+}
+
+void QAbstract3DSeriesPrivate::markItemLabelDirty()
+{
+ m_itemLabelDirty = true;
+ m_changeTracker.itemLabelChanged = true;
+ if (m_controller)
+ m_controller->markSeriesVisualsDirty();
+}
+
+void QAbstract3DSeriesPrivate::setItemLabelVisible(bool visible)
+{
+ m_itemLabelVisible = visible;
+ markItemLabelDirty();
+ m_changeTracker.itemLabelVisibilityChanged = true;
+}
+
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/qabstract3dseries.h b/src/datavisualization/data/qabstract3dseries.h
index bf56422f..55254904 100644
--- a/src/datavisualization/data/qabstract3dseries.h
+++ b/src/datavisualization/data/qabstract3dseries.h
@@ -50,6 +50,8 @@ class QT_DATAVISUALIZATION_EXPORT QAbstract3DSeries : public QObject
Q_PROPERTY(QColor multiHighlightColor READ multiHighlightColor WRITE setMultiHighlightColor NOTIFY multiHighlightColorChanged)
Q_PROPERTY(QLinearGradient multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(QString itemLabel READ itemLabel NOTIFY itemLabelChanged REVISION 1)
+ Q_PROPERTY(bool itemLabelVisible READ isItemLabelVisible WRITE setItemLabelVisible NOTIFY itemLabelVisibilityChanged REVISION 1)
public:
enum SeriesType {
@@ -119,6 +121,10 @@ public:
void setName(const QString &name);
QString name() const;
+ QString itemLabel() const;
+ void setItemLabelVisible(bool visible);
+ bool isItemLabelVisible() const;
+
signals:
void itemLabelFormatChanged(const QString &format);
void visibilityChanged(bool visible);
@@ -134,6 +140,8 @@ signals:
void multiHighlightColorChanged(const QColor &color);
void multiHighlightGradientChanged(const QLinearGradient &gradient);
void nameChanged(const QString &name);
+ void itemLabelChanged(const QString &label);
+ void itemLabelVisibilityChanged(bool visible);
protected:
QScopedPointer<QAbstract3DSeriesPrivate> d_ptr;
diff --git a/src/datavisualization/data/qabstract3dseries_p.h b/src/datavisualization/data/qabstract3dseries_p.h
index a803e99b..530afe5e 100644
--- a/src/datavisualization/data/qabstract3dseries_p.h
+++ b/src/datavisualization/data/qabstract3dseries_p.h
@@ -38,7 +38,6 @@ class QAbstractDataProxy;
class Abstract3DController;
struct QAbstract3DSeriesChangeBitField {
- bool itemLabelFormatChanged : 1;
bool meshChanged : 1;
bool meshSmoothChanged : 1;
bool meshRotationChanged : 1;
@@ -51,10 +50,11 @@ struct QAbstract3DSeriesChangeBitField {
bool multiHighlightColorChanged : 1;
bool multiHighlightGradientChanged : 1;
bool nameChanged : 1;
+ bool itemLabelChanged : 1;
+ bool itemLabelVisibilityChanged : 1;
QAbstract3DSeriesChangeBitField()
- : itemLabelFormatChanged(true),
- meshChanged(true),
+ : meshChanged(true),
meshSmoothChanged(true),
meshRotationChanged(true),
userDefinedMeshChanged(true),
@@ -65,7 +65,9 @@ struct QAbstract3DSeriesChangeBitField {
singleHighlightGradientChanged(true),
multiHighlightColorChanged(true),
multiHighlightGradientChanged(true),
- nameChanged(true)
+ nameChanged(true),
+ itemLabelChanged(true),
+ itemLabelVisibilityChanged(true)
{
}
};
@@ -102,6 +104,7 @@ public:
virtual void setDataProxy(QAbstractDataProxy *proxy);
virtual void setController(Abstract3DController *controller);
virtual void connectControllerAndProxy(Abstract3DController *newController) = 0;
+ virtual void createItemLabel() = 0;
void setItemLabelFormat(const QString &format);
void setVisible(bool visible);
@@ -120,6 +123,10 @@ public:
void setName(const QString &name);
void resetToTheme(const Q3DTheme &theme, int seriesIndex, bool force);
+ QString itemLabel();
+ void markItemLabelDirty();
+ inline bool itemLabelDirty() const { return m_itemLabelDirty; }
+ void setItemLabelVisible(bool visible);
QAbstract3DSeriesChangeBitField m_changeTracker;
QAbstract3DSeriesThemeOverrideBitField m_themeTracker;
@@ -143,6 +150,9 @@ public:
QLinearGradient m_multiHighlightGradient;
QString m_name;
+ QString m_itemLabel;
+ bool m_itemLabelDirty;
+ bool m_itemLabelVisible;
};
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/qbar3dseries.cpp b/src/datavisualization/data/qbar3dseries.cpp
index ed4ffaba..8a05100f 100644
--- a/src/datavisualization/data/qbar3dseries.cpp
+++ b/src/datavisualization/data/qbar3dseries.cpp
@@ -317,6 +317,56 @@ void QBar3DSeriesPrivate::connectControllerAndProxy(Abstract3DController *newCon
}
}
+void QBar3DSeriesPrivate::createItemLabel()
+{
+ static const QString rowIndexTag(QStringLiteral("@rowIdx"));
+ static const QString rowLabelTag(QStringLiteral("@rowLabel"));
+ static const QString rowTitleTag(QStringLiteral("@rowTitle"));
+ static const QString colIndexTag(QStringLiteral("@colIdx"));
+ static const QString colLabelTag(QStringLiteral("@colLabel"));
+ static const QString colTitleTag(QStringLiteral("@colTitle"));
+ static const QString valueTitleTag(QStringLiteral("@valueTitle"));
+ static const QString valueLabelTag(QStringLiteral("@valueLabel"));
+ static const QString seriesNameTag(QStringLiteral("@seriesName"));
+
+ if (m_selectedBar == QBar3DSeries::invalidSelectionPosition()) {
+ m_itemLabel = QString();
+ return;
+ }
+
+ QCategory3DAxis *categoryAxisZ = static_cast<QCategory3DAxis *>(m_controller->axisZ());
+ QCategory3DAxis *categoryAxisX = static_cast<QCategory3DAxis *>(m_controller->axisX());
+ QValue3DAxis *valueAxis = static_cast<QValue3DAxis *>(m_controller->axisY());
+ qreal selectedBarValue = qreal(qptr()->dataProxy()->itemAt(m_selectedBar)->value());
+
+ // Custom format expects printf format specifier. There is no tag for it.
+ m_itemLabel = valueAxis->formatter()->stringForValue(selectedBarValue, m_itemLabelFormat);
+
+ int selBarPosRow = m_selectedBar.x();
+ int selBarPosCol = m_selectedBar.y();
+ m_itemLabel.replace(rowIndexTag, QString::number(selBarPosRow));
+ if (categoryAxisZ->labels().size() > selBarPosRow)
+ m_itemLabel.replace(rowLabelTag, categoryAxisZ->labels().at(selBarPosRow));
+ else
+ m_itemLabel.replace(rowLabelTag, QString());
+ m_itemLabel.replace(rowTitleTag, categoryAxisZ->title());
+ m_itemLabel.replace(colIndexTag, QString::number(selBarPosCol));
+ if (categoryAxisX->labels().size() > selBarPosCol)
+ m_itemLabel.replace(colLabelTag, categoryAxisX->labels().at(selBarPosCol));
+ else
+ m_itemLabel.replace(colLabelTag, QString());
+ m_itemLabel.replace(colTitleTag, categoryAxisX->title());
+ m_itemLabel.replace(valueTitleTag, valueAxis->title());
+
+ if (m_itemLabel.contains(valueLabelTag)) {
+ QString valueLabelText = valueAxis->formatter()->stringForValue(selectedBarValue,
+ valueAxis->labelFormat());
+ m_itemLabel.replace(valueLabelTag, valueLabelText);
+ }
+
+ m_itemLabel.replace(seriesNameTag, m_name);
+}
+
void QBar3DSeriesPrivate::handleMeshRotationChanged(const QQuaternion &rotation)
{
emit qptr()->meshAngleChanged(quaternionAngle(rotation));
@@ -325,6 +375,7 @@ void QBar3DSeriesPrivate::handleMeshRotationChanged(const QQuaternion &rotation)
void QBar3DSeriesPrivate::setSelectedBar(const QPoint &position)
{
if (position != m_selectedBar) {
+ markItemLabelDirty();
m_selectedBar = position;
emit qptr()->selectedBarChanged(m_selectedBar);
}
diff --git a/src/datavisualization/data/qbar3dseries_p.h b/src/datavisualization/data/qbar3dseries_p.h
index 718f1237..c5b51108 100644
--- a/src/datavisualization/data/qbar3dseries_p.h
+++ b/src/datavisualization/data/qbar3dseries_p.h
@@ -43,6 +43,7 @@ public:
virtual void setDataProxy(QAbstractDataProxy *proxy);
virtual void connectControllerAndProxy(Abstract3DController *newController);
+ virtual void createItemLabel();
void handleMeshRotationChanged(const QQuaternion &rotation);
diff --git a/src/datavisualization/data/qscatter3dseries.cpp b/src/datavisualization/data/qscatter3dseries.cpp
index 43bde4dd..f4509ae4 100644
--- a/src/datavisualization/data/qscatter3dseries.cpp
+++ b/src/datavisualization/data/qscatter3dseries.cpp
@@ -298,9 +298,54 @@ void QScatter3DSeriesPrivate::connectControllerAndProxy(Abstract3DController *ne
}
}
+void QScatter3DSeriesPrivate::createItemLabel()
+{
+ static const QString xTitleTag(QStringLiteral("@xTitle"));
+ static const QString yTitleTag(QStringLiteral("@yTitle"));
+ static const QString zTitleTag(QStringLiteral("@zTitle"));
+ static const QString xLabelTag(QStringLiteral("@xLabel"));
+ static const QString yLabelTag(QStringLiteral("@yLabel"));
+ static const QString zLabelTag(QStringLiteral("@zLabel"));
+ static const QString seriesNameTag(QStringLiteral("@seriesName"));
+
+ if (m_selectedItem == QScatter3DSeries::invalidSelectionIndex()) {
+ m_itemLabel = QString();
+ return;
+ }
+
+ QValue3DAxis *axisX = static_cast<QValue3DAxis *>(m_controller->axisX());
+ QValue3DAxis *axisY = static_cast<QValue3DAxis *>(m_controller->axisY());
+ QValue3DAxis *axisZ = static_cast<QValue3DAxis *>(m_controller->axisZ());
+ QVector3D selectedPosition = qptr()->dataProxy()->itemAt(m_selectedItem)->position();
+
+ m_itemLabel = m_itemLabelFormat;
+
+ m_itemLabel.replace(xTitleTag, axisX->title());
+ m_itemLabel.replace(yTitleTag, axisY->title());
+ m_itemLabel.replace(zTitleTag, axisZ->title());
+
+ if (m_itemLabel.contains(xLabelTag)) {
+ QString valueLabelText = axisX->formatter()->stringForValue(
+ qreal(selectedPosition.x()), axisX->labelFormat());
+ m_itemLabel.replace(xLabelTag, valueLabelText);
+ }
+ if (m_itemLabel.contains(yLabelTag)) {
+ QString valueLabelText = axisY->formatter()->stringForValue(
+ qreal(selectedPosition.y()), axisY->labelFormat());
+ m_itemLabel.replace(yLabelTag, valueLabelText);
+ }
+ if (m_itemLabel.contains(zLabelTag)) {
+ QString valueLabelText = axisZ->formatter()->stringForValue(
+ qreal(selectedPosition.z()), axisZ->labelFormat());
+ m_itemLabel.replace(zLabelTag, valueLabelText);
+ }
+ m_itemLabel.replace(seriesNameTag, m_name);
+}
+
void QScatter3DSeriesPrivate::setSelectedItem(int index)
{
if (index != m_selectedItem) {
+ markItemLabelDirty();
m_selectedItem = index;
emit qptr()->selectedItemChanged(m_selectedItem);
}
diff --git a/src/datavisualization/data/qscatter3dseries_p.h b/src/datavisualization/data/qscatter3dseries_p.h
index 1abbd406..8717a616 100644
--- a/src/datavisualization/data/qscatter3dseries_p.h
+++ b/src/datavisualization/data/qscatter3dseries_p.h
@@ -43,6 +43,7 @@ public:
virtual void setDataProxy(QAbstractDataProxy *proxy);
virtual void connectControllerAndProxy(Abstract3DController *newController);
+ virtual void createItemLabel();
void setSelectedItem(int index);
void setItemSize(float size);
diff --git a/src/datavisualization/data/qsurface3dseries.cpp b/src/datavisualization/data/qsurface3dseries.cpp
index 72967bae..60e84f38 100644
--- a/src/datavisualization/data/qsurface3dseries.cpp
+++ b/src/datavisualization/data/qsurface3dseries.cpp
@@ -373,9 +373,54 @@ void QSurface3DSeriesPrivate::connectControllerAndProxy(Abstract3DController *ne
}
}
+void QSurface3DSeriesPrivate::createItemLabel()
+{
+ static const QString xTitleTag(QStringLiteral("@xTitle"));
+ static const QString yTitleTag(QStringLiteral("@yTitle"));
+ static const QString zTitleTag(QStringLiteral("@zTitle"));
+ static const QString xLabelTag(QStringLiteral("@xLabel"));
+ static const QString yLabelTag(QStringLiteral("@yLabel"));
+ static const QString zLabelTag(QStringLiteral("@zLabel"));
+ static const QString seriesNameTag(QStringLiteral("@seriesName"));
+
+ if (m_selectedPoint == QSurface3DSeries::invalidSelectionPosition()) {
+ m_itemLabel = QString();
+ return;
+ }
+
+ QValue3DAxis *axisX = static_cast<QValue3DAxis *>(m_controller->axisX());
+ QValue3DAxis *axisY = static_cast<QValue3DAxis *>(m_controller->axisY());
+ QValue3DAxis *axisZ = static_cast<QValue3DAxis *>(m_controller->axisZ());
+ QVector3D selectedPosition = qptr()->dataProxy()->itemAt(m_selectedPoint)->position();
+
+ m_itemLabel = m_itemLabelFormat;
+
+ m_itemLabel.replace(xTitleTag, axisX->title());
+ m_itemLabel.replace(yTitleTag, axisY->title());
+ m_itemLabel.replace(zTitleTag, axisZ->title());
+
+ if (m_itemLabel.contains(xLabelTag)) {
+ QString valueLabelText = axisX->formatter()->stringForValue(
+ qreal(selectedPosition.x()), axisX->labelFormat());
+ m_itemLabel.replace(xLabelTag, valueLabelText);
+ }
+ if (m_itemLabel.contains(yLabelTag)) {
+ QString valueLabelText = axisY->formatter()->stringForValue(
+ qreal(selectedPosition.y()), axisY->labelFormat());
+ m_itemLabel.replace(yLabelTag, valueLabelText);
+ }
+ if (m_itemLabel.contains(zLabelTag)) {
+ QString valueLabelText = axisZ->formatter()->stringForValue(
+ qreal(selectedPosition.z()), axisZ->labelFormat());
+ m_itemLabel.replace(zLabelTag, valueLabelText);
+ }
+ m_itemLabel.replace(seriesNameTag, m_name);
+}
+
void QSurface3DSeriesPrivate::setSelectedPoint(const QPoint &position)
{
if (position != m_selectedPoint) {
+ markItemLabelDirty();
m_selectedPoint = position;
emit qptr()->selectedPointChanged(m_selectedPoint);
}
diff --git a/src/datavisualization/data/qsurface3dseries_p.h b/src/datavisualization/data/qsurface3dseries_p.h
index bc8157bd..d4cc2820 100644
--- a/src/datavisualization/data/qsurface3dseries_p.h
+++ b/src/datavisualization/data/qsurface3dseries_p.h
@@ -43,6 +43,7 @@ public:
virtual void setDataProxy(QAbstractDataProxy *proxy);
virtual void connectControllerAndProxy(Abstract3DController *newController);
+ virtual void createItemLabel();
void setSelectedPoint(const QPoint &position);
void setFlatShadingEnabled(bool enabled);