]> git.lyx.org Git - features.git/commitdiff
simplify class structure
authorAndré Pönitz <poenitz@gmx.net>
Mon, 12 Nov 2007 20:18:19 +0000 (20:18 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 12 Nov 2007 20:18:19 +0000 (20:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21554 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/Timeout.cpp
src/support/Timeout.h

index e2123ac7bcdbc0c7f0e080035da62e4622f74cbe..9c16b595ad85aa8e11c8ccb77faf86297a1a62d9 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.
  *
@@ -23,46 +23,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,13 +58,7 @@ 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;
@@ -84,7 +66,7 @@ void qtTimeout::start()
 }
 
 
-void qtTimeout::stop()
+void Timeout::Impl::stop()
 {
        if (running())
                reset();
@@ -92,12 +74,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,7 +126,7 @@ void Timeout::emit()
 Timeout & Timeout::setType(Type t)
 {
        type = t;
-       return * this;
+       return *this;
 }
 
 
@@ -148,7 +136,7 @@ Timeout & Timeout::setTimeout(unsigned int msec)
        BOOST_ASSERT(msec);
 
        timeout_ms = msec;
-       return * this;
+       return *this;
 }
 
 
index 62118b20ff3a691aa730f457068024583291ca3b..28b00333be1e09c09000cc2f3d668ed1674afa70 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file qtTimeout.h
+ * \file Timeout.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -48,42 +48,16 @@ public:
        /// set the timeout value
        Timeout & setTimeout(unsigned int msec);
 
-       /** Base class for the GUI implementation.
-           It must be public so that C callback functions can access its
-           daughter classes.
-        */
-       class Impl
-       {
-       public:
-               ///
-               Impl(Timeout & owner) : owner_(owner) {}
-               ///
-               virtual ~Impl() {}
-               /// Is the timer running?
-               virtual bool running() const = 0;
-               /// start the timer
-               virtual void start() = 0;
-               /// stop the timer
-               virtual void stop() = 0;
-               /// reset
-               virtual void reset() = 0;
-
-       protected:
-               ///
-               void emit() { owner_.emit(); }
-               ///
-               unsigned int timeout_ms() const { return owner_.timeout_ms; }
-
-       private:
-               ///
-               Timeout & owner_;
-       };
-
 private:
+       /// noncopyable
+       Timeout(Timeout const &);
+       void operator=(Timeout const &);
+       ///
+       class Impl;
        ///
        friend class Impl;
        ///
-       boost::scoped_ptr<Impl> const pimpl_;
+       Impl * const pimpl_;
        /// one-shot or repeating
        Type type;
        /// timeout value in milliseconds