diff options
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtgui.cpp')
-rw-r--r-- | sources/pyside6/PySide6/glue/qtgui.cpp | 528 |
1 files changed, 464 insertions, 64 deletions
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp index 869fb9dc4..5c860a2bf 100644 --- a/sources/pyside6/PySide6/glue/qtgui.cpp +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -1,46 +1,271 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only /********************************************************************* * INJECT CODE ********************************************************************/ +// @snippet gui-declarations +QT_BEGIN_NAMESPACE +void qt_set_sequence_auto_mnemonic(bool); +QT_END_NAMESPACE +// @snippet gui-declarations + +// @snippet qaccessible-pysidefactory +// Helper for QAccessible::installFactory() that forwards the calls to +// Python callables. +class PySideAccessibleFactory +{ + PySideAccessibleFactory() = default; +public: + ~PySideAccessibleFactory(); + + static PySideAccessibleFactory *instance() { return m_instance; } + static PySideAccessibleFactory *ensureInstance(); + + static void installFactory(PyObject *f); + static void cleanup(); + + static QAccessibleInterface *factory(const QString &key, QObject *o); + +private: + QAccessibleInterface *callFactories(const QString &key, QObject *o); + + static PySideAccessibleFactory *m_instance; + + QList<PyObject *> m_factoryFunctions; + QList<PyObject *> m_objects; +}; + +PySideAccessibleFactory *PySideAccessibleFactory::m_instance = nullptr; + +PySideAccessibleFactory::~PySideAccessibleFactory() +{ + QAccessible::removeFactory(PySideAccessibleFactory::factory); + if (!m_factoryFunctions.isEmpty()) { + Shiboken::GilState state; + for (auto *f : m_factoryFunctions) + Py_DECREF(f); + for (auto *o : m_objects) + Py_DECREF(o); + } +} + +PySideAccessibleFactory *PySideAccessibleFactory::ensureInstance() +{ + if (m_instance == nullptr) { + m_instance = new PySideAccessibleFactory; + QAccessible::installFactory(PySideAccessibleFactory::factory); + qAddPostRoutine(PySideAccessibleFactory::cleanup); + } + return m_instance; +} + +void PySideAccessibleFactory::installFactory(PyObject *f) +{ + if (m_instance != nullptr) { + Py_INCREF(f); + m_instance->m_factoryFunctions.append(f); + } +} + +void PySideAccessibleFactory::cleanup() +{ + delete m_instance; + m_instance = nullptr; +} + +QAccessibleInterface *PySideAccessibleFactory::factory(const QString &key, QObject *o) +{ + return m_instance ? m_instance->callFactories(key, o) : nullptr; +} + +QAccessibleInterface *PySideAccessibleFactory::callFactories(const QString &key, QObject *o) +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(2)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QString](key)); + PyTuple_SET_ITEM(arglist, 1, %CONVERTTOPYTHON[QObject *](o)); + + for (auto *f : m_factoryFunctions) { + if (PyObject *pyResult = PyObject_CallObject(f, arglist)) { + if (pyResult != Py_None) { + m_objects.append(pyResult); + QAccessibleInterface* result = %CONVERTTOCPP[QAccessibleInterface *](pyResult); + return result; + } + Py_DECREF(pyResult); + } + } + + return nullptr; +} +// @snippet qaccessible-pysidefactory + +// @snippet qaccessible-installfactory +PySideAccessibleFactory::ensureInstance()->installFactory(%1); +// @snippet qaccessible-installfactory + +// @snippet qaction-menu +// %CPPSELF->menu(); // pretend it was called. +QObject *object = %CPPSELF->menu<QObject *>(); +%PYARG_0 = %CONVERTTOPYTHON[QObject*](object); +// @snippet qaction-menu + +// @snippet qopenglfunctions-glgetv-return-size +// Return the number of return values of the glGetBoolean/Double/Integerv functions +// cf https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGet.xhtml +static int glGetVReturnSize(GLenum pname) +{ + switch (pname) { + case GL_ALIASED_LINE_WIDTH_RANGE: + case GL_DEPTH_RANGE: + case GL_MAX_VIEWPORT_DIMS: +#if !QT_CONFIG(opengles2) + case GL_POINT_SIZE_RANGE: + case GL_SMOOTH_LINE_WIDTH_RANGE: + case GL_VIEWPORT_BOUNDS_RANGE: +#endif + return 2; + case GL_BLEND_COLOR: + case GL_COLOR_CLEAR_VALUE: + case GL_COLOR_WRITEMASK: + case GL_SCISSOR_BOX: + case GL_VIEWPORT: + return 4; + case GL_COMPRESSED_TEXTURE_FORMATS: + return GL_NUM_COMPRESSED_TEXTURE_FORMATS; + default: + break; + } + return 1; +} +// @snippet qopenglfunctions-glgetv-return-size + +// @snippet qopenglextrafunctions-glgeti-v-return-size +// Return the number of return values of the indexed +// glGetBoolean/Double/Integeri_v functions +// cf https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGet.xhtml +static int glGetI_VReturnSize(GLenum pname) +{ + return pname == GL_VIEWPORT ? 4 : 1; +} +// @snippet qopenglextrafunctions-glgeti-v-return-size + +// @snippet qopenglfunctions-glgetbooleanv +const int size = glGetVReturnSize(%1); +QVarLengthArray<GLboolean> result(size, GL_FALSE); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[bool](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createByteArray1(size, result.constData()); +} +// @snippet qopenglfunctions-glgetbooleanv + +// @snippet qopenglfunctions-glgetdoublev +const int size = glGetVReturnSize(%1); +QVarLengthArray<GLdouble> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[double](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createDoubleArray1(size, result.constData()); +} +// @snippet qopenglfunctions-glgetdoublev + +// @snippet qopenglfunctions-glgetfloatv +const int size = glGetVReturnSize(%1); +QVarLengthArray<GLfloat> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[float](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createFloatArray1(size, result.constData()); +} +// @snippet qopenglfunctions-glgetfloatv + +// @snippet qopenglfunctions-glgetintegerv +const int size = glGetVReturnSize(%1); +QVarLengthArray<GLint> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[int](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createIntArray1(size, result.constData()); +} +// @snippet qopenglfunctions-glgetintegerv + +// @snippet qopenglextrafunctions-glgetbooleani-v +const int size = glGetI_VReturnSize(%1); +QVarLengthArray<GLboolean> result(size, GL_FALSE); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[bool](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createByteArray1(size, result.constData()); +} +// @snippet qopenglextrafunctions-glgetbooleani-v + +// @snippet qopenglextrafunctions-glgetdoublei-v +const int size = glGetI_VReturnSize(%1); +QVarLengthArray<GLdouble> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[double](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createDoubleArray1(size, result.constData()); +} +// @snippet qopenglextrafunctions-glgetdoublei-v + +// @snippet qopenglextrafunctions-glgetfloati-v +const int size = glGetI_VReturnSize(%1); +QVarLengthArray<GLfloat> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[float](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createFloatArray1(size, result.constData()); +} +// @snippet qopenglextrafunctions-glgetfloati-v + +// @snippet qopenglextrafunctions-glgetintegeri-v +const int size = glGetI_VReturnSize(%1); +QVarLengthArray<GLint> result(size, 0); +%CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, result.data()); +if (size == 1) { + %PYARG_0 = %CONVERTTOPYTHON[int](result[0]); +} else { + %PYARG_0 = Shiboken::Numpy::createIntArray1(size, result.constData()); +} +// @snippet qopenglextrafunctions-glgetintegeri-v + +// @snippet glgetshadersource +GLsizei bufSize = 4096; +GLsizei length = bufSize - 1; +QByteArray buffer; +for (; length == bufSize - 1; bufSize += 4096) { + buffer.resize(qsizetype(bufSize)); + %CPPSELF->%FUNCTION_NAME(%1, bufSize, &length, buffer.data()); + if (%CPPSELF->glGetError() != GL_NO_ERROR) { + buffer.clear(); + break; + } +} +auto *data = buffer.constData(); +%PYARG_0 = %CONVERTTOPYTHON[char *](data); +// @snippet glgetshadersource + +// @snippet glshadersource +const QByteArray buffer = %2.toUtf8(); +const char *sources[] = {buffer.constData()}; +%CPPSELF->%FUNCTION_NAME(%1, 1, sources, nullptr); +// @snippet glshadersource + +// @snippet glgetstring-return +%PYARG_0 = %CONVERTTOPYTHON[const char *](%0); +// @snippet glgetstring-return + // @snippet qtransform-quadtoquad QTransform _result; if (QTransform::quadToQuad(%1, %2, _result)) { @@ -72,7 +297,7 @@ if (QTransform::squareToQuad(%1, _result)) { // @snippet qtransform-squaretoquad // @snippet qbitmap-fromdata -uchar *buffer = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_2)); +auto *buffer = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_2)); QBitmap %0 = QBitmap::fromData(%1, buffer, %3); %PYARG_0 = %CONVERTTOPYTHON[QBitmap](%0); // @snippet qbitmap-fromdata @@ -89,10 +314,19 @@ if (_i < 0 || _i >= %CPPSELF.count()) { PyErr_SetString(PyExc_IndexError, "index out of bounds"); return 0; } -int item = (*%CPPSELF)[_i]; -return %CONVERTTOPYTHON[int](item); +QKeyCombination item = (*%CPPSELF)[_i]; +return %CONVERTTOPYTHON[QKeyCombination](item); // @snippet qkeysequence-getitem +// @snippet qkeysequence-repr +auto ObTuple_Type = reinterpret_cast<PyObject *>(&PyTuple_Type); +auto ObSelf_Type = reinterpret_cast<PyObject *>(Py_TYPE(%PYSELF)); +Shiboken::AutoDecRef surrogate(PyObject_CallFunctionObjArgs(ObTuple_Type, %PYSELF, nullptr)); +Shiboken::AutoDecRef argstr(PyObject_Repr(surrogate)); +Shiboken::AutoDecRef name(PyObject_GetAttrString(ObSelf_Type, "__name__")); +return PyUnicode_Concat(name, argstr); +// @snippet qkeysequence-repr + // @snippet qpicture-data %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.data(), %CPPSELF.size()); // @snippet qpicture-data @@ -113,22 +347,13 @@ if (doc) { } // @snippet qtextblock-userdata -// @snippet qopenglshaderprogram_setuniformvalue_float -float value = %2; -%CPPSELF.setUniformValue(%1, value); -// @snippet qopenglshaderprogram_setuniformvalue_float - -// @snippet qopenglshaderprogram_setuniformvalue_int -int value = %2; -%CPPSELF.setUniformValue(%1, value); -// @snippet qopenglshaderprogram_setuniformvalue_int - // @snippet qpolygon-reduce -PyObject *points = PyList_New(%CPPSELF.count()); -for (int i = 0, i_max = %CPPSELF.count(); i < i_max; ++i){ +const Py_ssize_t count = %CPPSELF.size(); +PyObject *points = PyList_New(count); +for (Py_ssize_t i = 0; i < count; ++i){ int x, y; %CPPSELF.point(i, &x, &y); - QPoint pt = QPoint(x, y); + QPoint pt{x, y}; PyList_SET_ITEM(points, i, %CONVERTTOPYTHON[QPoint](pt)); } // @snippet qpolygon-reduce @@ -143,6 +368,31 @@ for (int i = 0, i_max = %CPPSELF.count(); i < i_max; ++i){ %0 = new %TYPE(QPixmap::fromImage(%1)); // @snippet qpixmap +// @snippet qicon-addpixmap +const auto path = PySide::pyPathToQString(%PYARG_1); +%CPPSELF->addPixmap(path); +// @snippet qicon-addpixmap + +// @snippet qclipboard-setpixmap +const auto path = PySide::pyPathToQString(%PYARG_1); +%CPPSELF->setPixmap(QPixmap(path)); +// @snippet qclipboard-setpixmap + +// @snippet qclipboard-setimage +const auto path = PySide::pyPathToQString(%PYARG_1); +%CPPSELF->setImage(QImage(path)); +// @snippet qclipboard-setimage + +// @snippet qimage-decref-image-data +static void imageDecrefDataHandler(void *data) +{ + // Avoid "Python memory allocator called without holding the GIL" + auto state = PyGILState_Ensure(); + Py_DECREF(reinterpret_cast<PyObject *>(data)); + PyGILState_Release(state); +} +// @snippet qimage-decref-image-data + // @snippet qimage-constbits %PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.sizeInBytes()); // @snippet qimage-constbits @@ -163,7 +413,7 @@ for (int i = 0, i_max = %CPPSELF.count(); i < i_max; ++i){ // @snippet qcolor-setstate Shiboken::AutoDecRef func(PyObject_GetAttr(%PYSELF, PyTuple_GET_ITEM(%1, 0))); PyObject *args = PyTuple_GET_ITEM(%1, 1); -%PYARG_0 = PyObject_Call(func, args, NULL); +%PYARG_0 = PyObject_Call(func, args, nullptr); // @snippet qcolor-setstate // @snippet qcolor-reduce @@ -441,21 +691,30 @@ PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1)); // @snippet qclipboard-text +// @snippet qpainter-drawpointsnp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.drawPoints(points); +// @snippet qpainter-drawpointsnp-numpy-x-y + // @snippet qpainter-drawpolygon -%CPPSELF.%FUNCTION_NAME(%1.data(), %1.size(), %2); +%CPPSELF.%FUNCTION_NAME(%1.constData(), %1.size(), %2); // @snippet qpainter-drawpolygon -// @snippet qmatrix-map-point -QPoint p(%CPPSELF.%FUNCTION_NAME(%1)); -%PYARG_0 = %CONVERTTOPYTHON[QPoint](p); -// @snippet qmatrix-map-point +// @snippet qpainter-enter +Py_INCREF(%PYSELF); +pyResult = %PYSELF; +// @snippet qpainter-enter + +// @snippet qpainter-exit +%CPPSELF.end(); +// @snippet qpainter-exit // @snippet qmatrix4x4 // PYSIDE-795: All PySequences can be made iterable with PySequence_Fast. Shiboken::AutoDecRef seq(PySequence_Fast(%PYARG_1, "Can't turn into sequence")); if (PySequence_Size(seq) == 16) { float values[16]; - for (int i=0; i < 16; ++i) { + for (Py_ssize_t i = 0; i < 16; ++i) { PyObject *pv = PySequence_Fast_GET_ITEM(seq.object(), i); values[i] = PyFloat_AsDouble(pv); } @@ -471,7 +730,7 @@ if (PySequence_Size(seq) == 16) { float values[16]; %CPPSELF.%FUNCTION_NAME(values); %PYARG_0 = PyTuple_New(16); -for (int i = 0; i < 16; ++i) { +for (Py_ssize_t i = 0; i < 16; ++i) { PyObject *v = PyFloat_FromDouble(values[i]); PyTuple_SET_ITEM(%PYARG_0, i, v); } @@ -483,8 +742,8 @@ if (PySequence_Check(_key)) { if (PySequence_Fast_GET_SIZE(key.object()) == 2) { PyObject *posx = PySequence_Fast_GET_ITEM(key.object(), 0); PyObject *posy = PySequence_Fast_GET_ITEM(key.object(), 1); - Py_ssize_t x = PyInt_AsSsize_t(posx); - Py_ssize_t y = PyInt_AsSsize_t(posy); + Py_ssize_t x = PyLong_AsSsize_t(posx); + Py_ssize_t y = PyLong_AsSsize_t(posy); float ret = (*%CPPSELF)(x,y); return %CONVERTTOPYTHON[float](ret); } @@ -518,18 +777,159 @@ if (!PyTuple_SetItem(empty, 0, PyList_New(0))) { } // @snippet qguiapplication-2 +// @snippet qguiapplication-setoverridecursor +auto *cppResult = new QtGuiHelper::QOverrideCursorGuard(); +%PYARG_0 = %CONVERTTOPYTHON[QtGuiHelper::QOverrideCursorGuard*](cppResult); +Shiboken::Object::getOwnership(%PYARG_0); // Ensure the guard is removed +// @snippet qguiapplication-setoverridecursor + +// @snippet qguiapplication-nativeInterface +bool hasNativeApp = false; +#if QT_CONFIG(xcb) +if (auto *x11App = %CPPSELF.nativeInterface<QNativeInterface::QX11Application>()) { + hasNativeApp = true; + %PYARG_0 = %CONVERTTOPYTHON[QNativeInterface::QX11Application*](x11App); +} +#endif +if (!hasNativeApp) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qguiapplication-nativeInterface + // @snippet qscreen-grabWindow WId id = %1; %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(id, %2, %3, %4, %5); %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); // @snippet qscreen-grabWindow +// @snippet qscreen-nativeInterface +bool hasNativeScreen = false; +#ifdef Q_OS_WIN +if (auto *winScreen = %CPPSELF.nativeInterface<QNativeInterface::QWindowsScreen>()) { + hasNativeScreen = true; + %PYARG_0 = %CONVERTTOPYTHON[QNativeInterface::QWindowsScreen*](winScreen); +} +#endif +if (!hasNativeScreen) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qscreen-nativeInterface + +// @snippet qx11application-resource-ptr + auto *resource = %CPPSELF.%FUNCTION_NAME(); +%PYARG_0 = PyLong_FromVoidPtr(resource); +// @snippet qx11application-resource-ptr + // @snippet qwindow-fromWinId WId id = %1; %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(id); %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); // @snippet qwindow-fromWinId +// @snippet set-qtkey-shortcut +%CPPSELF.%FUNCTION_NAME(QKeyCombination(%1)); +// @snippet set-qtkey-shortcut + +// @snippet qshortcut-1 +%0 = new %TYPE(%1, %2); +// @snippet qshortcut-1 + +// @snippet qshortcut-2 +Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, "connect", "OsO", + %PYSELF, SIGNAL(activated()), %PYARG_3) + ); +if (!result.isNull()) + Shiboken::Object::setParent(%PYARG_2, %PYSELF); +// @snippet qshortcut-2 + +// @snippet qguiapplication-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +int cppResult = %CPPSELF.exec(); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet qguiapplication-exec + +// @snippet qdrag-exec-arg1 +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +int cppResult = %CPPSELF.exec(%1); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet qdrag-exec-arg1 + +// @snippet qdrag-exec-arg2 +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +int cppResult; +if (numArgs == 2) + cppResult = %CPPSELF.exec(%1, %2); +else if (numArgs == 1) + cppResult = %CPPSELF.exec(%1); +else + cppResult = %CPPSELF.exec(); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet qdrag-exec-arg2 + +// @snippet qquaternion-getaxisandangle-vector3d-float +QVector3D outVec{}; +float angle{}; +%CPPSELF.%FUNCTION_NAME(&outVec, &angle); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[QVector3D](outVec)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[float](angle)); +// @snippet qquaternion-getaxisandangle-vector3d-float + +// @snippet qquaternion-geteulerangles +float pitch{}, yaw{}, roll{}; +%CPPSELF.%FUNCTION_NAME(&pitch, &yaw, &roll); +%PYARG_0 = PyTuple_New(3); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[float](pitch)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[float](yaw)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[float](roll)); +// @snippet qquaternion-geteulerangles + +// @snippet qregion-len +return %CPPSELF.rectCount(); +// @snippet qregion-len + +// @snippet qregion-getitem +if (_i < 0 || _i >= %CPPSELF.rectCount()) + return PyErr_Format(PyExc_IndexError, "index out of bounds"); + +const QRect cppResult = *(%CPPSELF.cbegin() + _i); +return %CONVERTTOPYTHON[QRect](cppResult); +// @snippet qregion-getitem + +// Some RHI functions take a std::initializer_list<>. Add functions +// to convert from list. + +// @snippet qrhi-initializer-list +%CPPSELF.%FUNCTION_NAME(%1.cbegin(), %1.cend()); +// @snippet qrhi-initializer-list + +// @snippet qrhi-commandbuffer-setvertexinput +%CPPSELF.%FUNCTION_NAME(%1, %2.size(), %2.constData(), %3, %4, %5); +// @snippet qrhi-commandbuffer-setvertexinput + /********************************************************************* * CONVERSIONS ********************************************************************/ |