|
Krita Source Code Documentation
|
#include <kis_signal_compressor.h>
Inheritance diagram for KisSignalCompressor:Public Types | |
| enum | Mode { POSTPONE , FIRST_ACTIVE_POSTPONE_NEXT , FIRST_ACTIVE , FIRST_INACTIVE , UNDEFINED } |
| enum | SlowHandlerMode { PRECISE_INTERVAL , ADDITIVE_INTERVAL } |
Public Slots | |
| void | setDelay (int delay) |
| void | start () |
| void | stop () |
Signals | |
| void | timeout () |
Public Member Functions | |
| int | delay () const |
| bool | isActive () const |
| KisSignalCompressor () | |
| KisSignalCompressor (int delay, Mode mode, QObject *parent=0) | |
| KisSignalCompressor (int delay, Mode mode, SlowHandlerMode slowHandlerMode, QObject *parent=0) | |
| void | setDelay (std::function< bool()> idleCallback, int idleDelay, int timeout) |
| void | setMode (Mode mode) |
Private Slots | |
| void | slotTimerExpired () |
Private Member Functions | |
| void | setDelayImpl (int delay) |
| bool | tryEmitOnTick (bool isFromTimer) |
| bool | tryEmitSignalSafely () |
Private Attributes | |
| std::function< bool()> | m_idleCallback |
| int | m_isEmitting = 0 |
| QElapsedTimer | m_lastEmittedTimer |
| Mode | m_mode = UNDEFINED |
| int | m_sanityIsStarting = 0 |
| bool | m_signalsPending = false |
| SlowHandlerMode | m_slowHandlerMode = PRECISE_INTERVAL |
| int | m_timeout = 0 |
| QTimer * | m_timer = 0 |
Sets a timer to delay or throttle activation of a Qt slot. One example of where this is used is to limit the amount of expensive redraw activity on the canvas.
There are four behaviors to choose from.
POSTPONE resets the timer after each call. Therefore if the calls are made quickly enough, the timer will never be activated.
FIRST_ACTIVE_POSTPONE_NEXT emits the first signal and postpones all the other actions like in POSTPONE. This mode is used e.g. in move/remove layer functionality. If you remove a single layer, you'll see the result immediately. But if you want to remove multiple layers, you should wait until all the actions are finished.
FIRST_ACTIVE emits the timeout() event immediately and sets a timer of duration delay. If the compressor is triggered during this time, it will wait until the end of the delay period to fire the signal. Further events are ignored until the timer elapses. Think of it as a queue with size 1, and where the leading element is popped every delay ms.
FIRST_INACTIVE emits the timeout() event at the end of a timer of duration delay ms. The compressor becomes inactive and all events are ignored until the timer has elapsed.
The current implementation allows the timeout() to be delayed by up to 2 times delay in certain situations (for details see cpp file).
Definition at line 48 of file kis_signal_compressor.h.
| Enumerator | |
|---|---|
| POSTPONE | |
| FIRST_ACTIVE_POSTPONE_NEXT | |
| FIRST_ACTIVE | |
| FIRST_INACTIVE | |
| UNDEFINED | |
Definition at line 53 of file kis_signal_compressor.h.
| Enumerator | |
|---|---|
| PRECISE_INTERVAL | |
| ADDITIVE_INTERVAL | |
Definition at line 61 of file kis_signal_compressor.h.
| KisSignalCompressor::KisSignalCompressor | ( | ) |
KisSignalCompressor will never trigger timeout more often than every delay ms, i.e. delay ms is a given lower limit defining the highest frequency.
The current implementation uses a long-running monitor timer to eliminate the overhead incurred by restarting and stopping timers with each signal. The consequence of this is that the given delay ms is not always exactly followed.
KisSignalCompressor makes the following callback guarantees (0 < err <= 1, with err == 0 if this is the first signal after a while):
POSTPONE:
delay ms. FIRST_ACTIVE_POSTPONE_NEXT:delay ms FIRST_ACTIVE:delay ms FIRST_INACTIVE:delay ms Definition at line 37 of file kis_signal_compressor.cpp.
References connect(), m_timer, slotTimerExpired(), and timeout().
| KisSignalCompressor::KisSignalCompressor | ( | int | delay, |
| Mode | mode, | ||
| QObject * | parent = 0 ) |
Definition at line 45 of file kis_signal_compressor.cpp.
| KisSignalCompressor::KisSignalCompressor | ( | int | delay, |
| Mode | mode, | ||
| SlowHandlerMode | slowHandlerMode, | ||
| QObject * | parent = 0 ) |
Definition at line 50 of file kis_signal_compressor.cpp.
References connect(), delay(), m_timer, slotTimerExpired(), and timeout().
| int KisSignalCompressor::delay | ( | ) | const |
Definition at line 240 of file kis_signal_compressor.cpp.
References m_timeout.
| bool KisSignalCompressor::isActive | ( | ) | const |
Definition at line 230 of file kis_signal_compressor.cpp.
References m_signalsPending, and m_timer.
|
slot |
Definition at line 77 of file kis_signal_compressor.cpp.
References delay(), m_idleCallback, m_timeout, and setDelayImpl().
| void KisSignalCompressor::setDelay | ( | std::function< bool()> | idleCallback, |
| int | idleDelay, | ||
| int | timeout ) |
Definition at line 84 of file kis_signal_compressor.cpp.
References m_idleCallback, m_timeout, setDelayImpl(), and timeout().
|
private |
| void KisSignalCompressor::setMode | ( | KisSignalCompressor::Mode | mode | ) |
Definition at line 235 of file kis_signal_compressor.cpp.
References m_mode.
|
privateslot |
Definition at line 208 of file kis_signal_compressor.cpp.
References KIS_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_NOOP, m_lastEmittedTimer, m_mode, m_sanityIsStarting, m_timeout, m_timer, tryEmitOnTick(), and UNDEFINED.
|
slot |
Definition at line 91 of file kis_signal_compressor.cpp.
References ADDITIVE_INTERVAL, FIRST_ACTIVE, FIRST_ACTIVE_POSTPONE_NEXT, FIRST_INACTIVE, KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, m_lastEmittedTimer, m_mode, m_sanityIsStarting, m_signalsPending, m_slowHandlerMode, m_timer, POSTPONE, PRECISE_INTERVAL, tryEmitOnTick(), tryEmitSignalSafely(), and UNDEFINED.
|
slot |
Definition at line 223 of file kis_signal_compressor.cpp.
References m_lastEmittedTimer, m_signalsPending, and m_timer.
|
signal |
|
private |
Definition at line 153 of file kis_signal_compressor.cpp.
References ADDITIVE_INTERVAL, KIS_SAFE_ASSERT_RECOVER_NOOP, m_idleCallback, m_isEmitting, m_lastEmittedTimer, m_signalsPending, m_slowHandlerMode, m_timeout, PRECISE_INTERVAL, and tryEmitSignalSafely().
|
private |
Definition at line 192 of file kis_signal_compressor.cpp.
References m_isEmitting, and timeout().
|
private |
Definition at line 101 of file kis_signal_compressor.h.
|
private |
Definition at line 99 of file kis_signal_compressor.h.
|
private |
Definition at line 98 of file kis_signal_compressor.h.
Definition at line 95 of file kis_signal_compressor.h.
|
private |
Definition at line 102 of file kis_signal_compressor.h.
|
private |
Definition at line 97 of file kis_signal_compressor.h.
|
private |
Definition at line 96 of file kis_signal_compressor.h.
|
private |
Definition at line 100 of file kis_signal_compressor.h.
|
private |
Definition at line 94 of file kis_signal_compressor.h.