diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-03-02 12:51:25 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-03-03 07:36:41 +0100 |
commit | ed80c940b659455e2bd98700157f5fc78a17b41c (patch) | |
tree | 15812829e16a24d050d1df845d2304735b02a309 /examples/datavisualization/graphgallery/topographicseries.cpp | |
parent | 1bfc0919b8ddb0f1576b6f7ad20a72dc5d23f3e4 (diff) |
graphgallery example: Streamline the code a bit
- Populate the data rows using reserve()/append() instead
of resize() / assign.
- Use prefix increment
- Use QStringView when splitting the data file lines
Pick-to: 6.5
Task-number: QTBUG-110698
Change-Id: I70fed07a9850e2636e6085b9a9190f1e5a062a67
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'examples/datavisualization/graphgallery/topographicseries.cpp')
-rw-r--r-- | examples/datavisualization/graphgallery/topographicseries.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/datavisualization/graphgallery/topographicseries.cpp b/examples/datavisualization/graphgallery/topographicseries.cpp index ea0be77d..ea6767e0 100644 --- a/examples/datavisualization/graphgallery/topographicseries.cpp +++ b/examples/datavisualization/graphgallery/topographicseries.cpp @@ -30,20 +30,21 @@ void TopographicSeries::setTopographyFile(const QString file, float width, float QSurfaceDataArray *dataArray = new QSurfaceDataArray; dataArray->reserve(imageHeight); - for (int i = 0; i < imageHeight; i++) { + for (int i = 0; i < imageHeight; ++i) { int p = i * widthBits; float z = height - float(i) * stepZ; - QSurfaceDataRow *newRow = new QSurfaceDataRow(imageWidth); - for (int j = 0; j < imageWidth; j++) { + QSurfaceDataRow *newRow = new QSurfaceDataRow; + newRow->reserve(imageWidth); + for (int j = 0; j < imageWidth; ++j) { uchar aa = bits[p + 0]; uchar rr = bits[p + 1]; uchar gg = bits[p + 2]; uint color = uint((gg << 16) + (rr << 8) + aa); float y = float(color) / packingFactor; - (*newRow)[j].setPosition(QVector3D(float(j) * stepX, y, z)); - p = p + 4; + newRow->append(QSurfaceDataItem({float(j) * stepX, y, z})); + p += 4; } - *dataArray << newRow; + dataArray->append(newRow); } dataProxy()->resetArray(dataArray); |