TaskTree: Reuse Repeat element in DataExchange example

Update the location of the target url so that it points to the
TaskTree wiki image.

Task-number: QTCREATORBUG-30081
Change-Id: Ic1c715c268b9e14711bc98415e747de8b75ed2dc
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-10 01:04:30 +01:00
parent ff46a9a8ef
commit bc2faebe02
2 changed files with 14 additions and 18 deletions

View File

@@ -34,6 +34,7 @@ static int sizeForIndex(int index) { return (index + 1) * s_sizeInterval; }
Group recipe(const Storage<ExternalData> &externalStorage)
{
Storage<InternalData> internalStorage;
Repeat repeater(s_imageCount);
const auto onDownloadSetup = [externalStorage](NetworkQuery &query) {
query.setNetworkAccessManager(externalStorage->inputNam);
@@ -60,27 +61,24 @@ Group recipe(const Storage<ExternalData> &externalStorage)
externalStorage->outputError = "Image Data Error.";
};
QList<GroupItem> parallelTasks;
parallelTasks.reserve(s_imageCount + 1); // +1 for parallelLimit
parallelTasks.append(parallelLimit(QThread::idealThreadCount() - 1));
for (int i = 0; i < s_imageCount; ++i) {
const int s = sizeForIndex(i);
const auto onScaleSetup = [internalStorage, s](ConcurrentCall<QImage> &data) {
data.setConcurrentCallData(&scaleImage, internalStorage->imageSource, QSize(s, s));
};
const auto onScaleDone = [externalStorage, s](const ConcurrentCall<QImage> &data) {
externalStorage->outputImages.insert(s, data.result());
};
parallelTasks.append(ConcurrentCallTask<QImage>(onScaleSetup, onScaleDone));
}
const auto onScaleSetup = [internalStorage, repeater](ConcurrentCall<QImage> &data) {
const int s = sizeForIndex(repeater.iteration());
data.setConcurrentCallData(&scaleImage, internalStorage->imageSource, QSize(s, s));
};
const auto onScaleDone = [externalStorage, repeater](const ConcurrentCall<QImage> &data) {
externalStorage->outputImages.insert(repeater.iteration(), data.result());
};
const QList<GroupItem> recipe {
externalStorage,
internalStorage,
NetworkQueryTask(onDownloadSetup, onDownloadDone),
ConcurrentCallTask<QImage>(onReadSetup, onReadDone),
Group { parallelTasks }
Group {
repeater,
parallelLimit(QThread::idealThreadCount() - 1),
ConcurrentCallTask<QImage>(onScaleSetup, onScaleDone)
}
};
return recipe;
}

View File

@@ -16,9 +16,7 @@ Viewer::Viewer(QWidget *parent)
setWindowTitle(tr("Data Exchange"));
QLabel *urlLabel = new QLabel(tr("Url:"));
m_lineEdit = new QLineEdit("https://media.licdn.com/dms/image/D4D22AQFj3ksh5rmnrg/"
"feedshare-shrink_800/0/1697023188446?e=1701302400&v=beta"
"&t=6dy5dmhzgONaLu139A6XmFSGqDohiezq1fH-q2mmu3w");
m_lineEdit = new QLineEdit("https://qt-wiki-uploads.s3.amazonaws.com/images/f/fd/TaskTree.jpg");
QPushButton *startButton = new QPushButton(tr("Start"));
QPushButton *stopButton = new QPushButton(tr("Stop"));
QPushButton *resetButton = new QPushButton(tr("Reset"));