]> git.lyx.org Git - lyx.git/blobdiff - src/support/Timeout.cpp
add onoff support for "inset-modify changetype xxx" in include inset
[lyx.git] / src / support / Timeout.cpp
index e2123ac7bcdbc0c7f0e080035da62e4622f74cbe..127d3bd008d6680f72987b35e2e6c80244d3b0ea 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file qtTimeout.cpp
+ * \file Timeout.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 
 #include <config.h>
 
+#include "support/lassert.h"
+#include "support/Timeout.h"
+#include "support/debug.h"
+
 #include <QObject>
 #include <QTimerEvent>
 
-#include "debug.h"
-#include "Timeout.h"
-
+using namespace std;
 
 namespace lyx {
 
@@ -23,46 +25,34 @@ namespace lyx {
  * This class executes the callback when the timeout expires
  * using Qt mechanisms
  */
-class qtTimeout : QObject, public Timeout::Impl {
+class Timeout::Impl : QObject {
 public:
        ///
-       qtTimeout(Timeout & owner_);
+       Impl(Timeout & owner) : owner_(owner), timeout_id(-1) {}
        ///
-       virtual bool running() const;
+       bool running() const { return timeout_id != -1; }
        /// start the timer
-       virtual void start();
+       void start();
        /// stop the timer
-       virtual void stop();
+       void stop();
        /// reset
-       virtual void reset();
+       void reset();
+       ///
+       unsigned int timeout_ms() const { return owner_.timeout_ms; }
 
 protected:
-       /// slot
-       virtual void timerEvent(QTimerEvent *);
+       ///
+       void timerEvent(QTimerEvent *) { owner_.emit(); }
 
 private:
+       ///
+       Timeout & owner_;
        /// timout id
        int timeout_id;
 };
 
 
-Timeout::Timeout(unsigned int msec, Type t)
-       : pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
-{}
-
-
-qtTimeout::qtTimeout(Timeout & owner)
-       : Timeout::Impl(owner), timeout_id(-1)
-{}
-
-
-void qtTimeout::timerEvent(QTimerEvent *)
-{
-       emit();
-}
-
-
-void qtTimeout::reset()
+void Timeout::Impl::reset()
 {
        if (timeout_id != -1)
                killTimer(timeout_id);
@@ -70,21 +60,15 @@ void qtTimeout::reset()
 }
 
 
-bool qtTimeout::running() const
-{
-       return timeout_id != -1;
-}
-
-
-void qtTimeout::start()
+void Timeout::Impl::start()
 {
        if (running())
-               lyxerr << "Timeout::start: already running!" << std::endl;
+               lyxerr << "Timeout::start: already running!" << endl;
        timeout_id = startTimer(timeout_ms());
 }
 
 
-void qtTimeout::stop()
+void Timeout::Impl::stop()
 {
        if (running())
                reset();
@@ -92,12 +76,18 @@ void qtTimeout::stop()
 
 
 //
-// Timeoute
+// Timeout
 //
 
+Timeout::Timeout(unsigned int msec, Type t)
+       : pimpl_(new Impl(*this)), type(t), timeout_ms(msec)
+{}
+
+
 Timeout::~Timeout()
 {
        pimpl_->stop();
+       delete pimpl_;
 }
 
 
@@ -138,17 +128,17 @@ void Timeout::emit()
 Timeout & Timeout::setType(Type t)
 {
        type = t;
-       return * this;
+       return *this;
 }
 
 
 Timeout & Timeout::setTimeout(unsigned int msec)
 {
        // Can't have a timeout of zero!
-       BOOST_ASSERT(msec);
+       LASSERT(msec, /**/);
 
        timeout_ms = msec;
-       return * this;
+       return *this;
 }