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

#include <kis_processing_applicator.h>

Public Types

enum  ProcessingFlag {
  NONE = 0x0 , RECURSIVE = 0x1 , NO_UI_UPDATES = 0x2 , SUPPORTS_WRAPAROUND_MODE = 0x4 ,
  NO_IMAGE_UPDATES = 0x8 , RECURSIVE_FRAME_TIMES = 0x10 , READ_ONLY_ACTION = 0x20
}
 

Public Member Functions

void applyCommand (KUndo2Command *command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
 
void applyVisitor (KisProcessingVisitorSP visitor, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
 
void applyVisitorAllFrames (KisProcessingVisitorSP visitor, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
 
void cancel ()
 
void end ()
 
void explicitlyEmitFinalSignals ()
 
const KisStrokeId getStroke () const
 
 KisProcessingApplicator (KisImageWSP image, KisNodeList nodes=KisNodeList(), ProcessingFlags flags=NONE, KisImageSignalVector emitSignals=KisImageSignalVector(), const KUndo2MagicString &name=KUndo2MagicString(), KUndo2CommandExtraData *extraData=0, int macroId=-1)
 
 KisProcessingApplicator (KisImageWSP image, KisNodeSP node, ProcessingFlags flags=NONE, KisImageSignalVector emitSignals=KisImageSignalVector(), const KUndo2MagicString &name=KUndo2MagicString(), KUndo2CommandExtraData *extraData=0, int macroId=-1)
 
std::future< bool > && successfullyCompletedFuture ()
 
 ~KisProcessingApplicator ()
 

Static Public Member Functions

static void runSingleCommandStroke (KisImageSP image, KUndo2Command *cmd, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
 runSingleCommandStroke creates a stroke and runs cmd in it. The text() field of cmd is used as a title of the stroke.
 

Private Member Functions

void visitRecursively (KisNodeSP node, KisProcessingVisitorSP visitor, KisStrokeJobData::Sequentiality sequentiality, KisStrokeJobData::Exclusivity exclusivity)
 

Private Attributes

KisImageSignalVector m_emitSignals
 
bool m_finalSignalsEmitted
 
ProcessingFlags m_flags
 
KisImageWSP m_image
 
KisNodeList m_nodes
 
QSharedPointer< bool > m_sharedAllFramesToken
 
KisStrokeId m_strokeId
 
std::future< bool > m_successfullyCompletedFuture
 

Detailed Description

Definition at line 21 of file kis_processing_applicator.h.

Member Enumeration Documentation

◆ ProcessingFlag

Enumerator
NONE 
RECURSIVE 
NO_UI_UPDATES 
SUPPORTS_WRAPAROUND_MODE 
NO_IMAGE_UPDATES 
RECURSIVE_FRAME_TIMES 

you might want to have the frame times be recursive, useful for group layers.

When there's a non-recursive applicator on all frames,

READ_ONLY_ACTION 

Do not save undo commands into the global undo stack after the action has been completed. Also, do not emit any updates and do not invalidate any frames.

Definition at line 24 of file kis_processing_applicator.h.

Constructor & Destructor Documentation

◆ KisProcessingApplicator() [1/2]

KisProcessingApplicator::KisProcessingApplicator ( KisImageWSP image,
KisNodeSP node,
ProcessingFlags flags = NONE,
KisImageSignalVector emitSignals = KisImageSignalVector(),
const KUndo2MagicString & name = KUndo2MagicString(),
KUndo2CommandExtraData * extraData = 0,
int macroId = -1 )

Definition at line 262 of file kis_processing_applicator.cpp.

269 : KisProcessingApplicator(image, node ? KisNodeList { node } : KisNodeList(), flags, emitSignals, name, extraData, macroId )
270{
271
272}
KisProcessingApplicator(KisImageWSP image, KisNodeSP node, ProcessingFlags flags=NONE, KisImageSignalVector emitSignals=KisImageSignalVector(), const KUndo2MagicString &name=KUndo2MagicString(), KUndo2CommandExtraData *extraData=0, int macroId=-1)
QList< KisNodeSP > KisNodeList
Definition kis_types.h:264
const char * name(StandardAction id)

◆ KisProcessingApplicator() [2/2]

KisProcessingApplicator::KisProcessingApplicator ( KisImageWSP image,
KisNodeList nodes = KisNodeList(),
ProcessingFlags flags = NONE,
KisImageSignalVector emitSignals = KisImageSignalVector(),
const KUndo2MagicString & name = KUndo2MagicString(),
KUndo2CommandExtraData * extraData = 0,
int macroId = -1 )

Definition at line 273 of file kis_processing_applicator.cpp.

280 : m_image(image),
281 m_nodes(nodes),
282 m_flags(flags),
283 m_emitSignals(emitSignals),
285 m_sharedAllFramesToken(new bool(false))
286{
287 StrategyWithStatusPromise *strategy =
288 new StrategyWithStatusPromise(name, !flags.testFlag(READ_ONLY_ACTION) ? m_image.data() : nullptr);
289
291
292 if (m_flags.testFlag(SUPPORTS_WRAPAROUND_MODE)) {
293 strategy->setSupportsWrapAroundMode(true);
294 }
295
296 if (extraData) {
297 strategy->setCommandExtraData(extraData);
298 }
299
300 strategy->setMacroId(macroId);
301
302 m_strokeId = m_image->startStroke(strategy);
303 if(!m_emitSignals.isEmpty()) {
305 }
306
307 if(m_flags.testFlag(NO_UI_UPDATES)) {
309 }
310
311 if (!m_nodes.isEmpty() && !m_flags.testFlag(READ_ONLY_ACTION)) {
315 }
316}
KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy) override
QSharedPointer< bool > m_sharedAllFramesToken
void applyCommand(KUndo2Command *command, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
std::future< bool > m_successfullyCompletedFuture

References applyCommand(), KisStrokeJobData::BARRIER, KisWeakSharedPtr< T >::data(), KisCommandUtils::FlipFlopCommand::INITIALIZING, m_emitSignals, m_flags, m_image, m_nodes, m_sharedAllFramesToken, m_strokeId, StrategyWithStatusPromise::m_successfullyCompleted, m_successfullyCompletedFuture, NO_UI_UPDATES, READ_ONLY_ACTION, KisStrokeStrategyUndoCommandBased::setCommandExtraData(), KisStrokeStrategyUndoCommandBased::setMacroId(), KisStrokeStrategyUndoCommandBased::setSupportsWrapAroundMode(), KisImage::startStroke(), and SUPPORTS_WRAPAROUND_MODE.

◆ ~KisProcessingApplicator()

KisProcessingApplicator::~KisProcessingApplicator ( )

Definition at line 318 of file kis_processing_applicator.cpp.

319{
320}

Member Function Documentation

◆ applyCommand()

void KisProcessingApplicator::applyCommand ( KUndo2Command * command,
KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL )

Definition at line 430 of file kis_processing_applicator.cpp.

433{
434 /*
435 * One should not add commands after the final signals have been
436 * emitted, only end or cancel the stroke
437 */
439
442 false,
443 sequentiality,
444 exclusivity));
445}
void addJob(KisStrokeId id, KisStrokeJobData *data) override
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
QSharedPointer< KUndo2Command > KUndo2CommandSP
Definition kis_types.h:262

References KisImage::addJob(), KIS_ASSERT_RECOVER_RETURN, m_finalSignalsEmitted, m_image, and m_strokeId.

◆ applyVisitor()

Definition at line 333 of file kis_processing_applicator.cpp.

336{
337 KUndo2Command *initCommand = visitor->createInitCommand();
338 if (initCommand) {
339 applyCommand(initCommand,
341 }
342
343 if (!m_nodes.isEmpty()) {
344 Q_FOREACH(KisNodeSP node, m_nodes) {
345 if(!m_flags.testFlag(RECURSIVE)) {
346 applyCommand(new KisProcessingCommand(visitor, node),
347 sequentiality, exclusivity);
348 }
349 else {
350 visitRecursively(node, visitor, sequentiality, exclusivity);
351 }
352 }
353 }
354}
void visitRecursively(KisNodeSP node, KisProcessingVisitorSP visitor, KisStrokeJobData::Sequentiality sequentiality, KisStrokeJobData::Exclusivity exclusivity)
virtual KUndo2Command * createInitCommand()

References applyCommand(), KisProcessingVisitor::createInitCommand(), m_flags, m_nodes, KisStrokeJobData::NORMAL, RECURSIVE, KisStrokeJobData::SEQUENTIAL, and visitRecursively().

◆ applyVisitorAllFrames()

void KisProcessingApplicator::applyVisitorAllFrames ( KisProcessingVisitorSP visitor,
KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL )

Definition at line 356 of file kis_processing_applicator.cpp.

359{
361
362 KUndo2Command *initCommand = visitor->createInitCommand();
363 if (initCommand) {
364 applyCommand(initCommand,
366 }
367
369
370 // TODO: implement a nonrecursive case when !m_flags.testFlag(RECURSIVE)
371 // (such case is not yet used anywhere)
372 //KIS_SAFE_ASSERT_RECOVER_NOOP(m_flags.testFlag(RECURSIVE));
373
374 if (!m_nodes.isEmpty()) {
375
376 if (m_flags.testFlag(RECURSIVE)) {
377 Q_FOREACH(KisNodeSP node, m_nodes) {
379 }
380 } else {
381 Q_FOREACH(KisNodeSP node, m_nodes) {
383 }
384 }
385 }
386
387 if (jobs.isEmpty()) {
388 applyVisitor(visitor, sequentiality, exclusivity);
389 return;
390 }
391
392 KisLayerUtils::FrameJobs::const_iterator it = jobs.constBegin();
393 KisLayerUtils::FrameJobs::const_iterator end = jobs.constEnd();
394
397
398 for (; it != end; ++it) {
399 const int frame = it.key();
400 const QSet<KisNodeSP> &nodes = it.value();
401
403
404 foreach (KisNodeSP node, nodes) {
405 applyCommand(new KisProcessingCommand(visitor, node),
406 sequentiality, exclusivity);
407 }
408
410 }
411}
void applyVisitor(KisProcessingVisitorSP visitor, KisStrokeJobData::Sequentiality sequentiality=KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::Exclusivity exclusivity=KisStrokeJobData::NORMAL)
void updateFrameJobsRecursive(FrameJobs *jobs, KisNodeSP rootNode)
QMap< int, QSet< KisNodeSP > > FrameJobs
void updateFrameJobsNonRecursive(FrameJobs *jobs, KisNodeSP rootNode, bool frameTimesRecursive)
updateFrameJobsNonRecursive updates the frame jobs non-recursively, that is, on the rootNode only.
The SwitchFrameCommand struct Switches to frame with undo/redo support.

References applyCommand(), applyVisitor(), KisStrokeJobData::BARRIER, KisProcessingVisitor::createInitCommand(), end(), KisStrokeJobData::EXCLUSIVE, m_flags, m_image, m_nodes, m_sharedAllFramesToken, KisStrokeJobData::NORMAL, RECURSIVE, RECURSIVE_FRAME_TIMES, KisStrokeJobData::SEQUENTIAL, KisLayerUtils::updateFrameJobsNonRecursive(), and KisLayerUtils::updateFrameJobsRecursive().

◆ cancel()

void KisProcessingApplicator::cancel ( )

Definition at line 478 of file kis_processing_applicator.cpp.

479{
481}
bool cancelStroke(KisStrokeId id) override

References KisImage::cancelStroke(), m_image, and m_strokeId.

◆ end()

void KisProcessingApplicator::end ( )

◆ explicitlyEmitFinalSignals()

void KisProcessingApplicator::explicitlyEmitFinalSignals ( )

This method emits all the final update signals of the stroke without actually ending the stroke. This can be used for long-running strokes which are kept open to implement preview of the actions.

WARNING: you cannot add new commands/processings after the final signals has been emitted. You should either call end() or cancel().

Definition at line 447 of file kis_processing_applicator.cpp.

References applyCommand(), KisStrokeJobData::BARRIER, KisCommandUtils::FlipFlopCommand::FINALIZING, KIS_ASSERT_RECOVER_RETURN, m_emitSignals, m_finalSignalsEmitted, m_flags, m_image, m_nodes, m_sharedAllFramesToken, NO_UI_UPDATES, and READ_ONLY_ACTION.

◆ getStroke()

const KisStrokeId KisProcessingApplicator::getStroke ( ) const

Returns the underlying stroke. Useful if you want to inject additional jobs in the applicator.

Definition at line 322 of file kis_processing_applicator.cpp.

323{
324 return m_strokeId;
325}

References m_strokeId.

◆ runSingleCommandStroke()

void KisProcessingApplicator::runSingleCommandStroke ( KisImageSP image,
KUndo2Command * cmd,
KisStrokeJobData::Sequentiality sequentiality = KisStrokeJobData::SEQUENTIAL,
KisStrokeJobData::Exclusivity exclusivity = KisStrokeJobData::NORMAL )
static

runSingleCommandStroke creates a stroke and runs cmd in it. The text() field of cmd is used as a title of the stroke.

Parameters
imagethe image to run the stroke on
cmdthe command to be executed
sequentialitysequentiality property of the command being executed (see strokes documentation)
exclusivitysequentiality property of the command being executed (see strokes documentation)

Definition at line 483 of file kis_processing_applicator.cpp.

484{
485 KisProcessingApplicator applicator(image, 0,
488 cmd->text(),
489 nullptr,
490 cmd->id());
491 applicator.applyCommand(cmd, sequentiality, exclusivity);
492 applicator.end();
493}
QVector< KisImageSignalType > KisImageSignalVector
KUndo2MagicString text() const
virtual int id() const

References applyCommand(), end(), KUndo2Command::id(), NONE, and KUndo2Command::text().

◆ successfullyCompletedFuture()

std::future< bool > && KisProcessingApplicator::successfullyCompletedFuture ( )

A future that notifies the caller when the whole processing stroke has been completed. The returned value shows if the stroke has been completed (true) or cancelled (false).

Definition at line 327 of file kis_processing_applicator.cpp.

328{
330 return std::move(m_successfullyCompletedFuture);
331}
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KIS_ASSERT, and m_successfullyCompletedFuture.

◆ visitRecursively()

void KisProcessingApplicator::visitRecursively ( KisNodeSP node,
KisProcessingVisitorSP visitor,
KisStrokeJobData::Sequentiality sequentiality,
KisStrokeJobData::Exclusivity exclusivity )
private

Definition at line 413 of file kis_processing_applicator.cpp.

417{
418 // simple tail-recursive iteration
419
420 KisNodeSP prevNode = node->lastChild();
421 while(prevNode) {
422 visitRecursively(prevNode, visitor, sequentiality, exclusivity);
423 prevNode = prevNode->prevSibling();
424 }
425
426 applyCommand(new KisProcessingCommand(visitor, node),
427 sequentiality, exclusivity);
428}
KisNodeSP prevSibling() const
Definition kis_node.cpp:402
KisNodeSP lastChild() const
Definition kis_node.cpp:367

References applyCommand(), KisNode::lastChild(), KisNode::prevSibling(), and visitRecursively().

Member Data Documentation

◆ m_emitSignals

KisImageSignalVector KisProcessingApplicator::m_emitSignals
private

Definition at line 120 of file kis_processing_applicator.h.

◆ m_finalSignalsEmitted

bool KisProcessingApplicator::m_finalSignalsEmitted
private

Definition at line 122 of file kis_processing_applicator.h.

◆ m_flags

ProcessingFlags KisProcessingApplicator::m_flags
private

Definition at line 119 of file kis_processing_applicator.h.

◆ m_image

KisImageWSP KisProcessingApplicator::m_image
private

Definition at line 117 of file kis_processing_applicator.h.

◆ m_nodes

KisNodeList KisProcessingApplicator::m_nodes
private

Definition at line 118 of file kis_processing_applicator.h.

◆ m_sharedAllFramesToken

QSharedPointer<bool> KisProcessingApplicator::m_sharedAllFramesToken
private

Definition at line 123 of file kis_processing_applicator.h.

◆ m_strokeId

KisStrokeId KisProcessingApplicator::m_strokeId
private

Definition at line 121 of file kis_processing_applicator.h.

◆ m_successfullyCompletedFuture

std::future<bool> KisProcessingApplicator::m_successfullyCompletedFuture
private

Definition at line 124 of file kis_processing_applicator.h.


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