qpywidgets_qlist.sip 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // This is the SIP interface definition for the QList based mapped types
  2. // specific to the QtWidgets 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. %MappedType QList<QWizard::WizardButton>
  21. /TypeHintIn="Iterable[QWizard.WizardButton]",
  22. TypeHintOut="List[QWizard.WizardButton]", TypeHintValue="[]"/
  23. {
  24. %TypeHeaderCode
  25. #include <qwizard.h>
  26. %End
  27. %ConvertFromTypeCode
  28. PyObject *l = PyList_New(sipCpp->size());
  29. if (!l)
  30. return 0;
  31. for (int i = 0; i < sipCpp->size(); ++i)
  32. {
  33. PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
  34. sipType_QWizard_WizardButton);
  35. if (!eobj)
  36. {
  37. Py_DECREF(l);
  38. return 0;
  39. }
  40. PyList_SetItem(l, i, eobj);
  41. }
  42. return l;
  43. %End
  44. %ConvertToTypeCode
  45. PyObject *iter = PyObject_GetIter(sipPy);
  46. if (!sipIsErr)
  47. {
  48. PyErr_Clear();
  49. Py_XDECREF(iter);
  50. return (iter && !PyBytes_Check(sipPy) && !PyUnicode_Check(sipPy));
  51. }
  52. if (!iter)
  53. {
  54. *sipIsErr = 1;
  55. return 0;
  56. }
  57. QList<QWizard::WizardButton> *ql = new QList<QWizard::WizardButton>;
  58. for (Py_ssize_t i = 0; ; ++i)
  59. {
  60. PyErr_Clear();
  61. PyObject *itm = PyIter_Next(iter);
  62. if (!itm)
  63. {
  64. if (PyErr_Occurred())
  65. {
  66. delete ql;
  67. Py_DECREF(iter);
  68. *sipIsErr = 1;
  69. return 0;
  70. }
  71. break;
  72. }
  73. int v = sipConvertToEnum(itm, sipType_QWizard_WizardButton);
  74. if (PyErr_Occurred())
  75. {
  76. PyErr_Format(PyExc_TypeError,
  77. "index %zd has type '%s' but 'QWizard.WizardButton' is expected",
  78. i, sipPyTypeName(Py_TYPE(itm)));
  79. Py_DECREF(itm);
  80. delete ql;
  81. Py_DECREF(iter);
  82. *sipIsErr = 1;
  83. return 0;
  84. }
  85. ql->append(static_cast<QWizard::WizardButton>(v));
  86. Py_DECREF(itm);
  87. }
  88. Py_DECREF(iter);
  89. *sipCppPtr = ql;
  90. return sipGetState(sipTransferObj);
  91. %End
  92. };