summaryrefslogtreecommitdiffstats
path: root/examples/qtconcurrent/imagescaling/imagescaling.cpp
diff options
context:
space:
mode:
authorMichael Winkelmann <michael.winkelmann@qt.io>2017-08-03 15:43:26 +0200
committerTopi Reiniƶ <topi.reinio@qt.io>2017-11-07 09:42:34 +0000
commitab9f4d5db6a4e183b9a26366e659ba642dedcbdd (patch)
tree2661ab6baacd6ec545449619a749d8a9f4e43c54 /examples/qtconcurrent/imagescaling/imagescaling.cpp
parentd4b3ce9a287b81eb9d7c6750ccca89e362343261 (diff)
Revamp QtConcurrent examples to C++11
I updated signals and slots and for each loops to the new syntax and replaced most free functions with std::function. Task-number: QTBUG-60641 Change-Id: I7693f81f71c7f53fcbe83189a0de2fb76ddf99a8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'examples/qtconcurrent/imagescaling/imagescaling.cpp')
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/examples/qtconcurrent/imagescaling/imagescaling.cpp b/examples/qtconcurrent/imagescaling/imagescaling.cpp
index 0a230c1194..6d22bb9598 100644
--- a/examples/qtconcurrent/imagescaling/imagescaling.cpp
+++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp
@@ -48,15 +48,10 @@
**
****************************************************************************/
#include "imagescaling.h"
-#include <qmath.h>
-const int imageSize = 100;
+#include <qmath.h>
-QImage scale(const QString &imageFileName)
-{
- QImage image(imageFileName);
- return image.scaled(QSize(imageSize, imageSize), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-}
+#include <functional>
Images::Images(QWidget *parent)
: QWidget(parent)
@@ -65,19 +60,19 @@ Images::Images(QWidget *parent)
resize(800, 600);
imageScaling = new QFutureWatcher<QImage>(this);
- connect(imageScaling, SIGNAL(resultReadyAt(int)), SLOT(showImage(int)));
- connect(imageScaling, SIGNAL(finished()), SLOT(finished()));
+ connect(imageScaling, &QFutureWatcher<QImage>::resultReadyAt, this, &Images::showImage);
+ connect(imageScaling, &QFutureWatcher<QImage>::finished, this, &Images::finished);
openButton = new QPushButton(tr("Open Images"));
- connect(openButton, SIGNAL(clicked()), SLOT(open()));
+ connect(openButton, &QPushButton::clicked, this, &Images::open);
cancelButton = new QPushButton(tr("Cancel"));
cancelButton->setEnabled(false);
- connect(cancelButton, SIGNAL(clicked()), imageScaling, SLOT(cancel()));
+ connect(cancelButton, &QPushButton::clicked, imageScaling, &QFutureWatcher<QImage>::cancel);
pauseButton = new QPushButton(tr("Pause/Resume"));
pauseButton->setEnabled(false);
- connect(pauseButton, SIGNAL(clicked()), imageScaling, SLOT(togglePaused()));
+ connect(pauseButton, &QPushButton::clicked, imageScaling, &QFutureWatcher<QImage>::togglePaused);
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addWidget(openButton);
@@ -113,9 +108,11 @@ void Images::open()
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation),
"*.jpg *.png");
- if (files.count() == 0)
+ if (files.isEmpty())
return;
+ const int imageSize = 100;
+
// Do a simple layout.
qDeleteAll(labels);
labels.clear();
@@ -130,6 +127,11 @@ void Images::open()
}
}
+ std::function<QImage(const QString&)> scale = [imageSize](const QString &imageFileName) {
+ QImage image(imageFileName);
+ return image.scaled(QSize(imageSize, imageSize), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ };
+
// Use mapped to run the thread safe scale function on the files.
imageScaling->setFuture(QtConcurrent::mapped(files, scale));