ctkVTKConnection.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. void setup(vtkObject* vtk_obj, unsigned long vtk_event,
  51. const QObject* qt_obj, const char* qt_slot, float priority = 0.f,
  52. Qt::ConnectionType connectionType = Qt::AutoConnection);
  53. ///
  54. /// Check the validity of the parameters. Parameters must be valid to add
  55. /// a connection
  56. static bool isValid(vtkObject* vtk_obj, unsigned long vtk_event,
  57. const QObject* qt_obj, const char* qt_slot);
  58. ///
  59. /// Temporarilly block any signals/slots. If the event is fired, the slot
  60. /// won't be called. You can restore the connection by calling SetBlocked
  61. /// with block = false.
  62. void setBlocked(bool block);
  63. bool isBlocked()const;
  64. ///
  65. bool isEqual(vtkObject* vtk_obj, unsigned long vtk_event,
  66. const QObject* qt_obj, const char* qt_slot)const;
  67. ///
  68. /// Return a string uniquely identifying the connection within the current process
  69. QString id()const;
  70. QObject* object()const;
  71. /// false by default, it is slower to observe vtk object deletion
  72. void observeDeletion(bool enable);
  73. bool deletionObserved()const;
  74. Q_SIGNALS:
  75. ///
  76. /// The qt signal emited by the VTK Callback
  77. /// The signal corresponding to the slot will be emited
  78. void emitExecute(vtkObject* caller, vtkObject* call_data);
  79. /// Note: even if the signal has a signature with 4 args, you can
  80. /// connect it to a slot with less arguments as long as the types of the
  81. /// argument are matching:
  82. /// connect(obj1,SIGNAL(signalFunc(A,B,C,D)),obj2,SLOT(slotFunc(A)));
  83. void emitExecute(vtkObject* caller, void* call_data, unsigned long vtk_event, void* client_data);
  84. /// The signal is fired when the observed vtk object or the receiving qt
  85. /// object is deleted. It can conveniently connected to the deleteLater
  86. /// slot
  87. void isBroke();
  88. protected Q_SLOTS:
  89. void vtkObjectDeleted();
  90. void qobjectDeleted();
  91. protected:
  92. QScopedPointer<ctkVTKConnectionPrivate> d_ptr;
  93. void disconnect();
  94. virtual void addObserver(vtkObject* caller, unsigned long vtk_event, vtkCallbackCommand* callback, float priority=0.0f);
  95. virtual void removeObserver(vtkObject* caller, unsigned long vtk_event, vtkCallbackCommand* callback);
  96. private:
  97. Q_DECLARE_PRIVATE(ctkVTKConnection);
  98. Q_DISABLE_COPY(ctkVTKConnection);
  99. friend QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  100. };
  101. /// \ingroup Visualization_VTK_Core
  102. QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  103. #endif