swift
Loading...
Searching...
No Matches
digestsignal.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "misc/digestsignal.h"
5
6#include <QPointer>
7
8#include "misc/threadutils.h"
9
10namespace swift::misc
11{
13 {
15 {
16 // call in correct thread
17 const QPointer<CDigestSignal> myself(this);
18 QTimer::singleShot(0, this, [=, this] {
19 if (!myself)
20 {
21 return;
22 }
23 this->inputSignal();
24 });
25 return;
26 }
27
28 m_timer.start(); // start or restart
29 m_inputsCount++;
30 if (m_inputsCount >= m_maxInputsPerDigest)
31 {
32 timerTimeout();
33 }
34 }
35
36 void CDigestSignal::timerTimeout()
37 {
38 m_timer.stop();
39 m_inputsCount = 0;
40 emit this->digestSignal();
41 }
42
43 void CDigestSignal::init(std::chrono::milliseconds maxDelay)
44 {
45 QObject::connect(&m_timer, &QTimer::timeout, this, &CDigestSignal::timerTimeout);
46 m_timer.setSingleShot(true);
47 m_timer.setInterval(maxDelay);
48 }
49} // namespace swift::misc
void digestSignal()
Send digest signal.
void inputSignal()
Received input signal, or manually trigger.
static bool isInThisThread(const QObject *toBeTested)
Is the current thread the object's thread?
Free functions in swift::misc.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setInterval(int msec)
void stop()
void timeout()