From 604d8a652cc088a4b3a4307ec291916757e03201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 13 May 2014 08:26:06 +0300 Subject: API to query custom item selection Task-number: QTRD-3046 + Added missing elementSelected signal to QML Change-Id: I5e79d8e910d2730e3d2ae5550ce576f01aac0b18 Change-Id: I5e79d8e910d2730e3d2ae5550ce576f01aac0b18 Reviewed-by: Miikka Heikkinen --- .../customitems/customitemgraph.cpp | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'examples/datavisualization/customitems/customitemgraph.cpp') diff --git a/examples/datavisualization/customitems/customitemgraph.cpp b/examples/datavisualization/customitems/customitemgraph.cpp index c2479a9a..0a757e7d 100644 --- a/examples/datavisualization/customitems/customitemgraph.cpp +++ b/examples/datavisualization/customitems/customitemgraph.cpp @@ -24,8 +24,9 @@ using namespace QtDataVisualization; -CustomItemGraph::CustomItemGraph(Q3DSurface *surface) - : m_graph(surface) +CustomItemGraph::CustomItemGraph(Q3DSurface *surface, QLabel *label) + : m_graph(surface), + m_textField(label) { QImage layerOneHMap(":/maps/layer_1.png"); QHeightMapSurfaceDataProxy *layerOneProxy = new QHeightMapSurfaceDataProxy(layerOneHMap); @@ -87,6 +88,9 @@ CustomItemGraph::CustomItemGraph(Q3DSurface *surface) m_graph->seriesList().at(2)->setColorStyle(Q3DTheme::ColorStyleRangeGradient); m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront); + + connect(m_graph, &QAbstract3DGraph::elementSelected, + this, &CustomItemGraph::handleElementSelected); } CustomItemGraph::~CustomItemGraph() @@ -189,3 +193,24 @@ void CustomItemGraph::toggleShadows(bool shadows) else m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualityNone); } + +void CustomItemGraph::handleElementSelected(QAbstract3DGraph::ElementType type) +{ + if (type == QAbstract3DGraph::ElementCustomItem) { + int index = m_graph->selectedCustomItemIndex(); + QCustom3DItem *item = m_graph->selectedCustomItem(); + QString text; + text.setNum(index); + text.append(": "); + QStringList split = item->meshFile().split("/"); + text.append(split.last()); + m_textField->setText(text); + } else if (type == QAbstract3DGraph::ElementSeries) { + m_textField->setText("Surface"); + } else if (type > QAbstract3DGraph::ElementSeries + && type < QAbstract3DGraph::ElementCustomItem) { + m_textField->setText("Axis"); + } else { + m_textField->setText("Nothing"); + } +} -- cgit v1.2.3