Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSynchronizedConnection.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QThread>
10#include <QCoreApplication>
11#include <kis_assert.h>
12
18{
20 eventType = QEvent::registerEventType(QEvent::User + 1000);
21 }
22
23 int eventType = -1;
25};
26
28{
29 std::function<void()> callback;
30};
31
34
35
36/************************************************************************/
37/* KisSynchronizedConnectionEvent */
38/************************************************************************/
39
41 : QEvent(QEvent::Type(s_instance->eventType)),
42 destination(_destination)
43{
44}
45
47 : QEvent(QEvent::Type(s_instance->eventType)),
48 destination(rhs.destination)
49{
50}
51
55
56/************************************************************************/
57/* KisSynchronizedConnectionBase */
58/************************************************************************/
59
61{
62 return s_instance->eventType;
63}
64
66{
67 KIS_SAFE_ASSERT_RECOVER_NOOP(!s_barrier->callback);
68 s_barrier->callback = callback;
69}
70
72{
73 s_instance->enableAutoModeForUnittests = value;
74}
75
77{
78 return s_instance->enableAutoModeForUnittests;
79}
80
82{
89 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
90 KIS_SAFE_ASSERT_RECOVER_RETURN(s_barrier->callback);
91 s_barrier->callback();
92}
93
95{
96 if (event->type() == s_instance->eventType) {
99
100 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(typedEvent->destination == this, false);
102 return true;
103 }
104
105 return QObject::event(event);
106}
107
109{
110 if (s_instance->enableAutoModeForUnittests && QThread::currentThread() == this->thread()) {
112
116
117 if (s_barrier->callback) {
118 s_barrier->callback();
119 }
120
122 } else {
123 qApp->postEvent(this, new KisSynchronizedConnectionEvent(this));
124 }
125}
126
float value(const T *src, size_t ch)
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
static void registerSynchronizedEventBarrier(std::function< void()> callback)
virtual void deliverEventToReceiver()=0
static void setAutoModeForUnittestsEnabled(bool value)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
The KisSynchronizedConnectionEventTypeRegistrar is a simple class to register QEvent type in the Qt's...
Event type used for synchronizing connection in KisSynchronizedConnection.
KisSynchronizedConnectionEvent(QObject *_destination)