Explorar o código

Added missing disconnect methods in ctkPluginContext.

Sascha Zelzer %!s(int64=13) %!d(string=hai) anos
pai
achega
e252fe46e6

+ 24 - 5
Libs/PluginFramework/ctkPluginContext.cpp

@@ -175,7 +175,7 @@ bool ctkPluginContext::ungetService(const ctkServiceReference& reference)
 }
 
 //----------------------------------------------------------------------------
-bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char* method,
+bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char* slot,
                                              Qt::ConnectionType type)
 {
   Q_D(ctkPluginContext);
@@ -183,11 +183,11 @@ bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char
   // TODO check permissions for a direct connection
   if (type == Qt::DirectConnection || type == Qt::BlockingQueuedConnection)
   {
-    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedDirect(ctkPluginEvent)), method, type);
+    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedDirect(ctkPluginEvent)), slot, type);
   }
   else if (type == Qt::QueuedConnection)
   {
-    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedQueued(ctkPluginEvent)), method, type);
+    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedQueued(ctkPluginEvent)), slot, type);
   }
   else
   {
@@ -196,12 +196,31 @@ bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char
 }
 
 //----------------------------------------------------------------------------
-bool ctkPluginContext::connectFrameworkListener(const QObject* receiver, const char* method, Qt::ConnectionType type)
+void ctkPluginContext::disconnectPluginListener(const QObject *receiver, const char* slot)
+{
+  Q_D(ctkPluginContext);
+  d->isPluginContextValid();
+
+  QObject::disconnect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedDirect(ctkPluginEvent)), receiver, slot);
+  QObject::disconnect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedQueued(ctkPluginEvent)), receiver, slot);
+}
+
+//----------------------------------------------------------------------------
+bool ctkPluginContext::connectFrameworkListener(const QObject* receiver, const char* slot, Qt::ConnectionType type)
 {
   Q_D(ctkPluginContext);
   d->isPluginContextValid();
   // TODO check permissions for a direct connection
-  return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(frameworkEvent(ctkPluginFrameworkEvent)), method, type);
+  return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(frameworkEvent(ctkPluginFrameworkEvent)), slot, type);
+}
+
+//----------------------------------------------------------------------------
+void ctkPluginContext::disconnectFrameworkListener(const QObject *receiver, const char* slot)
+{
+  Q_D(ctkPluginContext);
+  d->isPluginContextValid();
+
+  QObject::disconnect(&(d->plugin->fwCtx->listeners), SIGNAL(frameworkEvent(ctkPluginFrameworkEvent)), receiver, slot);
 }
 
 //----------------------------------------------------------------------------

+ 30 - 0
Libs/PluginFramework/ctkPluginContext.h

@@ -614,6 +614,21 @@ public:
   bool connectPluginListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
 
   /**
+   * Disconnects the specified <code>slot</code> from the context
+   * plugin.
+   *
+   * <p>
+   * If <code>slot</code> is not connected to the context plugin,
+   * this method does nothing.
+   *
+   * @param receiver The object which has previously connected <code>slot</code>.
+   * @param slot The Qt slot to be disconnected. If <code>NULL</code>, all slots
+   *        previously connected via connectPluginListener are disconnected.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
+   */
+  void disconnectPluginListener(const QObject* receiver, const char* slot = 0);
+
+  /**
    * Connects the specified <code>slot</code> to the context
    * plugin's signal which emits general Framework events. The signature
    * of the slot must be "slotName(ctkPluginFrameworkEvent)".
@@ -631,6 +646,21 @@ public:
   bool connectFrameworkListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
 
   /**
+   * Disconnects the specified <code>slot</slot> from the context
+   * plugin.
+   *
+   * <p>
+   * If <code>slot</code> is not connected to the context plugin,
+   * this method does nothing.
+   *
+   * @param receiver The object which has previously connected <code>slot</code>.
+   * @param slot The Qt slot to be disconnected. If <code>NULL</code>, all slots
+   *        previously connected via connectFrameworkListener are disconnected.
+   * @throws ctkIllegalStateException If this ctkPluginContext is no longer valid.
+   */
+  void disconnectFrameworkListener(const QObject* receiver, const char* slot = 0);
+
+  /**
    * Connects the specified <code>slot</code> with the
    * specified <code>filter</code> to the context plugins's signal emitting
    * service events when a service has a lifecycle state change. The signature