swift
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 
10 namespace swift::misc
11 {
13  {
15  {
16  // call in correct thread
17  const QPointer<CDigestSignal> myself(this);
18  QTimer::singleShot(0, this, [=] {
19  if (!myself) { return; }
20  this->inputSignal();
21  });
22  return;
23  }
24 
25  m_timer.start(); // start or restart
26  m_inputsCount++;
27  if (m_inputsCount >= m_maxInputsPerDigest) { timerTimeout(); }
28  }
29 
30  void CDigestSignal::timerTimeout()
31  {
32  m_timer.stop();
33  m_inputsCount = 0;
34  emit this->digestSignal();
35  }
36 
37  void CDigestSignal::init(std::chrono::milliseconds maxDelay)
38  {
39  QObject::connect(&m_timer, &QTimer::timeout, this, &CDigestSignal::timerTimeout);
40  m_timer.setSingleShot(true);
41  m_timer.setInterval(maxDelay);
42  }
43 } // 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?
Definition: threadutils.cpp:16
Free functions in swift::misc.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30