summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-02-11 13:33:11 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-02-11 13:37:23 +0200
commit911770952a1e4a70a97d82d8400fa85bd9b0664d (patch)
tree9a90e554e9d05d3117170fd79d051f282ec51e60 /examples
parent2790db21c15be8c4bcb4639bfe25b4199cf85cc8 (diff)
Make qmloscilloscope example animate
Change-Id: Ia4bd9e92c8e0d7d10a7b53c0ed3bf584e3e93658 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qmloscilloscope/datasource.cpp40
-rw-r--r--examples/qmloscilloscope/qml/qmloscilloscope/main.qml23
2 files changed, 39 insertions, 24 deletions
diff --git a/examples/qmloscilloscope/datasource.cpp b/examples/qmloscilloscope/datasource.cpp
index 922ed576..83ff0ff9 100644
--- a/examples/qmloscilloscope/datasource.cpp
+++ b/examples/qmloscilloscope/datasource.cpp
@@ -41,6 +41,9 @@ void DataSource::generateData(int cacheCount, int rowCount, int columnCount,
float xMin, float xMax, float yMin, float yMax,
float zMin, float zMax)
{
+ if (!cacheCount)
+ return;
+
clearData();
// Re-create the cache array
m_data.resize(cacheCount);
@@ -54,25 +57,38 @@ void DataSource::generateData(int cacheCount, int rowCount, int columnCount,
float xRange = xMax - xMin;
float yRange = yMax - yMin;
float zRange = zMax - zMin;
+ int cacheIndexStep = columnCount / cacheCount;
+ float cacheStep = float(cacheIndexStep) * xRange / float(columnCount);
// Populate caches
for (int i(0); i < cacheCount; i++) {
QSurfaceDataArray &cache = m_data[i];
+ float cacheXAdjustment = cacheStep * i;
+ float cacheIndexAdjustment = cacheIndexStep * i;
for (int j(0); j < rowCount; j++) {
QSurfaceDataRow &row = *(cache[j]);
+ float rowMod = (float(j)) / float(rowCount);
+ float yRangeMod = yRange * rowMod;
+ float zRangeMod = zRange * rowMod;
+ float z = zRangeMod + zMin;
+ qreal rowColWaveAngleMul = M_PI * M_PI * rowMod;
+ float rowColWaveMul = yRangeMod * 0.2f;
for (int k(0); k < columnCount; k++) {
- float colMod = (float(k)) / float(columnCount - 1.0f);
- float rowMod = (float(j)) / float(rowCount - 1.0f);
+ float colMod = (float(k)) / float(columnCount);
float xRangeMod = xRange * colMod;
- float yRangeMod = yRange * rowMod;
- float zRangeMod = zRange * rowMod;
- float x = xRangeMod + xMin;
- float y = (((float(qSin(M_PI * rowMod / 2.0) + 1.0)))
- + ((float(qSin(M_PI * rowMod * colMod * 5.0) + 1.0))))
- * yRangeMod * 0.2f +
- + (0.15f * float(rand()) / float(RAND_MAX)) * yRangeMod;
- float z = zRangeMod + zMin;
- row[k] = QVector3D(x, y, z);
+ float x = xRangeMod + xMin + cacheXAdjustment;
+ float colWave = float(qSin((2.0 * M_PI * colMod) - (1.0 / 2.0 * M_PI)) + 1.0);
+ float y = (colWave * ((float(qSin(rowColWaveAngleMul * colMod) + 1.0))))
+ * rowColWaveMul
+ + (0.15f * float(rand()) / float(RAND_MAX)) * yRangeMod;
+
+ int index = k + cacheIndexAdjustment;
+ if (index >= columnCount) {
+ // Wrap over
+ index -= columnCount;
+ x -= xRange;
+ }
+ row[index] = QVector3D(x, y, z);
}
}
}
@@ -82,7 +98,7 @@ void DataSource::generateData(int cacheCount, int rowCount, int columnCount,
//! [1]
void DataSource::update(QSurface3DSeries *series)
{
- if (series) {
+ if (series && m_data.size()) {
// Each iteration uses data from a different cached array
m_index++;
if (m_index > m_data.count() - 1)
diff --git a/examples/qmloscilloscope/qml/qmloscilloscope/main.qml b/examples/qmloscilloscope/qml/qmloscilloscope/main.qml
index 4d330b60..b9284777 100644
--- a/examples/qmloscilloscope/qml/qmloscilloscope/main.qml
+++ b/examples/qmloscilloscope/qml/qmloscilloscope/main.qml
@@ -27,9 +27,14 @@ Item {
width: 1280
height: 1024
- property int sampleCache: 5
property int sampleColumns: sampleSlider.value
property int sampleRows: sampleColumns / 2
+ property int sampleCache: 24
+
+ onSampleRowsChanged: {
+ surfaceSeries.selectedPoint = surfaceSeries.invalidSelectionPosition
+ generateData()
+ }
Item {
id: dataView
@@ -123,17 +128,11 @@ Item {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.minimumWidth: 100
- minimumValue: 10
- maximumValue: 400
- stepSize: 5
- updateValueWhileDragging: true
- value: 50
-
- onValueChanged: {
- refreshTimer
- surfaceSeries.selectedPoint = surfaceSeries.invalidSelectionPosition
- mainView.generateData()
- }
+ minimumValue: mainView.sampleCache * 2
+ maximumValue: minimumValue * 10
+ stepSize: mainView.sampleCache
+ updateValueWhileDragging: false
+ value: minimumValue * 2
}
Rectangle {