From 177f9d385c8cd062c4bad78cf6b794a96fa025ad Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 21 Jan 2014 08:55:03 +0200 Subject: Selection correction for scatter when data changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements item 3) in QTRD-2645 Task-number: QTRD-264 Change-Id: Ibe758bbfb3b4a74b55589a410b402bbdf07ea64f Reviewed-by: Tomi Korpipää --- tests/barstest/barstest.pro | 4 +- tests/barstest/chart.cpp | 74 +++++++++++++++++++++++- tests/barstest/chart.h | 10 ++++ tests/barstest/custominputhandler.cpp | 54 +++++++++++++++++ tests/barstest/custominputhandler.h | 36 ++++++++++++ tests/barstest/main.cpp | 7 +++ tests/qmldynamicdata/qml/qmldynamicdata/main.qml | 22 ++++++- 7 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 tests/barstest/custominputhandler.cpp create mode 100644 tests/barstest/custominputhandler.h (limited to 'tests') diff --git a/tests/barstest/barstest.pro b/tests/barstest/barstest.pro index 55fbefbd..108f8aa7 100644 --- a/tests/barstest/barstest.pro +++ b/tests/barstest/barstest.pro @@ -2,8 +2,8 @@ error( "Couldn't find the tests.pri file!" ) } -SOURCES += main.cpp chart.cpp -HEADERS += chart.h +SOURCES += main.cpp chart.cpp custominputhandler.cpp +HEADERS += chart.h custominputhandler.h QT += widgets diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp index 7f049645..abbf2a59 100644 --- a/tests/barstest/chart.cpp +++ b/tests/barstest/chart.cpp @@ -17,12 +17,14 @@ ****************************************************************************/ #include "chart.h" +#include "custominputhandler.h" #include #include #include #include #include #include +#include #include using namespace QtDataVisualization; @@ -65,7 +67,8 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog) m_useNullInputHandler(false), m_defaultInputHandler(0), m_ownTheme(0), - m_builtinTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss)) + m_builtinTheme(new Q3DTheme(Q3DTheme::ThemeStoneMoss)), + m_customInputHandler(new CustomInputHandler) { m_temperatureData->setObjectName("m_temperatureData"); m_temperatureData2->setObjectName("m_temperatureData2"); @@ -218,9 +221,15 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog) QObject::connect(m_graph, &Q3DBars::primarySeriesChanged, this, &GraphModifier::handlePrimarySeriesChanged); + QObject::connect(&m_insertRemoveTimer, &QTimer::timeout, this, + &GraphModifier::insertRemoveTimerTimeout); + m_graph->addSeries(m_temperatureData); m_graph->addSeries(m_temperatureData2); + QObject::connect(&m_selectionTimer, &QTimer::timeout, this, + &GraphModifier::triggerSelection); + resetTemperatureData(); } @@ -994,6 +1003,69 @@ void GraphModifier::primarySeriesTest() } +void GraphModifier::insertRemoveTestToggle() +{ + if (m_insertRemoveTimer.isActive()) { + m_insertRemoveTimer.stop(); + m_selectionTimer.stop(); + m_graph->removeSeries(m_dummyData); + m_graph->removeSeries(m_dummyData2); + releaseProxies(); + releaseAxes(); + m_graph->setActiveInputHandler(m_defaultInputHandler); + } else { + releaseProxies(); + releaseAxes(); + m_graph->rowAxis()->setRange(0, 32); + m_graph->columnAxis()->setRange(0, 10); + m_graph->setActiveInputHandler(m_customInputHandler); + m_graph->addSeries(m_dummyData); + m_graph->addSeries(m_dummyData2); + m_insertRemoveStep = 0; + m_insertRemoveTimer.start(100); + m_selectionTimer.start(10); + } +} + +void GraphModifier::insertRemoveTimerTimeout() +{ + if (m_insertRemoveStep < 32) { + for (int k = 0; k < 1; k++) { + QBarDataRow *dataRow = new QBarDataRow(10); + for (float i = 0; i < 10; i++) + (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100)); + + QString label = QStringLiteral("Insert %1").arg(insertCounter++); + m_dummyData->dataProxy()->insertRow(0, dataRow, label); + } + } else { + for (int k = 0; k < 1; k++) + m_dummyData->dataProxy()->removeRows(0, 1); + } + + if (m_insertRemoveStep < 16 || (m_insertRemoveStep > 31 && m_insertRemoveStep < 48)) { + for (int k = 0; k < 2; k++) { + QBarDataRow *dataRow = new QBarDataRow(10); + for (float i = 0; i < 10; i++) + (*dataRow)[i].setValue(((i + 1) / 10.0f) * (float)(rand() % 100)); + + QString label = QStringLiteral("Insert %1").arg(insertCounter++); + m_dummyData2->dataProxy()->insertRow(0, dataRow, label); + } + } else { + for (int k = 0; k < 2; k++) + m_dummyData2->dataProxy()->removeRows(0, 1); + } + + if (m_insertRemoveStep++ > 63) + m_insertRemoveStep = 0; +} + +void GraphModifier::triggerSelection() +{ + m_graph->scene()->setSelectionQueryPosition(m_customInputHandler->inputPosition()); +} + void GraphModifier::setBackgroundEnabled(int enabled) { m_graph->activeTheme()->setBackgroundEnabled(bool(enabled)); diff --git a/tests/barstest/chart.h b/tests/barstest/chart.h index 703f53e5..425af521 100644 --- a/tests/barstest/chart.h +++ b/tests/barstest/chart.h @@ -22,11 +22,13 @@ #include #include #include +#include #include #include #include #include #include +#include using namespace QtDataVisualization; @@ -81,6 +83,7 @@ public: void showFiveSeries(); QBarDataArray *makeDummyData(); void primarySeriesTest(); + void insertRemoveTestToggle(); public slots: void flipViews(); @@ -95,6 +98,9 @@ public slots: void handleValueAxisChanged(QValue3DAxis *axis); void handlePrimarySeriesChanged(QBar3DSeries *series); + void insertRemoveTimerTimeout(); + void triggerSelection(); + signals: void shadowQualityChanged(int quality); @@ -137,6 +143,10 @@ private: QAbstract3DInputHandler *m_defaultInputHandler; Q3DTheme *m_ownTheme; Q3DTheme *m_builtinTheme; + QTimer m_insertRemoveTimer; + int m_insertRemoveStep; + QAbstract3DInputHandler *m_customInputHandler; + QTimer m_selectionTimer; }; #endif diff --git a/tests/barstest/custominputhandler.cpp b/tests/barstest/custominputhandler.cpp new file mode 100644 index 00000000..3b050fda --- /dev/null +++ b/tests/barstest/custominputhandler.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "custominputhandler.h" + +#include + +CustomInputHandler::CustomInputHandler(QObject *parent) : + QAbstract3DInputHandler(parent) +{ +} + +//! [0] +void CustomInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) +{ + Q_UNUSED(event) + setInputPosition(mousePos); +} +//! [0] + +//! [1] +void CustomInputHandler::wheelEvent(QWheelEvent *event) +{ + // Adjust zoom level based on what zoom range we're in. + int zoomLevel = scene()->activeCamera()->zoomLevel(); + if (zoomLevel > 100) + zoomLevel += event->angleDelta().y() / 12; + else if (zoomLevel > 50) + zoomLevel += event->angleDelta().y() / 60; + else + zoomLevel += event->angleDelta().y() / 120; + if (zoomLevel > 500) + zoomLevel = 500; + else if (zoomLevel < 10) + zoomLevel = 10; + + scene()->activeCamera()->setZoomLevel(zoomLevel); +} +//! [1] diff --git a/tests/barstest/custominputhandler.h b/tests/barstest/custominputhandler.h new file mode 100644 index 00000000..1fecb8d8 --- /dev/null +++ b/tests/barstest/custominputhandler.h @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#ifndef CUSTOMINPUTHANDLER_H +#define CUSTOMINPUTHANDLER_H + +#include + +using namespace QtDataVisualization; + +class CustomInputHandler : public QAbstract3DInputHandler +{ + Q_OBJECT +public: + explicit CustomInputHandler(QObject *parent = 0); + + virtual void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos); + virtual void wheelEvent(QWheelEvent *event); +}; + +#endif diff --git a/tests/barstest/main.cpp b/tests/barstest/main.cpp index a0f9d783..a0e1bfc3 100644 --- a/tests/barstest/main.cpp +++ b/tests/barstest/main.cpp @@ -126,6 +126,10 @@ int main(int argc, char **argv) swapAxisButton->setText(QStringLiteral("Swap value axis")); swapAxisButton->setEnabled(false); + QPushButton *insertRemoveTestButton = new QPushButton(widget); + insertRemoveTestButton->setText(QStringLiteral("Toggle insert/remove cycle")); + insertRemoveTestButton->setEnabled(true); + QPushButton *releaseAxesButton = new QPushButton(widget); releaseAxesButton->setText(QStringLiteral("Release all axes")); releaseAxesButton->setEnabled(true); @@ -293,6 +297,7 @@ int main(int argc, char **argv) vLayout->addWidget(selectionButton, 0, Qt::AlignTop); vLayout->addWidget(setSelectedBarButton, 0, Qt::AlignTop); vLayout->addWidget(swapAxisButton, 0, Qt::AlignTop); + vLayout->addWidget(insertRemoveTestButton, 0, Qt::AlignTop); vLayout->addWidget(releaseAxesButton, 0, Qt::AlignTop); vLayout->addWidget(releaseProxiesButton, 1, Qt::AlignTop); vLayout->addWidget(flipViewsButton, 0, Qt::AlignTop); @@ -385,6 +390,8 @@ int main(int argc, char **argv) &GraphModifier::selectBar); QObject::connect(swapAxisButton, &QPushButton::clicked, modifier, &GraphModifier::swapAxis); + QObject::connect(insertRemoveTestButton, &QPushButton::clicked, modifier, + &GraphModifier::insertRemoveTestToggle); QObject::connect(releaseAxesButton, &QPushButton::clicked, modifier, &GraphModifier::releaseAxes); QObject::connect(releaseProxiesButton, &QPushButton::clicked, modifier, diff --git a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml index 4ed3b8ae..3ad454d0 100644 --- a/tests/qmldynamicdata/qml/qmldynamicdata/main.qml +++ b/tests/qmldynamicdata/qml/qmldynamicdata/main.qml @@ -34,7 +34,7 @@ Item { Timer { id: dataTimer - interval: 20 + interval: 1 running: true repeat: true property bool isIncreasing: true @@ -42,7 +42,16 @@ Item { onTriggered: { if (isIncreasing) { graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); - if (graphModel.count == 500) { + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + graphModel.append({"xPos": Math.random(), "yPos": Math.random(), "zPos": Math.random()}); + if (graphModel.count > 5000) { scatterGraph.theme.type = Theme3D.ThemeIsabelle; isIncreasing = false; } @@ -50,6 +59,15 @@ Item { // TODO: Once QTRD-2645 is fixed, change this to remove from // random index to add coverage. graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); + graphModel.remove(2); if (graphModel.count == 2) { scatterGraph.theme.type = Theme3D.ThemeDigia; isIncreasing = true; -- cgit v1.2.3