plotjuggler_base
include
PlotJuggler
util
delayed_callback.hpp
Go to the documentation of this file.
1
/*
2
* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
*/
6
7
#ifndef PJ_DELAYED_CALLBACK_HPP
8
#define PJ_DELAYED_CALLBACK_HPP
9
10
#include <QTimer>
11
#include <QMetaMethod>
12
#include <functional>
13
14
namespace
PJ
15
{
16
// Simple utility to avoid triggering a certain slot too often
17
class
DelayedCallback
18
{
19
public
:
20
DelayedCallback
()
21
{
22
_delay_timer
=
new
QTimer();
23
_delay_timer
->setSingleShot(
true
);
24
}
25
26
~DelayedCallback
()
27
{
28
delete
_delay_timer
;
29
}
30
31
template
<
class
Function>
32
void
connectCallback
(Function callback)
33
{
34
QObject::connect(
_delay_timer
, &QTimer::timeout, callback);
35
}
36
37
void
triggerSignal
(
int
delay_ms)
38
{
39
if
(!
_delay_timer
->isActive())
40
{
41
_delay_timer
->start(delay_ms);
42
}
43
}
44
45
private
:
46
QTimer*
_delay_timer
;
47
};
48
49
}
// namespace PJ
50
51
#endif // PJ_DELAYED_CALLBACK_HPP
PJ::DelayedCallback::~DelayedCallback
~DelayedCallback()
Definition:
delayed_callback.hpp:26
PJ::DelayedCallback::_delay_timer
QTimer * _delay_timer
Definition:
delayed_callback.hpp:46
PJ::DelayedCallback::triggerSignal
void triggerSignal(int delay_ms)
Definition:
delayed_callback.hpp:37
PJ::DelayedCallback::DelayedCallback
DelayedCallback()
Definition:
delayed_callback.hpp:20
PJ::DelayedCallback
Definition:
delayed_callback.hpp:17
PJ
Definition:
dataloader_base.h:16
PJ::DelayedCallback::connectCallback
void connectCallback(Function callback)
Definition:
delayed_callback.hpp:32
plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44