Index: trunk/BNC/qwt/qwt_sampling_thread.cpp
===================================================================
--- trunk/BNC/qwt/qwt_sampling_thread.cpp	(revision 4271)
+++ trunk/BNC/qwt/qwt_sampling_thread.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -9,23 +9,19 @@
 
 #include "qwt_sampling_thread.h"
-#include "qwt_system_clock.h"
+#include <qelapsedtimer.h>
 
 class QwtSamplingThread::PrivateData
 {
-public:
-    QwtSystemClock clock;
-
-    double interval;
-    bool isStopped;
+  public:
+    QElapsedTimer timer;
+    double msecsInterval;
 };
 
-
 //! Constructor
-QwtSamplingThread::QwtSamplingThread( QObject *parent ):
-    QThread( parent )
+QwtSamplingThread::QwtSamplingThread( QObject* parent )
+    : QThread( parent )
 {
-    d_data = new PrivateData;
-    d_data->interval = 1000; // 1 second
-    d_data->isStopped = true;
+    m_data = new PrivateData;
+    m_data->msecsInterval = 1e3; // 1 second
 }
 
@@ -33,5 +29,5 @@
 QwtSamplingThread::~QwtSamplingThread()
 {
-    delete d_data;
+    delete m_data;
 }
 
@@ -40,13 +36,13 @@
    The default interval is 1000.0 ( = 1s )
 
-   \param interval Interval
+   \param msecs Interval
    \sa interval()
-*/
-void QwtSamplingThread::setInterval( double interval )
+ */
+void QwtSamplingThread::setInterval( double msecs )
 {
-    if ( interval < 0.0 )
-        interval = 0.0;
+    if ( msecs < 0.0 )
+        msecs = 0.0;
 
-    d_data->interval = interval;
+    m_data->msecsInterval = msecs;
 }
 
@@ -54,8 +50,8 @@
    \return Interval (in ms), between 2 calls of sample()
    \sa setInterval()
-*/
+ */
 double QwtSamplingThread::interval() const
 {
-    return d_data->interval;
+    return m_data->msecsInterval;
 }
 
@@ -63,11 +59,11 @@
    \return Time (in ms) since the thread was started
    \sa QThread::start(), run()
-*/
+ */
 double QwtSamplingThread::elapsed() const
 {
-    if ( d_data->isStopped )
-        return 0.0;
+    if ( m_data->timer.isValid() )
+        return m_data->timer.nsecsElapsed() / 1e6;
 
-    return d_data->clock.elapsed();
+    return 0.0;
 }
 
@@ -75,8 +71,8 @@
    Terminate the collecting thread
    \sa QThread::start(), run()
-*/
+ */
 void QwtSamplingThread::stop()
 {
-    d_data->isStopped = true;
+    m_data->timer.invalidate();
 }
 
@@ -84,23 +80,31 @@
    Loop collecting samples started from QThread::start()
    \sa stop()
-*/
+ */
 void QwtSamplingThread::run()
 {
-    d_data->clock.start();
-    d_data->isStopped = false;
+    m_data->timer.start();
 
-    while ( !d_data->isStopped )
+    /*
+        We should have all values in nsecs/qint64, but
+        this would break existing code. TODO ...
+        Anyway - for QThread::usleep we even need microseconds( usecs )
+     */
+    while ( m_data->timer.isValid() )
     {
-        const double elapsed = d_data->clock.elapsed();
-        sample( elapsed / 1000.0 );
+        const qint64 timestamp = m_data->timer.nsecsElapsed();
+        sample( timestamp / 1e9 ); // seconds
 
-        if ( d_data->interval > 0.0 )
+        if ( m_data->msecsInterval > 0.0 )
         {
-            const double msecs =
-                d_data->interval - ( d_data->clock.elapsed() - elapsed );
+            const double interval = m_data->msecsInterval * 1e3;
+            const double elapsed = ( m_data->timer.nsecsElapsed() - timestamp ) / 1e3;
 
-            if ( msecs > 0.0 )
-                usleep( qRound( 1000.0 * msecs ) );
+            const double usecs = interval - elapsed;
+
+            if ( usecs > 0.0 )
+                QThread::usleep( qRound( usecs ) );
         }
     }
 }
+
+#include "moc_qwt_sampling_thread.cpp"
