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
7
#include "
kis_async_action_feedback.h
"
8
9
#include <QApplication>
10
#include <QEventLoop>
11
#include <QFutureWatcher>
12
#include <QtConcurrentRun>
13
#include <QProgressDialog>
14
15
16
struct
KisAsyncActionFeedback::Private
17
{
18
QScopedPointer<QProgressDialog>
progress
;
19
};
20
21
KisAsyncActionFeedback::KisAsyncActionFeedback
(
const
QString &message, QWidget *parent)
22
: m_d(new
Private
)
23
{
24
m_d
->progress.reset(
new
QProgressDialog(message,
""
, 0, 0, parent));
25
m_d
->progress->setWindowModality(Qt::ApplicationModal);
26
m_d
->progress->setCancelButton(0);
27
m_d
->progress->setMinimumDuration(1000);
28
m_d
->progress->setValue(0);
29
30
// disable close button
31
m_d
->progress->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
32
}
33
34
KisAsyncActionFeedback::~KisAsyncActionFeedback
()
35
{
36
}
37
38
template
<
typename
T>
39
T
runActionImpl
(std::function<T()> func)
40
{
41
QFuture<T>
result = QtConcurrent::run(func);
42
QFutureWatcher<T> watcher;
43
watcher.setFuture(result);
44
45
while
(watcher.isRunning()) {
46
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
47
}
48
49
watcher.waitForFinished();
50
return
watcher.result();
51
}
52
53
KisImportExportErrorCode
KisAsyncActionFeedback::runAction
(std::function<
KisImportExportErrorCode
()> func)
54
{
55
return
runActionImpl
(func);
56
}
57
58
void
KisAsyncActionFeedback::runVoidAction
(std::function<
void
()> func)
59
{
60
QFuture<void>
result = QtConcurrent::run(func);
61
QFutureWatcher<void> watcher;
62
watcher.setFuture(result);
63
64
while
(watcher.isRunning()) {
65
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
66
}
67
68
watcher.waitForFinished();
69
}
70
71
void
KisAsyncActionFeedback::waitForMutexLikeImpl
(std::unique_ptr<MutexLikeBase> &&
mutex
)
72
{
73
while
(!
mutex
->try_lock()) {
74
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
75
}
76
77
mutex
->unlock();
78
}
79
80
QString
KisAsyncActionFeedback::DefaultWaitingMessageCallback::operator()
()
const
81
{
82
return
i18nc(
"progress dialog message when the user has to wait for the image to become unlocked"
,
"Waiting for the action to complete..."
);
83
}
KisAsyncActionFeedback::m_d
const QScopedPointer< Private > m_d
Definition
kis_async_action_feedback.h:94
KisAsyncActionFeedback::runAction
KisImportExportErrorCode runAction(std::function< KisImportExportErrorCode()> func)
Definition
kis_async_action_feedback.cpp:53
KisAsyncActionFeedback::~KisAsyncActionFeedback
~KisAsyncActionFeedback()
Definition
kis_async_action_feedback.cpp:34
KisAsyncActionFeedback::KisAsyncActionFeedback
KisAsyncActionFeedback(const QString &message, QWidget *parent)
Definition
kis_async_action_feedback.cpp:21
KisAsyncActionFeedback::runVoidAction
void runVoidAction(std::function< void()> func)
Definition
kis_async_action_feedback.cpp:58
KisAsyncActionFeedback::waitForMutexLikeImpl
void waitForMutexLikeImpl(std::unique_ptr< MutexLikeBase > &&mutex)
Definition
kis_async_action_feedback.cpp:71
KisImportExportErrorCode
Definition
KisImportExportErrorCode.h:110
QFuture
Definition
KisImportExportManager.h:23
runActionImpl
T runActionImpl(std::function< T()> func)
Definition
kis_async_action_feedback.cpp:39
kis_async_action_feedback.h
mutex
static QMutex mutex
Definition
kis_extended_modifiers_mapper_osx.mm:37
Private
Definition
SvgTransformParser.cpp:20
KisAsyncActionFeedback::DefaultWaitingMessageCallback::operator()
QString operator()() const
Definition
kis_async_action_feedback.cpp:80
KisAsyncActionFeedback::Private
Definition
kis_async_action_feedback.cpp:17
KisAsyncActionFeedback::Private::progress
QScopedPointer< QProgressDialog > progress
Definition
kis_async_action_feedback.cpp:18
libs
ui
kis_async_action_feedback.cpp
Generated at
2026-07-16 02:30:11+02:00
from
Krita
branch
master
, commit
a788c87613f94f0657ee6a3d88f6745bc44af899