ctkVTKConnection.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 __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. /// Warning the slot must have its signature order:
  25. /// vtkObject*, vtkObject* : sender, callData
  26. /// or
  27. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  28. /// Of course the slot can contain less parameters, but always the same order
  29. /// though.
  30. class CTK_VISUALIZATION_VTK_CORE_EXPORT ctkVTKConnection : public QObject
  31. {
  32. Q_OBJECT
  33. public:
  34. typedef QObject Superclass;
  35. explicit ctkVTKConnection(QObject* parent);
  36. virtual ~ctkVTKConnection();
  37. ///
  38. QString shortDescription();
  39. static QString shortDescription(vtkObject* vtk_obj, unsigned long vtk_event,
  40. const QObject* qt_obj, QString qt_slot = "");
  41. ///
  42. /// Warning the slot must have its signature order:
  43. /// vtkObject*, vtkObject* : sender, callData
  44. /// or
  45. /// vtkObject*, void*, unsigned long, void*: sender, callData, eventId, clientData
  46. /// Of course the slot can contain less parameters, but always the same order
  47. /// though.
  48. void setup(vtkObject* vtk_obj, unsigned long vtk_event,
  49. const QObject* qt_obj, QString qt_slot, float priority = 0.f);
  50. ///
  51. /// Check the validity of the parameters. Parameters must be valid to add
  52. /// a connection
  53. static bool isValid(vtkObject* vtk_obj, unsigned long vtk_event,
  54. const QObject* qt_obj, QString qt_slot);
  55. ///
  56. /// Temporarilly block any signals/slots. If the event is fired, the slot
  57. /// won't be called. You can restore the connection by calling SetBlocked
  58. /// with block = false.
  59. void setBlocked(bool block);
  60. bool isBlocked()const;
  61. ///
  62. bool isEqual(vtkObject* vtk_obj, unsigned long vtk_event,
  63. const QObject* qt_obj, QString qt_slot)const;
  64. ///
  65. /// Return a string uniquely identifying the connection within the current process
  66. QString id()const;
  67. QObject* object()const;
  68. /// false by default, it is slower to observe vtk object deletion
  69. void observeDeletion(bool enable);
  70. bool deletionObserved()const;
  71. signals:
  72. ///
  73. /// The qt signal emited by the VTK Callback
  74. /// The signal corresponding to the slot will be emited
  75. void emitExecute(vtkObject* caller, vtkObject* call_data);
  76. /// Note: even if the signal has a signature with 4 args, you can
  77. /// connect it to a slot with less arguments as long as the types of the
  78. /// argument are matching:
  79. /// connect(obj1,SIGNAL(signalFunc(A,B,C,D)),obj2,SLOT(slotFunc(A)));
  80. void emitExecute(vtkObject* caller, void* call_data, unsigned long vtk_event, void* client_data);
  81. /// The signal is fired when the observed vtk object or the receiving qt
  82. /// object is deleted. It can conveniently connected to the deleteLater
  83. /// slot
  84. void isBroke();
  85. protected slots:
  86. void vtkObjectDeleted();
  87. void qobjectDeleted();
  88. protected:
  89. QScopedPointer<ctkVTKConnectionPrivate> d_ptr;
  90. private:
  91. Q_DECLARE_PRIVATE(ctkVTKConnection);
  92. Q_DISABLE_COPY(ctkVTKConnection);
  93. friend QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  94. };
  95. QDebug operator<<(QDebug dbg, const ctkVTKConnection& connection);
  96. #endif