QtBase  v6.3.1
src_concurrent_qtconcurrentmap.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
52 U function(const T &t);
54 
55 
58 {
59  return image.scaled(100, 100);
60 }
61 
65 
66 
68 U function(T &t);
70 
71 
74 {
75  image = image.scaled(100, 100);
76 }
77 
78 QList<QImage> images = ...;
81 
82 
84 V function(T &result, const U &intermediate)
86 
87 
90 {
91  QPainter p(&collage);
92  static QPoint offset = QPoint(0, 0);
93  p.drawImage(offset, thumbnail);
94  offset += ...;
95 }
96 
97 QList<QImage> images = ...;
100 
101 
103 QList<QImage> images = ...;
104 
106 
107 // Map in-place only works on non-const iterators.
109 
112 
113 
115 QList<QImage> images = ...;
116 
117 // Each call blocks until the entire operation is finished.
119 
121 
124 
125 
127 // Squeeze all strings in a QStringList.
130 
131 // Swap the rgb values of all pixels on a list of images.
132 QList<QImage> images = ...;
134  static_cast<QImage (QImage::*)() const &>(&QImage::rgbSwapped));
135 
136 // Create a set of the lengths of all strings in a list.
137 QStringList strings = ...;
139  qOverload<const int&>(&QSet<int>::insert));
141 
142 
144 // Can mix normal functions and member functions with QtConcurrent::mappedReduced().
145 
146 // Compute the average length of a list of strings.
147 extern void computeAverage(int &average, int length);
148 QStringList strings = ...;
150 
151 // Create a set of the color distribution of all images in a list.
152 extern int colorDistribution(const QImage &string);
153 QList<QImage> images = ...;
155  qOverload<const int&>(&QSet<int>::insert));
157 
158 
162 
165 {
167 };
168 
173 
175 QList<QImage> images = ...;
176 std::function<QImage(const QImage &)> scale = [](const QImage &img) {
178 };
181 
183 struct Scaled
184 {
186  : m_size(size) { }
187 
189 
191  {
192  return image.scaled(m_size, m_size);
193  }
194 
195  int m_size;
196 };
197 
198 QList<QImage> images = ...;
201 
203 QList<int> vector { 1, 2, 3, 4 };
204 QtConcurrent::blockingMap(vector, [](int &x) { x *= 2; });
205 
206 int size = 100;
207 QList<QImage> images = ...;
208 
210  [&size](const QImage &image) {
211  return image.scaled(size, size);
212  }
213  ).results();
215 
218  [&size](const QImage &image) {
219  return image.scaled(size, size);
220  },
222  ).results();
224 
227  [&size](const QImage &image) {
228  return image.scaled(size, size);
229  },
230  [](QImage &result, const QImage &value) {
231  // do some transformation
232  }
233  ).results();
#define value
[5]
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:73
QImage scaledToWidth(int w, Qt::TransformationMode mode=Qt::FastTransformation) const
[9]
Definition: qimage.cpp:3005
QImage rgbSwapped() const &
Definition: qimage.h:258
iterator end()
Definition: qlist.h:624
const_iterator constBegin() const noexcept
Definition: qlist.h:630
iterator begin()
Definition: qlist.h:623
const_iterator constEnd() const noexcept
Definition: qlist.h:631
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
Definition: qset.h:54
void squeeze()
Definition: qstring.h:1315
qsizetype length() const
Definition: qstring.h:415
The QStringList class provides a list of strings.
auto V(a, v))) struct
Definition: hb-algs.hh:317
void blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor map)
QFuture< void > map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< QtPrivate::MapResultType< Sequence, MapFunctor > > mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map)
QFuture< ResultType > mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
ResultType blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&map, ReduceFunctor &&reduce, ReduceOptions options=ReduceOptions(UnorderedReduce|SequentialReduce))
OutputSequence blockingMapped(QThreadPool *pool, InputSequence &&sequence, MapFunctor &&map)
TransformationMode
Definition: qnamespace.h:1349
@ SmoothTransformation
Definition: qnamespace.h:1351
Definition: image.cpp:51
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar ** strings
[1]
GLint GLsizei width
GLenum GLuint GLintptr offset
GLint void * img
Definition: qopenglext.h:233
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
GLenum GLenum GLenum GLenum GLenum scale
Definition: qopenglext.h:10817
QList< int > results
void addToCollage(QImage &collage, const QImage &grayscaleImage)
QFuture< int > averageWordLength
QList< int > vector
[14]
QList< QImage > images
[5]
QFuture< void > future
QFuture< QImage > bgrImages
void computeAverage(int &average, int length)
[8]
std::function< QImage(const QImage &)> scale
V const QImage & thumbnail
U function(const T &t)
[0]
QFuture< QSet< int > > wordLengths
QFuture< QSet< int > > totalColorDistribution
QImage scaled(const QImage &image)
[0]
int colorDistribution(const QImage &string)
QFuture< void > squeezedStrings
QFuture< QImage > collage
[15]
QFuture< QImage > thumbnails
QFuture< QImage > thumbNails
void operator()(QImage &result, const QImage &value)
QImage operator()(const QImage &image)
Definition: main.cpp:38