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 
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 
39  quit();
40  wait();
41 
42  delete timer_;
43 }
44 
45 /*****************************************************************************/
46 /* Accessors */
47 /*****************************************************************************/
48 
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 
66  timer_->start();
67 
68  QThread::exec();
69 }
70 
71 /*****************************************************************************/
72 /* Methods */
73 /*****************************************************************************/
74 
76  if (parent())
77  QApplication::postEvent(parent(), new QTimerEvent(timer_->timerId()));
78 }
79 
80 }
void wait(int seconds)
ThreadedTimer(QObject *parent=0)


rqt_multiplot_plugin
Author(s): Ralf Kaestner
autogenerated on Fri Jan 15 2021 03:47:53