diff options
author | Mika Salmela <mika.salmela@digia.com> | 2013-11-26 15:48:51 +0200 |
---|---|---|
committer | Mika Salmela <mika.salmela@digia.com> | 2013-11-27 11:30:44 +0200 |
commit | de3661089cb85701d7444bbf517711783df3aa49 (patch) | |
tree | e833426f16198da680101c9720c00ab4bcd2a678 /tests/surfacetest | |
parent | 7c942cc0f497fe7e61ce6a10fce45771c0858e09 (diff) |
Better proxy API for surface
Part 1, row change. More is on the way.
Change-Id: I4e152a5160275f2d629e7793d4d40b85082a2fc2
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'tests/surfacetest')
-rw-r--r-- | tests/surfacetest/graphmodifier.cpp | 60 | ||||
-rw-r--r-- | tests/surfacetest/graphmodifier.h | 2 | ||||
-rw-r--r-- | tests/surfacetest/main.cpp | 12 |
3 files changed, 74 insertions, 0 deletions
diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index 5a367c7a..1ee4f56b 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -402,6 +402,66 @@ void GraphModifier::changeSelectionMode(int mode) } } +void GraphModifier::changeRow() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Generating new values to a row at randon pos"; + float minX = -10.0f; + float maxX = 10.0f; + float minZ = -10.0f; + float maxZ = 10.0f; + float stepX = (maxX - minX) / float(m_xCount - 1); + float stepZ = (maxZ - minZ) / float(m_zCount - 1); + float i = float(rand() % m_zCount); + + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + for (float j = 0; j < m_xCount; j++) { + float x = qMin(maxX, (j * stepX + minX)); + float z = qMin(maxZ, (i * stepZ + minZ)); + float R = qSqrt(x * x + z * z) + 0.01f; + float y = (qSin(R) / R + 0.24f) * 1.61f + 1.2f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + + m_theSeries->dataProxy()->setRow(int(i), newRow); + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + +void GraphModifier::changeRows() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Generating new values to 3 rows from randon pos"; + + float minX = -10.0f; + float maxX = 10.0f; + float minZ = -10.0f; + float maxZ = 10.0f; + float stepX = (maxX - minX) / float(m_xCount - 1); + float stepZ = (maxZ - minZ) / float(m_zCount - 1); + float start = float(rand() % (m_zCount - 3)); + + QSurfaceDataArray dataArray; + + for (float i = start; i < (start + 3.0f); i++) { + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = qMin(maxZ, (i * stepZ + minZ)); + for (float j = 0; j < m_xCount; j++) { + float x = qMin(maxX, (j * stepX + minX)); + float R = qSqrt(x * x + z * z) + 0.01f; + float y = (qSin(R) / R + 0.24f) * 1.61f + 1.2f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + dataArray.append(newRow); + } + + m_theSeries->dataProxy()->setRows(int(start), dataArray); + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + void GraphModifier::updateSamples() { switch (m_activeSample) { diff --git a/tests/surfacetest/graphmodifier.h b/tests/surfacetest/graphmodifier.h index e7f19c4d..cc71f7d5 100644 --- a/tests/surfacetest/graphmodifier.h +++ b/tests/surfacetest/graphmodifier.h @@ -67,6 +67,8 @@ public: void selectButtonClicked(); void setSelectionInfoLabel(QLabel *label) {m_selectionInfoLabel = label; } void selectedPointChanged(const QPoint &point); + void changeRow(); + void changeRows(); public slots: void changeShadowQuality(int quality); diff --git a/tests/surfacetest/main.cpp b/tests/surfacetest/main.cpp index acb6fa37..0f891442 100644 --- a/tests/surfacetest/main.cpp +++ b/tests/surfacetest/main.cpp @@ -207,6 +207,12 @@ int main(int argc, char *argv[]) QLabel *selectionInfoLabel = new QLabel(widget); + QPushButton *changeRowButton = new QPushButton(widget); + changeRowButton->setText(QStringLiteral("Change a row")); + + QPushButton *changeRowsButton = new QPushButton(widget); + changeRowsButton->setText(QStringLiteral("Change 3 rows")); + // Add controls to the layout vLayout->addWidget(smoothCB); vLayout->addWidget(surfaceGridCB); @@ -238,6 +244,8 @@ int main(int argc, char *argv[]) vLayout->addWidget(selectButton); vLayout->addWidget(selectionInfoLabel); vLayout->addWidget(flipViewsButton); + vLayout->addWidget(changeRowButton); + vLayout->addWidget(changeRowsButton); widget->show(); @@ -286,6 +294,10 @@ int main(int argc, char *argv[]) modifier, &GraphModifier::selectButtonClicked); QObject::connect(flipViewsButton, &QPushButton::clicked, modifier, &GraphModifier::flipViews); + QObject::connect(changeRowButton,&QPushButton::clicked, + modifier, &GraphModifier::changeRow); + QObject::connect(changeRowsButton,&QPushButton::clicked, + modifier, &GraphModifier::changeRows); modifier->setGridSliderZ(gridSliderZ); modifier->setGridSliderX(gridSliderX); |