diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/audiolevels/audiolevels.cpp | 6 | ||||
-rw-r--r-- | examples/audiolevels/audiolevelsiodevice.cpp | 4 | ||||
-rw-r--r-- | examples/bars/graphmodifier.cpp | 44 | ||||
-rw-r--r-- | examples/bars/graphmodifier.h | 8 | ||||
-rw-r--r-- | examples/customproxy/rainfallgraph.cpp | 2 | ||||
-rw-r--r-- | examples/customproxy/variantbardataproxy.cpp | 2 | ||||
-rw-r--r-- | examples/itemmodel/main.cpp | 14 | ||||
-rw-r--r-- | examples/scatter/scatterdatamodifier.cpp | 8 | ||||
-rw-r--r-- | examples/surface/surfacegraph.cpp | 50 | ||||
-rw-r--r-- | examples/surface/surfacegraph.h | 12 |
10 files changed, 76 insertions, 74 deletions
diff --git a/examples/audiolevels/audiolevels.cpp b/examples/audiolevels/audiolevels.cpp index 0fc6d3c5..13a9c8c5 100644 --- a/examples/audiolevels/audiolevels.cpp +++ b/examples/audiolevels/audiolevels.cpp @@ -38,16 +38,16 @@ AudioLevels::AudioLevels(Q3DBars *graph, QObject *parent) m_audioInput(0) { // Set up the graph - m_graph->setBarThickness(0.5); + m_graph->setBarThickness(0.5f); m_graph->setBarSpacing(QSizeF(0.0, 1.0)); m_graph->setGridVisible(true); m_graph->setBackgroundVisible(false); - m_graph->valueAxis()->setRange(-100.0, 100.0); + m_graph->valueAxis()->setRange(-100.0f, 100.0f); m_graph->valueAxis()->setSegmentCount(20); m_graph->valueAxis()->setLabelFormat(QStringLiteral("%d%%")); m_graph->setShadowQuality(QDataVis::ShadowQualityNone); m_graph->setSelectionMode(QDataVis::SelectionNone); - m_graph->scene()->activeCamera()->setCameraPosition(-25.0, 10.0, 190.0); + m_graph->scene()->activeCamera()->setCameraPosition(-25.0f, 10.0f, 190.0f); m_graph->setTheme(new Q3DTheme(QDataVis::ThemeIsabelle)); m_graph->setBarType(QDataVis::MeshStyleBars); m_graph->addSeries(new QBar3DSeries); diff --git a/examples/audiolevels/audiolevelsiodevice.cpp b/examples/audiolevels/audiolevelsiodevice.cpp index 9fedd804..970677c6 100644 --- a/examples/audiolevels/audiolevelsiodevice.cpp +++ b/examples/audiolevels/audiolevelsiodevice.cpp @@ -75,11 +75,11 @@ qint64 AudioLevelsIODevice::writeData(const char *data, qint64 maxSize) for (int i = newDataSize - 1; i >= newDataStartIndex; i--) { // Add 0.01 to the value to avoid gaps in the graph (i.e. zero height bars). // Also, scale to 0...100 - qreal value = qreal(quint8(data[resolution * i]) - 128) / 1.28 + 0.01; + float value = float(quint8(data[resolution * i]) - 128) / 1.28f + 0.01f; (*m_array->at(middleRow))[index].setValue(value); // Insert a fractional value into front half of the rows. for (int j = 1; j <= middleRow; j++) { - qreal fractionalValue = value / qreal(j + 1); + float fractionalValue = value / float(j + 1); (*m_array->at(middleRow - j))[index].setValue(fractionalValue); } index++; diff --git a/examples/bars/graphmodifier.cpp b/examples/bars/graphmodifier.cpp index f38d88e9..8d9c9e88 100644 --- a/examples/bars/graphmodifier.cpp +++ b/examples/bars/graphmodifier.cpp @@ -34,13 +34,13 @@ const QString celsiusString = QString(QChar(0xB0)) + "C"; //! [0] GraphModifier::GraphModifier(Q3DBars *bargraph) : m_graph(bargraph), - m_xRotation(0.0), - m_yRotation(0.0), + m_xRotation(0.0f), + m_yRotation(0.0f), m_fontSize(30), m_segments(4), m_subSegments(3), - m_minval(-20.0), - m_maxval(20.0), + m_minval(-20.0f), + m_maxval(20.0f), //! [1] m_temperatureAxis(new Q3DValueAxis), m_yearAxis(new Q3DCategoryAxis), @@ -110,24 +110,24 @@ void GraphModifier::resetTemperatureData() { //! [5] // Set up data - static const qreal tempOulu[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 tempOulu[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 }; - static const qreal tempHelsinki[7][12] = { - {-3.7, -7.8, -5.4, 3.4, 10.7, 15.4, 18.6, 18.7, 14.3, 8.5, 2.9, 4.1}, // 2006 - {-1.2, -7.5, 3.1, 5.5, 10.3, 15.9, 17.4, 17.9, 11.2, 7.3, 1.1, 0.5}, // 2007 - {-0.6, 1.2, 0.2, 6.3, 10.2, 13.8, 18.1, 15.1, 10.1, 9.4, 2.5, 0.4}, // 2008 - {-2.9, -3.5, -0.9, 4.7, 10.9, 14.0, 17.4, 16.8, 13.2, 4.1, 2.6, -2.3}, // 2009 - {-10.2, -8.0, -1.9, 6.6, 11.3, 14.5, 21.0, 18.8, 12.6, 6.1, -0.5, -7.3}, // 2010 - {-4.4, -9.1, -2.0, 5.5, 9.9, 15.6, 20.8, 17.8, 13.4, 8.9, 3.6, 1.5}, // 2011 - {-3.5, -3.2, -0.7, 4.0, 11.1, 13.4, 17.3, 15.8, 13.1, 6.4, 4.1, -5.1} // 2012 + static const float tempHelsinki[7][12] = { + {-3.7f, -7.8f, -5.4f, 3.4f, 10.7f, 15.4f, 18.6f, 18.7f, 14.3f, 8.5f, 2.9f, 4.1f}, // 2006 + {-1.2f, -7.5f, 3.1f, 5.5f, 10.3f, 15.9f, 17.4f, 17.9f, 11.2f, 7.3f, 1.1f, 0.5f}, // 2007 + {-0.6f, 1.2f, 0.2f, 6.3f, 10.2f, 13.8f, 18.1f, 15.1f, 10.1f, 9.4f, 2.5f, 0.4f}, // 2008 + {-2.9f, -3.5f, -0.9f, 4.7f, 10.9f, 14.0f, 17.4f, 16.8f, 13.2f, 4.1f, 2.6f, -2.3f}, // 2009 + {-10.2f, -8.0f, -1.9f, 6.6f, 11.3f, 14.5f, 21.0f, 18.8f, 12.6f, 6.1f, -0.5f, -7.3f}, // 2010 + {-4.4f, -9.1f, -2.0f, 5.5f, 9.9f, 15.6f, 20.8f, 17.8f, 13.4f, 8.9f, 3.6f, 1.5f}, // 2011 + {-3.5f, -3.2f, -0.7f, 4.0f, 11.1f, 13.4f, 17.3f, 15.8f, 13.1f, 6.4f, 4.1f, -5.1f} // 2012 }; // Create data arrays @@ -260,10 +260,10 @@ void GraphModifier::setSeriesVisibility(int enabled) { m_graph->seriesList().at(1)->setVisible(bool(enabled)); if (enabled) { - m_graph->setBarThickness(2.0); + m_graph->setBarThickness(2.0f); m_graph->setBarSpacing(QSizeF(1.0, 3.0)); } else { - m_graph->setBarThickness(1.0); + m_graph->setBarThickness(1.0f); m_graph->setBarSpacing(QSizeF(1.0, 1.0)); } } diff --git a/examples/bars/graphmodifier.h b/examples/bars/graphmodifier.h index 978558e2..2e84790c 100644 --- a/examples/bars/graphmodifier.h +++ b/examples/bars/graphmodifier.h @@ -61,13 +61,13 @@ signals: private: Q3DBars *m_graph; - qreal m_xRotation; - qreal m_yRotation; + float m_xRotation; + float m_yRotation; 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; Q3DValueAxis *m_temperatureAxis; diff --git a/examples/customproxy/rainfallgraph.cpp b/examples/customproxy/rainfallgraph.cpp index a31200e8..71463103 100644 --- a/examples/customproxy/rainfallgraph.cpp +++ b/examples/customproxy/rainfallgraph.cpp @@ -48,7 +48,7 @@ RainfallGraph::RainfallGraph(Q3DBars *rainfall) // Set up bar specifications; make the bars as wide as they are deep, // and add a small space between the bars - m_graph->setBarThickness(1.0); + m_graph->setBarThickness(1.0f); m_graph->setBarSpacing(QSizeF(0.2, 0.2)); // Set axis labels and titles diff --git a/examples/customproxy/variantbardataproxy.cpp b/examples/customproxy/variantbardataproxy.cpp index 887115b8..2997810f 100644 --- a/examples/customproxy/variantbardataproxy.cpp +++ b/examples/customproxy/variantbardataproxy.cpp @@ -118,7 +118,7 @@ void VariantBarDataProxy::resolveDataSet() const QStringList &columnList = m_mapping->columnCategories(); // Sort values into rows and columns - typedef QHash<QString, qreal> ColumnValueMap; + typedef QHash<QString, float> ColumnValueMap; QHash <QString, ColumnValueMap> itemValueMap; foreach (const VariantDataItem *item, itemList) { itemValueMap[item->at(rowIndex).toString()][item->at(columnIndex).toString()] diff --git a/examples/itemmodel/main.cpp b/examples/itemmodel/main.cpp index 0c9ee0cb..789ff0ff 100644 --- a/examples/itemmodel/main.cpp +++ b/examples/itemmodel/main.cpp @@ -78,7 +78,7 @@ GraphDataGenerator::GraphDataGenerator(Q3DBars *bargraph, QTableWidget *tableWid //! [5] // Set up bar specifications; make the bars as wide as they are deep, // and add a small space between them - m_graph->setBarThickness(1.0); + m_graph->setBarThickness(1.0f); m_graph->setBarSpacing(QSizeF(0.2, 0.2)); // Set bar type to flat pyramids @@ -161,11 +161,11 @@ void GraphDataGenerator::setupModel() weeks << "week 1" << "week 2" << "week 3" << "week 4" << "week 5"; // Set up data Mon Tue Wed Thu Fri Sat Sun - qreal hours[5][7] = {{2.0, 1.0, 3.0, 0.2, 1.0, 5.0, 10.0}, // week 1 - {0.5, 1.0, 3.0, 1.0, 2.0, 2.0, 3.0}, // week 2 - {1.0, 1.0, 2.0, 1.0, 4.0, 4.0, 4.0}, // week 3 - {0.0, 1.0, 0.0, 0.0, 2.0, 2.0, 0.3}, // week 4 - {3.0, 3.0, 6.0, 2.0, 2.0, 1.0, 1.0}}; // week 5 + float hours[5][7] = {{2.0f, 1.0f, 3.0f, 0.2f, 1.0f, 5.0f, 10.0f}, // week 1 + {0.5f, 1.0f, 3.0f, 1.0f, 2.0f, 2.0f, 3.0f}, // week 2 + {1.0f, 1.0f, 2.0f, 1.0f, 4.0f, 4.0f, 4.0f}, // week 3 + {0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f, 0.3f}, // week 4 + {3.0f, 3.0f, 6.0f, 2.0f, 2.0f, 1.0f, 1.0f}}; // week 5 //! [9] // Add labels @@ -205,7 +205,7 @@ void GraphDataGenerator::addRow() for (int i = 0; i < m_columnCount; i++) { QModelIndex index = m_tableWidget->model()->index(0, i); m_tableWidget->model()->setData(index, - ((qreal)i / (qreal)m_columnCount) / 2.0 + (qreal)(rand() % 30) / 100.0); + ((float)i / (float)m_columnCount) / 2.0f + (float)(rand() % 30) / 100.0f); } m_tableWidget->resizeColumnsToContents(); } diff --git a/examples/scatter/scatterdatamodifier.cpp b/examples/scatter/scatterdatamodifier.cpp index f92ffd0f..ce4eaa03 100644 --- a/examples/scatter/scatterdatamodifier.cpp +++ b/examples/scatter/scatterdatamodifier.cpp @@ -81,9 +81,9 @@ void ScatterDataModifier::addData() m_graph->axisX()->setTitle("X"); m_graph->axisY()->setTitle("Y"); m_graph->axisZ()->setTitle("Z"); - m_graph->axisX()->setRange(-30.0, 30.0); - m_graph->axisY()->setRange(-1.0, 1.0); - m_graph->axisZ()->setRange(-30.0, 30.0); + m_graph->axisX()->setRange(-30.0f, 30.0f); + m_graph->axisY()->setRange(-1.0f, 1.0f); + m_graph->axisZ()->setRange(-30.0f, 30.0f); //! [4] //! [5] @@ -102,7 +102,7 @@ void ScatterDataModifier::addData() float limit = qSqrt(numberOfItems) / 2.0f; for (float i = -limit; i < limit; i++) { for (float j = -limit; j < limit; j++) { - ptrToDataArray->setPosition(QVector3D(i, qCos(qDegreesToRadians((i * j) / 3.0)), j)); + ptrToDataArray->setPosition(QVector3D(i, qCos(qDegreesToRadians((i * j) / 3.0f)), j)); ptrToDataArray++; } } diff --git a/examples/surface/surfacegraph.cpp b/examples/surface/surfacegraph.cpp index f774c537..d7def123 100644 --- a/examples/surface/surfacegraph.cpp +++ b/examples/surface/surfacegraph.cpp @@ -50,7 +50,7 @@ SurfaceGraph::SurfaceGraph(Q3DSurface *surface) QImage heightMapImage(":/maps/mountain"); m_heightMapProxy = new QHeightMapSurfaceDataProxy(heightMapImage); m_heightMapSeries = new QSurface3DSeries(m_heightMapProxy); - m_heightMapProxy->setValueRanges(34.0, 40.0, 18.0, 24.0); + m_heightMapProxy->setValueRanges(34.0f, 40.0f, 18.0f, 24.0f); //! [2] m_heightMapWidth = heightMapImage.width(); m_heightMapHeight = heightMapImage.height(); @@ -71,12 +71,14 @@ void SurfaceGraph::fillSqrtSinProxy() dataArray->reserve(sampleCountZ); for (int i = 0 ; i < sampleCountZ ; i++) { QSurfaceDataRow *newRow = new QSurfaceDataRow(sampleCountX); - float z = i * stepZ + sampleMin; + // Keep values within range bounds, since just adding step can cause minor drift due + // to the rounding errors. + float z = qMin(sampleMax, (i * stepZ + sampleMin)); int index = 0; for (int j = 0; j < sampleCountX; j++) { - float x = j * stepX + sampleMin; - float R = qSqrt(z * z + x * x) + 0.01; - float y = (qSin(R) / R + 0.24) * 1.61; + float x = qMin(sampleMax, (j * stepX + sampleMin)); + float R = qSqrt(z * z + x * x) + 0.01f; + float y = (qSin(R) / R + 0.24f) * 1.61f; (*newRow)[index++].setPosition(QVector3D(x, y, z)); } *dataArray << newRow; @@ -96,7 +98,7 @@ void SurfaceGraph::enableSqrtSinModel(bool enable) m_graph->axisX()->setLabelFormat("%.2f"); m_graph->axisZ()->setLabelFormat("%.2f"); m_graph->axisX()->setRange(sampleMin, sampleMax); - m_graph->axisY()->setRange(0.0, 2.0); + m_graph->axisY()->setRange(0.0f, 2.0f); m_graph->axisZ()->setRange(sampleMin, sampleMax); m_graph->removeSeries(m_heightMapSeries); @@ -106,8 +108,8 @@ void SurfaceGraph::enableSqrtSinModel(bool enable) // Reset range sliders for Sqrt&Sin m_rangeMinX = sampleMin; m_rangeMinZ = sampleMin; - m_stepX = (sampleMax - sampleMin) / qreal(sampleCountX - 1); - m_stepZ = (sampleMax - sampleMin) / qreal(sampleCountZ - 1); + m_stepX = (sampleMax - sampleMin) / float(sampleCountX - 1); + m_stepZ = (sampleMax - sampleMin) / float(sampleCountZ - 1); m_axisMinSliderX->setMaximum(sampleCountX - 2); m_axisMinSliderX->setValue(0); m_axisMaxSliderX->setMaximum(sampleCountX - 1); @@ -128,9 +130,9 @@ void SurfaceGraph::enableHeightMapModel(bool enable) m_graph->axisX()->setLabelFormat("%.1f N"); m_graph->axisZ()->setLabelFormat("%.1f E"); - m_graph->axisX()->setRange(34.0, 40.0); + m_graph->axisX()->setRange(34.0f, 40.0f); m_graph->axisY()->setAutoAdjustRange(true); - m_graph->axisZ()->setRange(18.0, 24.0); + m_graph->axisZ()->setRange(18.0f, 24.0f); m_graph->removeSeries(m_sqrtSinSeries); m_graph->addSeries(m_heightMapSeries); @@ -139,10 +141,10 @@ void SurfaceGraph::enableHeightMapModel(bool enable) // Reset range sliders for height map int mapGridCountX = m_heightMapWidth / heightMapGridStepX; int mapGridCountZ = m_heightMapHeight / heightMapGridStepZ; - m_rangeMinX = 34.0; - m_rangeMinZ = 18.0; - m_stepX = 6.0 / qreal(mapGridCountX - 1); - m_stepZ = 6.0 / qreal(mapGridCountZ - 1); + m_rangeMinX = 34.0f; + m_rangeMinZ = 18.0f; + m_stepX = 6.0f / float(mapGridCountX - 1); + m_stepZ = 6.0f / float(mapGridCountZ - 1); m_axisMinSliderX->setMaximum(mapGridCountX - 2); m_axisMinSliderX->setValue(0); m_axisMaxSliderX->setMaximum(mapGridCountX - 1); @@ -156,67 +158,67 @@ void SurfaceGraph::enableHeightMapModel(bool enable) void SurfaceGraph::adjustXMin(int min) { - qreal minX = m_stepX * qreal(min) + m_rangeMinX; + float minX = m_stepX * float(min) + m_rangeMinX; int max = m_axisMaxSliderX->value(); if (min >= max) { max = min + 1; m_axisMaxSliderX->setValue(max); } - qreal maxX = m_stepX * max + m_rangeMinX; + float maxX = m_stepX * max + m_rangeMinX; setAxisXRange(minX, maxX); } void SurfaceGraph::adjustXMax(int max) { - qreal maxX = m_stepX * qreal(max) + m_rangeMinX; + float maxX = m_stepX * float(max) + m_rangeMinX; int min = m_axisMinSliderX->value(); if (max <= min) { min = max - 1; m_axisMinSliderX->setValue(min); } - qreal minX = m_stepX * min + m_rangeMinX; + float minX = m_stepX * min + m_rangeMinX; setAxisXRange(minX, maxX); } void SurfaceGraph::adjustZMin(int min) { - qreal minZ = m_stepZ * qreal(min) + m_rangeMinZ; + float minZ = m_stepZ * float(min) + m_rangeMinZ; int max = m_axisMaxSliderZ->value(); if (min >= max) { max = min + 1; m_axisMaxSliderZ->setValue(max); } - qreal maxZ = m_stepZ * max + m_rangeMinZ; + float maxZ = m_stepZ * max + m_rangeMinZ; setAxisZRange(minZ, maxZ); } void SurfaceGraph::adjustZMax(int max) { - qreal maxX = m_stepZ * qreal(max) + m_rangeMinZ; + float maxX = m_stepZ * float(max) + m_rangeMinZ; int min = m_axisMinSliderZ->value(); if (max <= min) { min = max - 1; m_axisMinSliderZ->setValue(min); } - qreal minX = m_stepZ * min + m_rangeMinZ; + float minX = m_stepZ * min + m_rangeMinZ; setAxisZRange(minX, maxX); } //! [5] -void SurfaceGraph::setAxisXRange(qreal min, qreal max) +void SurfaceGraph::setAxisXRange(float min, float max) { m_graph->axisX()->setRange(min, max); } -void SurfaceGraph::setAxisZRange(qreal min, qreal max) +void SurfaceGraph::setAxisZRange(float min, float max) { m_graph->axisZ()->setRange(min, max); } diff --git a/examples/surface/surfacegraph.h b/examples/surface/surfacegraph.h index 92b06e54..ecdec672 100644 --- a/examples/surface/surfacegraph.h +++ b/examples/surface/surfacegraph.h @@ -73,15 +73,15 @@ private: QSlider *m_axisMaxSliderX; QSlider *m_axisMinSliderZ; QSlider *m_axisMaxSliderZ; - qreal m_rangeMinX; - qreal m_rangeMinZ; - qreal m_stepX; - qreal m_stepZ; + float m_rangeMinX; + float m_rangeMinZ; + float m_stepX; + float m_stepZ; int m_heightMapWidth; int m_heightMapHeight; - void setAxisXRange(qreal min, qreal max); - void setAxisZRange(qreal min, qreal max); + void setAxisXRange(float min, float max); + void setAxisZRange(float min, float max); void fillSqrtSinProxy(); }; |