ctkVTKConnection.h 3.3 KB

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