ctkVTKConnection.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.apache.org/licenses/LICENSE-2.0.txt
  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 __ctkVTKConnection_h
  15. #define __ctkVTKConnection_h
  16. // Qt includes
  17. #include <QObject>
  18. #include <QVector>
  19. // CTK includes
  20. #include <ctkPimpl.h>
  21. #include "ctkVisualizationVTKCoreExport.h"
  22. class vtkObject;
  23. class ctkVTKConnectionPrivate;
  24. class vtkCallbackCommand;
  25. /// \ingroup Visualization_VTK_Core
  26. /// Warning the slot must have its signature order:
  27. /// vtkObject*, vtkObject* : sender, callData
  28. /// or
  29. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  30. /// Of course the slot can contain less parameters, but always the same order
  31. /// though.
  32. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKConnection : public QObject
  33. {
  34. Q_OBJECT
  35. public:
  36. typedef QObject Superclass;
  37. explicit ctkVTKConnection(QObject* parent);
  38. virtual ~ctkVTKConnection();
  39. ///
  40. QString shortDescription();
  41. static QString shortDescription(vtkObject* vtk_obj, unsigned long vtk_event,
  42. const QObject* qt_obj, const char* qt_slot = 0);
  43. ///
  44. /// Warning the slot must have its signature order:
  45. /// vtkObject*, vtkObject* : sender, callData
  46. /// or
  47. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  48. /// Of course the slot can contain less parameters, but always the same order
  49. /// though.
  50. /// \sa object(), vtkobject()
  51. void setup(vtkObject* vtk_obj, unsigned long vtk_event,
  52. const QObject* qt_obj, const char* qt_slot, float priority = 0.f,
  53. Qt::ConnectionType connectionType = Qt::AutoConnection);
  54. ///
  55. /// Check the validity of the parameters. Parameters must be valid to add
  56. /// a connection
  57. static bool isValid(vtkObject* vtk_obj, unsigned long vtk_event,
  58. const QObject* qt_obj, const char* qt_slot);
  59. ///
  60. /// Temporarilly block any signals/slots. If the event is fired, the slot
  61. /// won't be called. You can restore the connection by calling SetBlocked
  62. /// with block = false.
  63. void setBlocked(bool block);
  64. bool isBlocked()const;
  65. ///
  66. bool isEqual(vtkObject* vtk_obj, unsigned long vtk_event,
  67. const QObject* qt_obj, const char* qt_slot)const;
  68. ///
  69. /// Return a string uniquely identifying the connection within the current process
  70. QString id()const;
  71. ///
  72. /// Return the QObject set using setup() method.
  73. QObject* object()const;
  74. /// Return the vtkObject set using setup() method.
  75. vtkObject* vtkobject() const;
  76. /// false by default, it is slower to observe vtk object deletion
  77. void observeDeletion(bool enable);
  78. bool deletionObserved()const;
  79. Q_SIGNALS:
  80. ///
  81. /// The qt signal emited by the VTK Callback
  82. /// The signal corresponding to the slot will be emited
  83. void emitExecute(vtkObject* caller, vtkObject* call_data);
  84. /// Note: even if the signal has a signature with 4 args, you can
  85. /// connect it to a slot with less arguments as long as the types of the
  86. /// argument are matching:
  87. /// connect(obj1,SIGNAL(signalFunc(A,B,C,D)),obj2,SLOT(slotFunc(A)));
  88. void emitExecute(vtkObject* caller, void* call_data, unsigned long vtk_event, void* client_data);
  89. protected Q_SLOTS:
  90. void vtkObjectDeleted();
  91. void qobjectDeleted();
  92. protected:
  93. QScopedPointer<ctkVTKConnectionPrivate> d_ptr;
  94. ctkVTKConnection(ctkVTKConnectionPrivate* pimpl, QObject* _parent);
  95. void disconnect();
  96. virtual void addObserver(vtkObject* caller, unsigned long vtk_event, vtkCallbackCommand* callback, float priority=0.0f);
  97. virtual void removeObserver(vtkObject* caller, unsigned long vtk_event, vtkCallbackCommand* callback);
  98. private:
  99. Q_DECLARE_PRIVATE(ctkVTKConnection);
  100. Q_DISABLE_COPY(ctkVTKConnection);
  101. friend QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  102. };
  103. /// \ingroup Visualization_VTK_Core
  104. QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  105. #endif