pysidesignal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright (C) 2020 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. #ifndef PYSIDE_SIGNAL_H
  4. #define PYSIDE_SIGNAL_H
  5. #include <pysidemacros.h>
  6. #include <sbkpython.h>
  7. #include <basewrapper.h>
  8. #include <QtCore/qlist.h>
  9. #include <QtCore/qmetaobject.h>
  10. QT_BEGIN_NAMESPACE
  11. struct QMetaObject;
  12. class QObject;
  13. QT_END_NAMESPACE
  14. extern "C"
  15. {
  16. extern PYSIDE_API PyTypeObject *PySideSignal_TypeF(void);
  17. extern PYSIDE_API PyTypeObject *PySideSignalInstance_TypeF(void);
  18. // Internal object
  19. struct PYSIDE_API PySideSignal;
  20. struct PySideSignalInstancePrivate;
  21. struct PYSIDE_API PySideSignalInstance
  22. {
  23. PyObject_HEAD
  24. PySideSignalInstancePrivate *d;
  25. };
  26. }; // extern "C"
  27. namespace PySide::Signal {
  28. /**
  29. * This function checks for the PySideSignal type.
  30. *
  31. * @param pyObj
  32. * @return whether pyObj is a PySideSignal
  33. **/
  34. PYSIDE_API bool checkType(PyObject *pyObj);
  35. /**
  36. * This function checks for the PySideSignalInstanceType type.
  37. *
  38. * @param pyObj
  39. * @return Whether pyObj is a PySideSignalInstance
  40. **/
  41. PYSIDE_API bool checkInstanceType(PyObject *pyObj);
  42. /**
  43. * Register all C++ signals of a QObject on Python type.
  44. */
  45. PYSIDE_API void registerSignals(PyTypeObject *pyObj, const QMetaObject *metaObject);
  46. /**
  47. * This function creates a Signal object which stays attached to QObject class based on a list of QMetaMethods
  48. *
  49. * @param source of the Signal to be registered on meta object
  50. * @param methods a list of QMetaMethod wich contains the supported signature
  51. * @return Return a new reference to PyObject* of type PySideSignal
  52. **/
  53. PYSIDE_API PySideSignalInstance *newObjectFromMethod(QObject *sourceQObject, PyObject *source,
  54. const QList<QMetaMethod> &methods);
  55. /**
  56. * This function initializes the Signal object by creating a PySideSignalInstance
  57. *
  58. * @param self a Signal object used as base to PySideSignalInstance
  59. * @param name the name to be used on PySideSignalInstance
  60. * @param object the PyObject where the signal will be attached
  61. * @return Return a new reference to PySideSignalInstance
  62. **/
  63. PYSIDE_API PySideSignalInstance *initialize(PySideSignal *signal, PyObject *name, PyObject *object);
  64. /**
  65. * This function is used to retrieve the object in which the signal is attached
  66. *
  67. * @param self The Signal object
  68. * @return Return the internal reference to the parent object of the signal
  69. **/
  70. PYSIDE_API PyObject *getObject(PySideSignalInstance *signal);
  71. /**
  72. * This function is used to retrieve the signal signature
  73. *
  74. * @param self The Signal object
  75. * @return Return the signal signature
  76. **/
  77. PYSIDE_API const char *getSignature(PySideSignalInstance *signal);
  78. struct EmitterData
  79. {
  80. QObject *emitter = nullptr;
  81. int methodIndex = -1;
  82. };
  83. /// A convenience to retrieve the emitter data from a signal instance
  84. ///
  85. /// @param signal The Signal object
  86. /// @return Data structure
  87. PYSIDE_API EmitterData getEmitterData(PySideSignalInstance *signal);
  88. /**
  89. * This function is used to retrieve the signal signature
  90. *
  91. * @param self The Signal object
  92. * @return Return the signal signature
  93. **/
  94. PYSIDE_API void updateSourceObject(PyObject *source);
  95. /**
  96. * This function verifies if the signature is a QtSignal base on SIGNAL flag
  97. * @param signature The signal signature
  98. * @return Return true if this is a Qt Signal, otherwise return false
  99. **/
  100. PYSIDE_API bool isQtSignal(const char *signature);
  101. /**
  102. * This function is similar to isQtSignal, however if it fails, it'll raise a Python error instead.
  103. *
  104. * @param signature The signal signature
  105. * @return Return true if this is a Qt Signal, otherwise return false
  106. **/
  107. PYSIDE_API bool checkQtSignal(const char *signature);
  108. /**
  109. * This function is used to retrieve the signature base on Signal and receiver callback
  110. * @param signature The signal signature
  111. * @param receiver The QObject which will receive the signal
  112. * @param callback Callback function which will connect to the signal
  113. * @param encodeName Used to specify if the returned signature will be encoded with Qt signal/slot style
  114. * @return Return the callback signature
  115. **/
  116. PYSIDE_API QByteArray getCallbackSignature(QMetaMethod signal, QObject *receiver,
  117. PyObject *callback, bool encodeName);
  118. } // namespace PySide::Signal
  119. #endif