1// This is the SIP interface definition for the QList based mapped types
2// specific to the QtWidgets module.
3//
4// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
5//
6// This file is part of PyQt5.
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
21
22%MappedType QList<QWizard::WizardButton>
23        /TypeHintIn="Iterable[QWizard.WizardButton]",
24        TypeHintOut="List[QWizard.WizardButton]", TypeHintValue="[]"/
25{
26%TypeHeaderCode
27#include <qwizard.h>
28%End
29
30%ConvertFromTypeCode
31    PyObject *l = PyList_New(sipCpp->size());
32
33    if (!l)
34        return 0;
35
36    for (int i = 0; i < sipCpp->size(); ++i)
37    {
38        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
39                sipType_QWizard_WizardButton);
40
41        if (!eobj)
42        {
43            Py_DECREF(l);
44
45            return 0;
46        }
47
48        PyList_SetItem(l, i, eobj);
49    }
50
51    return l;
52%End
53
54%ConvertToTypeCode
55    PyObject *iter = PyObject_GetIter(sipPy);
56
57    if (!sipIsErr)
58    {
59        PyErr_Clear();
60        Py_XDECREF(iter);
61
62        return (iter
63#if PY_MAJOR_VERSION < 3
64                && !PyString_Check(sipPy)
65#endif
66                && !PyUnicode_Check(sipPy));
67    }
68
69    if (!iter)
70    {
71        *sipIsErr = 1;
72
73        return 0;
74    }
75
76    QList<QWizard::WizardButton> *ql = new QList<QWizard::WizardButton>;
77
78    for (Py_ssize_t i = 0; ; ++i)
79    {
80        PyErr_Clear();
81        PyObject *itm = PyIter_Next(iter);
82
83        if (!itm)
84        {
85            if (PyErr_Occurred())
86            {
87                delete ql;
88                Py_DECREF(iter);
89                *sipIsErr = 1;
90
91                return 0;
92            }
93
94            break;
95        }
96
97        int v = sipConvertToEnum(itm, sipType_QWizard_WizardButton);
98
99        if (PyErr_Occurred())
100        {
101            PyErr_Format(PyExc_TypeError,
102                    "index %zd has type '%s' but 'QWizard.WizardButton' is expected",
103                    i, sipPyTypeName(Py_TYPE(itm)));
104
105            Py_DECREF(itm);
106            delete ql;
107            Py_DECREF(iter);
108            *sipIsErr = 1;
109
110            return 0;
111        }
112
113        ql->append(static_cast<QWizard::WizardButton>(v));
114
115        Py_DECREF(itm);
116    }
117
118    Py_DECREF(iter);
119
120    *sipCppPtr = ql;
121
122    return sipGetState(sipTransferObj);
123%End
124};
125