diff options
author | Rym Bouabid <rym.bouabid@qt.io> | 2023-09-20 18:12:29 +0200 |
---|---|---|
committer | Rym Bouabid <rym.bouabid@qt.io> | 2023-10-02 19:08:42 +0200 |
commit | 34ff72d0ba5284ff117ee4ae7f04072b51c85315 (patch) | |
tree | 563e9742c1b9fa3fc533901f0a1b8477ebfd149e | |
parent | aa9529408041ab16bb920840d78b3f41c759a2f8 (diff) |
Revamp Queued Custom Type Ex: Add const when applicable
Task-number: QTBUG-117147
Pick-to: 6.6 6.5
Change-Id: I2fe342fa585f8c1203fa64d2a9ceabc07070cc77
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r-- | examples/corelib/threads/queuedcustomtype/main.cpp | 4 | ||||
-rw-r--r-- | examples/corelib/threads/queuedcustomtype/renderthread.cpp | 14 | ||||
-rw-r--r-- | examples/corelib/threads/queuedcustomtype/window.cpp | 6 |
3 files changed, 12 insertions, 12 deletions
diff --git a/examples/corelib/threads/queuedcustomtype/main.cpp b/examples/corelib/threads/queuedcustomtype/main.cpp index 28e7687f02..0a14cb48e1 100644 --- a/examples/corelib/threads/queuedcustomtype/main.cpp +++ b/examples/corelib/threads/queuedcustomtype/main.cpp @@ -48,8 +48,8 @@ QImage createImage(int width, int height) int x = 0; int y = 0; - int starWidth = image.width()/3; - int starHeight = image.height()/3; + const int starWidth = image.width()/3; + const int starHeight = image.height()/3; QRect rect(x, y, starWidth, starHeight); diff --git a/examples/corelib/threads/queuedcustomtype/renderthread.cpp b/examples/corelib/threads/queuedcustomtype/renderthread.cpp index deb518e2b1..5a65f4ca76 100644 --- a/examples/corelib/threads/queuedcustomtype/renderthread.cpp +++ b/examples/corelib/threads/queuedcustomtype/renderthread.cpp @@ -35,21 +35,21 @@ void RenderThread::processImage(const QImage &image) void RenderThread::run() { - int size = qMax(m_image.width()/20, m_image.height()/20); + const int size = qMax(m_image.width()/20, m_image.height()/20); for (int s = size; s > 0; --s) { for (int c = 0; c < 400; ++c) { //![processing the image (start)] - int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2); - int x2 = qMin(x1 + s/2 + 1, m_image.width()); - int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2); - int y2 = qMin(y1 + s/2 + 1, m_image.height()); + const int x1 = qMax(0, QRandomGenerator::global()->bounded(m_image.width()) - s/2); + const int x2 = qMin(x1 + s/2 + 1, m_image.width()); + const int y1 = qMax(0, QRandomGenerator::global()->bounded(m_image.height()) - s/2); + const int y2 = qMin(y1 + s/2 + 1, m_image.height()); int n = 0; int red = 0; int green = 0; int blue = 0; for (int i = y1; i < y2; ++i) { for (int j = x1; j < x2; ++j) { - QRgb pixel = m_image.pixel(j, i); + const QRgb pixel = m_image.pixel(j, i); red += qRed(pixel); green += qGreen(pixel); blue += qBlue(pixel); @@ -57,7 +57,7 @@ void RenderThread::run() } } //![processing the image (finish)] - Block block(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1), + const Block block(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1), QColor(red/n, green/n, blue/n)); emit sendBlock(block); if (m_abort) diff --git a/examples/corelib/threads/queuedcustomtype/window.cpp b/examples/corelib/threads/queuedcustomtype/window.cpp index a91b2e6b8d..9a56007b40 100644 --- a/examples/corelib/threads/queuedcustomtype/window.cpp +++ b/examples/corelib/threads/queuedcustomtype/window.cpp @@ -60,13 +60,13 @@ void Window::loadImage() if (format.toLower() == format) formats.append(QLatin1String("*.") + QString::fromLatin1(format)); - QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"), + const QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"), path, tr("Image files (%1)").arg(formats.join(' '))); if (newPath.isEmpty()) return; - QImage image(newPath); + const QImage image(newPath); if (!image.isNull()) { loadImage(image); path = newPath; @@ -76,7 +76,7 @@ void Window::loadImage() void Window::loadImage(const QImage &image) { QImage useImage; - QRect space = QGuiApplication::primaryScreen()->availableGeometry(); + const QRect space = QGuiApplication::primaryScreen()->availableGeometry(); if (image.width() > 0.75*space.width() || image.height() > 0.75*space.height()) useImage = image.scaled(0.75*space.width(), 0.75*space.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); |