qpygui_qlist.sip 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // This is the SIP interface definition for the QList based mapped types
  2. // specific to the QtGui 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<QFontDatabase::WritingSystem>
  21. /TypeHintIn="Sequence[QFontDatabase.WritingSystem]",
  22. TypeHintOut="List[QFontDatabase.WritingSystem]",
  23. TypeHintValue="[]"/
  24. {
  25. %TypeHeaderCode
  26. #include <qfontdatabase.h>
  27. %End
  28. %ConvertFromTypeCode
  29. PyObject *l = PyList_New(sipCpp->size());
  30. if (!l)
  31. return 0;
  32. for (int i = 0; i < sipCpp->size(); ++i)
  33. {
  34. PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
  35. sipType_QFontDatabase_WritingSystem);
  36. if (!eobj)
  37. {
  38. Py_DECREF(l);
  39. return 0;
  40. }
  41. PyList_SetItem(l, i, eobj);
  42. }
  43. return l;
  44. %End
  45. %ConvertToTypeCode
  46. if (!sipIsErr)
  47. return (PySequence_Check(sipPy) && !PyBytes_Check(sipPy) && !PyUnicode_Check(sipPy));
  48. Py_ssize_t len = PySequence_Size(sipPy);
  49. if (len < 0)
  50. return 0;
  51. QList<QFontDatabase::WritingSystem> *ql = new QList<QFontDatabase::WritingSystem>;
  52. for (Py_ssize_t i = 0; i < len; ++i)
  53. {
  54. PyObject *itm = PySequence_GetItem(sipPy, i);
  55. if (!itm)
  56. {
  57. delete ql;
  58. *sipIsErr = 1;
  59. return 0;
  60. }
  61. int v = sipConvertToEnum(itm, sipType_QFontDatabase_WritingSystem);
  62. if (PyErr_Occurred())
  63. {
  64. PyErr_Format(PyExc_TypeError,
  65. "element %zd has type '%s' but 'QFontDatabase.WritingSystem' is expected",
  66. i, sipPyTypeName(Py_TYPE(itm)));
  67. Py_DECREF(itm);
  68. delete ql;
  69. *sipIsErr = 1;
  70. return 0;
  71. }
  72. ql->append(static_cast<QFontDatabase::WritingSystem>(v));
  73. Py_DECREF(itm);
  74. }
  75. *sipCppPtr = ql;
  76. return sipGetState(sipTransferObj);
  77. %End
  78. };