From a9174d2daf0cb8a9ecace0f82df235f4518ae534 Mon Sep 17 00:00:00 2001 From: Hannes Matuschek Date: Tue, 2 Dec 2014 21:07:57 +0100 Subject: [PATCH] Fixed Queue to allow for removal of callbacks. --- src/gui/waterfallview.cc | 2 -- src/queue.hh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/gui/waterfallview.cc b/src/gui/waterfallview.cc index b8c13e6..c5f36af 100644 --- a/src/gui/waterfallview.cc +++ b/src/gui/waterfallview.cc @@ -188,8 +188,6 @@ WaterFallView::paintEvent(QPaintEvent *evt) QRect exposedRect = painter.matrix().inverted() .mapRect(evt->rect()) .adjusted(-1, -1, 1, 1); - qDebug() << "Draw " << QRect(0,0,_N,_M) << " at " - << painter.matrix().mapRect(QRect(0,0,_N,_M)); // the adjust is to account for half pixels along edges painter.drawPixmap(exposedRect, _waterfall, exposedRect); //painter.drawPixmap(0,0, _waterfall); diff --git a/src/queue.hh b/src/queue.hh index 3e429ac..27fe597 100644 --- a/src/queue.hh +++ b/src/queue.hh @@ -5,6 +5,7 @@ #include #include "buffer.hh" #include +#include namespace sdr { @@ -17,6 +18,7 @@ class DelegateInterface { public: /** Call back interface. */ virtual void operator() () = 0; + virtual void *instance() = 0; }; /** Specific delegate to a method of an object . */ @@ -30,6 +32,8 @@ public: virtual ~Delegate() {} /** Callback, simply calls the method of the instance given to the constructor. */ virtual void operator() () { (_instance->*_function)(); } + virtual void *instance() { return _instance; } + protected: /** The instance. */ T *_instance; @@ -122,18 +126,53 @@ public: _idle.push_back(new Delegate(instance, function)); } + template + void remIdle(T *instance) { + std::list::iterator item = _idle.begin(); + while (item != _idle.end()) { + if ( (*item)->instance() == ((void *)instance)) { + item = _idle.erase(item); + } else { + item++; + } + } + } + /** Adds a callback to the start event. The method gets called once the queue loop is started. */ template void addStart(T *instance, void (T::*function)(void)) { _onStart.push_back(new Delegate(instance, function)); } + template + void remStart(T *instance) { + std::list::iterator item = _onStart.begin(); + while (item != _onStart.end()) { + if ( (*item)->instance() == ((void *)instance)) { + item = _onStart.erase(item); + } else { + item++; + } + } + } + /** Adds a callback to the stop event. The method gets called once the queue loop is stopped. */ template void addStop(T *instance, void (T::*function)(void)) { _onStop.push_back(new Delegate(instance, function)); } + template + void remStop(T *instance) { + std::list::iterator item = _onStop.begin(); + while (item != _onStop.end()) { + if ( (*item)->instance() == ((void *)instance)) { + item = _onStop.erase(item); + } else { + item++; + } + } + } protected: /** The actual queue loop. */