Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_async_action_feedback.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QtConcurrent>
10#include <QProgressDialog>
11
12
14{
15 QScopedPointer<QProgressDialog> progress;
16};
17
18KisAsyncActionFeedback::KisAsyncActionFeedback(const QString &message, QWidget *parent)
19 : m_d(new Private)
20{
21 m_d->progress.reset(new QProgressDialog(message, "", 0, 0, parent));
22 m_d->progress->setWindowModality(Qt::ApplicationModal);
23 m_d->progress->setCancelButton(0);
24 m_d->progress->setMinimumDuration(1000);
25 m_d->progress->setValue(0);
26
27 // disable close button
28 m_d->progress->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
29}
30
34
35template <typename T>
36T runActionImpl(std::function<T()> func)
37{
38 QFuture<T> result = QtConcurrent::run(func);
39 QFutureWatcher<T> watcher;
40 watcher.setFuture(result);
41
42 while (watcher.isRunning()) {
43 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
44 }
45
46 watcher.waitForFinished();
47 return watcher.result();
48}
49
54
55void KisAsyncActionFeedback::runVoidAction(std::function<void()> func)
56{
57 QFuture<void> result = QtConcurrent::run(func);
58 QFutureWatcher<void> watcher;
59 watcher.setFuture(result);
60
61 while (watcher.isRunning()) {
62 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
63 }
64
65 watcher.waitForFinished();
66}
67
68void KisAsyncActionFeedback::waitForMutexLikeImpl(std::unique_ptr<MutexLikeBase> &&mutex)
69{
70 while (!mutex->try_lock()) {
71 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
72 }
73
74 mutex->unlock();
75}
76
78{
79 return i18nc("progress dialog message when the user has to wait for the image to become unlocked", "Waiting for the action to complete...");
80}
const QScopedPointer< Private > m_d
KisImportExportErrorCode runAction(std::function< KisImportExportErrorCode()> func)
KisAsyncActionFeedback(const QString &message, QWidget *parent)
void runVoidAction(std::function< void()> func)
void waitForMutexLikeImpl(std::unique_ptr< MutexLikeBase > &&mutex)
T runActionImpl(std::function< T()> func)
static QMutex mutex
QScopedPointer< QProgressDialog > progress