From 78d4deb0be21f22d74e3e01315686857ef8edf2e Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Wed, 4 Dec 2013 10:56:39 +0200 Subject: Better proxy API for surface Part 3, add, insert and remove row(s). Change-Id: I4e30d7f129576bebce9216d5cc00a66b2f8af6cd Reviewed-by: Miikka Heikkinen --- tests/surfacetest/graphmodifier.cpp | 135 +++++++++++++++++++++++++++++++++++- tests/surfacetest/graphmodifier.h | 8 +++ tests/surfacetest/main.cpp | 30 ++++++++ 3 files changed, 171 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index 11e651a3..3bf90981 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -48,6 +48,9 @@ GraphModifier::GraphModifier(Q3DSurface *graph) m_rangeZ(16.0), m_minX(-8.0), m_minZ(-8.0), + m_addRowCounter(m_zCount), + m_insertTestZPos(0), + m_insertTestIndexPos(1), m_planeArray(0), m_theSeries(new QSurface3DSeries) { @@ -410,9 +413,9 @@ void GraphModifier::changeRow() float i = float(rand() % m_zCount); 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 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)); @@ -494,6 +497,135 @@ void GraphModifier::changeMultipleItem() changeItem(); } +void GraphModifier::addRow() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Adding a new row"; + + 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); + + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = float(m_addRowCounter) * 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.0f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + m_addRowCounter++; + + m_theSeries->dataProxy()->addRow(newRow); + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + +void GraphModifier::addRows() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Adding few new row"; + + 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); + + QSurfaceDataArray dataArray; + + for (int i = 0; i < 3; i++) { + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = m_addRowCounter * 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.0f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + dataArray.append(newRow); + m_addRowCounter++; + } + + m_theSeries->dataProxy()->addRows(dataArray); + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + +void GraphModifier::insertRow() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Inserting a row"; + 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); + + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = qMin(maxZ, (float(m_insertTestZPos) * stepZ + minZ + (stepZ / 2.0f))); + 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.3f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + m_insertTestZPos++; + + m_theSeries->dataProxy()->insertRow(m_insertTestIndexPos, newRow); + m_insertTestIndexPos += 2; + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + +void GraphModifier::insertRows() +{ + if (m_activeSample == GraphModifier::SqrtSin) { + qDebug() << "Inserting 3 rows"; + 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); + + QSurfaceDataArray dataArray; + for (int i = 0; i < 3; i++) { + QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + float z = qMin(maxZ, (float(m_insertTestZPos) * stepZ + minZ + i * (stepZ / 4.0f))); + 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.3f; + (*newRow)[j].setPosition(QVector3D(x, y, z)); + } + dataArray.append(newRow); + } + m_insertTestZPos++; + + m_theSeries->dataProxy()->insertRows(m_insertTestIndexPos, dataArray); + m_insertTestIndexPos += 4; + } else { + qDebug() << "Change row function active only for SqrtSin"; + } +} + +void GraphModifier::removeRow() +{ + qDebug() << "Remove an arbitrary row"; + int row = rand() % m_zCount; + m_theSeries->dataProxy()->removeRows(row, 1); + m_zCount--; +} + void GraphModifier::changeMesh() { static int model = 0; @@ -559,4 +691,3 @@ void GraphModifier::updateSamples() break; } } - diff --git a/tests/surfacetest/graphmodifier.h b/tests/surfacetest/graphmodifier.h index be1f6de7..8269962a 100644 --- a/tests/surfacetest/graphmodifier.h +++ b/tests/surfacetest/graphmodifier.h @@ -73,6 +73,11 @@ public: void changeItem(); void changeMultipleItem(); void changeMultipleRows(); + void addRow(); + void addRows(); + void insertRow(); + void insertRows(); + void removeRow(); public slots: void changeShadowQuality(int quality); @@ -101,6 +106,9 @@ private: float m_rangeZ; float m_minX; float m_minZ; + int m_addRowCounter; + int m_insertTestZPos; + int m_insertTestIndexPos; QTimer m_timer; QSurfaceDataArray *m_planeArray; QLabel *m_selectionInfoLabel; diff --git a/tests/surfacetest/main.cpp b/tests/surfacetest/main.cpp index 6db05718..d2cafae9 100644 --- a/tests/surfacetest/main.cpp +++ b/tests/surfacetest/main.cpp @@ -228,6 +228,21 @@ int main(int argc, char *argv[]) QPushButton *changeMultipleRowsButton = new QPushButton(widget); changeMultipleRowsButton->setText(QStringLiteral("Change many rows")); + QPushButton *addRowButton = new QPushButton(widget); + addRowButton->setText(QStringLiteral("Add a row")); + + QPushButton *addRowsButton = new QPushButton(widget); + addRowsButton->setText(QStringLiteral("Add 3 rows")); + + QPushButton *insertRowButton = new QPushButton(widget); + insertRowButton->setText(QStringLiteral("Insert a row")); + + QPushButton *insertRowsButton = new QPushButton(widget); + insertRowsButton->setText(QStringLiteral("Insert 3 rows")); + + QPushButton *removeRowButton = new QPushButton(widget); + removeRowButton->setText(QStringLiteral("Remove a row")); + // Add controls to the layout vLayout->addWidget(smoothCB); vLayout->addWidget(surfaceGridCB); @@ -266,6 +281,11 @@ int main(int argc, char *argv[]) vLayout2->addWidget(changeMultipleRowsButton); vLayout2->addWidget(changeItemButton); vLayout2->addWidget(changeMultipleItemButton); + vLayout2->addWidget(addRowButton); + vLayout2->addWidget(addRowsButton); + vLayout2->addWidget(insertRowButton); + vLayout2->addWidget(insertRowsButton); + vLayout2->addWidget(removeRowButton); widget->show(); @@ -326,6 +346,16 @@ int main(int argc, char *argv[]) modifier, &GraphModifier::changeMultipleItem); QObject::connect(changeMultipleRowsButton,&QPushButton::clicked, modifier, &GraphModifier::changeMultipleRows); + QObject::connect(addRowButton,&QPushButton::clicked, + modifier, &GraphModifier::addRow); + QObject::connect(addRowsButton,&QPushButton::clicked, + modifier, &GraphModifier::addRows); + QObject::connect(insertRowButton,&QPushButton::clicked, + modifier, &GraphModifier::insertRow); + QObject::connect(insertRowsButton,&QPushButton::clicked, + modifier, &GraphModifier::insertRows); + QObject::connect(removeRowButton,&QPushButton::clicked, + modifier, &GraphModifier::removeRow); modifier->setGridSliderZ(gridSliderZ); modifier->setGridSliderX(gridSliderX); -- cgit v1.2.3