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

#include <KoUpdater.h>

+ Inheritance diagram for KoUpdater:

Public Slots

void setProgress (int percent)
 

Signals

void sigCancel ()
 emitted whenever the subtask has called cancel on us
 
void sigHasValidRangeChanged (bool value)
 
void sigNestedNameChanged (const QString &value)
 
void sigProgress (int percent)
 emitted whenever the subtask has called setProgress on us
 

Public Member Functions

void cancel ()
 
bool interrupted () const
 
int maximum () const override
 
int progress () const
 
void setAutoNestedName (const QString &name) override
 
void setFormat (const QString &format) override
 
void setRange (int minimum, int maximum) override
 
void setValue (int value) override
 
virtual ~KoUpdater ()
 
- Public Member Functions inherited from KoProgressProxy
virtual ~KoProgressProxy ()
 

Public Attributes

QPointer< KoUpdaterPrivated
 
int max
 
int min
 
int range
 

Protected Member Functions

 KoUpdater (KoUpdaterPrivate *_d)
 

Private Slots

void setInterrupted (bool value)
 

Private Attributes

QAtomicInt m_interrupted
 
int m_progressPercent
 

Friends

class KoUpdaterPrivate
 

Detailed Description

An KoUpdater is a helper for keeping the progress of each subtask up to speed. This class is not thread safe, and it should only be used from one thread. The thread it is used in can be different from any other subtask or the KoProgressUpdater, though.

It is possible to create a KoProgressUpdater on a KoUpdater for when you need to recursively split up progress reporting. (For instance, when your progress reporting routine can be called by other progress reporting routines.)

KoUpdater implements KoProgressProxy because it is possible to recursively create another KoProgressUpdater with an updater as progress proxy.

See also
KoProgressUpdater::startSubtask()

Definition at line 36 of file KoUpdater.h.

Constructor & Destructor Documentation

◆ ~KoUpdater()

KoUpdater::~KoUpdater ( )
virtual

Definition at line 29 of file KoUpdater.cpp.

30{
31}

◆ KoUpdater()

KoUpdater::KoUpdater ( KoUpdaterPrivate * _d)
protected

Definition at line 13 of file KoUpdater.cpp.

15{
16 d = _d;
17 Q_ASSERT(!d.isNull());
18
19 connect(this, SIGNAL(sigCancel()), d, SLOT(cancel()));
20 connect(this, SIGNAL(sigProgress(int)), d, SLOT(setProgress(int)));
21 connect(this, SIGNAL(sigNestedNameChanged(QString)), d, SLOT(setAutoNestedName(QString)));
22 connect(this, SIGNAL(sigHasValidRangeChanged(bool)), d, SLOT(setHasValidRange(bool)));
23
24
25 setRange(0, 100);
26 m_interrupted = false;
27}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void sigProgress(int percent)
emitted whenever the subtask has called setProgress on us
QAtomicInt m_interrupted
Definition KoUpdater.h:110
void sigCancel()
emitted whenever the subtask has called cancel on us
int m_progressPercent
Definition KoUpdater.h:111
void sigHasValidRangeChanged(bool value)
void setProgress(int percent)
Definition KoUpdater.cpp:38
void setAutoNestedName(const QString &name) override
Definition KoUpdater.cpp:92
QPointer< KoUpdaterPrivate > d
Definition KoUpdater.h:99
void cancel()
Definition KoUpdater.cpp:33
void setRange(int minimum, int maximum) override
Definition KoUpdater.cpp:79
void sigNestedNameChanged(const QString &value)

References cancel(), connect(), d, m_interrupted, setAutoNestedName(), setProgress(), setRange(), sigCancel(), sigHasValidRangeChanged(), sigNestedNameChanged(), and sigProgress().

Member Function Documentation

◆ cancel()

void KoUpdater::cancel ( )

Call this when this subtask wants to abort all the actions.

Definition at line 33 of file KoUpdater.cpp.

34{
35 Q_EMIT sigCancel();
36}

References sigCancel().

◆ interrupted()

bool KoUpdater::interrupted ( ) const

return true when this task should stop processing immediately. When the task has been cancelled all the subtasks will get interrupted and should stop working. It is therefore important to have repeated calls to this method at regular (time) intervals and as soon as the method returns true cancel the subtask.

Returns
true when this task should stop processing immediately.

