pysidevariantutils.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2025 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 PYSIDEVARIANTUTILS_H
  4. #define PYSIDEVARIANTUTILS_H
  5. #include <sbkpython.h>
  6. #include <pysidemacros.h>
  7. #include <QtCore/qvariant.h>
  8. #include <QtCore/qvariantlist.h>
  9. #include <optional>
  10. namespace PySide::Variant
  11. {
  12. /// Return a QMetaType for a PyTypeObject for purposes of
  13. /// converting to a QVariant.
  14. PYSIDE_API QMetaType resolveMetaType(PyTypeObject *type);
  15. /// Convert a heterogenous Python list to a QVariantList by converting each
  16. /// item using the QVariant converter.
  17. PYSIDE_API std::optional<QVariantList> pyListToVariantList(PyObject *list);
  18. /// Converts a list to a QVariant following the PySide semantics:
  19. /// - A list of strings is returned as QVariant<QStringList>
  20. /// - A list of convertible values is returned as QVariant<QList<Value>>
  21. /// - Remaining types are returned as QVariant(QVariantList)
  22. PYSIDE_API QVariant convertToVariantList(PyObject *list);
  23. /// Converts a map to a QVariantMap (string keys and QVariant values)
  24. PYSIDE_API QVariant convertToVariantMap(PyObject *map);
  25. } // namespace PySide::Variant
  26. #endif // PYSIDEVARIANTUTILS_H