pysideqobject.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2021 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 PYSIDEQOBJECT_H
  4. #define PYSIDEQOBJECT_H
  5. #include <sbkpython.h>
  6. #include <pysidemacros.h>
  7. #include <QtCore/qtclasshelpermacros.h>
  8. #include <cstddef>
  9. QT_FORWARD_DECLARE_CLASS(QObject)
  10. QT_FORWARD_DECLARE_STRUCT(QMetaObject)
  11. QT_FORWARD_DECLARE_CLASS(QMutex)
  12. namespace PySide
  13. {
  14. /// Fill QObject properties and do signal connections using the values found in \p kwds dictionary.
  15. /// \param qObj PyObject fot the QObject.
  16. /// \param metaObj QMetaObject of \p qObj.
  17. /// \param kwds key->value dictonary.
  18. /// \return True if everything goes well, false with a Python error set otherwise.
  19. PYSIDE_API bool fillQtProperties(PyObject *qObj, const QMetaObject *metaObj,
  20. PyObject *kwds, bool allowErrors);
  21. /// Initialize the DynamicMetaObject helper for a wrapped Qt type (generated code)
  22. PYSIDE_API void initDynamicMetaObject(PyTypeObject *type, const QMetaObject *base,
  23. std::size_t cppObjSize);
  24. /// Initialize a Python-derived type
  25. PYSIDE_API void initQObjectSubType(PyTypeObject *type, PyObject *args, PyObject *kwds);
  26. /// Return the size in bytes of a type that inherits QObject.
  27. PYSIDE_API std::size_t getSizeOfQObject(PyTypeObject *type);
  28. /// Check if a PyTypeObject or its bases contains a QObject
  29. /// \param pyType is the PyTypeObject to check
  30. /// \param raiseError controls if a TypeError is raised when an object does not
  31. /// inherit QObject
  32. PYSIDE_API bool isQObjectDerived(PyTypeObject *pyType, bool raiseError);
  33. /// Convenience to convert a PyObject to QObject
  34. PYSIDE_API QObject *convertToQObject(PyObject *object, bool raiseError);
  35. /// Check for properties and signals registered on MetaObject and return these.
  36. /// Also handle Python properties when true_property was selected.
  37. /// \param cppSelf Is the QObject which contains the metaobject
  38. /// \param self Python object of cppSelf
  39. /// \param name Name of the argument which the function will try retrieve from MetaData
  40. /// \return The Python object which contains the Data obtained in metaObject or the Python
  41. /// method pulled out of a Python property.
  42. PYSIDE_API PyObject *getHiddenDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *name);
  43. /// Mutex for accessing QObject memory helpers from multiple threads
  44. PYSIDE_API QMutex &nextQObjectMemoryAddrMutex();
  45. PYSIDE_API void *nextQObjectMemoryAddr();
  46. /// Set the address where to allocate the next QObject (for QML)
  47. PYSIDE_API void setNextQObjectMemoryAddr(void *addr);
  48. PYSIDE_API PyObject *getWrapperForQObject(QObject *cppSelf, PyTypeObject *sbk_type);
  49. /// Return the best-matching type for a QObject (Helper for QObject.findType())
  50. /// \param cppSelf QObject instance
  51. /// \return type object
  52. PYSIDE_API PyTypeObject *getTypeForQObject(const QObject *cppSelf);
  53. } //namespace PySide
  54. #endif // PYSIDEQOBJECT_H