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

#include <kis_stroke.h>

Public Types

enum  Type {
  LEGACY , LOD0 , LODN , SUSPEND ,
  RESUME
}
 

Public Member Functions

void addJob (KisStrokeJobData *data)
 
void addMutatedJobs (const QVector< KisStrokeJobData * > list)
 
qreal balancingRatioOverride () const
 
bool canCancel () const
 
void cancelStroke ()
 
bool canForgetAboutMe () const
 
bool clearsRedoOnStart () const
 
void endStroke ()
 
bool hasJobs () const
 
QString id () const
 
bool isAsynchronouslyCancellable () const
 
bool isCancelled () const
 
bool isEnded () const
 
bool isExclusive () const
 
bool isInitialized () const
 
 KisStroke (KisStrokeStrategy *strokeStrategy, Type type=LEGACY, int levelOfDetail=0)
 
KisStrokeSP lodBuddy () const
 
KUndo2MagicString name () const
 
int nextJobLevelOfDetail () const
 
KisStrokeJobData::Sequentiality nextJobSequentiality () const
 
qint32 numJobs () const
 
KisStrokeJobpopOneJob ()
 
void setLodBuddy (KisStrokeSP buddy)
 
bool supportsSuspension ()
 
bool supportsWrapAroundMode () const
 
void suspendStroke (KisStrokeSP recipient)
 
Type type () const
 
int worksOnLevelOfDetail () const
 
 ~KisStroke ()
 

Private Member Functions

void clearQueueOnCancel ()
 
KisStrokeJobdequeue ()
 
void enqueue (KisStrokeJobStrategy *strategy, KisStrokeJobData *data)
 
void prepend (KisStrokeJobStrategy *strategy, KisStrokeJobData *data, int levelOfDetail, bool isOwnJob)
 
bool sanityCheckAllJobsAreCancellable () const
 
QQueue< KisStrokeJob * > & testingGetQueue ()
 

Private Attributes

QScopedPointer< KisStrokeJobStrategym_cancelStrategy
 
QScopedPointer< KisStrokeJobStrategym_dabStrategy
 
QScopedPointer< KisStrokeJobStrategym_finishStrategy
 
QScopedPointer< KisStrokeJobStrategym_initStrategy
 
bool m_isCancelled
 
QQueue< KisStrokeJob * > m_jobsQueue
 
KisStrokeSP m_lodBuddy
 
QScopedPointer< KisStrokeJobStrategym_resumeStrategy
 
bool m_strokeEnded
 
bool m_strokeInitialized
 
QScopedPointer< KisStrokeStrategym_strokeStrategy
 
bool m_strokeSuspended
 
QScopedPointer< KisStrokeJobStrategym_suspendStrategy
 
Type m_type
 
int m_worksOnLevelOfDetail
 

Friends

class KisStrokeStrategyUndoCommandBasedTest
 
class KisStrokeTest
 

Detailed Description

Definition at line 21 of file kis_stroke.h.

Member Enumeration Documentation

◆ Type

Enumerator
LEGACY 
LOD0 
LODN 
SUSPEND 
RESUME 

Definition at line 24 of file kis_stroke.h.

24 {
25 LEGACY,
26 LOD0,
27 LODN,
28 SUSPEND,
29 RESUME
30 };

Constructor & Destructor Documentation

◆ KisStroke()

KisStroke::KisStroke ( KisStrokeStrategy * strokeStrategy,
Type type = LEGACY,
int levelOfDetail = 0 )

Definition at line 12 of file kis_stroke.cpp.

