summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2016-08-19 15:16:32 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2016-08-24 10:37:18 +0000
commit8a4f42d88b32747e0c222b06638b8f2aef4d9701 (patch)
tree782957ffd4cdcab12cbcba0ca241bd7bd2d54569 /tests/manual
parentd43d429ea710b1885719b131b2acac42cd955ccb (diff)
Add mouse events support for OpenGL accelerated series
On QML side, the mouse events for accelerated series work asynchronously, as the rendering is typically done in a different thread. Change-Id: I08c478768b40ed90b34b0904b7a3e74e315c3caa Reviewed-by: Mika Salmela <mika.salmela@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/openglseriestest/datasource.cpp9
-rw-r--r--tests/manual/openglseriestest/datasource.h3
-rw-r--r--tests/manual/openglseriestest/mainwindow.cpp52
-rw-r--r--tests/manual/openglseriestest/mainwindow.h5
-rw-r--r--tests/manual/openglseriestest/mainwindow.ui50
-rw-r--r--tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml2
-rw-r--r--tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml4
7 files changed, 118 insertions, 7 deletions
diff --git a/tests/manual/openglseriestest/datasource.cpp b/tests/manual/openglseriestest/datasource.cpp
index 1897f196..459b9f01 100644
--- a/tests/manual/openglseriestest/datasource.cpp
+++ b/tests/manual/openglseriestest/datasource.cpp
@@ -77,12 +77,17 @@ void DataSource::updateAllSeries()
}
}
-void DataSource::startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel)
+void DataSource::setInterval(int interval)
+{
+ m_dataUpdater.setInterval(interval);
+}
+
+void DataSource::startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel, int interval)
{
m_seriesList = &seriesList;
m_fpsLabel = fpsLabel;
- m_dataUpdater.setInterval(0);
+ m_dataUpdater.setInterval(interval);
m_dataUpdater.setSingleShot(true);
QObject::connect(&m_dataUpdater, &QTimer::timeout,
this, &DataSource::updateAllSeries);
diff --git a/tests/manual/openglseriestest/datasource.h b/tests/manual/openglseriestest/datasource.h
index 338fcea0..6b31c6da 100644
--- a/tests/manual/openglseriestest/datasource.h
+++ b/tests/manual/openglseriestest/datasource.h
@@ -46,13 +46,14 @@ class DataSource : public QObject
public:
explicit DataSource(QObject *parent = 0);
- void startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel);
+ void startUpdates(QList<QXYSeries *> &seriesList, QLabel *fpsLabel, int interval);
public slots:
void generateData(int seriesIndex, int rowCount, int colCount);
void update(QXYSeries *series, int seriesIndex);
void handleSceneChanged();
void updateAllSeries();
+ void setInterval(int interval);
private:
QVector<QVector<QVector<QPointF> > > m_data;
diff --git a/tests/manual/openglseriestest/mainwindow.cpp b/tests/manual/openglseriestest/mainwindow.cpp
index 8b20c7e8..4aaeed13 100644
--- a/tests/manual/openglseriestest/mainwindow.cpp
+++ b/tests/manual/openglseriestest/mainwindow.cpp
@@ -106,6 +106,8 @@ MainWindow::MainWindow(QWidget *parent) :
this, SLOT(widthIndexChanged(int)));
connect(ui->antiAliasCheckBox, SIGNAL(clicked(bool)),
this, SLOT(antiAliasCheckBoxClicked(bool)));
+ connect(ui->intervalSpinbox, SIGNAL(valueChanged(int)),
+ &m_dataSource, SLOT(setInterval(int)));
ui->chartView->setChart(m_chart);
ui->chartView->setRenderHint(QPainter::Antialiasing);
@@ -113,7 +115,7 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(m_chart->scene(), &QGraphicsScene::changed,
&m_dataSource, &DataSource::handleSceneChanged);
- m_dataSource.startUpdates(m_seriesList, ui->fpsLabel);
+ m_dataSource.startUpdates(m_seriesList, ui->fpsLabel, ui->intervalSpinbox->value());
}
MainWindow::~MainWindow()
@@ -426,6 +428,42 @@ void MainWindow::antiAliasCheckBoxClicked(bool checked)
ui->chartView->setRenderHint(QPainter::Antialiasing, checked);
}
+void MainWindow::handleHovered(const QPointF &point, bool state)
+{
+ QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
+ if (series) {
+ qDebug() << __FUNCTION__ << series->name() << point << state;
+ const QString labelTemplate = QStringLiteral("%3: %1 x %2 - %4");
+ ui->coordinatesLabel->setText(
+ labelTemplate.arg(point.x()).arg(point.y()).arg(series->name())
+ .arg(state ? QStringLiteral("enter") : QStringLiteral("leave")));
+ }
+}
+
+void MainWindow::handleClicked(const QPointF &point)
+{
+ QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
+ qDebug() << __FUNCTION__ << series->name() << point;
+}
+
+void MainWindow::handlePressed(const QPointF &point)
+{
+ QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
+ qDebug() << __FUNCTION__ << series->name() << point;
+}
+
+void MainWindow::handleReleased(const QPointF &point)
+{
+ QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
+ qDebug() << __FUNCTION__ << series->name() << point;
+}
+
+void MainWindow::handleDoubleClicked(const QPointF &point)
+{
+ QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
+ qDebug() << __FUNCTION__ << series->name() << point;
+}
+
void MainWindow::backgroundIndexChanged(int index)
{
delete m_backgroundBrush;
@@ -521,6 +559,12 @@ void MainWindow::addSeries(bool gl)
series = scatterSeries;
}
series->setUseOpenGL(gl);
+ const QString glNameTemplate = QStringLiteral("GL_%1");
+ const QString rasterNameTemplate = QStringLiteral("Raster_%1");
+ if (gl)
+ series->setName(glNameTemplate.arg(m_seriesList.size()));
+ else
+ series->setName(rasterNameTemplate.arg(m_seriesList.size()));
m_dataSource.generateData(m_seriesList.size(), 2, m_pointCount);
m_seriesList.append(series);
m_chart->addSeries(series);
@@ -529,5 +573,11 @@ void MainWindow::addSeries(bool gl)
if (m_yAxis)
series->attachAxis(m_yAxis);
applyRanges();
+
+ QObject::connect(series, &QXYSeries::hovered, this, &MainWindow::handleHovered);
+ QObject::connect(series, &QXYSeries::clicked, this, &MainWindow::handleClicked);
+ QObject::connect(series, &QXYSeries::pressed, this, &MainWindow::handlePressed);
+ QObject::connect(series, &QXYSeries::released, this, &MainWindow::handleReleased);
+ QObject::connect(series, &QXYSeries::doubleClicked, this, &MainWindow::handleDoubleClicked);
}
}
diff --git a/tests/manual/openglseriestest/mainwindow.h b/tests/manual/openglseriestest/mainwindow.h
index 8590fea3..b7e84136 100644
--- a/tests/manual/openglseriestest/mainwindow.h
+++ b/tests/manual/openglseriestest/mainwindow.h
@@ -74,6 +74,11 @@ public slots:
void colorIndexChanged(int index);
void widthIndexChanged(int index);
void antiAliasCheckBoxClicked(bool checked);
+ void handleHovered(const QPointF &point, bool state);
+ void handleClicked(const QPointF &point);
+ void handlePressed(const QPointF &point);
+ void handleReleased(const QPointF &point);
+ void handleDoubleClicked(const QPointF &point);
private:
enum AxisMode {
diff --git a/tests/manual/openglseriestest/mainwindow.ui b/tests/manual/openglseriestest/mainwindow.ui
index ac52ff7f..56158d37 100644
--- a/tests/manual/openglseriestest/mainwindow.ui
+++ b/tests/manual/openglseriestest/mainwindow.ui
@@ -16,7 +16,11 @@
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="ChartView" name="chartView"/>
+ <widget class="ChartView" name="chartView">
+ <property name="mouseTracking">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
<item>
<widget class="QGroupBox" name="settingsBox">
@@ -549,7 +553,7 @@
<property name="geometry">
<rect>
<x>10</x>
- <y>370</y>
+ <y>380</y>
<width>91</width>
<height>17</height>
</rect>
@@ -561,6 +565,48 @@
<bool>true</bool>
</property>
</widget>
+ <widget class="QLabel" name="coordinatesLabel">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>400</y>
+ <width>181</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>0 x 0</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox" name="intervalSpinbox">
+ <property name="geometry">
+ <rect>
+ <x>100</x>
+ <y>420</y>
+ <width>91</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="maximum">
+ <number>10000</number>
+ </property>
+ <property name="singleStep">
+ <number>5</number>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>420</y>
+ <width>91</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Update Interval:</string>
+ </property>
+ </widget>
</widget>
</item>
</layout>
diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml
index 08f336e7..7c092cc5 100644
--- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml
+++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineChart.qml
@@ -62,7 +62,7 @@ ChartView {
onStyleChanged: console.log("lineSeries.onStyleChanged: " + style);
onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle);
onCountChanged: console.log("lineSeries.onCountChanged: " + count);
- onHovered: console.log("lineSeries.onHovered:" + point.x + "," + point.y + " " + state);
+ onHovered: console.log(name + ".onHovered:" + point.x + "," + point.y + " " + state);
onPointLabelsVisibilityChanged: console.log("lineSeries.onPointLabelsVisibilityChanged: "
+ visible);
onPointLabelsFormatChanged: console.log("lineSeries.onPointLabelsFormatChanged: "
diff --git a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml
index 64ca8691..baee3550 100644
--- a/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml
+++ b/tests/manual/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml
@@ -143,4 +143,8 @@ Flow {
text: "clear"
onClicked: series.clear();
}
+ Button {
+ text: "toggle useOpenGL"
+ onClicked: series.useOpenGL = !series.useOpenGL
+ }
}