Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (2 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_sampling_thread.cpp

    r4271 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_sampling_thread.h"
    11 #include "qwt_system_clock.h"
     11#include <qelapsedtimer.h>
    1212
    1313class QwtSamplingThread::PrivateData
    1414{
    15 public:
    16     QwtSystemClock clock;
    17 
    18     double interval;
    19     bool isStopped;
     15  public:
     16    QElapsedTimer timer;
     17    double msecsInterval;
    2018};
    2119
    22 
    2320//! Constructor
    24 QwtSamplingThread::QwtSamplingThread( QObject *parent ):
    25     QThread( parent )
     21QwtSamplingThread::QwtSamplingThread( QObject* parent )
     22    : QThread( parent )
    2623{
    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
    3026}
    3127
    … …  
    3329QwtSamplingThread::~QwtSamplingThread()
    3430{
    35     delete d_data;
     31    delete m_data;
    3632}
    3733
    … …  
    4036   The default interval is 1000.0 ( = 1s )
    4137
    42    \param interval Interval
     38   \param msecs Interval
    4339   \sa interval()
    44 */
    45 void QwtSamplingThread::setInterval( double interval )
     40 */
     41void QwtSamplingThread::setInterval( double msecs )
    4642{
    47     if ( interval < 0.0 )
    48         interval = 0.0;
     43    if ( msecs < 0.0 )
     44        msecs = 0.0;
    4945
    50     d_data->interval = interval;
     46    m_data->msecsInterval = msecs;
    5147}
    5248
    … …  
    5450   \return Interval (in ms), between 2 calls of sample()
    5551   \sa setInterval()
    56 */
     52 */
    5753double QwtSamplingThread::interval() const
    5854{
    59     return d_data->interval;
     55    return m_data->msecsInterval;
    6056}
    6157
    … …  
    6359   \return Time (in ms) since the thread was started
    6460   \sa QThread::start(), run()
    65 */
     61 */
    6662double QwtSamplingThread::elapsed() const
    6763{
    68     if ( d_data->isStopped )
    69         return 0.0;
     64    if ( m_data->timer.isValid() )
     65        return m_data->timer.nsecsElapsed() / 1e6;
    7066
    71     return d_data->clock.elapsed();
     67    return 0.0;
    7268}
    7369
    … …  
    7571   Terminate the collecting thread
    7672   \sa QThread::start(), run()
    77 */
     73 */
    7874void QwtSamplingThread::stop()
    7975{
    80     d_data->isStopped = true;
     76    m_data->timer.invalidate();
    8177}
    8278
    … …  
    8480   Loop collecting samples started from QThread::start()
    8581   \sa stop()
    86 */
     82 */
    8783void QwtSamplingThread::run()
    8884{
    89     d_data->clock.start();
    90     d_data->isStopped = false;
     85    m_data->timer.start();
    9186
    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() )
    9393    {
    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
    9696
    97         if ( d_data->interval > 0.0 )
     97        if ( m_data->msecsInterval > 0.0 )
    9898        {
    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;
    101101
    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 ) );
    104106        }
    105107    }
    106108}
     109
     110#include "moc_qwt_sampling_thread.cpp"
Note: See TracChangeset for help on using the changeset viewer.