Krita Source Code Documentation
Loading...
Searching...
No Matches
BatchMoveUpdateData Class Reference

Classes

struct  NewParentCollisionPolicy
 
struct  OldParentCollisionPolicy
 

Public Member Functions

void addInitialUpdate (MoveNodeStructSP moveStruct)
 
 BatchMoveUpdateData (KisNodeJugglerCompressed *parentJuggler)
 
void emitFinalUpdates (KisCommandUtils::FlipFlopCommand::State state)
 
void processUnhandledUpdates ()
 

Static Private Member Functions

static void addToHashLazy (MovedNodesHash *hash, MoveNodeStructSP moveStruct)
 
static void resolveParentCollisions (MovedNodesHash *hash)
 
template<typename CollisionPolicy >
static void resolveParentCollisionsImpl (MovedNodesHash *hash)
 

Private Attributes

MovedNodesHash m_movedNodesInitial
 
MovedNodesHash m_movedNodesUpdated
 
QMutex m_mutex
 
QPointer< KisNodeJugglerCompressedm_parentJuggler
 

Detailed Description

All the commands executed by the stroke system are running in the background asynchronously. But, at the same time, they Q_EMIT updates in parallel to the ones emitted by the juggler. Therefore, the juggler and all its commands should share some data: which updates have been requested, but not yet dispatched (m_movedNodesInitial), and what updates have already been processed and executed (m_movedNodesUpdated). This object is shared via a shared pointer and guarantees safe (including thread-safe) access to the shared data.

Definition at line 120 of file kis_node_juggler_compressed.cpp.

Constructor & Destructor Documentation

◆ BatchMoveUpdateData()

BatchMoveUpdateData::BatchMoveUpdateData ( KisNodeJugglerCompressed * parentJuggler)
inline

Definition at line 129 of file kis_node_juggler_compressed.cpp.

130 : m_parentJuggler(parentJuggler) {}
QPointer< KisNodeJugglerCompressed > m_parentJuggler

Member Function Documentation

◆ addInitialUpdate()

void BatchMoveUpdateData::addInitialUpdate ( MoveNodeStructSP moveStruct)
inline

Definition at line 206 of file kis_node_juggler_compressed.cpp.

206 {
207 {
208 QMutexLocker l(&m_mutex);
211
212 // the juggler might directly forward the signal to processUnhandledUpdates,
213 // which would also like to get a lock, so we should release it beforehand
214 }
215 if (m_parentJuggler) {
216 Q_EMIT m_parentJuggler->requestUpdateAsyncFromCommand();
217 }
218 }
static void addToHashLazy(MovedNodesHash *hash, MoveNodeStructSP moveStruct)
static void resolveParentCollisions(MovedNodesHash *hash)

References addToHashLazy(), m_movedNodesInitial, m_mutex, m_parentJuggler, and resolveParentCollisions().

◆ addToHashLazy()

static void BatchMoveUpdateData::addToHashLazy ( MovedNodesHash * hash,
MoveNodeStructSP moveStruct )
inlinestaticprivate

Definition at line 177 of file kis_node_juggler_compressed.cpp.

177 {
178 if (hash->contains(moveStruct->node)) {
179 bool result = hash->value(moveStruct->node)->tryMerge(*moveStruct);
181 } else {
182 hash->insert(moveStruct->node, moveStruct);
183 }
184 }
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References KIS_ASSERT_RECOVER_NOOP.

◆ emitFinalUpdates()

void BatchMoveUpdateData::emitFinalUpdates ( KisCommandUtils::FlipFlopCommand::State state)
inline

Definition at line 220 of file kis_node_juggler_compressed.cpp.

220 {
221 QMutexLocker l(&m_mutex);
222
223 if (m_movedNodesUpdated.isEmpty()) return;
224
225 MovedNodesHash::const_iterator it = m_movedNodesUpdated.constBegin();
226 MovedNodesHash::const_iterator end = m_movedNodesUpdated.constEnd();
227
228 for (; it != end; ++it) {
230 it.value()->doRedoUpdates();
231 } else {
232 it.value()->doUndoUpdates();
233 }
234 }
235 }

References KisCommandUtils::FlipFlopCommand::FINALIZING, m_movedNodesUpdated, and m_mutex.

◆ processUnhandledUpdates()

void BatchMoveUpdateData::processUnhandledUpdates ( )
inline

Definition at line 188 of file kis_node_juggler_compressed.cpp.

188 {
189 QMutexLocker l(&m_mutex);
190
191 if (m_movedNodesInitial.isEmpty()) return;
192
193 MovedNodesHash::const_iterator it = m_movedNodesInitial.constBegin();
194 MovedNodesHash::const_iterator end = m_movedNodesInitial.constEnd();
195
196 for (; it != end; ++it) {
197 it.value()->doRedoUpdates();
199 }
200
202
203 m_movedNodesInitial.clear();
204 }

References addToHashLazy(), m_movedNodesInitial, m_movedNodesUpdated, m_mutex, and resolveParentCollisions().

◆ resolveParentCollisions()

static void BatchMoveUpdateData::resolveParentCollisions ( MovedNodesHash * hash)
inlinestaticprivate

Definition at line 172 of file kis_node_juggler_compressed.cpp.

172 {
173 resolveParentCollisionsImpl<NewParentCollisionPolicy>(hash);
174 resolveParentCollisionsImpl<OldParentCollisionPolicy>(hash);
175 }

◆ resolveParentCollisionsImpl()

template<typename CollisionPolicy >
static void BatchMoveUpdateData::resolveParentCollisionsImpl ( MovedNodesHash * hash)
inlinestaticprivate

Definition at line 153 of file kis_node_juggler_compressed.cpp.

153 {
155 std::copy(hash->begin(), hash->end(), std::back_inserter(updates));
156 std::sort(updates.begin(), updates.end(), CollisionPolicy::compare);
157
158 auto rangeBegin = updates.begin();
159
160 while (rangeBegin != updates.end()) {
161 auto rangeEnd = std::upper_bound(rangeBegin, updates.end(), *rangeBegin, CollisionPolicy::compare);
162
163 for (auto it = rangeBegin; it != std::prev(rangeEnd); ++it) {
164 CollisionPolicy::setSuppressRefresh(*it, true);
165 }
166 CollisionPolicy::setSuppressRefresh(*std::prev(rangeEnd), false);
167
168 rangeBegin = rangeEnd;
169 }
170 }

Member Data Documentation

◆ m_movedNodesInitial

MovedNodesHash BatchMoveUpdateData::m_movedNodesInitial
private

Definition at line 121 of file kis_node_juggler_compressed.cpp.

◆ m_movedNodesUpdated

MovedNodesHash BatchMoveUpdateData::m_movedNodesUpdated
private

Definition at line 122 of file kis_node_juggler_compressed.cpp.

◆ m_mutex

QMutex BatchMoveUpdateData::m_mutex
private

Definition at line 124 of file kis_node_juggler_compressed.cpp.

◆ m_parentJuggler

QPointer<KisNodeJugglerCompressed> BatchMoveUpdateData::m_parentJuggler
private

Definition at line 126 of file kis_node_juggler_compressed.cpp.


The documentation for this class was generated from the following file: