1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 /*********************************************************************
41  * INJECT CODE
42  ********************************************************************/
43 
44 // @snippet qtransform-quadtoquad
45 QTransform _result;
46 if (QTransform::quadToQuad(%1, %2, _result)) {
47     %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result);
48 } else {
49     Py_INCREF(Py_None);
50     %PYARG_0 = Py_None;
51 }
52 // @snippet qtransform-quadtoquad
53 
54 // @snippet qtransform-quadtosquare
55 QTransform _result;
56 if (QTransform::quadToSquare(%1, _result)) {
57     %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result);
58 } else {
59     Py_INCREF(Py_None);
60     %PYARG_0 = Py_None;
61 }
62 // @snippet qtransform-quadtosquare
63 
64 // @snippet qtransform-squaretoquad
65 QTransform _result;
66 if (QTransform::squareToQuad(%1, _result)) {
67     %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result);
68 } else {
69     Py_INCREF(Py_None);
70     %PYARG_0 = Py_None;
71 }
72 // @snippet qtransform-squaretoquad
73 
74 // @snippet qbitmap-fromdata
75 uchar *buffer = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_2));
76 QBitmap %0 = QBitmap::fromData(%1, buffer, %3);
77 %PYARG_0 = %CONVERTTOPYTHON[QBitmap](%0);
78 // @snippet qbitmap-fromdata
79 
80 // @snippet qtextline-cursortox
81 %RETURN_TYPE %0 = %CPPSELF->::%TYPE::%FUNCTION_NAME(&%1, %2);
82 %PYARG_0 = PyTuple_New(2);
83 PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](%0));
84 PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1));
85 // @snippet qtextline-cursortox
86 
87 // @snippet qkeysequence-getitem
88 if (_i < 0 || _i >= %CPPSELF.count()) {
89     PyErr_SetString(PyExc_IndexError, "index out of bounds");
90     return 0;
91 }
92 int item = (*%CPPSELF)[_i];
93 return %CONVERTTOPYTHON[int](item);
94 // @snippet qkeysequence-getitem
95 
96 // @snippet qpicture-data
97 %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.data(), %CPPSELF.size());
98 // @snippet qpicture-data
99 
100 // @snippet qtextblock-setuserdata
101 const QTextDocument *doc = %CPPSELF.document();
102 if (doc) {
103     Shiboken::AutoDecRef pyDocument(%CONVERTTOPYTHON[QTextDocument *](doc));
104     Shiboken::Object::setParent(pyDocument, %PYARG_1);
105 }
106 // @snippet qtextblock-setuserdata
107 
108 // @snippet qtextblock-userdata
109 const QTextDocument *doc = %CPPSELF.document();
110 if (doc) {
111     Shiboken::AutoDecRef pyDocument(%CONVERTTOPYTHON[QTextDocument *](doc));
112     Shiboken::Object::setParent(pyDocument, %PYARG_0);
113 }
114 // @snippet qtextblock-userdata
115 
116 // @snippet qopenglshaderprogram_setuniformvalue_float
117 float value = %2;
118 %CPPSELF.setUniformValue(%1, value);
119 // @snippet qopenglshaderprogram_setuniformvalue_float
120 
121 // @snippet qopenglshaderprogram_setuniformvalue_int
122 int value = %2;
123 %CPPSELF.setUniformValue(%1, value);
124 // @snippet qopenglshaderprogram_setuniformvalue_int
125 
126 // @snippet qpolygon-reduce
127 PyObject *points = PyList_New(%CPPSELF.count());
128 for (int i = 0, i_max = %CPPSELF.count(); i < i_max; ++i){
129     int x, y;
130     %CPPSELF.point(i, &x, &y);
131     QPoint pt = QPoint(x, y);
132     PyList_SET_ITEM(points, i, %CONVERTTOPYTHON[QPoint](pt));
133 }
134 // @snippet qpolygon-reduce
135 
136 // @snippet qpolygon-operatorlowerlower
137 // %FUNCTION_NAME()
138 *%CPPSELF << %1;
139 %PYARG_0 = %CONVERTTOPYTHON[QPolygon *](%CPPSELF);
140 // @snippet qpolygon-operatorlowerlower
141 
142 // @snippet qpixmap
143 %0 = new %TYPE(QPixmap::fromImage(%1));
144 // @snippet qpixmap
145 
146 // @snippet qimage-constbits
147 %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.byteCount());
148 // @snippet qimage-constbits
149 
150 // @snippet qimage-bits
151 // byteCount() is only available on Qt4.7, so we use bytesPerLine * height
152 %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height(), Shiboken::Buffer::ReadWrite);
153 // @snippet qimage-bits
154 
155 // @snippet qimage-constscanline
156 %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine());
157 // @snippet qimage-constscanline
158 
159 // @snippet qimage-scanline
160 %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine(), Shiboken::Buffer::ReadWrite);
161 // @snippet qimage-scanline
162 
163 // @snippet qcolor-setstate
164 Shiboken::AutoDecRef func(PyObject_GetAttr(%PYSELF, PyTuple_GET_ITEM(%1, 0)));
165 PyObject *args = PyTuple_GET_ITEM(%1, 1);
166 %PYARG_0 = PyObject_Call(func, args, NULL);
167 // @snippet qcolor-setstate
168 
169 // @snippet qcolor-reduce
170 switch (%CPPSELF.spec()) {
171     case QColor::Rgb:
172     {
173         qreal r, g, b, a;
174         %CPPSELF.getRgbF(&r, &g, &b, &a);
175         %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0),
176                                  "setRgbF", float(r), float(g), float(b), float(a));
177         break;
178     }
179     case QColor::Hsv:
180     {
181         qreal h, s, v, a;
182         %CPPSELF.getHsvF(&h, &s, &v, &a);
183         %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0),
184                                  "setHsvF", float(h), float(s), float(v), float(a));
185         break;
186     }
187     case QColor::Cmyk:
188     {
189         qreal c, m, y, k, a;
190         %CPPSELF.getCmykF(&c, &m, &y, &k, &a);
191         %PYARG_0 = Py_BuildValue("(ON(s(fffff)))", Py_TYPE(%PYSELF), PyTuple_New(0),
192                                  "setCmykF", float(c), float(m), float(y), float(k), float(a));
193         break;
194     }
195     case QColor::Hsl:
196     {
197         qreal h, s, l, a;
198         %CPPSELF.getHslF(&h, &s, &l, &a);
199         %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0),
200                                  "setHslF", float(h), float(s), float(l), float(a));
201         break;
202     }
203     default:
204     {
205         %PYARG_0 = Py_BuildValue("(N(O))", PyObject_Type(%PYSELF), Py_None);
206     }
207 }
208 // @snippet qcolor-reduce
209 
210 // @snippet qcolor-totuple
211 switch (%CPPSELF.spec()) {
212   case QColor::Rgb:
213   {
214         int r, g, b, a;
215         %CPPSELF.getRgb(&r, &g, &b, &a);
216         %PYARG_0 = Py_BuildValue("iiii", r, g, b, a);
217         break;
218   }
219   case QColor::Hsv:
220   {
221         int h, s, v, a;
222         %CPPSELF.getHsv(&h, &s, &v, &a);
223         %PYARG_0 = Py_BuildValue("iiii", h, s, v, a);
224         break;
225   }
226   case QColor::Cmyk:
227   {
228         int c, m, y, k, a;
229         %CPPSELF.getCmyk(&c, &m, &y, &k, &a);
230         %PYARG_0 = Py_BuildValue("iiiii", c, m, y, k, a);
231         break;
232   }
233   case QColor::Hsl:
234   {
235         int h, s, l, a;
236         %CPPSELF.getHsl(&h, &s, &l, &a);
237         %PYARG_0 = Py_BuildValue("iiii", h, s, l, a);
238         break;
239   }
240   default:
241   {
242         %PYARG_0 = 0;
243   }
244 }
245 // @snippet qcolor-totuple
246 
247 // @snippet qcolor
248 if (%1.type() == QVariant::Color)
249     %0 = new %TYPE(%1.value<QColor>());
250 else
251     PyErr_SetString(PyExc_TypeError, "QVariant must be holding a QColor");
252 // @snippet qcolor
253 
254 // @snippet qfontmetricsf-boundingrect
255 int *array = nullptr;
256 bool errorOccurred = false;
257 
258 if (numArgs == 5) {
259     array = Shiboken::sequenceToIntArray(%PYARG_5, true);
260     if (PyErr_Occurred()) {
261         delete [] array;
262         errorOccurred = true;
263     }
264 }
265 
266 if (!errorOccurred) {
267     %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, array);
268 
269     delete [] array;
270 
271     %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
272 }
273 // @snippet qfontmetricsf-boundingrect
274 
275 // @snippet qfontmetricsf-size
276 int *array = nullptr;
277 bool errorOccurred = false;
278 
279 if (numArgs == 4) {
280     array = Shiboken::sequenceToIntArray(%PYARG_4, true);
281     if (PyErr_Occurred()) {
282         delete [] array;
283         errorOccurred = true;
284     }
285 }
286 
287 if (!errorOccurred) {
288     %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, array);
289 
290     delete [] array;
291 
292     %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
293 }
294 // @snippet qfontmetricsf-size
295 
296 // @snippet qfontmetrics-boundingrect-1
297 int *array = nullptr;
298 bool errorOccurred = false;
299 
300 if (numArgs == 8) {
301     array = Shiboken::sequenceToIntArray(%PYARG_8, true);
302     if (PyErr_Occurred()) {
303         delete [] array;
304         errorOccurred = true;
305     }
306 }
307 
308 if (!errorOccurred) {
309     %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, %5, %6, %7, array);
310 
311     delete [] array;
312 
313     %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
314 }
315 // @snippet qfontmetrics-boundingrect-1
316 
317 // @snippet qfontmetrics-boundingrect-2
318 int *array = nullptr;
319 bool errorOccurred = false;
320 
321 if (numArgs == 5) {
322     array = Shiboken::sequenceToIntArray(%PYARG_5, true);
323     if (PyErr_Occurred()) {
324         delete [] array;
325         errorOccurred = true;
326     }
327 }
328 
329 if (!errorOccurred) {
330     %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, array);
331 
332     delete [] array;
333 
334     %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
335 }
336 // @snippet qfontmetrics-boundingrect-2
337 
338 // @snippet qfontmetrics-size
339 int *array = nullptr;
340 bool errorOccurred = false;
341 
342 if (numArgs == 4) {
343     array = Shiboken::sequenceToIntArray(%PYARG_4, true);
344     if (PyErr_Occurred()) {
345         delete [] array;
346         errorOccurred = true;
347     }
348 }
349 
350 if (!errorOccurred) {
351     %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, array);
352 
353     delete [] array;
354 
355     %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
356 }
357 // @snippet qfontmetrics-size
358 
359 // @snippet qpixmapcache-find
360 QPixmap p;
361 if (%CPPSELF.%FUNCTION_NAME(%1, &p)) {
362     %PYARG_0 = %CONVERTTOPYTHON[QPixmap](p);
363 } else {
364     %PYARG_0 = Py_None;
365     Py_INCREF(%PYARG_0);
366 }
367 // @snippet qpixmapcache-find
368 
369 // @snippet qstandarditem-setchild-1
370 // Clear parent from the old child
371 QStandardItem *_i = %CPPSELF->child(%1, %2);
372 if (_i) {
373     PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i);
374     Shiboken::Object::setParent(nullptr, _pyI);
375 }
376 // @snippet qstandarditem-setchild-1
377 
378 // @snippet qstandarditem-setchild-2
379 // Clear parent from the old child
380 QStandardItem *_i = %CPPSELF->child(%1);
381 if (_i) {
382     PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i);
383     Shiboken::Object::setParent(nullptr, _pyI);
384 }
385 // @snippet qstandarditem-setchild-2
386 
387 // @snippet qkeyevent-operatornotequal
388 bool ret = !(&%CPPSELF == %1);
389 %PYARG_0 = %CONVERTTOPYTHON[bool](ret);
390 // @snippet qkeyevent-operatornotequal
391 
392 // @snippet qstandarditemmodel-setitem-1
393 // Clear parent from the old child
394 QStandardItem *_i = %CPPSELF->item(%1, %2);
395 if (_i) {
396     PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i);
397     Shiboken::Object::setParent(nullptr, _pyI);
398 }
399 // @snippet qstandarditemmodel-setitem-1
400 
401 // @snippet qstandarditemmodel-setitem-2
402 // Clear parent from the old child
403 QStandardItem *_i = %CPPSELF->item(%1);
404 if (_i) {
405     PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i);
406     Shiboken::Object::setParent(nullptr, _pyI);
407 }
408 // @snippet qstandarditemmodel-setitem-2
409 
410 // @snippet qstandarditemmodel-setverticalheaderitem
411 // Clear parent from the old child
412 QStandardItem *_i = %CPPSELF->verticalHeaderItem(%1);
413 if (_i) {
414     PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i);
415     Shiboken::Object::setParent(nullptr, _pyI);
416 }
417 // @snippet qstandarditemmodel-setverticalheaderitem
418 
419 // @snippet qstandarditemmodel-clear
420 Shiboken::BindingManager &bm = Shiboken::BindingManager::instance();
421 SbkObject *pyRoot = bm.retrieveWrapper(%CPPSELF.invisibleRootItem());
422 if (pyRoot) {
423   Shiboken::Object::destroy(pyRoot, %CPPSELF.invisibleRootItem());
424 }
425 
426 for (int r=0, r_max = %CPPSELF.rowCount(); r < r_max; r++) {
427   QList<QStandardItem *> ri = %CPPSELF.takeRow(0);
428 
429   PyObject *pyResult = %CONVERTTOPYTHON[QList<QStandardItem * >](ri);
430   Shiboken::Object::setParent(Py_None, pyResult);
431   Py_XDECREF(pyResult);
432 }
433 // @snippet qstandarditemmodel-clear
434 
435 // @snippet qclipboard-text
436 %BEGIN_ALLOW_THREADS
437 %RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(%1, %2);
438 %END_ALLOW_THREADS
439 %PYARG_0 = PyTuple_New(2);
440 PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
441 PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1));
442 // @snippet qclipboard-text
443 
444 // @snippet qpainter-drawpolygon
445 %CPPSELF.%FUNCTION_NAME(%1.data(), %1.size(), %2);
446 // @snippet qpainter-drawpolygon
447 
448 // @snippet qmatrix-map-point
449 QPoint p(%CPPSELF.%FUNCTION_NAME(%1));
450 %PYARG_0 = %CONVERTTOPYTHON[QPoint](p);
451 // @snippet qmatrix-map-point
452 
453 // @snippet qmatrix4x4
454 // PYSIDE-795: All PySequences can be made iterable with PySequence_Fast.
455 Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence"));
456 if (PySequence_Size(seq) == 16) {
457     float values[16];
458     for (int i=0; i < 16; ++i) {
459         PyObject *pv = PySequence_Fast_GET_ITEM(seq.object(), i);
460         values[i] = PyFloat_AsDouble(pv);
461     }
462 
463     %0 = new %TYPE(values[0], values[1], values[2], values[3],
464                    values[4], values[5], values[6], values[7],
465                    values[8], values[9], values[10], values[11],
466                    values[12], values[13], values[14], values[15]);
467 }
468 // @snippet qmatrix4x4
469 
470 // @snippet qmatrix4x4-copydatato
471 float values[16];
472 %CPPSELF.%FUNCTION_NAME(values);
473 %PYARG_0 = PyTuple_New(16);
474 for (int i = 0; i < 16; ++i) {
475   PyObject *v = PyFloat_FromDouble(values[i]);
476   PyTuple_SET_ITEM(%PYARG_0, i, v);
477 }
478 // @snippet qmatrix4x4-copydatato
479 
480 // @snippet qmatrix4x4-mgetitem
481 if (PySequence_Check(_key)) {
482     Shiboken::AutoDecRef key(PySequence_Fast(_key, "Invalid matrix index."));
483     if (PySequence_Fast_GET_SIZE(key.object()) == 2) {
484         PyObject *posx = PySequence_Fast_GET_ITEM(key.object(), 0);
485         PyObject *posy = PySequence_Fast_GET_ITEM(key.object(), 1);
486         Py_ssize_t x = PyInt_AsSsize_t(posx);
487         Py_ssize_t y = PyInt_AsSsize_t(posy);
488         float ret = (*%CPPSELF)(x,y);
489         return %CONVERTTOPYTHON[float](ret);
490     }
491 }
492 PyErr_SetString(PyExc_IndexError, "Invalid matrix index.");
493 return 0;
494 // @snippet qmatrix4x4-mgetitem
495 
496 // @snippet qguiapplication-init
QGuiApplicationConstructor(PyObject * self,PyObject * pyargv,QGuiApplicationWrapper ** cptr)497 static void QGuiApplicationConstructor(PyObject *self, PyObject *pyargv, QGuiApplicationWrapper **cptr)
498 {
499     static int argc;
500     static char **argv;
501     PyObject *stringlist = PyTuple_GET_ITEM(pyargv, 0);
502     if (Shiboken::listToArgcArgv(stringlist, &argc, &argv, "PySideApp")) {
503         *cptr = new QGuiApplicationWrapper(argc, argv, 0);
504         Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(self));
505         PySide::registerCleanupFunction(&PySide::destroyQCoreApplication);
506     }
507 }
508 // @snippet qguiapplication-init
509 
510 // @snippet qguiapplication-1
511 QGuiApplicationConstructor(%PYSELF, args, &%0);
512 // @snippet qguiapplication-1
513 
514 // @snippet qguiapplication-2
515 PyObject *empty = PyTuple_New(2);
516 if (!PyTuple_SetItem(empty, 0, PyList_New(0))) {
517     QGuiApplicationConstructor(%PYSELF, empty, &%0);
518 }
519 // @snippet qguiapplication-2
520 
521 // @snippet qscreen-grabWindow
522 WId id = %1;
523 %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(id, %2, %3, %4, %5);
524 %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
525 // @snippet qscreen-grabWindow
526 
527 // @snippet qwindow-fromWinId
528 WId id = %1;
529 %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(id);
530 %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
531 // @snippet qwindow-fromWinId
532 
533 /*********************************************************************
534  * CONVERSIONS
535  ********************************************************************/
536 
537 // @snippet conversion-pylong
538 %out = reinterpret_cast<%OUTTYPE>(PyLong_AsVoidPtr(%in));
539 // @snippet conversion-pylong
540 
541 /*********************************************************************
542  * NATIVE TO TARGET CONVERSIONS
543  ********************************************************************/
544 
545 // @snippet return-pylong-voidptr
546 return PyLong_FromVoidPtr(reinterpret_cast<void *>(%in));
547 // @snippet return-pylong-voidptr
548