1// This is the SIP interface definition for the QList based mapped types
2// specific to the QtPrintSupport 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%If (PyQt_Printer)
23
24%MappedType QList<QPagedPaintDevice::PageSize>
25        /TypeHintIn="Iterable[QPagedPaintDevice.PageSize]",
26        TypeHintOut="List[QPagedPaintDevice.PageSize]", TypeHintValue="[]"/
27{
28%TypeHeaderCode
29#include <qprinterinfo.h>
30%End
31
32%ConvertFromTypeCode
33    PyObject *l = PyList_New(sipCpp->size());
34
35    if (!l)
36        return 0;
37
38    for (int i = 0; i < sipCpp->size(); ++i)
39    {
40        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
41                sipType_QPagedPaintDevice_PageSize);
42
43        if (!eobj)
44        {
45            Py_DECREF(l);
46
47            return 0;
48        }
49
50        PyList_SetItem(l, i, eobj);
51    }
52
53    return l;
54%End
55
56%ConvertToTypeCode
57    PyObject *iter = PyObject_GetIter(sipPy);
58
59    if (!sipIsErr)
60    {
61        PyErr_Clear();
62        Py_XDECREF(iter);
63
64        return (iter
65#if PY_MAJOR_VERSION < 3
66                && !PyString_Check(sipPy)
67#endif
68                && !PyUnicode_Check(sipPy));
69    }
70
71    if (!iter)
72    {
73        *sipIsErr = 1;
74
75        return 0;
76    }
77
78    QList<QPagedPaintDevice::PageSize> *ql = new QList<QPagedPaintDevice::PageSize>;
79
80    for (Py_ssize_t i = 0; ; ++i)
81    {
82        PyErr_Clear();
83        PyObject *itm = PyIter_Next(iter);
84
85        if (!itm)
86        {
87            if (PyErr_Occurred())
88            {
89                delete ql;
90                Py_DECREF(iter);
91                *sipIsErr = 1;
92
93                return 0;
94            }
95
96            break;
97        }
98
99        int v = sipConvertToEnum(itm, sipType_QPagedPaintDevice_PageSize);
100
101        if (PyErr_Occurred())
102        {
103            PyErr_Format(PyExc_TypeError,
104                    "index %zd has type '%s' but 'QPagedPaintDevice.PageSize' is expected",
105                    i, sipPyTypeName(Py_TYPE(itm)));
106
107            Py_DECREF(itm);
108            delete ql;
109            Py_DECREF(iter);
110            *sipIsErr = 1;
111
112            return 0;
113        }
114
115        ql->append(static_cast<QPagedPaintDevice::PageSize>(v));
116
117        Py_DECREF(itm);
118    }
119
120    Py_DECREF(iter);
121
122    *sipCppPtr = ql;
123
124    return sipGetState(sipTransferObj);
125%End
126};
127
128%End
129
130
131%If (PyQt_Printer)
132
133%If (Qt_5_4_0 -)
134
135%MappedType QList<QPrinter::DuplexMode>
136        /TypeHintIn="Iterable[QPrinter.DuplexMode]",
137        TypeHintOut="List[QPrinter.DuplexMode]", TypeHintValue="[]"/
138{
139%TypeHeaderCode
140#include <qprinter.h>
141%End
142
143%ConvertFromTypeCode
144    PyObject *l = PyList_New(sipCpp->size());
145
146    if (!l)
147        return 0;
148
149    for (int i = 0; i < sipCpp->size(); ++i)
150    {
151        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
152                sipType_QPrinter_DuplexMode);
153
154        if (!eobj)
155        {
156            Py_DECREF(l);
157
158            return 0;
159        }
160
161        PyList_SetItem(l, i, eobj);
162    }
163
164    return l;
165%End
166
167%ConvertToTypeCode
168    PyObject *iter = PyObject_GetIter(sipPy);
169
170    if (!sipIsErr)
171    {
172        PyErr_Clear();
173        Py_XDECREF(iter);
174
175        return (iter
176#if PY_MAJOR_VERSION < 3
177                && !PyString_Check(sipPy)
178#endif
179                && !PyUnicode_Check(sipPy));
180    }
181
182    if (!iter)
183    {
184        *sipIsErr = 1;
185
186        return 0;
187    }
188
189    QList<QPrinter::DuplexMode> *ql = new QList<QPrinter::DuplexMode>;
190
191    for (Py_ssize_t i = 0; ; ++i)
192    {
193        PyErr_Clear();
194        PyObject *itm = PyIter_Next(iter);
195
196        if (!itm)
197        {
198            if (PyErr_Occurred())
199            {
200                delete ql;
201                Py_DECREF(iter);
202                *sipIsErr = 1;
203
204                return 0;
205            }
206
207            break;
208        }
209
210        int v = sipConvertToEnum(itm, sipType_QPrinter_DuplexMode);
211
212        if (PyErr_Occurred())
213        {
214            PyErr_Format(PyExc_TypeError,
215                    "index %zd has type '%s' but 'QPrinter.DuplexMode' is expected",
216                    i, sipPyTypeName(Py_TYPE(itm)));
217
218            Py_DECREF(itm);
219            delete ql;
220            Py_DECREF(iter);
221            *sipIsErr = 1;
222
223            return 0;
224        }
225
226        ql->append(static_cast<QPrinter::DuplexMode>(v));
227
228        Py_DECREF(itm);
229    }
230
231    Py_DECREF(iter);
232
233    *sipCppPtr = ql;
234
235    return sipGetState(sipTransferObj);
236%End
237};
238
239%End
240
241%End
242
243
244%If (PyQt_Printer)
245
246%If (Qt_5_13_0 -)
247
248%MappedType QList<QPrinter::ColorMode>
249        /TypeHintIn="Iterable[QPrinter.ColorMode]",
250        TypeHintOut="List[QPrinter.ColorMode]", TypeHintValue="[]"/
251{
252%TypeHeaderCode
253#include <qprinter.h>
254%End
255
256%ConvertFromTypeCode
257    PyObject *l = PyList_New(sipCpp->size());
258
259    if (!l)
260        return 0;
261
262    for (int i = 0; i < sipCpp->size(); ++i)
263    {
264        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
265                sipType_QPrinter_ColorMode);
266
267        if (!eobj)
268        {
269            Py_DECREF(l);
270
271            return 0;
272        }
273
274        PyList_SetItem(l, i, eobj);
275    }
276
277    return l;
278%End
279
280%ConvertToTypeCode
281    PyObject *iter = PyObject_GetIter(sipPy);
282
283    if (!sipIsErr)
284    {
285        PyErr_Clear();
286        Py_XDECREF(iter);
287
288        return (iter
289#if PY_MAJOR_VERSION < 3
290                && !PyString_Check(sipPy)
291#endif
292                && !PyUnicode_Check(sipPy));
293    }
294
295    if (!iter)
296    {
297        *sipIsErr = 1;
298
299        return 0;
300    }
301
302    QList<QPrinter::ColorMode> *ql = new QList<QPrinter::ColorMode>;
303
304    for (Py_ssize_t i = 0; ; ++i)
305    {
306        PyErr_Clear();
307        PyObject *itm = PyIter_Next(iter);
308
309        if (!itm)
310        {
311            if (PyErr_Occurred())
312            {
313                delete ql;
314                Py_DECREF(iter);
315                *sipIsErr = 1;
316
317                return 0;
318            }
319
320            break;
321        }
322
323        int v = sipConvertToEnum(itm, sipType_QPrinter_ColorMode);
324
325        if (PyErr_Occurred())
326        {
327            PyErr_Format(PyExc_TypeError,
328                    "index %zd has type '%s' but 'QPrinter.ColorMode' is expected",
329                    i, sipPyTypeName(Py_TYPE(itm)));
330
331            Py_DECREF(itm);
332            delete ql;
333            Py_DECREF(iter);
334            *sipIsErr = 1;
335
336            return 0;
337        }
338
339        ql->append(static_cast<QPrinter::ColorMode>(v));
340
341        Py_DECREF(itm);
342    }
343
344    Py_DECREF(iter);
345
346    *sipCppPtr = ql;
347
348    return sipGetState(sipTransferObj);
349%End
350};
351
352%End
353
354%End
355