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 ++++++++++++++++++++-- .../customitems/customitemgraph.h | 7 +++++- examples/datavisualization/customitems/main.cpp | 15 ++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) (limited to 'examples') 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"); + } +} diff --git a/examples/datavisualization/customitems/customitemgraph.h b/examples/datavisualization/customitems/customitemgraph.h index a13e8620..aee32c62 100644 --- a/examples/datavisualization/customitems/customitemgraph.h +++ b/examples/datavisualization/customitems/customitemgraph.h @@ -24,6 +24,7 @@ #include #include #include +#include using namespace QtDataVisualization; @@ -31,7 +32,7 @@ class CustomItemGraph : public QObject { Q_OBJECT public: - explicit CustomItemGraph(Q3DSurface *surface); + explicit CustomItemGraph(Q3DSurface *surface, QLabel *label); ~CustomItemGraph(); void toggleItemOne(bool show); @@ -41,8 +42,12 @@ public: void toggleOilHighlight(bool highlight); void toggleShadows(bool shadows); +private: + void handleElementSelected(QAbstract3DGraph::ElementType type); + private: Q3DSurface *m_graph; + QLabel *m_textField; }; #endif diff --git a/examples/datavisualization/customitems/main.cpp b/examples/datavisualization/customitems/main.cpp index a37cc76f..fe2d0edc 100644 --- a/examples/datavisualization/customitems/main.cpp +++ b/examples/datavisualization/customitems/main.cpp @@ -65,10 +65,12 @@ int main(int argc, char **argv) vLayoutLeft->addWidget(checkboxThree); QLabel *label2 = new QLabel("Visuals:"); + font.setBold(true); label2->setFont(font); vLayoutRight->addWidget(label2); QCheckBox *checkboxOneRight = new QCheckBox("See-Through"); + font.setBold(false); checkboxOneRight->setFont(font); vLayoutRight->addWidget(checkboxOneRight); @@ -81,11 +83,22 @@ int main(int argc, char **argv) checkboxThreeRight->setChecked(true); vLayoutRight->addWidget(checkboxThreeRight); + QLabel *label3 = new QLabel("Selection:"); + font.setBold(true); + label3->setFont(font); + vLayoutRight->addWidget(label3); + + QLabel *label4 = new QLabel("Nothing"); + font.setBold(false); + font.setPointSize(12); + label4->setFont(font); + vLayoutRight->addWidget(label4); + widget->setWindowTitle(QStringLiteral("Custom Items Example")); widget->show(); - CustomItemGraph *modifier = new CustomItemGraph(graph); + CustomItemGraph *modifier = new CustomItemGraph(graph, label4); QObject::connect(checkboxOne, &QCheckBox::stateChanged, modifier, &CustomItemGraph::toggleItemOne); -- cgit v1.2.3