13 : m_strokeStrategy(strokeStrategy),
15 m_strokeEnded(false),
16 m_strokeSuspended(false),
17 m_isCancelled(false),
18 m_worksOnLevelOfDetail(levelOfDetail),
20{
21 m_initStrategy.reset(m_strokeStrategy->createInitStrategy());
22 m_dabStrategy.reset(m_strokeStrategy->createDabStrategy());
23 m_cancelStrategy.reset(m_strokeStrategy->createCancelStrategy());
24 m_finishStrategy.reset(m_strokeStrategy->createFinishStrategy());
25 m_suspendStrategy.reset(m_strokeStrategy->createSuspendStrategy());
26 m_resumeStrategy.reset(m_strokeStrategy->createResumeStrategy());
27
28 m_strokeStrategy->notifyUserStartedStroke();
29
30 if(!m_initStrategy) {
32 }
33 else {
34 enqueue(m_initStrategy.data(), m_strokeStrategy->createInitData());
35 }
36}
QScopedPointer< KisStrokeJobStrategy > m_initStrategy
Definition kis_stroke.h:101
QScopedPointer< KisStrokeStrategy > m_strokeStrategy
Definition kis_stroke.h:100
QScopedPointer< KisStrokeJobStrategy > m_resumeStrategy
Definition kis_stroke.h:106
Type type() const
Type m_type
Definition kis_stroke.h:115
bool m_isCancelled
Definition kis_stroke.h:112
QScopedPointer< KisStrokeJobStrategy > m_finishStrategy
Definition kis_stroke.h:104
void enqueue(KisStrokeJobStrategy *strategy, KisStrokeJobData *data)
QScopedPointer< KisStrokeJobStrategy > m_cancelStrategy
Definition kis_stroke.h:103
QScopedPointer< KisStrokeJobStrategy > m_dabStrategy
Definition kis_stroke.h:102
QScopedPointer< KisStrokeJobStrategy > m_suspendStrategy
Definition kis_stroke.h:105
bool m_strokeInitialized
Definition kis_stroke.h:109
bool m_strokeSuspended
Definition kis_stroke.h:111
int m_worksOnLevelOfDetail
Definition kis_stroke.h:114
bool m_strokeEnded
Definition kis_stroke.h:110

References enqueue(), m_cancelStrategy, m_dabStrategy, m_finishStrategy, m_initStrategy, m_resumeStrategy, m_strokeInitialized, m_strokeStrategy, and m_suspendStrategy.

◆ ~KisStroke()

KisStroke::~KisStroke ( )

Definition at line 38 of file kis_stroke.cpp.

39{
40 Q_ASSERT(m_strokeEnded);
41 Q_ASSERT(m_jobsQueue.isEmpty());
42}
QQueue< KisStrokeJob * > m_jobsQueue
Definition kis_stroke.h:108

References m_jobsQueue, and m_strokeEnded.

Member Function Documentation

◆ addJob()

void KisStroke::addJob ( KisStrokeJobData * data)

Definition at line 70 of file kis_stroke.cpp.

71{
73 enqueue(m_dabStrategy.data(), data);
74}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References enqueue(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_dabStrategy, and m_strokeEnded.

◆ addMutatedJobs()

void KisStroke::addMutatedJobs ( const QVector< KisStrokeJobData * > list)

Definition at line 76 of file kis_stroke.cpp.

77{
78 // factory methods can return null, if no action is needed
79 if (!m_dabStrategy) {
80 qDeleteAll(list);
81 return;
82 }
83
84 // Find first non-alien (non-suspend/non-resume) job
85 //
86 // Please note that this algorithm will stop working at the day we start
87 // adding alien jobs not to the beginning of the stroke, but to other places.
88 // Right now both suspend and resume jobs are added to the beginning of
89 // the stroke.
90
91 auto it = std::find_if(m_jobsQueue.begin(), m_jobsQueue.end(),
92 std::mem_fn(&KisStrokeJob::isOwnJob));
93
94 Q_FOREACH (KisStrokeJobData *data, list) {
95 it = m_jobsQueue.insert(it, new KisStrokeJob(m_dabStrategy.data(), data, worksOnLevelOfDetail(), true));
96 ++it;
97 }
98}
bool isOwnJob() const
int worksOnLevelOfDetail() const

References KisStrokeJob::isOwnJob(), m_dabStrategy, m_jobsQueue, and worksOnLevelOfDetail().

◆ balancingRatioOverride()

qreal KisStroke::balancingRatioOverride ( ) const

Definition at line 272 of file kis_stroke.cpp.

273{
274 return m_strokeStrategy->balancingRatioOverride();
275}

References m_strokeStrategy.

◆ canCancel()

bool KisStroke::canCancel ( ) const

Definition at line 197 of file kis_stroke.cpp.

198{
200 !m_jobsQueue.isEmpty() || !m_strokeEnded;
201}

References m_isCancelled, m_jobsQueue, m_strokeEnded, and m_strokeInitialized.

◆ cancelStroke()

void KisStroke::cancelStroke ( )

About cancelling the stroke There may be four different states of the stroke, when cancel is requested: 1) Not initialized, has jobs – just clear the queue 2) Initialized, has jobs, not finished – clear the queue, enqueue the cancel job 5) Initialized, no jobs, not finished – enqueue the cancel job 3) Initialized, has jobs, finished – clear the queue, enqueue the cancel job 4) Initialized, no jobs, finished – it's too late to cancel anything 6) Initialized, has jobs, cancelled – cancelling twice is a permitted operation, though it does nothing

