ctkVTKObjectEventsObserver.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 also returned
  38. /// Warning the slot must have its signature order:
  39. /// vtkObject*, vtkObject* : sender, callData
  40. /// or
  41. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  42. /// Of course the slot can contain less parameters, but always the same order
  43. /// though.
  44. QString addConnection(vtkObject* vtk_obj, unsigned long vtk_event,
  45. const QObject* qt_obj, const char* qt_slot, float priority = 0.0);
  46. ///
  47. /// Utility function that remove a connection on old_vtk_obj and add a connection
  48. /// to vtk_obj (same event, object, slot, priority)
  49. /// Warning the slot must have its signature order:
  50. /// vtkObject*, vtkObject* : sender, callData
  51. /// or
  52. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  53. /// Of course the slot can contain less parameters, but always the same order
  54. /// though.
  55. QString addConnection(vtkObject* old_vtk_obj, vtkObject* vtk_obj, unsigned long vtk_event,
  56. const QObject* qt_obj, const char* qt_slot, float priority = 0.0);
  57. ///
  58. /// Utility function that remove a connection on old_vtk_obj and add a connection
  59. /// to vtk_obj (same event, object, slot, priority)
  60. /// Warning the slot must have its signature order:
  61. /// vtkObject*, vtkObject* : sender, callData
  62. /// or
  63. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  64. /// Of course the slot can contain less parameters, but always the same order
  65. /// though.
  66. QString reconnection(vtkObject* vtk_obj, unsigned long vtk_event,
  67. const QObject* qt_obj, const char* qt_slot,
  68. float priority = 0.0);
  69. ///
  70. /// Remove a connection
  71. int removeConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  72. const QObject* qt_obj = 0, const char* qt_slot = 0);
  73. ///
  74. /// Remove all the connections
  75. inline int removeAllConnections();
  76. ///
  77. /// Temporarilly block all the connection
  78. /// Returns the previous value of connectionsBlocked()
  79. bool blockAllConnections(bool block);
  80. ///
  81. /// Returns true if connections are blocked; otherwise returns false.
  82. /// Connections are not blocked by default.
  83. bool connectionsBlocked()const;
  84. ///
  85. /// Block/Unblock one or multiple connection.
  86. /// Return the number of connections blocked/unblocked
  87. int blockConnection(bool block, vtkObject* vtk_obj,
  88. unsigned long vtk_event, const QObject* qt_obj);
  89. /// Block/Unblock a connection
  90. /// Return true if the connection exists and was blocked, otherwise returns
  91. /// false.
  92. bool blockConnection(const QString& id, bool blocked);
  93. /// Return true if there is at least 1 connection that match the parameter
  94. bool containsConnection(vtkObject* vtk_obj, unsigned long vtk_event = vtkCommand::NoEvent,
  95. const QObject* qt_obj =0, const char* qt_slot =0)const;
  96. protected:
  97. QScopedPointer<ctkVTKObjectEventsObserverPrivate> d_ptr;
  98. private:
  99. Q_DECLARE_PRIVATE(ctkVTKObjectEventsObserver);
  100. Q_DISABLE_COPY(ctkVTKObjectEventsObserver);
  101. };
  102. //-----------------------------------------------------------------------------
  103. int ctkVTKObjectEventsObserver::removeAllConnections()
  104. {
  105. return this->removeConnection(0, vtkCommand::NoEvent, 0, 0);
  106. }
  107. #endif