Definition at line 54 of file KoUpdater.cpp.

55{
56 return m_interrupted.loadAcquire();
57}

References m_interrupted.

◆ maximum()

int KoUpdater::maximum ( ) const
overridevirtual

Implements KoProgressProxy.

Definition at line 59 of file KoUpdater.cpp.

60{
61 return max;
62}

References max.

◆ progress()

int KoUpdater::progress ( ) const

return the progress this subtask has made.

Definition at line 48 of file KoUpdater.cpp.

49{
50
51 return m_progressPercent;
52}

References m_progressPercent.

◆ setAutoNestedName()

void KoUpdater::setAutoNestedName ( const QString & name)
overridevirtual

Reimplemented from KoProgressProxy.

Definition at line 92 of file KoUpdater.cpp.

93{
94 Q_EMIT sigNestedNameChanged(name);
95}

References sigNestedNameChanged().

◆ setFormat()

void KoUpdater::setFormat ( const QString & format)
overridevirtual

Implements KoProgressProxy.

Definition at line 87 of file KoUpdater.cpp.

88{
89 Q_EMIT sigNestedNameChanged(format);
90}

References sigNestedNameChanged().

◆ setInterrupted

void KoUpdater::setInterrupted ( bool value)
privateslot

Definition at line 97 of file KoUpdater.cpp.

98{
99 m_interrupted.storeRelease(value);
100}
float value(const T *src, size_t ch)

References m_interrupted, and value().

◆ setProgress

void KoUpdater::setProgress ( int percent)
slot

Update your progress. Progress is always from 0 to 100. The global progress shown to the user is determined by the total amount of subtasks there are. This means that each subtasks can just report its own private progress in the range from 0 to 100.

Definition at line 38 of file KoUpdater.cpp.

39{
40 const bool percentChanged = m_progressPercent != percent;
41
42 if (percentChanged || percent == 0 || percent == 100) {
43 m_progressPercent = percent;
44 Q_EMIT sigProgress( percent );
45 }
46}

References m_progressPercent, and sigProgress().

◆ setRange()

void KoUpdater::setRange ( int minimum,
int maximum )
overridevirtual

Implements KoProgressProxy.

Definition at line 79 of file KoUpdater.cpp.

80{
81 min = minimum;
82 max = maximum;
83 range = max - min;
84 Q_EMIT sigHasValidRangeChanged(range != 0);
85}
int maximum() const override
Definition KoUpdater.cpp:59

References max, maximum(), min, range, and sigHasValidRangeChanged().

◆ setValue()

void KoUpdater::setValue ( int value)
overridevirtual

Implements KoProgressProxy.

Definition at line 64 of file KoUpdater.cpp.

65{
66 value = qBound(min, value, max);
67
68 // Go from range to percent
69 const int range = max - min;
70
71 if (range == 0) {
73 Q_EMIT sigProgress(max);
74 } else {
75 setProgress((100 * (value - min)) / range);
76 }
77}

References m_progressPercent, max, min, range, setProgress(), sigProgress(), and value().

◆ sigCancel

void KoUpdater::sigCancel ( )
signal

emitted whenever the subtask has called cancel on us

◆ sigHasValidRangeChanged

void KoUpdater::sigHasValidRangeChanged ( bool value)
signal

◆ sigNestedNameChanged

void KoUpdater::sigNestedNameChanged ( const QString & value)
signal

◆ sigProgress

void KoUpdater::sigProgress ( int percent)
signal

emitted whenever the subtask has called setProgress on us

Friends And Related Symbol Documentation

◆ KoUpdaterPrivate

friend class KoUpdaterPrivate
friend

Definition at line 94 of file KoUpdater.h.

Member Data Documentation

◆ d

QPointer<KoUpdaterPrivate> KoUpdater::d

Definition at line 99 of file KoUpdater.h.

◆ m_interrupted

QAtomicInt KoUpdater::m_interrupted
private

Definition at line 110 of file KoUpdater.h.

◆ m_progressPercent

int KoUpdater::m_progressPercent
private

Definition at line 111 of file KoUpdater.h.

◆ max

int KoUpdater::max

Definition at line 102 of file KoUpdater.h.

◆ min

int KoUpdater::min

Definition at line 101 of file KoUpdater.h.

◆ range

int KoUpdater::range

Definition at line 100 of file KoUpdater.h.


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