Lod0 stroke cannot be suspended and !initialized at the same time, because the suspend job is created iff the stroke has already done some meaningful work.

At the same time, LodN stroke can be prepended with a 'suspend' job even when it has not been started yet. That is obvious: we should suspend the other stroke before doing anything else.

Definition at line 157 of file kis_stroke.cpp.

158{
159 // case 6
160 if (m_isCancelled) return;
161
162 const bool effectivelyInitialized =
163 m_strokeInitialized || m_strokeStrategy->needsExplicitCancel();
164
165 if(!effectivelyInitialized) {
179 }
180 else if(effectivelyInitialized &&
181 (!m_jobsQueue.isEmpty() || !m_strokeEnded)) {
182
183 m_strokeStrategy->tryCancelCurrentStrokeJobAsync();
184
187 m_strokeStrategy->createCancelData());
188 }
189 // else {
190 // too late ...
191 // }
192
193 m_isCancelled = true;
194 m_strokeEnded = true;
195}
void clearQueueOnCancel()
bool sanityCheckAllJobsAreCancellable() const
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References clearQueueOnCancel(), enqueue(), KIS_ASSERT_RECOVER_NOOP, LODN, m_cancelStrategy, m_isCancelled, m_jobsQueue, m_strokeEnded, m_strokeInitialized, m_strokeStrategy, sanityCheckAllJobsAreCancellable(), and type().

◆ canForgetAboutMe()

bool KisStroke::canForgetAboutMe ( ) const

Definition at line 257 of file kis_stroke.cpp.

258{
259 return m_strokeStrategy->canForgetAboutMe();
260}

References m_strokeStrategy.

◆ clearQueueOnCancel()

void KisStroke::clearQueueOnCancel ( )
private

Definition at line 213 of file kis_stroke.cpp.

214{
215 QQueue<KisStrokeJob*>::iterator it = m_jobsQueue.begin();
216
217 while (it != m_jobsQueue.end()) {
218 if ((*it)->isCancellable()) {
219 delete (*it);
220 it = m_jobsQueue.erase(it);
221 } else {
222 ++it;
223 }
224 }
225}

References m_jobsQueue.

◆ clearsRedoOnStart()

bool KisStroke::clearsRedoOnStart ( ) const

Definition at line 267 of file kis_stroke.cpp.

268{
269 return m_strokeStrategy->clearsRedoOnStart();
270}

References m_strokeStrategy.

◆ dequeue()

KisStrokeJob * KisStroke::dequeue ( )
private

Definition at line 318 of file kis_stroke.cpp.

319{
320 return !m_jobsQueue.isEmpty() ? m_jobsQueue.dequeue() : 0;
321}

References m_jobsQueue.

◆ endStroke()

void KisStroke::endStroke ( )

Definition at line 132 of file kis_stroke.cpp.

133{
135 m_strokeEnded = true;
136
137 enqueue(m_finishStrategy.data(), m_strokeStrategy->createFinishData());
138 m_strokeStrategy->notifyUserEndedStroke();
139}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References enqueue(), KIS_SAFE_ASSERT_RECOVER_RETURN, m_finishStrategy, m_strokeEnded, and m_strokeStrategy.

◆ enqueue()

void KisStroke::enqueue ( KisStrokeJobStrategy * strategy,
KisStrokeJobData * data )
private

Definition at line 289 of file kis_stroke.cpp.

291{
292 // factory methods can return null, if no action is needed
293 if(!strategy) {
294 delete data;
295 return;
296 }
297
298 m_jobsQueue.enqueue(new KisStrokeJob(strategy, data, worksOnLevelOfDetail(), true));
299}

References m_jobsQueue, and worksOnLevelOfDetail().

◆ hasJobs()

bool KisStroke::hasJobs ( ) const

Definition at line 122 of file kis_stroke.cpp.

123{
124 return !m_jobsQueue.isEmpty();
125}

References m_jobsQueue.

◆ id()

QString KisStroke::id ( ) const

Definition at line 117 of file kis_stroke.cpp.

118{
119 return m_strokeStrategy->id();
120}

References m_strokeStrategy.

◆ isAsynchronouslyCancellable()

bool KisStroke::isAsynchronouslyCancellable ( ) const

Definition at line 262 of file kis_stroke.cpp.

263{
264 return m_strokeStrategy->isAsynchronouslyCancellable();
265}

References m_strokeStrategy.

◆ isCancelled()

bool KisStroke::isCancelled ( ) const

Definition at line 237 of file kis_stroke.cpp.

238{
239 return m_isCancelled;
240}

References m_isCancelled.

◆ isEnded()

