Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_sampling_thread.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (2 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_sampling_thread.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_sampling_thread.cpp
r4271 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_sampling_thread.h" 11 #include "qwt_system_clock.h"11 #include <qelapsedtimer.h> 12 12 13 13 class QwtSamplingThread::PrivateData 14 14 { 15 public: 16 QwtSystemClock clock; 17 18 double interval; 19 bool isStopped; 15 public: 16 QElapsedTimer timer; 17 double msecsInterval; 20 18 }; 21 19 22 23 20 //! Constructor 24 QwtSamplingThread::QwtSamplingThread( QObject *parent ):25 QThread( parent ) 21 QwtSamplingThread::QwtSamplingThread( QObject* parent ) 22 : QThread( parent ) 26 23 { 27 d_data = new PrivateData; 28 d_data->interval = 1000; // 1 second 29 d_data->isStopped = true; 24 m_data = new PrivateData; 25 m_data->msecsInterval = 1e3; // 1 second 30 26 } 31 27 … … 33 29 QwtSamplingThread::~QwtSamplingThread() 34 30 { 35 delete d_data;31 delete m_data; 36 32 } 37 33 … … 40 36 The default interval is 1000.0 ( = 1s ) 41 37 42 \param intervalInterval38 \param msecs Interval 43 39 \sa interval() 44 */ 45 void QwtSamplingThread::setInterval( double interval)40 */ 41 void QwtSamplingThread::setInterval( double msecs ) 46 42 { 47 if ( interval< 0.0 )48 interval= 0.0;43 if ( msecs < 0.0 ) 44 msecs = 0.0; 49 45 50 d_data->interval =interval;46 m_data->msecsInterval = msecs; 51 47 } 52 48 … … 54 50 \return Interval (in ms), between 2 calls of sample() 55 51 \sa setInterval() 56 */ 52 */ 57 53 double QwtSamplingThread::interval() const 58 54 { 59 return d_data->interval;55 return m_data->msecsInterval; 60 56 } 61 57 … … 63 59 \return Time (in ms) since the thread was started 64 60 \sa QThread::start(), run() 65 */ 61 */ 66 62 double QwtSamplingThread::elapsed() const 67 63 { 68 if ( d_data->isStopped)69 return 0.0;64 if ( m_data->timer.isValid() ) 65 return m_data->timer.nsecsElapsed() / 1e6; 70 66 71 return d_data->clock.elapsed();67 return 0.0; 72 68 } 73 69 … … 75 71 Terminate the collecting thread 76 72 \sa QThread::start(), run() 77 */ 73 */ 78 74 void QwtSamplingThread::stop() 79 75 { 80 d_data->isStopped = true;76 m_data->timer.invalidate(); 81 77 } 82 78 … … 84 80 Loop collecting samples started from QThread::start() 85 81 \sa stop() 86 */ 82 */ 87 83 void QwtSamplingThread::run() 88 84 { 89 d_data->clock.start(); 90 d_data->isStopped = false; 85 m_data->timer.start(); 91 86 92 while ( !d_data->isStopped ) 87 /* 88 We should have all values in nsecs/qint64, but 89 this would break existing code. TODO ... 90 Anyway - for QThread::usleep we even need microseconds( usecs ) 91 */ 92 while ( m_data->timer.isValid() ) 93 93 { 94 const double elapsed = d_data->clock.elapsed();95 sample( elapsed / 1000.0 );94 const qint64 timestamp = m_data->timer.nsecsElapsed(); 95 sample( timestamp / 1e9 ); // seconds 96 96 97 if ( d_data->interval > 0.0 )97 if ( m_data->msecsInterval > 0.0 ) 98 98 { 99 const double msecs =100 d_data->interval - ( d_data->clock.elapsed() -elapsed );99 const double interval = m_data->msecsInterval * 1e3; 100 const double elapsed = ( m_data->timer.nsecsElapsed() - timestamp ) / 1e3; 101 101 102 if ( msecs > 0.0 ) 103 usleep( qRound( 1000.0 * msecs ) ); 102 const double usecs = interval - elapsed; 103 104 if ( usecs > 0.0 ) 105 QThread::usleep( qRound( usecs ) ); 104 106 } 105 107 } 106 108 } 109 110 #include "moc_qwt_sampling_thread.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
