summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2014-05-13 06:22:30 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-05-13 08:08:21 +0300
commite5c7d46ba8c817e663d373fda191662b3276fdc6 (patch)
treebad6aad73a0dd016096e6ef0e86f5d1286115b7d /src
parent3d7f8820a86a4852fe2df27df53b745cfa32eb94 (diff)
Added API for querying label selection
Task-number: QTRD-3045 Change-Id: Ib5c8f29bcf0148ae604e27b2a81e6f72a2dbca2a Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc21
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp38
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h9
-rw-r--r--src/datavisualization/engine/abstract3drenderer_p.h4
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp4
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp28
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.h4
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp4
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp3
-rw-r--r--src/datavisualizationqml2/abstractdeclarative.cpp10
-rw-r--r--src/datavisualizationqml2/abstractdeclarative_p.h3
11 files changed, 121 insertions, 7 deletions
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
index 4d0b8212..fc91e795 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
@@ -186,3 +186,24 @@
* \since Qt Data Visualization 1.1
*/
+/*!
+ * \qmlmethod int AbstractGraph3D::selectedLabelIndex()
+ *
+ * Can be used to query the index of the selected label after receiving elementSelected signal with
+ * any label type. Selection is valid until the next elementSelected signal.
+ *
+ * \return index of the selected label, or -1.
+ *
+ * \since Qt Data Visualization 1.1
+ */
+
+/*!
+ * \qmlmethod Abstract3DAxis AbstractGraph3D::selectedAxis()
+ *
+ * Can be used to get the selected axis after receiving elementSelected signal with any label type.
+ * Selection is valid until the next elementSelected signal.
+ *
+ * \return the selected axis, or null.
+ *
+ * \since Qt Data Visualization 1.1
+ */
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index 790a0889..fd773675 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -580,7 +580,7 @@ void Abstract3DController::setAxisX(QAbstract3DAxis *axis)
}
}
-QAbstract3DAxis *Abstract3DController::axisX()
+QAbstract3DAxis *Abstract3DController::axisX() const
{
return m_axisX;
}
@@ -594,7 +594,7 @@ void Abstract3DController::setAxisY(QAbstract3DAxis *axis)
}
}
-QAbstract3DAxis *Abstract3DController::axisY()
+QAbstract3DAxis *Abstract3DController::axisY() const
{
return m_axisY;
}
@@ -608,7 +608,7 @@ void Abstract3DController::setAxisZ(QAbstract3DAxis *axis)
}
}
-QAbstract3DAxis *Abstract3DController::axisZ()
+QAbstract3DAxis *Abstract3DController::axisZ() const
{
return m_axisZ;
}
@@ -1263,6 +1263,36 @@ void Abstract3DController::handlePendingClick()
{
QAbstract3DGraph::ElementType type = m_renderer->clickedType();
emit elementSelected(type);
- // TODO: Consider adding type specific signals
}
+
+int Abstract3DController::selectedLabelIndex() const
+{
+ int index = m_renderer->m_selectedLabelIndex;
+ if (selectedAxis()->labels().count() <= index)
+ index = -1;
+ return index;
+}
+
+QAbstract3DAxis *Abstract3DController::selectedAxis() const
+{
+ QAbstract3DAxis *axis = 0;
+ QAbstract3DGraph::ElementType type = m_renderer->clickedType();
+ switch (type) {
+ case QAbstract3DGraph::ElementAxisXLabel:
+ axis = axisX();
+ break;
+ case QAbstract3DGraph::ElementAxisYLabel:
+ axis = axisY();
+ break;
+ case QAbstract3DGraph::ElementAxisZLabel:
+ axis = axisZ();
+ break;
+ default:
+ axis = 0;
+ break;
+ }
+
+ return axis;
+}
+
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index 53560760..cebae72b 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -195,11 +195,11 @@ public:
QList<QAbstract3DSeries *> seriesList();
virtual void setAxisX(QAbstract3DAxis *axis);
- virtual QAbstract3DAxis *axisX();
+ virtual QAbstract3DAxis *axisX() const;
virtual void setAxisY(QAbstract3DAxis *axis);
- virtual QAbstract3DAxis *axisY();
+ virtual QAbstract3DAxis *axisY() const;
virtual void setAxisZ(QAbstract3DAxis *axis);
- virtual QAbstract3DAxis *axisZ();
+ virtual QAbstract3DAxis *axisZ() const;
virtual void addAxis(QAbstract3DAxis *axis);
virtual void releaseAxis(QAbstract3DAxis *axis);
virtual QList<QAbstract3DAxis *> axes() const; // Omits default axes
@@ -241,6 +241,9 @@ public:
void deleteCustomItem(QCustom3DItem *item);
void deleteCustomItem(const QVector3D &position);
+ int selectedLabelIndex() const;
+ QAbstract3DAxis *selectedAxis() const;
+
void emitNeedRender();
virtual void clearSelection() = 0;
diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h
index ea61ae51..3ae36450 100644
--- a/src/datavisualization/engine/abstract3drenderer_p.h
+++ b/src/datavisualization/engine/abstract3drenderer_p.h
@@ -180,12 +180,16 @@ protected:
bool m_clickPending;
QAbstract3DSeries *m_clickedSeries;
QAbstract3DGraph::ElementType m_clickedType;
+ int m_selectedLabelIndex;
QString m_selectionLabel;
LabelItem *m_selectionLabelItem;
int m_visibleSeriesCount;
ShaderHelper *m_customItemShader;
+
+private:
+ friend class Abstract3DController;
};
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index a6f893e5..bf381754 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -2269,6 +2269,7 @@ QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector4D &selectionC
{
QPoint position = Bars3DController::invalidSelectionPosition();
m_clickedType = QAbstract3DGraph::ElementNone;
+ m_selectedLabelIndex = -1;
if (selectionColor.w() == itemAlpha) {
// Normal selection item
position = QPoint(int(selectionColor.x() + int(m_axisCacheZ.min())),
@@ -2282,6 +2283,7 @@ QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector4D &selectionC
GLint previousCol = qMax(0, m_selectedBarPos.y()); // Use 0 if previous is invalid
position = QPoint(int(selectionColor.x() + int(m_axisCacheZ.min())), previousCol);
}
+ m_selectedLabelIndex = selectionColor.x();
// Pass label clicked info to input handler
m_clickedType = QAbstract3DGraph::ElementAxisZLabel;
} else if (selectionColor.w() == labelColumnAlpha) {
@@ -2291,11 +2293,13 @@ QPoint Bars3DRenderer::selectionColorToArrayPosition(const QVector4D &selectionC
GLint previousRow = qMax(0, m_selectedBarPos.x()); // Use 0 if previous is invalid
position = QPoint(previousRow, int(selectionColor.y()) + int(m_axisCacheX.min()));
}
+ m_selectedLabelIndex = selectionColor.y();
// Pass label clicked info to input handler
m_clickedType = QAbstract3DGraph::ElementAxisXLabel;
} else if (selectionColor.w() == labelValueAlpha) {
// Value selection
position = Bars3DController::invalidSelectionPosition();
+ m_selectedLabelIndex = selectionColor.z();
// Pass label clicked info to input handler
m_clickedType = QAbstract3DGraph::ElementAxisYLabel;
} else if (selectionColor.w() == customItemAlpha) {
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index 85ee79c9..13d7972a 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -427,6 +427,32 @@ void QAbstract3DGraph::removeCustomItemAt(const QVector3D &position)
}
/*!
+ * Can be used to query the index of the selected label after receiving elementSelected signal with
+ * any label type. Selection is valid until the next elementSelected signal.
+ *
+ * \return index of the selected label, or -1.
+ *
+ * \since Qt Data Visualization 1.1
+ */
+int QAbstract3DGraph::selectedLabelIndex() const
+{
+ return d_ptr->m_visualController->selectedLabelIndex();
+}
+
+/*!
+ * Can be used to get the selected axis after receiving elementSelected signal with any label type.
+ * Selection is valid until the next elementSelected signal.
+ *
+ * \return pointer to the selected axis, or null.
+ *
+ * \since Qt Data Visualization 1.1
+ */
+QAbstract3DAxis *QAbstract3DGraph::selectedAxis() const
+{
+ return d_ptr->m_visualController->selectedAxis();
+}
+
+/*!
* Renders current frame to an image of \a imageSize. Default size is the window size. Image is
* rendered with antialiasing level given in \a msaaSamples. Default level is \c{0}.
*
@@ -449,6 +475,8 @@ QImage QAbstract3DGraph::renderToImage(int msaaSamples, const QSize &imageSize)
*
* Signal can be used for example for implementing custom input handlers, as demonstrated in this
* \l {Axis Range Dragging With Labels Example}{example}.
+ *
+ * \sa selectedLabelIndex(), selectedAxis()
*/
/*!
diff --git a/src/datavisualization/engine/qabstract3dgraph.h b/src/datavisualization/engine/qabstract3dgraph.h
index ae1efacf..2ff2d84f 100644
--- a/src/datavisualization/engine/qabstract3dgraph.h
+++ b/src/datavisualization/engine/qabstract3dgraph.h
@@ -30,6 +30,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
class QAbstract3DGraphPrivate;
class QCustom3DItem;
+class QAbstract3DAxis;
class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions
{
@@ -113,6 +114,9 @@ public:
void removeCustomItem(QCustom3DItem *item);
void removeCustomItemAt(const QVector3D &position);
+ int selectedLabelIndex() const;
+ QAbstract3DAxis *selectedAxis() const;
+
QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize());
void setMeasureFps(bool enable);
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index c1705179..ff01d51e 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -1761,18 +1761,22 @@ void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector4D &color,
QAbstract3DSeries *&series)
{
m_clickedType = QAbstract3DGraph::ElementNone;
+ m_selectedLabelIndex = -1;
if (color != selectionSkipColor) {
if (color.w() == labelRowAlpha) {
// Row selection
index = Scatter3DController::invalidSelectionIndex();
+ m_selectedLabelIndex = color.x();
m_clickedType = QAbstract3DGraph::ElementAxisZLabel;
} else if (color.w() == labelColumnAlpha) {
// Column selection
index = Scatter3DController::invalidSelectionIndex();
+ m_selectedLabelIndex = color.y();
m_clickedType = QAbstract3DGraph::ElementAxisXLabel;
} else if (color.w() == labelValueAlpha) {
// Value selection
index = Scatter3DController::invalidSelectionIndex();
+ m_selectedLabelIndex = color.z();
m_clickedType = QAbstract3DGraph::ElementAxisYLabel;
} else if (color.w() == customItemAlpha) {
// Custom item selection
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index d3898476..00e6e21f 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -2289,12 +2289,15 @@ QPoint Surface3DRenderer::selectionIdToSurfacePoint(uint id)
m_clickedType = QAbstract3DGraph::ElementNone;
// Check for label and custom item selection
if (id / alphaMultiplier == labelRowAlpha) {
+ m_selectedLabelIndex = id - (alphaMultiplier * labelRowAlpha);
m_clickedType = QAbstract3DGraph::ElementAxisZLabel;
return Surface3DController::invalidSelectionPosition();
} else if (id / alphaMultiplier == labelColumnAlpha) {
+ m_selectedLabelIndex = (id - (alphaMultiplier * labelColumnAlpha)) / greenMultiplier;
m_clickedType = QAbstract3DGraph::ElementAxisXLabel;
return Surface3DController::invalidSelectionPosition();
} else if (id / alphaMultiplier == labelValueAlpha) {
+ m_selectedLabelIndex = (id - (alphaMultiplier * labelValueAlpha)) / blueMultiplier;
m_clickedType = QAbstract3DGraph::ElementAxisYLabel;
return Surface3DController::invalidSelectionPosition();
} else if (id / alphaMultiplier == customItemAlpha) {
diff --git a/src/datavisualizationqml2/abstractdeclarative.cpp b/src/datavisualizationqml2/abstractdeclarative.cpp
index fa69cac9..cdcfcf65 100644
--- a/src/datavisualizationqml2/abstractdeclarative.cpp
+++ b/src/datavisualizationqml2/abstractdeclarative.cpp
@@ -231,6 +231,16 @@ void AbstractDeclarative::removeCustomItemAt(const QVector3D &position)
m_controller->deleteCustomItem(position);
}
+int AbstractDeclarative::selectedLabelIndex() const
+{
+ return m_controller->selectedLabelIndex();
+}
+
+QAbstract3DAxis *AbstractDeclarative::selectedAxis() const
+{
+ return m_controller->selectedAxis();
+}
+
QQmlListProperty<QCustom3DItem> AbstractDeclarative::customItemList()
{
return QQmlListProperty<QCustom3DItem>(this, this,
diff --git a/src/datavisualizationqml2/abstractdeclarative_p.h b/src/datavisualizationqml2/abstractdeclarative_p.h
index 8121e35d..7db6c935 100644
--- a/src/datavisualizationqml2/abstractdeclarative_p.h
+++ b/src/datavisualizationqml2/abstractdeclarative_p.h
@@ -134,6 +134,9 @@ public:
Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItem(QCustom3DItem *item);
Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItemAt(const QVector3D &position);
+ Q_REVISION(1) Q_INVOKABLE virtual int selectedLabelIndex() const;
+ Q_REVISION(1) Q_INVOKABLE virtual QAbstract3DAxis *selectedAxis() const;
+
QQmlListProperty<QCustom3DItem> customItemList();
static void appendCustomItemFunc(QQmlListProperty<QCustom3DItem> *list,
QCustom3DItem *item);