bool KisStroke::isEnded ( ) const

Definition at line 232 of file kis_stroke.cpp.

233{
234 return m_strokeEnded;
235}

References m_strokeEnded.

◆ isExclusive()

bool KisStroke::isExclusive ( ) const

Definition at line 242 of file kis_stroke.cpp.

243{
244 return m_strokeStrategy->isExclusive();
245}

References m_strokeStrategy.

◆ isInitialized()

bool KisStroke::isInitialized ( ) const

Definition at line 227 of file kis_stroke.cpp.

228{
229 return m_strokeInitialized;
230}

References m_strokeInitialized.

◆ lodBuddy()

KisStrokeSP KisStroke::lodBuddy ( ) const

Definition at line 328 of file kis_stroke.cpp.

329{
330 return m_lodBuddy;
331}
KisStrokeSP m_lodBuddy
Definition kis_stroke.h:116

References m_lodBuddy.

◆ name()

KUndo2MagicString KisStroke::name ( ) const

Definition at line 112 of file kis_stroke.cpp.

113{
114 return m_strokeStrategy->name();
115}

References m_strokeStrategy.

◆ nextJobLevelOfDetail()

int KisStroke::nextJobLevelOfDetail ( ) const

Definition at line 283 of file kis_stroke.cpp.

284{
285 return !m_jobsQueue.isEmpty() ?
286 m_jobsQueue.head()->levelOfDetail() : worksOnLevelOfDetail();
287}

References m_jobsQueue, and worksOnLevelOfDetail().

◆ nextJobSequentiality()

KisStrokeJobData::Sequentiality KisStroke::nextJobSequentiality ( ) const

Definition at line 277 of file kis_stroke.cpp.

278{
279 return !m_jobsQueue.isEmpty() ?
280 m_jobsQueue.head()->sequentiality() : KisStrokeJobData::SEQUENTIAL;
281}

References m_jobsQueue, and KisStrokeJobData::SEQUENTIAL.

◆ numJobs()

qint32 KisStroke::numJobs ( ) const

Definition at line 127 of file kis_stroke.cpp.

128{
129 return m_jobsQueue.size();
130}

References m_jobsQueue.

◆ popOneJob()

KisStrokeJob * KisStroke::popOneJob ( )

Definition at line 100 of file kis_stroke.cpp.

101{
102 KisStrokeJob *job = dequeue();
103
104 if(job) {
105 m_strokeInitialized = true;
106 m_strokeSuspended = false;
107 }
108
109 return job;
110}
KisStrokeJob * dequeue()

References dequeue(), m_strokeInitialized, and m_strokeSuspended.

◆ prepend()

void KisStroke::prepend ( KisStrokeJobStrategy * strategy,
KisStrokeJobData * data,
int levelOfDetail,
bool isOwnJob )
private

Definition at line 301 of file kis_stroke.cpp.

305{
306 // factory methods can return null, if no action is needed
307 if(!strategy) {
308 delete data;
309 return;
310 }
311
312 // LOG_MERGE_FIXME:
313 Q_UNUSED(levelOfDetail);
314
315 m_jobsQueue.prepend(new KisStrokeJob(strategy, data, worksOnLevelOfDetail(), isOwnJob));
316}

References m_jobsQueue, and worksOnLevelOfDetail().

◆ sanityCheckAllJobsAreCancellable()

bool KisStroke::sanityCheckAllJobsAreCancellable ( ) const
private

Definition at line 203 of file kis_stroke.cpp.

204{
205 Q_FOREACH (KisStrokeJob *item, m_jobsQueue) {
206 if (!item->isCancellable()) {
207 return false;
208 }
209 }
210 return true;
211}
bool isCancellable() const

References KisStrokeJob::isCancellable(), and m_jobsQueue.

◆ setLodBuddy()

void KisStroke::setLodBuddy ( KisStrokeSP buddy)

Definition at line 323 of file kis_stroke.cpp.

324{
325 m_lodBuddy = buddy;
326}

References m_lodBuddy.

◆ supportsSuspension()

bool KisStroke::supportsSuspension ( )

Definition at line 44 of file kis_stroke.cpp.

References m_resumeStrategy, m_strokeInitialized, and m_suspendStrategy.

◆ supportsWrapAroundMode()

bool KisStroke::supportsWrapAroundMode ( ) const

Definition at line 247 of file kis_stroke.cpp.

248{
249 return m_strokeStrategy->supportsWrapAroundMode();
250}

References m_strokeStrategy.

◆ suspendStroke()

void KisStroke::suspendStroke ( KisStrokeSP recipient)

