From e029d0ea1d486dd3dbbfa4519a2125da202f22e4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 25 Nov 2013 12:19:18 +0200 Subject: Change qreals to floats + Fix default axes to sensible + Fix some rounding errors in surface creation Task-number: QTRD-2622 Change-Id: I44450efc1e77ac8d8dbefc75814345949b8fb1f1 Reviewed-by: Mika Salmela --- tests/barstest/chart.cpp | 60 +++++++++++++++++----------------- tests/barstest/chart.h | 12 +++---- tests/multigraphs/data.cpp | 8 ++--- tests/qmlcamera/qml/qmlcamera/main.qml | 6 ---- tests/scattertest/scatterchart.cpp | 6 ++-- tests/spectrum/spectrumapp/main.cpp | 10 +++--- tests/surfacetest/graphmodifier.cpp | 40 +++++++++++++++-------- tests/surfacetest/graphmodifier.h | 12 +++---- 8 files changed, 80 insertions(+), 74 deletions(-) (limited to 'tests') diff --git a/tests/barstest/chart.cpp b/tests/barstest/chart.cpp index bd99168f..46bc0be1 100644 --- a/tests/barstest/chart.cpp +++ b/tests/barstest/chart.cpp @@ -34,16 +34,16 @@ GraphModifier::GraphModifier(Q3DBars *barchart, QColorDialog *colorDialog) m_colorDialog(colorDialog), m_columnCount(21), m_rowCount(21), - m_xRotation(0.0), - m_yRotation(0.0), + m_xRotation(0.0f), + m_yRotation(0.0f), m_static(true), - m_barSpacingX(0.1), - m_barSpacingZ(0.1), + m_barSpacingX(0.1f), + m_barSpacingZ(0.1f), m_fontSize(20), m_segments(4), m_subSegments(3), - m_minval(-16.0), - m_maxval(20.0), + m_minval(-16.0f), + m_maxval(20.0f), m_selectedBar(-1, -1), m_autoAdjustingAxis(new Q3DValueAxis), m_fixedRangeAxis(new Q3DValueAxis), @@ -268,9 +268,9 @@ void GraphModifier::createMassiveArray() QBarDataRow *dataRow = new QBarDataRow(arrayDimension); for (int j = 0; j < arrayDimension; j++) { if (!m_negativeValuesOn) - (*dataRow)[j].setValue((qreal(i % 300 + 1) / 300.0) * qreal(rand() % int(m_maxval))); + (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0) * float(rand() % int(m_maxval))); else - (*dataRow)[j].setValue((qreal(i % 300 + 1) / 300.0) * qreal(rand() % int(m_maxval)) + (*dataRow)[j].setValue((float(i % 300 + 1) / 300.0) * float(rand() % int(m_maxval)) + m_minval); } dataArray->append(dataRow); @@ -285,14 +285,14 @@ void GraphModifier::resetTemperatureData() { // Set up data - static const qreal temp[7][12] = { - {-6.7, -11.7, -9.7, 3.3, 9.2, 14.0, 16.3, 17.8, 10.2, 2.1, -2.6, -0.3}, // 2006 - {-6.8, -13.3, 0.2, 1.5, 7.9, 13.4, 16.1, 15.5, 8.2, 5.4, -2.6, -0.8}, // 2007 - {-4.2, -4.0, -4.6, 1.9, 7.3, 12.5, 15.0, 12.8, 7.6, 5.1, -0.9, -1.3}, // 2008 - {-7.8, -8.8, -4.2, 0.7, 9.3, 13.2, 15.8, 15.5, 11.2, 0.6, 0.7, -8.4}, // 2009 - {-14.4, -12.1, -7.0, 2.3, 11.0, 12.6, 18.8, 13.8, 9.4, 3.9, -5.6, -13.0}, // 2010 - {-9.0, -15.2, -3.8, 2.6, 8.3, 15.9, 18.6, 14.9, 11.1, 5.3, 1.8, -0.2}, // 2011 - {-8.7, -11.3, -2.3, 0.4, 7.5, 12.2, 16.4, 14.1, 9.2, 3.1, 0.3, -12.1} // 2012 + static const float temp[7][12] = { + {-6.7f, -11.7f, -9.7f, 3.3f, 9.2f, 14.0f, 16.3f, 17.8f, 10.2f, 2.1f, -2.6f, -0.3f}, // 2006 + {-6.8f, -13.3f, 0.2f, 1.5f, 7.9f, 13.4f, 16.1f, 15.5f, 8.2f, 5.4f, -2.6f, -0.8f}, // 2007 + {-4.2f, -4.0f, -4.6f, 1.9f, 7.3f, 12.5f, 15.0f, 12.8f, 7.6f, 5.1f, -0.9f, -1.3f}, // 2008 + {-7.8f, -8.8f, -4.2f, 0.7f, 9.3f, 13.2f, 15.8f, 15.5f, 11.2f, 0.6f, 0.7f, -8.4f}, // 2009 + {-14.4f, -12.1f, -7.0f, 2.3f, 11.0f, 12.6f, 18.8f, 13.8f, 9.4f, 3.9f, -5.6f, -13.0f}, // 2010 + {-9.0f, -15.2f, -3.8f, 2.6f, 8.3f, 15.9f, 18.6f, 14.9f, 11.1f, 5.3f, 1.8f, -0.2f}, // 2011 + {-8.7f, -11.3f, -2.3f, 0.4f, 7.5f, 12.2f, 16.4f, 14.1f, 9.2f, 3.1f, 0.3f, -12.1f} // 2012 }; // Create data rows @@ -338,12 +338,12 @@ static int changeCounter = 0; void GraphModifier::addRow() { QBarDataRow *dataRow = new QBarDataRow(m_columnCount); - for (qreal i = 0; i < m_columnCount; i++) { + for (float i = 0; i < m_columnCount; i++) { if (!m_negativeValuesOn) - (*dataRow)[i].setValue(((i + 1) / (qreal)m_columnCount) * (qreal)(rand() % int(m_maxval))); + (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval))); else - (*dataRow)[i].setValue(((i + 1) / (qreal)m_columnCount) * (qreal)(rand() % int(m_maxval)) - - (qreal)(rand() % int(m_minval))); + (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval)) + - (float)(rand() % int(m_minval))); } // TODO Needs to be changed to account for data window offset once it is implemented. @@ -358,7 +358,7 @@ void GraphModifier::addRows() for (int i = 0; i < m_rowCount; i++) { QBarDataRow *dataRow = new QBarDataRow(m_columnCount); for (int j = 0; j < m_columnCount; j++) - (*dataRow)[j].setValue(qreal(j + i + m_genericData->dataProxy()->rowCount()) + m_minval); + (*dataRow)[j].setValue(float(j + i + m_genericData->dataProxy()->rowCount()) + m_minval); dataArray.append(dataRow); labels.append(QStringLiteral("Add %1").arg(addCounter++)); } @@ -370,8 +370,8 @@ void GraphModifier::addRows() void GraphModifier::insertRow() { QBarDataRow *dataRow = new QBarDataRow(m_columnCount); - for (qreal i = 0; i < m_columnCount; i++) - (*dataRow)[i].setValue(((i + 1) / (qreal)m_columnCount) * (qreal)(rand() % int(m_maxval)) + for (float i = 0; i < m_columnCount; i++) + (*dataRow)[i].setValue(((i + 1) / (float)m_columnCount) * (float)(rand() % int(m_maxval)) + m_minval); // TODO Needs to be changed to account for data window offset once it is implemented. @@ -389,7 +389,7 @@ void GraphModifier::insertRows() for (int i = 0; i < m_rowCount; i++) { QBarDataRow *dataRow = new QBarDataRow(m_columnCount); for (int j = 0; j < m_columnCount; j++) - (*dataRow)[j].setValue(qreal(j + i + m_genericData->dataProxy()->rowCount()) + m_minval); + (*dataRow)[j].setValue(float(j + i + m_genericData->dataProxy()->rowCount()) + m_minval); dataArray.append(dataRow); labels.append(QStringLiteral("Insert %1").arg(insertCounter++)); } @@ -406,7 +406,7 @@ void GraphModifier::changeItem() int row = m_selectedBar.x(); int column = m_selectedBar.y(); if (row >= 0 && column >= 0) { - QBarDataItem item(qreal(rand() % 100)); + QBarDataItem item(float(rand() % 100)); m_genericData->dataProxy()->setItem(row, column, item); } } @@ -418,7 +418,7 @@ void GraphModifier::changeRow() if (row >= 0) { QBarDataRow *newRow = new QBarDataRow(m_genericData->dataProxy()->rowAt(row)->size()); for (int i = 0; i < newRow->size(); i++) - (*newRow)[i].setValue(qreal(rand() % int(m_maxval)) + m_minval); + (*newRow)[i].setValue(float(rand() % int(m_maxval)) + m_minval); QString label = QStringLiteral("Change %1").arg(changeCounter++); m_genericData->dataProxy()->setRow(row, newRow, label); } @@ -435,7 +435,7 @@ void GraphModifier::changeRows() for (int i = startRow; i <= row; i++ ) { QBarDataRow *newRow = new QBarDataRow(m_genericData->dataProxy()->rowAt(i)->size()); for (int j = 0; j < newRow->size(); j++) - (*newRow)[j].setValue(qreal(rand() % int(m_maxval)) + m_minval); + (*newRow)[j].setValue(float(rand() % int(m_maxval)) + m_minval); newArray.append(newRow); labels.append(QStringLiteral("Change %1").arg(changeCounter++)); } @@ -622,18 +622,18 @@ void GraphModifier::rotateY(int rotation) void GraphModifier::setSpecsRatio(int barwidth) { - m_graph->setBarThickness((qreal)barwidth / 30.0); + m_graph->setBarThickness((float)barwidth / 30.0f); } void GraphModifier::setSpacingSpecsX(int spacing) { - m_barSpacingX = (qreal)spacing / 100.0; + m_barSpacingX = (float)spacing / 100.0f; m_graph->setBarSpacing(QSizeF(m_barSpacingX, m_barSpacingZ)); } void GraphModifier::setSpacingSpecsZ(int spacing) { - m_barSpacingZ = (qreal)spacing / 100.0; + m_barSpacingZ = (float)spacing / 100.0f; m_graph->setBarSpacing(QSizeF(m_barSpacingX, m_barSpacingZ)); } diff --git a/tests/barstest/chart.h b/tests/barstest/chart.h index 2b323a2f..5d29cc86 100644 --- a/tests/barstest/chart.h +++ b/tests/barstest/chart.h @@ -95,16 +95,16 @@ private: QColorDialog *m_colorDialog; int m_columnCount; int m_rowCount; - qreal m_xRotation; - qreal m_yRotation; + float m_xRotation; + float m_yRotation; bool m_static; - qreal m_barSpacingX; - qreal m_barSpacingZ; + float m_barSpacingX; + float m_barSpacingZ; int m_fontSize; int m_segments; int m_subSegments; - qreal m_minval; - qreal m_maxval; + float m_minval; + float m_maxval; QStringList m_months; QStringList m_years; QPoint m_selectedBar; diff --git a/tests/multigraphs/data.cpp b/tests/multigraphs/data.cpp index f69c296e..dc4fcaec 100644 --- a/tests/multigraphs/data.cpp +++ b/tests/multigraphs/data.cpp @@ -217,14 +217,14 @@ void Data::setData(const QImage &image) int limitsX = imageWidth / 2; int limitsZ = imageHeight / 2; - qreal height = 0; + float height = 0; int count = 0; for (int i = -limitsZ; i < limitsZ; i++, bitCount -= widthBits) { for (int j = -limitsX; j < limitsX; j++) { - height = qreal(bits[bitCount + ((j + limitsX) * 4)]) - 128.0; + height = float(bits[bitCount + ((j + limitsX) * 4)]) - 128.0; if (height > -128) { - ptrToDataArray->setPosition(QVector3D(qreal(j), height, qreal(i))); + ptrToDataArray->setPosition(QVector3D(float(j), height, float(i))); ptrToDataArray++; count++; } @@ -238,7 +238,7 @@ void Data::setData(const QImage &image) for (int i = 0; i < imageHeight; i++, bitCount -= widthBits) { QBarDataRow &newRow = *dataArray->at(i); for (int j = 0; j < imageWidth; j++) - newRow[j] = qreal(bits[bitCount + (j * 4)]); + newRow[j] = float(bits[bitCount + (j * 4)]); } m_bars->seriesList().at(0)->dataProxy()->resetArray(dataArray); diff --git a/tests/qmlcamera/qml/qmlcamera/main.qml b/tests/qmlcamera/qml/qmlcamera/main.qml index 5b80abfd..fce5cc33 100644 --- a/tests/qmlcamera/qml/qmlcamera/main.qml +++ b/tests/qmlcamera/qml/qmlcamera/main.qml @@ -58,12 +58,6 @@ Item { columnAxis: chartAxes.column valueAxis: chartAxes.expenses - onSelectedBarChanged: { - // Set camControlArea current row to selected bar - var rowRole = chartData.proxy.rowLabels[position.x]; - var colRole = chartData.proxy.columnLabels[position.y]; - } - // Bind UI controls to the camera scene.activeCamera.wrapXRotation: false scene.activeCamera.xRotation: camControlArea.xValue diff --git a/tests/scattertest/scatterchart.cpp b/tests/scattertest/scatterchart.cpp index fe784d74..d0615193 100644 --- a/tests/scattertest/scatterchart.cpp +++ b/tests/scattertest/scatterchart.cpp @@ -74,9 +74,9 @@ void ScatterDataModifier::addData() m_chart->axisX()->setTitle("X"); m_chart->axisY()->setTitle("Y"); m_chart->axisZ()->setTitle("Z"); - m_chart->axisX()->setRange(-50.0, 50.0); - m_chart->axisY()->setRange(-1.0, 1.2); - m_chart->axisZ()->setRange(-50.0, 50.0); + m_chart->axisX()->setRange(-50.0f, 50.0f); + m_chart->axisY()->setRange(-1.0f, 1.2f); + m_chart->axisZ()->setRange(-50.0f, 50.0f); QScatterDataArray *dataArray = new QScatterDataArray; dataArray->resize(numberOfItems); diff --git a/tests/spectrum/spectrumapp/main.cpp b/tests/spectrum/spectrumapp/main.cpp index e9913706..8b18e467 100644 --- a/tests/spectrum/spectrumapp/main.cpp +++ b/tests/spectrum/spectrumapp/main.cpp @@ -75,7 +75,7 @@ MainApp::MainApp(Q3DBars *window) // Disable grid m_chart->setGridVisible(false); // Disable auto-scaling of height by defining explicit range - m_chart->valueAxis()->setRange(0.0, 1.0); + m_chart->valueAxis()->setRange(0.0f, 1.0f); // Disable shadows m_chart->setShadowQuality(QDataVis::ShadowQualityNone); #if USE_CONES @@ -87,15 +87,15 @@ MainApp::MainApp(Q3DBars *window) m_chart->setBarType(QDataVis::MeshStyleCones, true); // Adjust zoom manually; automatic zoom level calculation does not work well with negative // spacings (in setBarSpacing) - m_chart->setCameraPosition(10.0f, 5.0f, 70); + m_chart->setCameraPosition(10.0f, 5.0f, 70.0f); #else // Set bar specifications; make them twice as wide as they're deep - m_chart->setBarThickness(2.0); + m_chart->setBarThickness(2.0f); m_chart->setBarSpacing(QSizeF(0.0, 0.0)); // Set bar type, flat bars m_chart->setBarType(QDataVis::MeshStyleBars, false); // Adjust camera position - m_chart->scene()->activeCamera()->setCameraPosition(10.0f, 7.5f, 75); + m_chart->scene()->activeCamera()->setCameraPosition(10.0f, 7.5f, 75.0f); #endif // Set color scheme m_chart->setBarColor(QColor(Qt::red)); @@ -141,7 +141,7 @@ void MainApp::spectrumChanged(qint64 position, qint64 length, const FrequencySpe for ( ; i != end; ++i) { const FrequencySpectrum::Element e = *i; if (e.frequency >= m_lowFreq && e.frequency < m_highFreq) { - (*data)[barIndex(e.frequency)].setValue(qMax(data->at(barIndex(e.frequency)).value(), qreal(e.amplitude))); + (*data)[barIndex(e.frequency)].setValue(qMax(data->at(barIndex(e.frequency)).value(), float(e.amplitude))); } } m_chart->seriesList().at(0)->dataProxy()->insertRow(0, data); diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index 568d57c9..5a367c7a 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -30,7 +30,7 @@ QT_DATAVISUALIZATION_USE_NAMESPACE //#define JITTER_PLANE -#define WONKY_PLANE +//#define WONKY_PLANE GraphModifier::GraphModifier(Q3DSurface *graph) : m_graph(graph), @@ -91,10 +91,10 @@ void GraphModifier::toggleSqrtSin(bool enable) if (enable) { qDebug() << "Create Sqrt&Sin surface, (" << m_xCount << ", " << m_zCount << ")"; - float minX = -10.0; - float maxX = 10.0; - float minZ = -10.0; - float maxZ = 10.0; + 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); @@ -102,9 +102,11 @@ void GraphModifier::toggleSqrtSin(bool enable) dataArray->reserve(m_zCount); for (float i = 0; i < m_zCount; i++) { QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + // Keep values within range bounds, since just adding step can cause minor drift due + // to the rounding errors. + float z = qMin(maxZ, (i * stepZ + minZ)); for (float j = 0; j < m_xCount; j++) { - float x = j * stepX + minX; - float z = i * stepZ + minZ; + 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)); @@ -139,10 +141,10 @@ void GraphModifier::togglePlane(bool enable) m_graph->axisZ()->setLabelFormat("%.2f"); m_planeArray->reserve(m_zCount); - float minX = -10.0; - float maxX = 20.0; - float minZ = -10.0; - float maxZ = 10.0; + float minX = -10.0f; + float maxX = 20.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); #ifdef WONKY_PLANE @@ -172,8 +174,18 @@ void GraphModifier::togglePlane(bool enable) #else for (float i = 0; i < m_zCount; i++) { QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); - for (float j = 0; j < m_xCount; j++) - (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, i * stepZ + minZ)); + // Keep values within range bounds, since just adding step can cause minor drift due + // to the rounding errors. + float zVal; + if (i == (m_zCount - 1)) + zVal = maxZ; + else + zVal = i * stepZ + minZ; + + float j = 0; + for (; j < m_xCount - 1; j++) + (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, zVal)); + (*newRow)[j].setPosition(QVector3D(maxX, -0.04f, zVal)); *m_planeArray << newRow; } @@ -365,7 +377,7 @@ void GraphModifier::timeout() m_theSeries->dataProxy()->resetArray(m_planeArray); } -void GraphModifier::resetArrayAndSliders(QSurfaceDataArray *array, qreal minZ, qreal maxZ, qreal minX, qreal maxX) +void GraphModifier::resetArrayAndSliders(QSurfaceDataArray *array, float minZ, float maxZ, float minX, float maxX) { m_axisMinSliderX->setValue(minX); m_axisMinSliderZ->setValue(minZ); diff --git a/tests/surfacetest/graphmodifier.h b/tests/surfacetest/graphmodifier.h index b0f9b3da..e7f19c4d 100644 --- a/tests/surfacetest/graphmodifier.h +++ b/tests/surfacetest/graphmodifier.h @@ -76,8 +76,8 @@ public slots: void timeout(); private: - void resetArrayAndSliders(QSurfaceDataArray *array, qreal minZ, qreal maxZ, qreal minX, - qreal maxX); + void resetArrayAndSliders(QSurfaceDataArray *array, float minZ, float maxZ, float minX, + float maxX); Q3DSurface *m_graph; QSlider *m_gridSliderX; @@ -91,10 +91,10 @@ private: int m_zCount; int m_activeSample; int m_fontSize; - qreal m_rangeX; - qreal m_rangeZ; - qreal m_minX; - qreal m_minZ; + float m_rangeX; + float m_rangeZ; + float m_minX; + float m_minZ; QTimer m_timer; QSurfaceDataArray *m_planeArray; QLabel *m_selectionInfoLabel; -- cgit v1.2.3