Main Page
Namespaces
Classes
Files
File List
src
rqt_multiplot
ThreadedTimer.cpp
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright (C) 2015 by Ralf Kaestner *
3
* ralf.kaestner@gmail.com *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the Lesser GNU General Public License as published by*
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* Lesser GNU General Public License for more details. *
14
* *
15
* You should have received a copy of the Lesser GNU General Public License *
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
******************************************************************************/
18
19
#include <QApplication>
20
#include <QTimerEvent>
21
22
#include "
rqt_multiplot/ThreadedTimer.h
"
23
24
namespace
rqt_multiplot
{
25
26
/*****************************************************************************/
27
/* Constructors and Destructor */
28
/*****************************************************************************/
29
30
ThreadedTimer::ThreadedTimer
(QObject* parent) :
31
QThread(parent),
32
timer_(new QTimer()) {
33
timer_
->moveToThread(
this
);
34
35
connect(
timer_
, SIGNAL(timeout()),
this
, SLOT(
timerTimeout
()));
36
}
37
38
ThreadedTimer::~ThreadedTimer
() {
39
quit();
40
wait
();
41
42
delete
timer_
;
43
}
44
45
/*****************************************************************************/
46
/* Accessors */
47
/*****************************************************************************/
48
49
int
ThreadedTimer::getTimerId
()
const
{
50
return
timer_
->timerId();
51
}
52
53
void
ThreadedTimer::setRate
(
double
rate) {
54
timer_
->setInterval(1e3/rate);
55
}
56
57
double
ThreadedTimer::getRate
()
const
{
58
return
1e3/
timer_
->interval();
59
}
60
61
/*****************************************************************************/
62
/* Methods */
63
/*****************************************************************************/
64
65
void
ThreadedTimer::run
() {
66
timer_
->start();
67
68
QThread::exec();
69
}
70
71
/*****************************************************************************/
72
/* Methods */
73
/*****************************************************************************/
74
75
void
ThreadedTimer::timerTimeout
() {
76
if
(parent())
77
QApplication::postEvent(parent(),
new
QTimerEvent(
timer_
->timerId()));
78
}
79
80
}
rqt_multiplot::ThreadedTimer::~ThreadedTimer
virtual ~ThreadedTimer()
Definition:
ThreadedTimer.cpp:38
rqt_multiplot::ThreadedTimer::setRate
void setRate(double rate)
Definition:
ThreadedTimer.cpp:53
ThreadedTimer.h
rqt_multiplot::ThreadedTimer::getTimerId
int getTimerId() const
Definition:
ThreadedTimer.cpp:49
rqt_multiplot::ThreadedTimer::getRate
double getRate() const
Definition:
ThreadedTimer.cpp:57
rqt_multiplot::ThreadedTimer::run
void run()
Definition:
ThreadedTimer.cpp:65
wait
void wait(int seconds)
rqt_multiplot::ThreadedTimer::ThreadedTimer
ThreadedTimer(QObject *parent=0)
Definition:
ThreadedTimer.cpp:30
rqt_multiplot::ThreadedTimer::timerTimeout
void timerTimeout()
Definition:
ThreadedTimer.cpp:75
rqt_multiplot
Definition:
BagQuery.h:33
rqt_multiplot::ThreadedTimer::timer_
QTimer * timer_
Definition:
ThreadedTimer.h:41
rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44