Definition at line 49 of file kis_stroke.cpp.

50{
52 (m_strokeEnded && !hasJobs())) {
53
54 return;
55 }
56
58
60 m_strokeStrategy->createResumeData(),
61 worksOnLevelOfDetail(), false);
62
63 recipient->prepend(m_suspendStrategy.data(),
64 m_strokeStrategy->createSuspendData(),
65 worksOnLevelOfDetail(), false);
66
67 m_strokeSuspended = true;
68}
void prepend(KisStrokeJobStrategy *strategy, KisStrokeJobData *data, int levelOfDetail, bool isOwnJob)
bool hasJobs() const

References hasJobs(), KIS_ASSERT_RECOVER_NOOP, m_resumeStrategy, m_strokeEnded, m_strokeInitialized, m_strokeStrategy, m_strokeSuspended, m_suspendStrategy, prepend(), and worksOnLevelOfDetail().

◆ testingGetQueue()

QQueue< KisStrokeJob * > & KisStroke::testingGetQueue ( )
inlineprivate

Definition at line 94 of file kis_stroke.h.

94 {
95 return m_jobsQueue;
96 }

◆ type()

KisStroke::Type KisStroke::type ( ) const

Definition at line 333 of file kis_stroke.cpp.

334{
335 if (m_type == LOD0) {
336 KIS_ASSERT_RECOVER_NOOP(m_lodBuddy && "LOD0 strokes must always have a buddy");
337 } else if (m_type == LODN) {
338 KIS_ASSERT_RECOVER_NOOP(m_worksOnLevelOfDetail > 0 && "LODN strokes must work on LOD > 0!");
339 } else if (m_type == LEGACY) {
340 KIS_ASSERT_RECOVER_NOOP(m_worksOnLevelOfDetail == 0 && "LEGACY strokes must work on LOD == 0!");
341 }
342
343 return m_type;
344}

References KIS_ASSERT_RECOVER_NOOP, LEGACY, LOD0, LODN, m_lodBuddy, m_type, and m_worksOnLevelOfDetail.

◆ worksOnLevelOfDetail()

int KisStroke::worksOnLevelOfDetail ( ) const

Definition at line 252 of file kis_stroke.cpp.

253{
255}

References m_worksOnLevelOfDetail.

Friends And Related Symbol Documentation

◆ KisStrokeStrategyUndoCommandBasedTest

friend class KisStrokeStrategyUndoCommandBasedTest
friend

Definition at line 93 of file kis_stroke.h.

◆ KisStrokeTest

friend class KisStrokeTest
friend

Definition at line 92 of file kis_stroke.h.

Member Data Documentation

◆ m_cancelStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_cancelStrategy
private

Definition at line 103 of file kis_stroke.h.

◆ m_dabStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_dabStrategy
private

Definition at line 102 of file kis_stroke.h.

◆ m_finishStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_finishStrategy
private

Definition at line 104 of file kis_stroke.h.

◆ m_initStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_initStrategy
private

Definition at line 101 of file kis_stroke.h.

◆ m_isCancelled

bool KisStroke::m_isCancelled
private

Definition at line 112 of file kis_stroke.h.

◆ m_jobsQueue

QQueue<KisStrokeJob*> KisStroke::m_jobsQueue
private

Definition at line 108 of file kis_stroke.h.

◆ m_lodBuddy

KisStrokeSP KisStroke::m_lodBuddy
private

Definition at line 116 of file kis_stroke.h.

◆ m_resumeStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_resumeStrategy
private

Definition at line 106 of file kis_stroke.h.

◆ m_strokeEnded

bool KisStroke::m_strokeEnded
private

Definition at line 110 of file kis_stroke.h.

◆ m_strokeInitialized

bool KisStroke::m_strokeInitialized
private

Definition at line 109 of file kis_stroke.h.

◆ m_strokeStrategy

QScopedPointer<KisStrokeStrategy> KisStroke::m_strokeStrategy
private

Definition at line 100 of file kis_stroke.h.

◆ m_strokeSuspended

bool KisStroke::m_strokeSuspended
private

Definition at line 111 of file kis_stroke.h.

◆ m_suspendStrategy

QScopedPointer<KisStrokeJobStrategy> KisStroke::m_suspendStrategy
private

Definition at line 105 of file kis_stroke.h.

◆ m_type

Type KisStroke::m_type
private

Definition at line 115 of file kis_stroke.h.

◆ m_worksOnLevelOfDetail

int KisStroke::m_worksOnLevelOfDetail
private

Definition at line 114 of file kis_stroke.h.


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