From bda4432c80fd340a3d75ba077830ed93724fd9f1 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 28 May 2014 09:23:54 +0300 Subject: Implement binary search for determining surface sample space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-3066 Change-Id: I3a6d727c528e37e914aa1c3f08ee6d268a2c5230 Reviewed-by: Tomi Korpipää --- tests/surfacetest/graphmodifier.cpp | 56 +++++++++++++++++++++++++++++++++++++ tests/surfacetest/graphmodifier.h | 2 ++ tests/surfacetest/main.cpp | 14 ++++++++++ 3 files changed, 72 insertions(+) (limited to 'tests') diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index 13cf9fad..ed86f03c 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -721,6 +721,62 @@ void GraphModifier::toggleAxisTitleFixed(bool enabled) m_graph->axisZ()->setTitleFixed(enabled); } +void GraphModifier::toggleXAscending(bool enabled) +{ + // Flip data array contents if necessary + foreach (QSurface3DSeries *series, m_graph->seriesList()) { + QSurfaceDataArray *array = const_cast(series->dataProxy()->array()); + const int rowCount = array->size(); + const int columnCount = array->at(0)->size(); + const bool dataAscending = array->at(0)->at(0).x() < array->at(0)->at(columnCount - 1).x(); + if (dataAscending != enabled) { + // Create new array of equal size + QSurfaceDataArray *newArray = new QSurfaceDataArray; + newArray->reserve(rowCount); + for (int i = 0; i < rowCount; i++) + newArray->append(new QSurfaceDataRow(columnCount)); + + // Flip each row + for (int i = 0; i < rowCount; i++) { + QSurfaceDataRow *oldRow = array->at(i); + QSurfaceDataRow *newRow = newArray->at(i); + for (int j = 0; j < columnCount; j++) + (*newRow)[j] = oldRow->at(columnCount - 1 - j); + } + + series->dataProxy()->resetArray(newArray); + } + } +} + +void GraphModifier::toggleZAscending(bool enabled) +{ + // Flip data array contents if necessary + foreach (QSurface3DSeries *series, m_graph->seriesList()) { + QSurfaceDataArray *array = const_cast(series->dataProxy()->array()); + const int rowCount = array->size(); + const int columnCount = array->at(0)->size(); + const bool dataAscending = array->at(0)->at(0).z() < array->at(rowCount - 1)->at(0).z(); + if (dataAscending != enabled) { + // Create new array of equal size + QSurfaceDataArray *newArray = new QSurfaceDataArray; + newArray->reserve(rowCount); + for (int i = 0; i < rowCount; i++) + newArray->append(new QSurfaceDataRow(columnCount)); + + // Flip each column + for (int i = 0; i < rowCount; i++) { + QSurfaceDataRow *oldRow = array->at(rowCount - 1 - i); + QSurfaceDataRow *newRow = newArray->at(i); + for (int j = 0; j < columnCount; j++) + (*newRow)[j] = oldRow->at(j); + } + + series->dataProxy()->resetArray(newArray); + } + } +} + void GraphModifier::resetArrayAndSliders(QSurfaceDataArray *array, float minZ, float maxZ, float minX, float maxX) { m_axisMinSliderX->setValue(minX); diff --git a/tests/surfacetest/graphmodifier.h b/tests/surfacetest/graphmodifier.h index 1cf13b97..5f1a252a 100644 --- a/tests/surfacetest/graphmodifier.h +++ b/tests/surfacetest/graphmodifier.h @@ -129,6 +129,8 @@ public slots: void changeLabelRotation(int rotation); void toggleAxisTitleVisibility(bool enabled); void toggleAxisTitleFixed(bool enabled); + void toggleXAscending(bool enabled); + void toggleZAscending(bool enabled); private: void fillSeries(); diff --git a/tests/surfacetest/main.cpp b/tests/surfacetest/main.cpp index 0b146678..5806d7b0 100644 --- a/tests/surfacetest/main.cpp +++ b/tests/surfacetest/main.cpp @@ -385,6 +385,14 @@ int main(int argc, char *argv[]) axisLabelRotationSlider->setValue(0); axisLabelRotationSlider->setMaximum(90); + QCheckBox *xAscendingCB = new QCheckBox(widget); + xAscendingCB->setText(QStringLiteral("X Ascending")); + xAscendingCB->setChecked(true); + + QCheckBox *zAscendingCB = new QCheckBox(widget); + zAscendingCB->setText(QStringLiteral("Z Ascending")); + zAscendingCB->setChecked(true); + // Add controls to the layout #ifdef MULTI_SERIES vLayout->addWidget(series1CB); @@ -433,6 +441,8 @@ int main(int argc, char *argv[]) vLayout->addWidget(axisMinSliderX); vLayout->addWidget(axisMinSliderY); vLayout->addWidget(axisMinSliderZ); + vLayout->addWidget(xAscendingCB); + vLayout->addWidget(zAscendingCB); vLayout2->addWidget(new QLabel(QStringLiteral("Change font"))); vLayout2->addWidget(fontList); vLayout2->addWidget(labelButton); @@ -636,6 +646,10 @@ int main(int argc, char *argv[]) modifier, &GraphModifier::toggleAxisTitleFixed); QObject::connect(axisLabelRotationSlider, &QSlider::valueChanged, modifier, &GraphModifier::changeLabelRotation); + QObject::connect(xAscendingCB, &QCheckBox::stateChanged, + modifier, &GraphModifier::toggleXAscending); + QObject::connect(zAscendingCB, &QCheckBox::stateChanged, + modifier, &GraphModifier::toggleZAscending); QObject::connect(aspectRatioSlider, &QSlider::valueChanged, modifier, &GraphModifier::setAspectRatio); -- cgit v1.2.3