ctkVTKObjectEventsObserver.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkVTKObjectEventsObserver_h
  15. #define __ctkVTKObjectEventsObserver_h
  16. /// CTK includes
  17. #include <ctkPimpl.h>
  18. /// Qt includes
  19. #include <QObject>
  20. #include <QList>
  21. #include <QString>
  22. /// VTK includes
  23. #include <vtkCommand.h>
  24. #include "ctkVisualizationVTKCoreExport.h"
  25. class ctkVTKConnection;
  26. class vtkObject;
  27. class ctkVTKObjectEventsObserverPrivate;
  28. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKObjectEventsObserver : public QObject
  29. {
  30. Q_OBJECT
  31. public:
  32. typedef QObject Superclass;
  33. explicit ctkVTKObjectEventsObserver(QObject* parent = 0);
  34. virtual ~ctkVTKObjectEventsObserver();
  35. virtual void printAdditionalInfo();
  36. ///
  37. /// Add a connection, an Id allowing to uniquely identify the connection is
  38. /// returned. It is a no-op if vtk_obj is NULL, the parameters are invalid or
  39. /// if the connection already exist.
  40. /// Warning the slot must have its signature order:
  41. /// vtkObject*, vtkObject* : sender, callData
  42. /// or
  43. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  44. /// Of course the slot can contain less parameters, but always the same order
  45. /// though.
  46. QString addConnection(vtkObject* vtk_obj, unsigned long vtk_event,
  47. const QObject* qt_obj, const char* qt_slot, float priority = 0.0);
  48. ///
  49. /// Utility function that remove a connection on old_vtk_obj and add a connection
  50. /// to vtk_obj (same event, object, slot, priority)
  51. /// Warning the slot must have its signature order:
  52. /// vtkObject*, vtkObject* : sender, callData
  53. /// or
  54. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  55. /// Of course the slot can contain less parameters, but always the same order
  56. /// though.
  57. QString addConnection(vtkObject* old_vtk_obj, vtkObject* vtk_obj, unsigned long vtk_event,
  58. const QObject* qt_obj, const char* qt_slot, float priority = 0.0);
  59. ///
  60. /// Utility function that remove a connection on old_vtk_obj and add a connection
  61. /// to vtk_obj (same event, object, slot, priority)
  62. /// Warning the slot must have its signature order:
  63. /// vtkObject*, vtkObject* : sender, callData
  64. /// or
  65. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  66. /// Of course the slot can contain less parameters, but always the same order
  67. /// though.
  68. QString reconnection(vtkObject* vtk_obj, unsigned long vtk_event,
  69. const QObject* qt_obj, const char* qt_slot,
  70. float priority = 0.0);
  71. ///
  72. /// Remove a connection
  73. int removeConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  74. const QObject* qt_obj = 0, const char* qt_slot = 0);
  75. ///
  76. /// Remove all the connections
  77. inline int removeAllConnections();
  78. ///
  79. /// Temporarilly block all the connection
  80. /// Returns the previous value of connectionsBlocked()
  81. bool blockAllConnections(bool block);
  82. ///
  83. /// Returns true if connections are blocked; otherwise returns false.
  84. /// Connections are not blocked by default.
  85. bool connectionsBlocked()const;
  86. ///
  87. /// Block/Unblock one or multiple connection.
  88. /// Return the number of connections blocked/unblocked
  89. int blockConnection(bool block, vtkObject* vtk_obj,
  90. unsigned long vtk_event, const QObject* qt_obj);
  91. /// Block/Unblock a connection
  92. /// Return true if the connection exists and was blocked, otherwise returns
  93. /// false.
  94. bool blockConnection(const QString& id, bool blocked);
  95. /// Return true if there is at least 1 connection that match the parameter
  96. bool containsConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  97. const QObject* qt_obj =0, const char* qt_slot =0)const;
  98. protected:
  99. QScopedPointer<ctkVTKObjectEventsObserverPrivate> d_ptr;
  100. private:
  101. Q_DECLARE_PRIVATE(ctkVTKObjectEventsObserver);
  102. Q_DISABLE_COPY(ctkVTKObjectEventsObserver);
  103. };
  104. //-----------------------------------------------------------------------------
  105. int ctkVTKObjectEventsObserver::removeAllConnections()
  106. {
  107. return this->removeConnection(0, vtkCommand::NoEvent, 0, 0);
  108. }
  109. #endif