qpybluetooth_qlist.sip 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // This is the SIP interface definition for the QList based mapped types
  2. // specific to the QtBluetooth module.
  3. //
  4. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  5. //
  6. // This file is part of PyQt6.
  7. //
  8. // This file may be used under the terms of the GNU General Public License
  9. // version 3.0 as published by the Free Software Foundation and appearing in
  10. // the file LICENSE included in the packaging of this file. Please review the
  11. // following information to ensure the GNU General Public License version 3.0
  12. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  13. //
  14. // If you do not wish to use this file under the terms of the GPL version 3.0
  15. // then you may purchase a commercial license. For more information contact
  16. // info@riverbankcomputing.com.
  17. //
  18. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  19. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. %If (Qt_6_2_0 -)
  21. // QBluetoothServiceInfo::Sequence is actually a sub-class of QList<QVariant>.
  22. // Note that QBluetoothServiceInfo::Alternative is identical and they are both
  23. // syntactic sugar. By ignoring methods using the latter then everything works
  24. // as expected.
  25. %MappedType QBluetoothServiceInfo::Sequence
  26. /TypeHintIn="Iterable[QVariant]", TypeHintOut="List[QVariant]",
  27. TypeHintValue="[]"/
  28. {
  29. %TypeHeaderCode
  30. #include <qbluetoothserviceinfo.h>
  31. %End
  32. %ConvertFromTypeCode
  33. PyObject *l = PyList_New(sipCpp->size());
  34. if (!l)
  35. return 0;
  36. for (int i = 0; i < sipCpp->size(); ++i)
  37. {
  38. QVariant *t = new QVariant(sipCpp->at(i));
  39. PyObject *tobj = sipConvertFromNewType(t, sipType_QVariant,
  40. sipTransferObj);
  41. if (!tobj)
  42. {
  43. delete t;
  44. Py_DECREF(l);
  45. return 0;
  46. }
  47. PyList_SetItem(l, i, tobj);
  48. }
  49. return l;
  50. %End
  51. %ConvertToTypeCode
  52. PyObject *iter = PyObject_GetIter(sipPy);
  53. if (!sipIsErr)
  54. {
  55. PyErr_Clear();
  56. Py_XDECREF(iter);
  57. return (iter && !PyBytes_Check(sipPy) && !PyUnicode_Check(sipPy));
  58. }
  59. if (!iter)
  60. {
  61. *sipIsErr = 1;
  62. return 0;
  63. }
  64. QBluetoothServiceInfo::Sequence *ql = new QBluetoothServiceInfo::Sequence;
  65. for (Py_ssize_t i = 0; ; ++i)
  66. {
  67. PyErr_Clear();
  68. PyObject *itm = PyIter_Next(iter);
  69. if (!itm)
  70. {
  71. if (PyErr_Occurred())
  72. {
  73. delete ql;
  74. Py_DECREF(iter);
  75. *sipIsErr = 1;
  76. return 0;
  77. }
  78. break;
  79. }
  80. int state;
  81. QVariant *t = reinterpret_cast<QVariant *>(
  82. sipForceConvertToType(itm, sipType_QVariant, sipTransferObj,
  83. SIP_NOT_NONE, &state, sipIsErr));
  84. if (*sipIsErr)
  85. {
  86. PyErr_Format(PyExc_TypeError,
  87. "index %zd has type '%s' but '_TYPE_' is expected", i,
  88. sipPyTypeName(Py_TYPE(itm)));
  89. Py_DECREF(itm);
  90. delete ql;
  91. Py_DECREF(iter);
  92. return 0;
  93. }
  94. ql->append(*t);
  95. sipReleaseType(t, sipType_QVariant, state);
  96. Py_DECREF(itm);
  97. }
  98. Py_DECREF(iter);
  99. *sipCppPtr = ql;
  100. return sipGetState(sipTransferObj);
  101. %End
  102. };
  103. %End