Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
qwt
src
qwt_sampling_thread.cpp
Go to the documentation of this file.
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2
* Qwt Widget Library
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
9
10
#include "
qwt_sampling_thread.h
"
11
#include "
qwt_system_clock.h
"
12
13
class
QwtSamplingThread::PrivateData
14
{
15
public
:
16
QwtSystemClock
clock
;
17
18
double
interval
;
19
bool
isStopped
;
20
};
21
22
24
QwtSamplingThread::QwtSamplingThread
( QObject *parent ):
25
QThread( parent )
26
{
27
d_data
=
new
PrivateData
;
28
d_data
->
interval
= 1000;
// 1 second
29
d_data
->
isStopped
=
true
;
30
}
31
33
QwtSamplingThread::~QwtSamplingThread
()
34
{
35
delete
d_data
;
36
}
37
45
void
QwtSamplingThread::setInterval
(
double
interval
)
46
{
47
if
( interval < 0.0 )
48
interval = 0.0;
49
50
d_data
->
interval
=
interval
;
51
}
52
57
double
QwtSamplingThread::interval
()
const
58
{
59
return
d_data
->
interval
;
60
}
61
66
double
QwtSamplingThread::elapsed
()
const
67
{
68
if
(
d_data
->
isStopped
)
69
return
0.0;
70
71
return
d_data
->
clock
.
elapsed
();
72
}
73
78
void
QwtSamplingThread::stop
()
79
{
80
d_data
->
isStopped
=
true
;
81
}
82
87
void
QwtSamplingThread::run
()
88
{
89
d_data
->
clock
.
start
();
90
d_data
->
isStopped
=
false
;
91
92
while
( !
d_data
->
isStopped
)
93
{
94
const
double
elapsed
=
d_data
->
clock
.
elapsed
();
95
sample
( elapsed / 1000.0 );
96
97
if
(
d_data
->
interval
> 0.0 )
98
{
99
const
double
msecs =
100
d_data
->
interval
- (
d_data
->
clock
.
elapsed
() -
elapsed
);
101
102
if
( msecs > 0.0 )
103
usleep( qRound( 1000.0 * msecs ) );
104
}
105
}
106
}
qwt_system_clock.h
QwtSamplingThread::sample
virtual void sample(double elapsed)=0
QwtSystemClock::start
void start()
Definition:
qwt_system_clock.cpp:345
QwtSamplingThread::elapsed
double elapsed() const
Definition:
qwt_sampling_thread.cpp:66
QwtSamplingThread::stop
void stop()
Definition:
qwt_sampling_thread.cpp:78
QwtSamplingThread::~QwtSamplingThread
virtual ~QwtSamplingThread()
Destructor.
Definition:
qwt_sampling_thread.cpp:33
QwtSamplingThread::PrivateData::clock
QwtSystemClock clock
Definition:
qwt_sampling_thread.cpp:16
QwtSamplingThread::PrivateData::interval
double interval
Definition:
qwt_sampling_thread.cpp:18
QwtSamplingThread::run
virtual void run()
Definition:
qwt_sampling_thread.cpp:87
QwtSamplingThread::PrivateData
Definition:
qwt_sampling_thread.cpp:13
QwtSamplingThread::PrivateData::isStopped
bool isStopped
Definition:
qwt_sampling_thread.cpp:19
qwt_sampling_thread.h
QwtSamplingThread::QwtSamplingThread
QwtSamplingThread(QObject *parent=NULL)
Constructor.
Definition:
qwt_sampling_thread.cpp:24
QwtSystemClock::elapsed
double elapsed() const
Definition:
qwt_system_clock.cpp:376
QwtSamplingThread::interval
double interval() const
Definition:
qwt_sampling_thread.cpp:57
QwtSamplingThread::d_data
PrivateData * d_data
Definition:
qwt_sampling_thread.h:46
QwtSamplingThread::setInterval
void setInterval(double interval)
Definition:
qwt_sampling_thread.cpp:45
QwtSystemClock
QwtSystemClock provides high resolution clock time functions.
Definition:
qwt_system_clock.h:33
plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17