diff options
Diffstat (limited to 'sources/pyside6/PySide6/glue')
25 files changed, 5173 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/glue/qhttpserver.cpp b/sources/pyside6/PySide6/glue/qhttpserver.cpp new file mode 100644 index 000000000..b6e485e2c --- /dev/null +++ b/sources/pyside6/PySide6/glue/qhttpserver.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2022 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 + ********************************************************************/ + +// Note: Lambdas need to be inline, QTBUG-104481 +// @snippet qhttpserver-route +QString rule = %CONVERTTOCPP[QString](%PYARG_1); +auto *callable = %PYARG_2; + +bool cppResult = %CPPSELF.%FUNCTION_NAME(rule, + [callable](const QHttpServerRequest &request) -> QString { + Shiboken::GilState state; + auto *requestPtr = &request; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, + %CONVERTTOPYTHON[QHttpServerRequest *](requestPtr)); + PyObject *ret = PyObject_CallObject(callable, arglist); + if (PyErr_Occurred()) + PyErr_Print(); + if (ret == nullptr) + return QString{}; + QString cppResult = %CONVERTTOCPP[QString](ret); + return cppResult; +}); + +%PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +// @snippet qhttpserver-route + +// @snippet qhttpserver-afterrequest +auto *callable = %PYARG_1; + +%CPPSELF.%FUNCTION_NAME([callable](QHttpServerResponse &&response, + const QHttpServerRequest &request) { + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(2)); + auto *responsePtr = &response; + auto *requestPtr = &request; + PyTuple_SET_ITEM(arglist, 0, + %CONVERTTOPYTHON[QHttpServerResponse *](responsePtr)); + PyTuple_SET_ITEM(arglist, 1, + %CONVERTTOPYTHON[QHttpServerRequest *](requestPtr)); + PyObject_CallObject(callable, arglist); + if (PyErr_Occurred()) + PyErr_Print(); + return std::move(response); +}); +// @snippet qhttpserver-afterrequest diff --git a/sources/pyside6/PySide6/glue/qtcharts.cpp b/sources/pyside6/PySide6/glue/qtcharts.cpp new file mode 100644 index 000000000..a99dbbb8a --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtcharts.cpp @@ -0,0 +1,16 @@ +// 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 + +// @snippet qchart-releaseownership +Shiboken::Object::releaseOwnership(%PYARG_1); +// @snippet qchart-releaseownership + +// @snippet qxyseries-appendnp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.append(points); +// @snippet qxyseries-appendnp-numpy-x-y + +// @snippet qxyseries-replacenp-numpy-x-y +const auto points = PySide::Numpy::xyDataToQPointFList(%PYARG_1, %PYARG_2); +%CPPSELF.replace(points); +// @snippet qxyseries-replacenp-numpy-x-y diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp new file mode 100644 index 000000000..0c206db72 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -0,0 +1,2150 @@ +// 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 include-pyside +#include <pysideinit.h> +#include <limits> +#include "glue/core_snippets_p.h" +// @snippet include-pyside + +// @snippet core-snippets-p-h +#include "glue/core_snippets_p.h" +// @snippet core-snippets-p-h + +// @snippet qarg_helper + +// Helper for the Q_ARG/Q_RETURN_ARG functions, creating a meta type +// and instance. +struct QArgData +{ + operator bool() const { return metaType.isValid() && data != nullptr; } + + QMetaType metaType; + void *data = nullptr; +}; + +QArgData qArgDataFromPyType(PyObject *t) +{ + QArgData result; + const char *typeName{}; + if (PyType_Check(t)) { + auto *pyType = reinterpret_cast<PyTypeObject *>(t); + typeName = pyType->tp_name; + result.metaType = PySide::qMetaTypeFromPyType(pyType); + } else if (PyUnicode_Check(t)) { + typeName = Shiboken::String::toCString(t); + result.metaType = QMetaType::fromName(typeName); + } else { + PyErr_Format(PyExc_RuntimeError, "%s: Parameter should be a type or type string.", + __FUNCTION__); + return result; + } + + if (!result.metaType.isValid()) { + PyErr_Format(PyExc_RuntimeError, "%s: Unable to find a QMetaType for \"%s\".", + __FUNCTION__, typeName); + return result; + } + + result.data = result.metaType.create(); + if (result.data == nullptr) { + PyErr_Format(PyExc_RuntimeError, "%s: Unable to create an instance of \"%s\" (%s).", + __FUNCTION__, typeName, result.metaType.name()); + return result; + } + return result; +} +// @snippet qarg_helper + +// @snippet settings-value-helpers +// Convert a QVariant to a desired primitive type +static PyObject *convertToPrimitiveType(const QVariant &out, int metaTypeId) +{ + switch (metaTypeId) { + case QMetaType::QByteArray: + return PyBytes_FromString(out.toByteArray().constData()); + case QMetaType::QString: + return PyUnicode_FromString(out.toByteArray().constData()); + case QMetaType::Short: + case QMetaType::Long: + case QMetaType::LongLong: + case QMetaType::UShort: + case QMetaType::ULong: + case QMetaType::ULongLong: + case QMetaType::Int: + case QMetaType::UInt: + return PyLong_FromDouble(out.toFloat()); + case QMetaType::Double: + case QMetaType::Float: + case QMetaType::Float16: + return PyFloat_FromDouble(out.toFloat()); + case QMetaType::Bool: + if (out.toBool()) { + Py_RETURN_TRUE; + } + Py_RETURN_FALSE; + default: + break; + } + return nullptr; +} + +// Helper for QSettings::value() to convert a value to the desired type +static PyObject *settingsTypeCoercion(const QVariant &out, PyTypeObject *typeObj) +{ + if (typeObj == &PyList_Type) { + // Convert any string, etc, to a list of 1 element + if (auto *primitiveValue = convertToPrimitiveType(out, out.typeId())) { + PyObject *list = PyList_New(1); + PyList_SET_ITEM(list, 0, primitiveValue); + return list; + } + + const QByteArray out_ba = out.toByteArray(); + if (out_ba.isEmpty()) + return PyList_New(0); + + const QByteArrayList valuesList = out_ba.split(','); + const Py_ssize_t valuesSize = valuesList.size(); + PyObject *list = PyList_New(valuesSize); + for (Py_ssize_t i = 0; i < valuesSize; ++i) { + PyObject *item = PyUnicode_FromString(valuesList.at(i).constData()); + PyList_SET_ITEM(list, i, item); + } + return list; + } + + if (typeObj == &PyBytes_Type) + return convertToPrimitiveType(out, QMetaType::QByteArray); + if (typeObj == &PyUnicode_Type) + return convertToPrimitiveType(out, QMetaType::QString); + if (typeObj == &PyLong_Type) + return convertToPrimitiveType(out, QMetaType::Int); + if (typeObj == &PyFloat_Type) + return convertToPrimitiveType(out, QMetaType::Double); + if (typeObj == &PyBool_Type) + return convertToPrimitiveType(out, QMetaType::Bool); + + // TODO: PyDict_Type and PyTuple_Type + PyErr_SetString(PyExc_TypeError, + "Invalid type parameter.\n" + "\tUse 'list', 'bytes', 'str', 'int', 'float', 'bool', " + "or a Qt-derived type"); + return nullptr; +} + +static bool isEquivalentSettingsType(PyTypeObject *typeObj, int metaTypeId) +{ + switch (metaTypeId) { + case QMetaType::QVariantList: + case QMetaType::QStringList: + return typeObj == &PyList_Type; + case QMetaType::QByteArray: + return typeObj == &PyBytes_Type; + case QMetaType::QString: + return typeObj == &PyUnicode_Type; + case QMetaType::Short: + case QMetaType::Long: + case QMetaType::LongLong: + case QMetaType::UShort: + case QMetaType::ULong: + case QMetaType::ULongLong: + case QMetaType::Int: + case QMetaType::UInt: + return typeObj == &PyLong_Type; + case QMetaType::Double: + case QMetaType::Float: + case QMetaType::Float16: + return typeObj == &PyFloat_Type; + case QMetaType::Bool: + return typeObj == &PyBool_Type; + default: + break; + } + return false; +} +// @snippet settings-value-helpers + +// @snippet qsettings-value +// If we enter the kwds, means that we have a defaultValue or +// at least a type. +// This avoids that we are passing '0' as defaultValue. +// defaultValue can also be passed as positional argument, +// not only as keyword. +// PySide-535: Allow for empty dict instead of nullptr in PyPy +QVariant out; +if ((kwds && PyDict_Size(kwds) > 0) || numArgs > 1) { + Py_BEGIN_ALLOW_THREADS + out = %CPPSELF.value(%1, %2); + Py_END_ALLOW_THREADS +} else { + Py_BEGIN_ALLOW_THREADS + out = %CPPSELF.value(%1); + Py_END_ALLOW_THREADS +} + +PyTypeObject *typeObj = reinterpret_cast<PyTypeObject*>(%PYARG_3); + +if (typeObj && !Shiboken::ObjectType::checkType(typeObj) + && !isEquivalentSettingsType(typeObj, out.typeId())) { + %PYARG_0 = settingsTypeCoercion(out, typeObj); +} else { + if (out.isValid()) { + %PYARG_0 = %CONVERTTOPYTHON[QVariant](out); + } else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; + } +} + +// @snippet qsettings-value + +// @snippet metatype-from-type +%0 = new %TYPE(PySide::qMetaTypeFromPyType(reinterpret_cast<PyTypeObject *>(%1))); +// @snippet metatype-from-type + +// @snippet metatype-from-metatype-type +Shiboken::AutoDecRef intArg(PyObject_GetAttrString(%PYARG_1, "value")); +%0 = new %TYPE(PyLong_AsLong(intArg)); +// @snippet metatype-from-metatype-type + +// @snippet conversion-pytypeobject-qmetatype +auto *pyType = reinterpret_cast<PyTypeObject *>(%in); +%out = PySide::qMetaTypeFromPyType(pyType); +// @snippet conversion-pytypeobject-qmetatype + +// @snippet conversion-qmetatype-pytypeobject +auto pyType = Shiboken::Conversions::getPythonTypeObject(%in.name()); +%out = pyType ? (reinterpret_cast<PyObject *>(pyType)) : Py_None; +Py_INCREF(%out); +return %out; +// @snippet conversion-qmetatype-pytypeobject + +// @snippet qvariant-conversion +static QVariant QVariant_convertToVariantMap(PyObject *map) +{ + Py_ssize_t pos = 0; + Shiboken::AutoDecRef keys(PyDict_Keys(map)); + if (!QVariant_isStringList(keys)) + return {}; + PyObject *key; + PyObject *value; + QMap<QString,QVariant> ret; + while (PyDict_Next(map, &pos, &key, &value)) { + QString cppKey = %CONVERTTOCPP[QString](key); + QVariant cppValue = %CONVERTTOCPP[QVariant](value); + ret.insert(cppKey, cppValue); + } + return QVariant(ret); +} +static QVariant QVariant_convertToVariantList(PyObject *list) +{ + if (QVariant_isStringList(list)) { + QList<QString > lst = %CONVERTTOCPP[QList<QString>](list); + return QVariant(QStringList(lst)); + } + QVariant valueList = QVariant_convertToValueList(list); + if (valueList.isValid()) + return valueList; + + if (PySequence_Size(list) < 0) { + // clear the error if < 0 which means no length at all + PyErr_Clear(); + return {}; + } + + QList<QVariant> lst; + Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList")); + const Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object()); + for (Py_ssize_t i = 0; i < size; ++i) { + PyObject *pyItem = PySequence_Fast_GET_ITEM(fast.object(), i); + QVariant item = %CONVERTTOCPP[QVariant](pyItem); + lst.append(item); + } + return QVariant(lst); +} + +using SpecificConverter = Shiboken::Conversions::SpecificConverter; + +static std::optional<SpecificConverter> converterForQtType(const char *typeNameC) +{ + // Fix typedef "QGenericMatrix<3,3,float>" -> QMatrix3x3". The reverse + // conversion happens automatically in QMetaType::fromName() in + // QVariant_resolveMetaType(). + QByteArrayView typeNameV(typeNameC); + if (typeNameV.startsWith("QGenericMatrix<") && typeNameV.endsWith(",float>")) { + QByteArray typeName = typeNameV.toByteArray(); + typeName.remove(1, 7); + typeName.remove(7, 1); // '<' + typeName.chop(7); + typeName.replace(',', 'x'); + SpecificConverter matrixConverter(typeName.constData()); + if (matrixConverter) + return matrixConverter; + } + SpecificConverter converter(typeNameC); + if (converter) + return converter; + return std::nullopt; +} +// @snippet qvariant-conversion + +// @snippet qt-qabs +double _abs = qAbs(%1); +%PYARG_0 = %CONVERTTOPYTHON[double](_abs); +// @snippet qt-qabs + +// @snippet qt-addpostroutine +PySide::addPostRoutine(%1); +// @snippet qt-addpostroutine + +// @snippet qt-qaddpostroutine +qAddPostRoutine(PySide::globalPostRoutineCallback); +// @snippet qt-qaddpostroutine + +// @snippet qcompress-buffer +auto *ptr = reinterpret_cast<uchar*>(Shiboken::Buffer::getPointer(%PYARG_1)); +QByteArray compressed = %FUNCTION_NAME(ptr, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](compressed); +// @snippet qcompress-buffer + +// @snippet quncompress-buffer +auto *ptr = reinterpret_cast<uchar*>(Shiboken::Buffer::getPointer(%PYARG_1)); +QByteArray uncompressed = %FUNCTION_NAME(ptr, %2); +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](uncompressed); +// @snippet quncompress-buffer + +// @snippet qt-version +QList<QByteArray> version = QByteArray(qVersion()).split('.'); +PyObject *pyQtVersion = PyTuple_New(3); +for (int i = 0; i < 3; ++i) + PyTuple_SET_ITEM(pyQtVersion, i, PyLong_FromLong(version[i].toInt())); +PyModule_AddObject(module, "__version_info__", pyQtVersion); +PyModule_AddStringConstant(module, "__version__", qVersion()); +// @snippet qt-version + +// @snippet qobject-connect +#include <qobjectconnect.h> +// @snippet qobject-connect + +// @snippet qobject-connect-1 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnect(%1, %2, %CPPSELF, %3, %4); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-1 + +// @snippet qobject-connect-2 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnect(%1, %2, %3, %4, %5); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-2 + +// @snippet qobject-connect-3 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnect(%1, %2, %3, %4, %5); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-3 + +// @snippet qobject-connect-4 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnectCallback(%1, %2, %PYARG_3, %4); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-4 + +// @snippet qobject-connect-4-context +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnectCallback(%1, %2, %3, %PYARG_4, %5); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-4-context + +// @snippet qobject-connect-5 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnectCallback(%CPPSELF, %1, %PYARG_2, %3); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-5 + +// @snippet qobject-connect-6 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectConnect(%CPPSELF, %1, %2, %3, %4); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-connect-6 + +// @snippet qobject-emit +%RETURN_TYPE %0 = PySide::SignalManager::instance().emitSignal(%CPPSELF, %1, %PYARG_2); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-emit + +// @snippet qobject-disconnect-1 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectDisconnectCallback(%CPPSELF, %1, %2); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-disconnect-1 + +// @snippet qobject-disconnect-2 +// %FUNCTION_NAME() - disable generation of function call. +%RETURN_TYPE %0 = PySide::qobjectDisconnectCallback(%1, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-disconnect-2 + +// @snippet qfatal +// qFatal doesn't have a stream version, so we do a +// qWarning call followed by a qFatal() call using a +// literal. +Py_BEGIN_ALLOW_THREADS +qWarning() << %1; +qFatal("[A qFatal() call was made from Python code]"); +Py_END_ALLOW_THREADS +// @snippet qfatal + +// @snippet moduleshutdown +PySide::runCleanupFunctions(); +// @snippet moduleshutdown + +// @snippet qt-qenum +%PYARG_0 = PySide::QEnum::QEnumMacro(%1, false); +// @snippet qt-qenum + +// @snippet qt-qflag +%PYARG_0 = PySide::QEnum::QEnumMacro(%1, true); +// @snippet qt-qflag + +// @snippet qt-init-feature +PySide::Feature::init(); +// @snippet qt-init-feature + +// @snippet qt-pysideinit +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QString_IDX], "unicode"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QString_IDX], "str"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QtCore_QList_QVariant_IDX], "QVariantList"); +Shiboken::Conversions::registerConverterName(SbkPySide6_QtCoreTypeConverters[SBK_QtCore_QMap_QString_QVariant_IDX], "QVariantMap"); + +PySide::registerInternalQtConf(); +PySide::init(module); +Py_AtExit(QtCoreModuleExit); +// @snippet qt-pysideinit + +// @snippet qt-messagehandler +// Define a global variable to handle qInstallMessageHandler callback +static PyObject *qtmsghandler = nullptr; + +static void msgHandlerCallback(QtMsgType type, const QMessageLogContext &ctx, const QString &msg) +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(3)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QtMsgType](type)); + PyTuple_SET_ITEM(arglist, 1, %CONVERTTOPYTHON[QMessageLogContext &](ctx)); + QByteArray array = msg.toUtf8(); // Python handler requires UTF-8 + const char *data = array.constData(); + PyTuple_SET_ITEM(arglist, 2, %CONVERTTOPYTHON[const char *](data)); + Shiboken::AutoDecRef ret(PyObject_CallObject(qtmsghandler, arglist)); +} +static void QtCoreModuleExit() +{ + PySide::SignalManager::instance().clear(); +} +// @snippet qt-messagehandler + +// @snippet qt-installmessagehandler +if (%PYARG_1 == Py_None) { + qInstallMessageHandler(0); + %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; + qtmsghandler = 0; +} else if (!PyCallable_Check(%PYARG_1)) { + PyErr_SetString(PyExc_TypeError, "parameter must be callable"); +} else { + %PYARG_0 = qtmsghandler ? qtmsghandler : Py_None; + Py_INCREF(%PYARG_1); + qtmsghandler = %PYARG_1; + qInstallMessageHandler(msgHandlerCallback); +} + +if (%PYARG_0 == Py_None) + Py_INCREF(%PYARG_0); +// @snippet qt-installmessagehandler + +// @snippet qline-hash +namespace PySide { + template<> inline Py_ssize_t hash(const QLine &l) + { + return qHashMulti(0, l.x1(), l.y1(), l.x2(), l.y2()); + } +}; +// @snippet qline-hash + +// @snippet qlinef-intersect +QPointF p; +%RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &p); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QPointF](p)); +// @snippet qlinef-intersect + +// @snippet qresource-data +const void *d = %CPPSELF.%FUNCTION_NAME(); +if (d) { + %PYARG_0 = Shiboken::Buffer::newObject(d, %CPPSELF.size()); +} else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qresource-data + +// @snippet qdate-topython +if (!PyDateTimeAPI) + PyDateTime_IMPORT; +%PYARG_0 = PyDate_FromDate(%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()); +// @snippet qdate-topython + +// @snippet qdate-getdate +int year, month, day; +%CPPSELF.%FUNCTION_NAME(&year, &month, &day); +%PYARG_0 = PyTuple_New(3); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](year)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](month)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[int](day)); +// @snippet qdate-getdate + +// @snippet qdate-weeknumber +int yearNumber; +int week = %CPPSELF.%FUNCTION_NAME(&yearNumber); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](week)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](yearNumber)); +// @snippet qdate-weeknumber + +// @snippet qdatetime-1 +QDate date(%1, %2, %3); +QTime time(%4, %5, %6, %7); +%0 = new %TYPE(date, time, Qt::TimeSpec(%8)); +// @snippet qdatetime-1 + +// @snippet qdatetime-2 +QDate date(%1, %2, %3); +QTime time(%4, %5, %6); +%0 = new %TYPE(date, time); +// @snippet qdatetime-2 + +// @snippet qdatetime-3 +QDate date(%1, %2, %3); +QTime time(%4, %5, %6, %7); +%0 = new %TYPE(date, time, %8); +// @snippet qdatetime-3 + +// @snippet qdatetime-topython +QDate date = %CPPSELF.date(); +QTime time = %CPPSELF.time(); +if (!PyDateTimeAPI) + PyDateTime_IMPORT; +%PYARG_0 = PyDateTime_FromDateAndTime(date.year(), date.month(), date.day(), time.hour(), time.minute(), time.second(), time.msec()*1000); +// @snippet qdatetime-topython + +// @snippet qtime-topython +if (!PyDateTimeAPI) + PyDateTime_IMPORT; +%PYARG_0 = PyTime_FromTime(%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()*1000); +// @snippet qtime-topython + +// @snippet qbitarray-len +return %CPPSELF.size(); +// @snippet qbitarray-len + +// @snippet qbitarray-getitem +if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; +} +bool ret = %CPPSELF.at(_i); +return %CONVERTTOPYTHON[bool](ret); +// @snippet qbitarray-getitem + +// @snippet qbitarray-setitem +PyObject *args = Py_BuildValue("(iiO)", _i, 1, _value); +PyObject *result = Sbk_QBitArrayFunc_setBit(self, args); +Py_DECREF(args); +Py_XDECREF(result); +return !result ? -1 : 0; +// @snippet qbitarray-setitem + +// @snippet default-enter +Py_INCREF(%PYSELF); +pyResult = %PYSELF; +// @snippet default-enter + +// @snippet qsignalblocker-unblock +%CPPSELF.unblock(); +// @snippet qsignalblocker-unblock + +// @snippet unlock +%CPPSELF.unlock(); +// @snippet unlock + +// @snippet qabstractitemmodel-createindex +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1, %2, %PYARG_3); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qabstractitemmodel-createindex + +// @snippet qabstractitemmodel +qRegisterMetaType<QList<int> >("QList<int>"); +// @snippet qabstractitemmodel + +// @snippet qobject-metaobject +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qobject-metaobject + +// @snippet qobject-findchild-2 +QObject *child = qObjectFindChild(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>(%PYARG_1), %3); +%PYARG_0 = %CONVERTTOPYTHON[QObject *](child); +// @snippet qobject-findchild-2 + +// @snippet qobject-findchildren +%PYARG_0 = PyList_New(0); +qObjectFindChildren(%CPPSELF, %2, reinterpret_cast<PyTypeObject *>(%PYARG_1), %3, + [%PYARG_0](QObject *child) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject *](child)); + PyList_Append(%PYARG_0, pyChild.object()); + }); +// @snippet qobject-findchildren + +// @snippet qobject-tr +const QString result = qObjectTr(reinterpret_cast<PyTypeObject *>(%PYSELF), %1, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[QString](result); +// @snippet qobject-tr + +// @snippet qobject-sender +// Retrieve the sender from a dynamic property set by GlobalReceiverV2 in case of a +// non-C++ slot (Python callback). +auto *ret = %CPPSELF.%FUNCTION_NAME(); +if (ret == nullptr) { + auto senderV = %CPPSELF.property("_q_pyside_sender"); + if (senderV.typeId() == QMetaType::QObjectStar) + ret = senderV.value<QObject *>(); +} +%PYARG_0 = %CONVERTTOPYTHON[QObject*](ret); +// @snippet qobject-sender + +// @snippet qbytearray-mgetitem +if (PyIndex_Check(_key)) { + const Py_ssize_t _i = PyNumber_AsSsize_t(_key, PyExc_IndexError); + if (_i < 0 || _i >= %CPPSELF.size()) + return PyErr_Format(PyExc_IndexError, "index out of bounds"); + char res[2] = {%CPPSELF.at(_i), '\0'}; + return PyBytes_FromStringAndSize(res, 1); +} + +if (PySlice_Check(_key) == 0) + return PyErr_Format(PyExc_TypeError, + "list indices must be integers or slices, not %.200s", + Py_TYPE(_key)->tp_name); + +Py_ssize_t start, stop, step, slicelength; +if (PySlice_GetIndicesEx(_key, %CPPSELF.size(), &start, &stop, &step, &slicelength) < 0) + return nullptr; + +QByteArray ba; +if (slicelength <= 0) + return %CONVERTTOPYTHON[QByteArray](ba); + +if (step == 1) { + Py_ssize_t max = %CPPSELF.size(); + start = qBound(Py_ssize_t(0), start, max); + stop = qBound(Py_ssize_t(0), stop, max); + if (start < stop) + ba = %CPPSELF.mid(start, stop - start); + return %CONVERTTOPYTHON[QByteArray](ba); +} + +for (Py_ssize_t cur = start; slicelength > 0; cur += step, --slicelength) + ba.append(%CPPSELF.at(cur)); + +return %CONVERTTOPYTHON[QByteArray](ba); +// @snippet qbytearray-mgetitem + +// @snippet qbytearray-msetitem +// PYSIDE-2404: Usage of the `get()` function not necessary, the type exists. +if (PyIndex_Check(_key)) { + Py_ssize_t _i = PyNumber_AsSsize_t(_key, PyExc_IndexError); + if (_i == -1 && PyErr_Occurred()) + return -1; + + if (_i < 0) + _i += %CPPSELF.size(); + + if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "QByteArray index out of range"); + return -1; + } + + // Provide more specific error message for bytes/str, bytearray, QByteArray respectively + if (PyBytes_Check(_value)) { + if (Py_SIZE(_value) != 1) { + PyErr_SetString(PyExc_ValueError, "bytes must be of size 1"); + return -1; + } + } else if (PyByteArray_Check(_value)) { + if (Py_SIZE(_value) != 1) { + PyErr_SetString(PyExc_ValueError, "bytearray must be of size 1"); + return -1; + } + } else if (Py_TYPE(_value) == reinterpret_cast<PyTypeObject *>( + SbkPySide6_QtCoreTypeStructs[SBK_QByteArray_IDX].type)) { + if (PyObject_Length(_value) != 1) { + PyErr_SetString(PyExc_ValueError, "QByteArray must be of size 1"); + return -1; + } + } else { + PyErr_SetString(PyExc_ValueError, "a bytes, bytearray, QByteArray of size 1 is required"); + return -1; + } + + // Not support int or long. + %CPPSELF.remove(_i, 1); + PyObject *args = Py_BuildValue("(nO)", _i, _value); + PyObject *result = Sbk_QByteArrayFunc_insert(self, args); + Py_DECREF(args); + Py_XDECREF(result); + return result != nullptr ? 0: -1; +} + +if (PySlice_Check(_key) == 0) { + PyErr_Format(PyExc_TypeError, "QBytearray indices must be integers or slices, not %.200s", + Py_TYPE(_key)->tp_name); + return -1; +} + +Py_ssize_t start, stop, step, slicelength; +if (PySlice_GetIndicesEx(_key, %CPPSELF.size(), &start, &stop, &step, &slicelength) < 0) + return -1; + +// The parameter candidates are: bytes/str, bytearray, QByteArray itself. +// Not supported are iterables containing ints between 0~255 +// case 1: value is nullpre, means delete the items within the range +// case 2: step is 1, means shrink or expand +// case 3: step is not 1, then the number of slots have to equal the number of items in _value +Py_ssize_t value_length = 0; +if (_value != nullptr && _value != Py_None) { + if (!(PyBytes_Check(_value) || PyByteArray_Check(_value) + || Py_TYPE(_value) == SbkPySide6_QtCoreTypeStructs[SBK_QByteArray_IDX].type)) { + PyErr_Format(PyExc_TypeError, "bytes, bytearray or QByteArray is required, not %.200s", + Py_TYPE(_value)->tp_name); + return -1; + } + value_length = PyObject_Length(_value); +} + +if (step != 1 && value_length != slicelength) { + PyErr_Format(PyExc_ValueError, "attempt to assign %s of size %d to extended slice of size %d", + Py_TYPE(_value)->tp_name, int(value_length), int(slicelength)); + return -1; +} + +if (step != 1) { + Py_ssize_t i = start; + for (Py_ssize_t j = 0; j < slicelength; ++j) { + PyObject *item = PyObject_GetItem(_value, PyLong_FromSsize_t(j)); + QByteArray temp; + if (PyLong_Check(item)) { + int overflow; + const long ival = PyLong_AsLongAndOverflow(item, &overflow); + // Not supposed to be bigger than 255 because only bytes, + // bytearray, QByteArray were accepted + temp.append(char(ival)); + } else { + temp = %CONVERTTOCPP[QByteArray](item); + } + %CPPSELF.replace(i, 1, temp); + i += step; + } + return 0; +} + +QByteArray ba = %CONVERTTOCPP[QByteArray](_value); +%CPPSELF.replace(start, slicelength, ba); +return 0; +// @snippet qbytearray-msetitem + +// @snippet qbytearray-bufferprotocol +extern "C" { +// QByteArray buffer protocol functions +// see: http://www.python.org/dev/peps/pep-3118/ + +static int SbkQByteArray_getbufferproc(PyObject *obj, Py_buffer *view, int flags) +{ + if (!view || !Shiboken::Object::isValid(obj)) + return -1; + + QByteArray * cppSelf = %CONVERTTOCPP[QByteArray *](obj); + //XXX /|\ omitting this space crashes shiboken! +#ifdef Py_LIMITED_API + view->obj = obj; + view->buf = reinterpret_cast<void *>(cppSelf->data()); + view->len = cppSelf->size(); + view->readonly = 0; + view->itemsize = 1; + view->format = (flags & PyBUF_FORMAT) == PyBUF_FORMAT ? const_cast<char *>("B") : nullptr; + view->ndim = 1; + view->shape = (flags & PyBUF_ND) == PyBUF_ND ? &(view->len) : nullptr; + view->strides = (flags & PyBUF_STRIDES) == PyBUF_STRIDES ? &(view->itemsize) : nullptr; + view->suboffsets = nullptr; + view->internal = nullptr; + + Py_XINCREF(obj); + return 0; +#else // Py_LIMITED_API + const int result = PyBuffer_FillInfo(view, obj, reinterpret_cast<void *>(cppSelf->data()), + cppSelf->size(), 0, flags); + if (result == 0) + Py_XINCREF(obj); + return result; +#endif +} + +static PyBufferProcs SbkQByteArrayBufferProc = { + /*bf_getbuffer*/ (getbufferproc)SbkQByteArray_getbufferproc, + /*bf_releasebuffer*/ (releasebufferproc)0, +}; + +} +// @snippet qbytearray-bufferprotocol + +// @snippet qbytearray-operatorplus-1 +QByteArray ba = QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)) + *%CPPSELF; +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); +// @snippet qbytearray-operatorplus-1 + +// @snippet qbytearray-operatorplus-2 +QByteArray ba = QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)) + *%CPPSELF; +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); +// @snippet qbytearray-operatorplus-2 + +// @snippet qbytearray-operatorplus-3 +QByteArray ba = *%CPPSELF + QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](ba); +// @snippet qbytearray-operatorplus-3 + +// @snippet qbytearray-operatorplusequal +*%CPPSELF += QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); +// @snippet qbytearray-operatorplusequal + +// @snippet qbytearray-operatorequalequal +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF == ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatorequalequal + +// @snippet qbytearray-operatornotequal +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF != ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatornotequal + +// @snippet qbytearray-operatorgreater +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF > ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatorgreater + +// @snippet qbytearray-operatorgreaterequal +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF >= ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatorgreaterequal + +// @snippet qbytearray-operatorlower +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF < ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatorlower + +// @snippet qbytearray-operatorlowerequal +if (PyUnicode_CheckExact(%PYARG_1)) { + Shiboken::AutoDecRef data(PyUnicode_AsASCIIString(%PYARG_1)); + QByteArray ba = QByteArray(PyBytes_AsString(data.object()), PyBytes_GET_SIZE(data.object())); + bool cppResult = %CPPSELF <= ba; + %PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +} +// @snippet qbytearray-operatorlowerequal + +// @snippet qbytearray-repr +PyObject *aux = PyBytes_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); +if (aux == nullptr) { + return nullptr; +} +QByteArray b(Py_TYPE(%PYSELF)->tp_name); +%PYARG_0 = PyUnicode_FromFormat("%s(%R)", b.constData(), aux); +Py_DECREF(aux); +// @snippet qbytearray-repr + +// @snippet qbytearray-2 +%0 = new QByteArray(PyByteArray_AsString(%PYARG_1), PyByteArray_Size(%PYARG_1)); +// @snippet qbytearray-2 + +// @snippet qbytearray-3 +%0 = new QByteArray(PyBytes_AS_STRING(%PYARG_1), PyBytes_GET_SIZE(%PYARG_1)); +// @snippet qbytearray-3 + +// @snippet qbytearray-py3 +PepType_AS_BUFFER(Shiboken::SbkType<QByteArray>()) = &SbkQByteArrayBufferProc; +// @snippet qbytearray-py3 + +// @snippet qbytearray-data +%PYARG_0 = PyBytes_FromStringAndSize(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size()); +// @snippet qbytearray-data + +// @snippet qbytearray-str +PyObject *aux = PyBytes_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size()); +if (aux == nullptr) { + return nullptr; +} +%PYARG_0 = PyObject_Repr(aux); +Py_DECREF(aux); +// @snippet qbytearray-str + +// @snippet qbytearray-len +return %CPPSELF.size(); +// @snippet qbytearray-len + +// @snippet qbytearray-getitem +if (_i < 0 || _i >= %CPPSELF.size()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; +} else { + char res[2]; + res[0] = %CPPSELF.at(_i); + res[1] = 0; + return PyBytes_FromStringAndSize(res, 1); +} +// @snippet qbytearray-getitem + +// @snippet qbytearray-setitem +%CPPSELF.remove(_i, 1); +PyObject *args = Py_BuildValue("(nO)", _i, _value); +PyObject *result = Sbk_QByteArrayFunc_insert(self, args); +Py_DECREF(args); +Py_XDECREF(result); +return !result ? -1 : 0; +// @snippet qbytearray-setitem + +// @snippet qfiledevice-unmap +uchar *ptr = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_1)); +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(ptr); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qfiledevice-unmap + +// @snippet qfiledevice-map +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1, %2, %3), %2, Shiboken::Buffer::ReadWrite); +// @snippet qfiledevice-map + +// @snippet qiodevice-bufferedread +Py_ssize_t bufferLen; +auto *data = reinterpret_cast<char*>(Shiboken::Buffer::getPointer(%PYARG_1, &bufferLen)); +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(data, PyLong_AsLongLong(%PYARG_2)); +return PyLong_FromLong(%0); +// @snippet qiodevice-bufferedread + +// @snippet qiodevice-readdata +QByteArray ba(1 + qsizetype(%2), char(0)); +%CPPSELF.%FUNCTION_NAME(ba.data(), qint64(%2)); +%PYARG_0 = Shiboken::String::fromCString(ba.constData()); +// @snippet qiodevice-readdata + +// @snippet qcryptographichash-adddata +%CPPSELF.%FUNCTION_NAME(Shiboken::String::toCString(%PYARG_1), Shiboken::String::len(%PYARG_1)); +// @snippet qcryptographichash-adddata + +// @snippet qmetaobject-repr +const QByteArray repr = PySide::MetaObjectBuilder::formatMetaObject(%CPPSELF).toUtf8(); +%PYARG_0 = PyUnicode_FromString(repr.constData()); +// @snippet qmetaobject-repr + +// @snippet qsocketdescriptor +#ifdef WIN32 +using DescriptorType = Qt::HANDLE; +#else +using DescriptorType = int; +#endif +// @snippet qsocketdescriptor + +// @snippet qsocketnotifier +PyObject *socket = %PYARG_1; +if (socket != nullptr) { + // We use qintptr as PyLong, but we check for int + // since it is currently an alias to be Python2 compatible. + // Internally, ints are qlonglongs. + if (%CHECKTYPE[int](socket)) { + int cppSocket = %CONVERTTOCPP[int](socket); + qintptr socket = (qintptr)cppSocket; + %0 = new %TYPE(socket, %2, %3); + } else { + PyErr_SetString(PyExc_TypeError, + "QSocketNotifier: first argument (socket) must be an int."); + } +} +// @snippet qsocketnotifier + +// @snippet qtranslator-load +Py_ssize_t size; +auto *ptr = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_1, &size)); +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar *>(ptr), size); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qtranslator-load + +// @snippet qtimer-singleshot-functorclass +struct QSingleShotTimerFunctor : public Shiboken::PyObjectHolder +{ +public: + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(); +}; + +void QSingleShotTimerFunctor::operator()() +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(0)); + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); + if (Shiboken::Errors::occurred()) + Shiboken::Errors::storeErrorOrPrint(); + release(); // single shot +} +// @snippet qtimer-singleshot-functorclass + +// @snippet qtimer-singleshot-direct-mapping +Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); +%CPPSELF.%FUNCTION_NAME(%1, %2, %3); +// @snippet qtimer-singleshot-direct-mapping + +// @snippet qtimer-singleshot-functor +auto msec = %1; +if (msec == 0) { + if (PyObject_TypeCheck(%2, PySideSignalInstance_TypeF())) { + auto *signal = %PYARG_2; + auto cppCallback = [signal]() + { + Shiboken::GilState state; + Shiboken::AutoDecRef ret(PyObject_CallMethod(signal, "emit", "()")); + Py_DECREF(signal); + }; + + Py_INCREF(signal); + %CPPSELF.%FUNCTION_NAME(msec, cppCallback); + } else { + %CPPSELF.%FUNCTION_NAME(msec, QSingleShotTimerFunctor(%PYARG_2)); + } +} else { + // %FUNCTION_NAME() - disable generation of c++ function call + Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); + auto *timerType = Shiboken::SbkType<QTimer>(); + auto newFunc = reinterpret_cast<newfunc>(PepType_GetSlot(timerType, Py_tp_new)); + auto initFunc = reinterpret_cast<initproc>(PepType_GetSlot(timerType, Py_tp_init)); + auto *pyTimer = newFunc(Shiboken::SbkType<QTimer>(), emptyTuple, nullptr); + initFunc(pyTimer, emptyTuple, nullptr); + + QTimer * timer = %CONVERTTOCPP[QTimer *](pyTimer); + timer->setSingleShot(true); + + if (PyObject_TypeCheck(%2, PySideSignalInstance_TypeF())) { + PySideSignalInstance *signalInstance = reinterpret_cast<PySideSignalInstance *>(%2); + Shiboken::AutoDecRef signalSignature(Shiboken::String::fromFormat("2%s", PySide::Signal::getSignature(signalInstance))); + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, "connect", "OsOO", + pyTimer, + SIGNAL(timeout()), + PySide::Signal::getObject(signalInstance), + signalSignature.object()) + ); + } else { + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, "connect", "OsO", + pyTimer, + SIGNAL(timeout()), + %PYARG_2) + ); + } + + timer->connect(timer, &QTimer::timeout, timer, &QObject::deleteLater, Qt::DirectConnection); + Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(pyTimer)); + Py_XDECREF(pyTimer); + timer->start(msec); +} +// @snippet qtimer-singleshot-functor + +// @snippet qtimer-singleshot-functor-context +auto msec = %1; +if (msec == 0) { + Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); + auto *callable = %PYARG_3; + auto cppCallback = [callable]() + { + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(0)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); + }; + + Py_INCREF(callable); + %CPPSELF.%FUNCTION_NAME(msec, %2, cppCallback); +} else { + Shiboken::AutoDecRef emptyTuple(PyTuple_New(0)); + auto *timerType = Shiboken::SbkType<QTimer>(); + auto newFunc = reinterpret_cast<newfunc>(PepType_GetSlot(timerType, Py_tp_new)); + auto initFunc = reinterpret_cast<initproc>(PepType_GetSlot(timerType, Py_tp_init)); + auto *pyTimer = newFunc(Shiboken::SbkType<QTimer>(), emptyTuple, nullptr); + initFunc(pyTimer, emptyTuple, nullptr); + + QTimer * timer = %CONVERTTOCPP[QTimer *](pyTimer); + timer->setSingleShot(true); + + Shiboken::AutoDecRef result( + PyObject_CallMethod(pyTimer, "connect", "OsOO", + pyTimer, + SIGNAL(timeout()), + %PYARG_2, + %PYARG_3) + ); + + timer->connect(timer, &QTimer::timeout, timer, &QObject::deleteLater, Qt::DirectConnection); + Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(pyTimer)); + Py_XDECREF(pyTimer); + timer->start(msec); +} +// @snippet qtimer-singleshot-functor-context + +// @snippet qprocess-startdetached +qint64 pid; +%RETURN_TYPE retval = %TYPE::%FUNCTION_NAME(%1, %2, %3, &pid); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[qint64](pid)); +// @snippet qprocess-startdetached + +// @snippet qcoreapplication-init +static void QCoreApplicationConstructor(PyObject *self, PyObject *pyargv, QCoreApplicationWrapper **cptr) +{ + static int argc; + static char **argv; + PyObject *stringlist = PyTuple_GET_ITEM(pyargv, 0); + if (Shiboken::listToArgcArgv(stringlist, &argc, &argv, "PySideApp")) { + *cptr = new QCoreApplicationWrapper(argc, argv); + Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(self)); + PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); + } +} +// @snippet qcoreapplication-init + +// @snippet qcoreapplication-1 +QCoreApplicationConstructor(%PYSELF, args, &%0); +// @snippet qcoreapplication-1 + +// @snippet qcoreapplication-2 +PyObject *empty = PyTuple_New(2); +if (!PyTuple_SetItem(empty, 0, PyList_New(0))) { + QCoreApplicationConstructor(%PYSELF, empty, &%0); +} +// @snippet qcoreapplication-2 + +// @snippet qcoreapplication-instance +PyObject *pyApp = Py_None; +if (qApp) { + pyApp = reinterpret_cast<PyObject *>( + Shiboken::BindingManager::instance().retrieveWrapper(qApp)); + if (!pyApp) + pyApp = %CONVERTTOPYTHON[QCoreApplication *](qApp); + // this will keep app live after python exit (extra ref) +} +// PYSIDE-571: make sure that we return the singleton "None" +if (Py_TYPE(pyApp) == Py_TYPE(Py_None)) + Py_DECREF(MakeQAppWrapper(nullptr)); +%PYARG_0 = pyApp; +Py_XINCREF(%PYARG_0); +// @snippet qcoreapplication-instance + +// @snippet qdatastream-readrawdata +QByteArray data; +data.resize(%2); +int result = 0; +Py_BEGIN_ALLOW_THREADS +result = %CPPSELF.%FUNCTION_NAME(data.data(), data.size()); +Py_END_ALLOW_THREADS +if (result == -1) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} else { + %PYARG_0 = PyBytes_FromStringAndSize(data.constData(), result); +} +// @snippet qdatastream-readrawdata + +// @snippet qdatastream-writerawdata-pybuffer +int r = 0; +Py_ssize_t bufferLen; +auto *data = reinterpret_cast<const char*>(Shiboken::Buffer::getPointer(%PYARG_1, &bufferLen)); +Py_BEGIN_ALLOW_THREADS +r = %CPPSELF.%FUNCTION_NAME(data, bufferLen); +Py_END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](r); +// @snippet qdatastream-writerawdata-pybuffer + +// @snippet qdatastream-writerawdata +int r = 0; +Py_BEGIN_ALLOW_THREADS +r = %CPPSELF.%FUNCTION_NAME(%1, Shiboken::String::len(%PYARG_1)); +Py_END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](r); +// @snippet qdatastream-writerawdata + +// @snippet releaseownership +Shiboken::Object::releaseOwnership(%PYARG_0); +// @snippet releaseownership + +// @snippet qanimationgroup-clear +for (int counter = 0, count = %CPPSELF.animationCount(); counter < count; ++counter ) { + QAbstractAnimation *animation = %CPPSELF.animationAt(counter); + PyObject *obj = %CONVERTTOPYTHON[QAbstractAnimation *](animation); + Shiboken::Object::setParent(nullptr, obj); + Py_DECREF(obj); +} +%CPPSELF.clear(); +// @snippet qanimationgroup-clear + +// @snippet qeasingcurve +PySideEasingCurveFunctor::init(); +// @snippet qeasingcurve + +// @snippet qeasingcurve-setcustomtype +QEasingCurve::EasingFunction func = PySideEasingCurveFunctor::createCustomFuntion(%PYSELF, %PYARG_1); +if (func) + %CPPSELF.%FUNCTION_NAME(func); +// @snippet qeasingcurve-setcustomtype + +// @snippet qeasingcurve-customtype +//%FUNCTION_NAME() +%PYARG_0 = PySideEasingCurveFunctor::callable(%PYSELF); +// @snippet qeasingcurve-customtype + +// @snippet qt-signal +%PYARG_0 = Shiboken::String::fromFormat("2%s",QMetaObject::normalizedSignature(%1).constData()); +// @snippet qt-signal + +// @snippet qt-slot +%PYARG_0 = Shiboken::String::fromFormat("1%s",QMetaObject::normalizedSignature(%1).constData()); +// @snippet qt-slot + +// @snippet qt-registerresourcedata +QT_BEGIN_NAMESPACE +extern bool +qRegisterResourceData(int, + const unsigned char *, + const unsigned char *, + const unsigned char *); + +extern bool +qUnregisterResourceData(int, + const unsigned char *, + const unsigned char *, + const unsigned char *); +QT_END_NAMESPACE +// @snippet qt-registerresourcedata + +// @snippet qt-qregisterresourcedata +%RETURN_TYPE %0 = %FUNCTION_NAME(%1, reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_2)), + reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_3)), + reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_4))); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qt-qregisterresourcedata + +// @snippet qt-qunregisterresourcedata +%RETURN_TYPE %0 = %FUNCTION_NAME(%1, reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_2)), + reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_3)), + reinterpret_cast<uchar *>(PyBytes_AS_STRING(%PYARG_4))); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qt-qunregisterresourcedata + +// @snippet use-stream-for-format-security +// Uses the stream version for security reasons +// see gcc man page at -Wformat-security +Py_BEGIN_ALLOW_THREADS +%FUNCTION_NAME() << %1; +Py_END_ALLOW_THREADS +// @snippet use-stream-for-format-security + +// @snippet qresource-registerResource + auto ptr = reinterpret_cast<uchar *>(Shiboken::Buffer::getPointer(%PYARG_1)); + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(const_cast<const uchar *>(ptr), %2); + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qresource-registerResource + +// @snippet qstring-return +%PYARG_0 = %CONVERTTOPYTHON[QString](%1); +// @snippet qstring-return + +// @snippet stream-write-method +Py_BEGIN_ALLOW_THREADS +(*%CPPSELF) << %1; +Py_END_ALLOW_THREADS +// @snippet stream-write-method + +// @snippet stream-read-method +%RETURN_TYPE _cpp_result; +Py_BEGIN_ALLOW_THREADS +(*%CPPSELF) >> _cpp_result; +Py_END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](_cpp_result); +// @snippet stream-read-method + +// @snippet return-qstring-ref +QString &res = *%0; +%PYARG_0 = %CONVERTTOPYTHON[QString](res); +// @snippet return-qstring-ref + +// @snippet return-readData +%RETURN_TYPE %0 = 0; +if (PyBytes_Check(%PYARG_0)) { + %0 = PyBytes_GET_SIZE(%PYARG_0.object()); + memcpy(%1, PyBytes_AS_STRING(%PYARG_0.object()), %0); +} else if (Shiboken::String::check(%PYARG_0.object())) { + %0 = Shiboken::String::len(%PYARG_0.object()); + memcpy(%1, Shiboken::String::toCString(%PYARG_0.object()), %0); +} +// @snippet return-readData + +// @snippet qiodevice-readData +QByteArray ba(1 + qsizetype(%2), char(0)); +Py_BEGIN_ALLOW_THREADS +%CPPSELF.%FUNCTION_NAME(ba.data(), qint64(%2)); +Py_END_ALLOW_THREADS +%PYARG_0 = Shiboken::String::fromCString(ba.constData()); +// @snippet qiodevice-readData + +// @snippet qt-module-shutdown +{ // Avoid name clash + Shiboken::AutoDecRef regFunc(static_cast<PyObject *>(nullptr)); + Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit")); + if (atexit.isNull()) { + qWarning("Module atexit not found for registering __moduleShutdown"); + PyErr_Clear(); + } else { + regFunc.reset(PyObject_GetAttrString(atexit, "register")); + if (regFunc.isNull()) { + qWarning("Function atexit.register not found for registering __moduleShutdown"); + PyErr_Clear(); + } + } + if (!atexit.isNull() && !regFunc.isNull()){ + PyObject *shutDownFunc = PyObject_GetAttrString(module, "__moduleShutdown"); + Shiboken::AutoDecRef args(PyTuple_New(1)); + PyTuple_SET_ITEM(args, 0, shutDownFunc); + Shiboken::AutoDecRef retval(PyObject_Call(regFunc, args, 0)); + Q_ASSERT(!retval.isNull()); + } +} +// @snippet qt-module-shutdown + +// @snippet qthread_init_pypy +#ifdef PYPY_VERSION +// PYSIDE-535: PyPy 7.3.8 needs this call, which is actually a no-op in Python 3.9 +// This function should be replaced by a `Py_Initialize` call, but +// that is still undefined. So we don't rely yet on any PyPy version. +PyEval_InitThreads(); +#endif +// @snippet qthread_init_pypy + +// @snippet qthread_exec_ +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +#ifndef AVOID_PROTECTED_HACK +int cppResult = %CPPSELF.exec(); +#else +int cppResult = static_cast<::QThreadWrapper *>(cppSelf)->QThreadWrapper::exec_protected(); +#endif +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet qthread_exec_ + +// @snippet 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 exec_ + +// @snippet 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; +if (numArgs == 1) + cppResult = %CPPSELF.exec(%1); +else + cppResult = %CPPSELF.exec(); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet exec_arg1 + +// @snippet exec_arg1_noreturn +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +if (numArgs == 1) + %CPPSELF.exec(%1); +else + %CPPSELF.exec(); +%END_ALLOW_THREADS +// @snippet exec_arg1_noreturn + +// @snippet qtextstreammanipulator-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%CPPSELF.exec(%1); +// @snippet qtextstreammanipulator-exec + +/********************************************************************* + * CONVERSIONS + ********************************************************************/ + +// @snippet conversion-pybool +%out = %OUTTYPE(%in == Py_True); +// @snippet conversion-pybool + +// @snippet conversion-pylong-quintptr +#if QT_POINTER_SIZE == 8 +%out = %OUTTYPE(PyLong_AsUnsignedLongLong(%in)); +#else +%out = %OUTTYPE(PyLong_AsUnsignedLong(%in)); +#endif +// @snippet conversion-pylong-quintptr + +// @snippet conversion-pyunicode +%out = PySide::pyUnicodeToQString(%in); +// @snippet conversion-pyunicode + +// @snippet conversion-pynone +SBK_UNUSED(%in) +%out = %OUTTYPE(); +// @snippet conversion-pynone + +// @snippet qfile-path-1 +auto cppArg0 = PySide::pyPathToQString(%PYARG_1); +// @snippet qfile-path-1 + +// @snippet qfile-path-2 +auto cppArg1 = PySide::pyPathToQString(%PYARG_2); +// @snippet qfile-path-2 + +// @snippet qitemselection-add +auto res = (*%CPPSELF) + cppArg0; +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](res); +// @snippet qitemselection-add + +// @snippet conversion-pystring-char +char c = %CONVERTTOCPP[char](%in); +%out = %OUTTYPE(static_cast<unsigned short>(c)); +// @snippet conversion-pystring-char + +// @snippet conversion-pyint +int i = %CONVERTTOCPP[int](%in); +%out = %OUTTYPE(i); +// @snippet conversion-pyint + +// @snippet conversion-qlonglong +// PYSIDE-1250: For QVariant, if the type fits into an int; use int preferably. +qlonglong in = %CONVERTTOCPP[qlonglong](%in); +constexpr qlonglong intMax = qint64(std::numeric_limits<int>::max()); +constexpr qlonglong intMin = qint64(std::numeric_limits<int>::min()); +%out = in >= intMin && in <= intMax ? %OUTTYPE(int(in)) : %OUTTYPE(in); +// @snippet conversion-qlonglong + +// @snippet conversion-qstring +QString in = %CONVERTTOCPP[QString](%in); +%out = %OUTTYPE(in); +// @snippet conversion-qstring + +// @snippet conversion-qbytearray +QByteArray in = %CONVERTTOCPP[QByteArray](%in); +%out = %OUTTYPE(in); +// @snippet conversion-qbytearray + +// @snippet conversion-pyfloat +double in = %CONVERTTOCPP[double](%in); +%out = %OUTTYPE(in); +// @snippet conversion-pyfloat + +// @snippet conversion-sbkobject +// a class supported by QVariant? +const QMetaType metaType = QVariant_resolveMetaType(Py_TYPE(%in)); +bool ok = false; +if (metaType.isValid()) { + QVariant var(metaType); + auto converterO = converterForQtType(metaType.name()); + ok = converterO.has_value(); + if (ok) { + converterO.value().toCpp(pyIn, var.data()); + %out = var; + } else { + qWarning("%s: Cannot find a converter for \"%s\".", + __FUNCTION__, metaType.name()); + } +} + +// If the type was not encountered, return a default PyObjectWrapper +if (!ok) + %out = QVariant::fromValue(PySide::PyObjectWrapper(%in)); +// @snippet conversion-sbkobject + +// @snippet conversion-pydict +QVariant ret = QVariant_convertToVariantMap(%in); +%out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in)); +// @snippet conversion-pydict + +// @snippet conversion-pylist +QVariant ret = QVariant_convertToVariantList(%in); +%out = ret.isValid() ? ret : QVariant::fromValue(PySide::PyObjectWrapper(%in)); +// @snippet conversion-pylist + +// @snippet conversion-pyobject +// Is a shiboken type not known by Qt +%out = QVariant::fromValue(PySide::PyObjectWrapper(%in)); +// @snippet conversion-pyobject + +// @snippet conversion-qjsonobject-pydict +QVariant dict = QVariant_convertToVariantMap(%in); +QJsonValue val = QJsonValue::fromVariant(dict); +%out = val.toObject(); +// @snippet conversion-qjsonobject-pydict + +// @snippet conversion-qdate-pydate +int day = PyDateTime_GET_DAY(%in); +int month = PyDateTime_GET_MONTH(%in); +int year = PyDateTime_GET_YEAR(%in); +%out = %OUTTYPE(year, month, day); +// @snippet conversion-qdate-pydate + +// @snippet conversion-qdatetime-pydatetime +int day = PyDateTime_GET_DAY(%in); +int month = PyDateTime_GET_MONTH(%in); +int year = PyDateTime_GET_YEAR(%in); +int hour = PyDateTime_DATE_GET_HOUR(%in); +int min = PyDateTime_DATE_GET_MINUTE(%in); +int sec = PyDateTime_DATE_GET_SECOND(%in); +int usec = PyDateTime_DATE_GET_MICROSECOND(%in); +%out = %OUTTYPE(QDate(year, month, day), QTime(hour, min, sec, usec/1000)); +// @snippet conversion-qdatetime-pydatetime + +// @snippet conversion-qtime-pytime +int hour = PyDateTime_TIME_GET_HOUR(%in); +int min = PyDateTime_TIME_GET_MINUTE(%in); +int sec = PyDateTime_TIME_GET_SECOND(%in); +int usec = PyDateTime_TIME_GET_MICROSECOND(%in); +%out = %OUTTYPE(hour, min, sec, usec/1000); +// @snippet conversion-qtime-pytime + +// @snippet conversion-qbytearray-pybytes +%out = %OUTTYPE(PyBytes_AS_STRING(%in), PyBytes_GET_SIZE(%in)); +// @snippet conversion-qbytearray-pybytes + +// @snippet conversion-qbytearray-pybytearray +%out = %OUTTYPE(PyByteArray_AsString(%in), PyByteArray_Size(%in)); +// @snippet conversion-qbytearray-pybytearray + +// @snippet conversion-qbytearray-pystring +%out = %OUTTYPE(Shiboken::String::toCString(%in), Shiboken::String::len(%in)); +// @snippet conversion-qbytearray-pystring + +/********************************************************************* + * NATIVE TO TARGET CONVERSIONS + ********************************************************************/ + +// @snippet return-pybool +return PyBool_FromLong((bool)%in); +// @snippet return-pybool + +// @snippet return-pybytes +return PyBytes_FromStringAndSize(%in.constData(), %in.size()); +// @snippet return-pybytes + +// @snippet return-pylong +return PyLong_FromLong(%in); +// @snippet return-pylong + +// @snippet return-pylong-quintptr +#if QT_POINTER_SIZE == 8 +return PyLong_FromUnsignedLongLong(%in); +#else +return PyLong_FromUnsignedLong(%in); +#endif +// @snippet return-pylong-quintptr + +// @snippet return-qfunctionpointer-pylong +return PyLong_FromVoidPtr(reinterpret_cast<void *>(%in)); +// @snippet return-qfunctionpointer-pylong + +// @snippet conversion-pylong-qfunctionpointer +%out = reinterpret_cast<QFunctionPointer>(PyLong_AsVoidPtr(%in)); +// @snippet conversion-pylong-qfunctionpointer + +// @snippet return-pyunicode +return PySide::qStringToPyUnicode(%in); +// @snippet return-pyunicode + +// @snippet return-pyunicode-from-qlatin1string +#ifdef Py_LIMITED_API +return PySide::qStringToPyUnicode(QString::fromLatin1(%in)); +#else +return PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, %in.constData(), %in.size()); +#endif +// @snippet return-pyunicode-from-qlatin1string + +// @snippet qlatin1string-check +static bool qLatin1StringCheck(PyObject *o) +{ + return PyUnicode_CheckExact(o) != 0 + && _PepUnicode_KIND(o) == PepUnicode_1BYTE_KIND; +} +// @snippet qlatin1string-check + +// @snippet conversion-pystring-qlatin1string +const char *data = reinterpret_cast<const char *>(_PepUnicode_DATA(%in)); +const Py_ssize_t len = PyUnicode_GetLength(%in); +%out = QLatin1String(data, len); +// @snippet conversion-pystring-qlatin1string + +// @snippet return-pyunicode-from-qanystringview +return PySide::qStringToPyUnicode(%in.toString()); +// @snippet return-pyunicode-from-qanystringview + +// @snippet return-pyunicode-qchar +auto c = wchar_t(%in.unicode()); +return PyUnicode_FromWideChar(&c, 1); +// @snippet return-pyunicode-qchar + +// @snippet return-qvariant +if (!%in.isValid()) + Py_RETURN_NONE; + +switch (%in.typeId()) { +case QMetaType::UnknownType: +case QMetaType::Nullptr: + Py_RETURN_NONE; +case QMetaType::VoidStar: + if (%in.constData() == nullptr) + Py_RETURN_NONE; + break; + +case QMetaType::QVariantList: { + const auto var = %in.value<QVariantList>(); + return %CONVERTTOPYTHON[QList<QVariant>](var); +} +case QMetaType::QStringList: { + const auto var = %in.value<QStringList>(); + return %CONVERTTOPYTHON[QList<QString>](var); +} +case QMetaType::QVariantMap: { + const auto var = %in.value<QVariantMap>(); + return %CONVERTTOPYTHON[QMap<QString, QVariant>](var); +} +default: + break; +} + +auto converterO = converterForQtType(cppInRef.typeName()); +if (converterO.has_value()) + return converterO.value().toPython(cppInRef.data()); + +PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s'.", %in.typeName()); +return 0; +// @snippet return-qvariant + +// @snippet return-qjsonobject +// The QVariantMap returned by QJsonObject seems to cause a segfault, so +// using QJsonObject.toVariantMap() won't work. +// Wrapping it in a QJsonValue first allows it to work +QJsonValue val(%in); +QVariant ret = val.toVariant(); + +return %CONVERTTOPYTHON[QVariant](ret); +// @snippet return-qjsonobject + +// @snippet qthread_pthread_cleanup +#ifdef Q_OS_UNIX +# include <pthread.h> +static void qthread_pthread_cleanup(void *arg) +{ + // PYSIDE 1282: When terminating a thread using QThread::terminate() + // (pthread_cancel()), QThread::run() is aborted and the lock is released, + // but ~GilState() is still executed for some reason. Prevent it from + // releasing. + auto gil = reinterpret_cast<Shiboken::GilState *>(arg); + gil->abandon(); +} +#endif // Q_OS_UNIX +// @snippet qthread_pthread_cleanup + +// @snippet qthread_pthread_cleanup_install +#ifdef Q_OS_UNIX +pthread_cleanup_push(qthread_pthread_cleanup, &gil); +#endif +// @snippet qthread_pthread_cleanup_install + +// @snippet qthread_pthread_cleanup_uninstall +#ifdef Q_OS_UNIX +pthread_cleanup_pop(0); +#endif +// @snippet qthread_pthread_cleanup_uninstall + +// @snippet qlibraryinfo_build +auto oldResult = pyResult; +const auto version = _PepRuntimeVersion(); +pyResult = PyUnicode_FromFormat( +#ifdef Py_LIMITED_API + "%U [Python limited API %d.%d.%d]", +#else + "%U [Python %d.%d.%d]", +#endif + oldResult, (version >> 16) & 0xFF, + (version >> 8) & 0xFF, version & 0xFF); +Py_DECREF(oldResult); +// @snippet qlibraryinfo_build + +// @snippet qsharedmemory_data_readonly +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size()); +// @snippet qsharedmemory_data_readonly + +// @snippet qsharedmemory_data_readwrite +// FIXME: There is no way to tell whether QSharedMemory was attached read/write +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.size(), + Shiboken::Buffer::ReadWrite); +// @snippet qsharedmemory_data_readwrite + +// @snippet std-function-void-lambda +auto *callable = %PYARG_1; +auto cppCallback = [callable]() +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(0)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); +}; +// @snippet std-function-void-lambda + +// @snippet qthreadpool-start +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(cppCallback, %2); +// @snippet qthreadpool-start + +// @snippet qthreadpool-trystart +Py_INCREF(callable); +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(cppCallback); +%PYARG_0 = %CONVERTTOPYTHON[int](cppResult); +// @snippet qthreadpool-trystart + +// @snippet repr-qevent +QString result; +QDebug(&result).nospace() << "<PySide6.QtCore.QEvent(" << %CPPSELF->type() << ")>"; +%PYARG_0 = Shiboken::String::fromCString(qPrintable(result)); +// @snippet repr-qevent + +// @snippet qmetaproperty_write_enum +if (Shiboken::Enum::check(%PYARG_2)) + cppArg1 = QVariant(int(Shiboken::Enum::getValue(%PYARG_2))); +// @snippet qmetaproperty_write_enum + +// @snippet qdatastream-read-bytes +QByteArray data; +data.resize(%2); +auto dataChar = data.data(); +cppSelf->readBytes(dataChar, %2); +const char *constDataChar = dataChar; +if (dataChar == nullptr) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} else { + %PYARG_0 = PyBytes_FromStringAndSize(constDataChar, %2); +} +// @snippet qdatastream-read-bytes + +// @snippet qloggingcategory_to_cpp +// PYSIDE-2404: Usage of the `get()` function not necessary, the type exists. + QLoggingCategory *category{nullptr}; + Shiboken::Conversions::pythonToCppPointer(SbkPySide6_QtCoreTypeStructs[SBK_QLoggingCategory_IDX].type, + pyArgs[0], &(category)); +// @snippet qloggingcategory_to_cpp + +// Q_ARG()-equivalent +// @snippet q_arg +const QArgData qArgData = qArgDataFromPyType(%1); +if (!qArgData) + return nullptr; + +switch (qArgData.metaType.id()) { + case QMetaType::Bool: + *reinterpret_cast<bool *>(qArgData.data) = %2 == Py_True; + break; + case QMetaType::Int: + *reinterpret_cast<int *>(qArgData.data) = int(PyLong_AsLong(%2)); + break; + case QMetaType::Double: + *reinterpret_cast<double *>(qArgData.data) = PyFloat_AsDouble(%2); + break; + case QMetaType::QString: + *reinterpret_cast<QString *>(qArgData.data) = PySide::pyUnicodeToQString(%2); + break; + default: { + Shiboken::Conversions::SpecificConverter converter(qArgData.metaType.name()); + const auto type = converter.conversionType(); + // Copy for values, Pointer for objects + if (type == Shiboken::Conversions::SpecificConverter::InvalidConversion) { + PyErr_Format(PyExc_RuntimeError, "%s: Unable to find converter for \"%s\".", + __FUNCTION__, qArgData.metaType.name()); + return nullptr; + } + converter.toCpp(%2, qArgData.data); + } +} + +QtCoreHelper::QGenericArgumentHolder result(qArgData.metaType, qArgData.data); +%PYARG_0 = %CONVERTTOPYTHON[QtCoreHelper::QGenericArgumentHolder](result); +// @snippet q_arg + +// Q_RETURN_ARG()-equivalent +// @snippet q_return_arg +const QArgData qArgData = qArgDataFromPyType(%1); +if (!qArgData) + return nullptr; + +QtCoreHelper::QGenericReturnArgumentHolder result(qArgData.metaType, qArgData.data); +%PYARG_0 = %CONVERTTOPYTHON[QtCoreHelper::QGenericReturnArgumentHolder](result); +// @snippet q_return_arg + +// @snippet qmetamethod-invoke-helpers +static InvokeMetaMethodFunc + createInvokeMetaMethodFunc(const QMetaMethod &method, QObject *object, + Qt::ConnectionType type = Qt::AutoConnection) +{ + return [&method, object, type](QGenericArgument a0, QGenericArgument a1, + QGenericArgument a2, QGenericArgument a3, + QGenericArgument a4, QGenericArgument a5, + QGenericArgument a6, QGenericArgument a7, + QGenericArgument a8, QGenericArgument a9) -> bool + { + return method.invoke(object, type, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + }; +} + +static InvokeMetaMethodFuncWithReturn + createInvokeMetaMethodFuncWithReturn(const QMetaMethod &method, QObject *object, + Qt::ConnectionType type = Qt::AutoConnection) +{ + return [&method, object, type](QGenericReturnArgument r, + QGenericArgument a0, QGenericArgument a1, + QGenericArgument a2, QGenericArgument a3, + QGenericArgument a4, QGenericArgument a5, + QGenericArgument a6, QGenericArgument a7, + QGenericArgument a8, QGenericArgument a9) -> bool + { + return method.invoke(object, type, r, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + }; +} +// @snippet qmetamethod-invoke-helpers + +// @snippet qmetamethod-invoke-conn-type-return-arg +%PYARG_0 = invokeMetaMethodWithReturn(createInvokeMetaMethodFuncWithReturn(*%CPPSELF, %1, %2), + %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13); +// @snippet qmetamethod-invoke-conn-type-return-arg + +// @snippet qmetamethod-invoke-return-arg +%PYARG_0 = invokeMetaMethodWithReturn(createInvokeMetaMethodFuncWithReturn(*%CPPSELF, %1), + %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12); +// @snippet qmetamethod-invoke-return-arg + +// @snippet qmetamethod-invoke-conn-type +%PYARG_0 = invokeMetaMethod(createInvokeMetaMethodFunc(*%CPPSELF, %1, %2), + %3, %4, %5, %6, %7, %8, %9, %10, %11, %12); +// @snippet qmetamethod-invoke-conn-type + +// @snippet qmetamethod-invoke +%PYARG_0 = invokeMetaMethod(createInvokeMetaMethodFunc(*%CPPSELF, %1), + %2, %3, %4, %5, %6, %7, %8, %9, %10, %11); +// @snippet qmetamethod-invoke + +// @snippet qmetaobject-invokemethod-helpers +static InvokeMetaMethodFunc + createInvokeMetaMethodFunc(QObject *object, const char *methodName, + Qt::ConnectionType type = Qt::AutoConnection) +{ + return [object, methodName, type](QGenericArgument a0, QGenericArgument a1, + QGenericArgument a2, QGenericArgument a3, + QGenericArgument a4, QGenericArgument a5, + QGenericArgument a6, QGenericArgument a7, + QGenericArgument a8, QGenericArgument a9) -> bool + { + return QMetaObject::invokeMethod(object, methodName, type, + a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + }; +} + +static InvokeMetaMethodFuncWithReturn + createInvokeMetaMethodFuncWithReturn(QObject *object, const char *methodName, + Qt::ConnectionType type = Qt::AutoConnection) +{ + return [object, methodName, type](QGenericReturnArgument r, + QGenericArgument a0, QGenericArgument a1, + QGenericArgument a2, QGenericArgument a3, + QGenericArgument a4, QGenericArgument a5, + QGenericArgument a6, QGenericArgument a7, + QGenericArgument a8, QGenericArgument a9) -> bool + { + return QMetaObject::invokeMethod(object, methodName, type, + r, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + }; +} +// @snippet qmetaobject-invokemethod-helpers + +// invokeMethod(QObject *,const char *, QGenericArgument a0, a1, a2 ) +// @snippet qmetaobject-invokemethod-arg +%PYARG_0 = invokeMetaMethod(createInvokeMetaMethodFunc(%1, %2), + %3, %4, %5, %6, %7, %8, %9, %10, %11, %12); +// @snippet qmetaobject-invokemethod-arg + +// invokeMethod(QObject *,const char *,Qt::ConnectionType, QGenericArgument a0, a1, a2 ) +// @snippet qmetaobject-invokemethod-conn-type-arg +%PYARG_0 = invokeMetaMethod(createInvokeMetaMethodFunc(%1, %2, %3), + %4, %5, %6, %7, %8, %9, %10, %11, %12, %13); +// @snippet qmetaobject-invokemethod-conn-type-arg + +// invokeMethod(QObject *,const char *, Qt::ConnectionType, QGenericReturnArgument,QGenericArgument a0, a1, a2 ) +// @snippet qmetaobject-invokemethod-conn-type-return-arg +%PYARG_0 = invokeMetaMethodWithReturn(createInvokeMetaMethodFuncWithReturn(%1, %2, %3), + %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14); +// @snippet qmetaobject-invokemethod-conn-type-return-arg + +// invokeMethod(QObject *,const char *, QGenericReturnArgument,QGenericArgument a0, a1, a2 ) +// @snippet qmetaobject-invokemethod-return-arg +%PYARG_0 = invokeMetaMethodWithReturn(createInvokeMetaMethodFuncWithReturn(%1, %2), + %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13); +// @snippet qmetaobject-invokemethod-return-arg + +// @snippet keycombination-from-keycombination +cptr = new ::%TYPE(%1); +// @snippet keycombination-from-keycombination + +// @snippet keycombination-from-modifier +cptr = new ::%TYPE(%1, %2); +// @snippet keycombination-from-modifier + +// @snippet qmetamethod-from-signal +auto *signalInst = reinterpret_cast<PySideSignalInstance *>(%PYARG_1); +const auto data = PySide::Signal::getEmitterData(signalInst); +const auto result = data.methodIndex != -1 + ? data.emitter->metaObject()->method(data.methodIndex) + : QMetaMethod{}; +%PYARG_0 = %CONVERTTOPYTHON[QMetaMethod](result); +// @snippet qmetamethod-from-signal + +// @snippet qrunnable_create +auto callable = %PYARG_1; +auto callback = [callable]() -> void +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 1 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, nullptr)); + Py_DECREF(callable); +}; +Py_INCREF(callable); +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(callback); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qrunnable_create + +// @snippet qlocale_system +// For darwin systems, QLocale::system() involves looking at the Info.plist of the application +// bundle to detect the system localization. In the case of Qt for Python, the application bundle +// is the used Python framework. To enable retreival of localized string, the property list key +// CFBunldeAllowMixedLocalizations should be set to True inside the Info.plist file. Otherwise, +// CFBundleDevelopmentRegion will be used to find the language preference of the user, which in the +// case of Python is always english. +// This is a hack until CFBunldeAllowMixedLocalizations will be set in the Python framework +// installation in darwin systems. +// Upstream issue in CPython: https://github.com/python/cpython/issues/108269 +#ifdef Q_OS_DARWIN + Shiboken::AutoDecRef locale(PyImport_ImportModule("locale")); + Shiboken::AutoDecRef getLocale(PyObject_GetAttrString(locale, "getlocale")); + Shiboken::AutoDecRef systemLocale(PyObject_CallObject(getLocale, nullptr)); + PyObject* localeCode = PyTuple_GetItem(systemLocale, 0); + %RETURN_TYPE %0; + if (localeCode != Py_None) { + QString localeCodeStr = PySide::pyStringToQString(localeCode); + %0 = QLocale(localeCodeStr); + } else { + // The default locale is 'C' locale as mentioned in + // https://docs.python.org/3/library/locale.html + %0 = ::QLocale::c(); + } +#else + %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(); +#endif +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet qlocale_system + +// @snippet qcoreapplication-requestpermission +auto permission = %1; +auto callable = %PYARG_3; + +// check if callable +if (!PyCallable_Check(callable)) { + qWarning("Functor of %FUNCTION_NAME is not a callable"); + return {}; +} + +// find the number of arguments of callable. It should either be empy or accept a QPermission +// object +int count = 0; +PyObject* fc = nullptr; +bool classMethod = false; +Shiboken::AutoDecRef func_ob(PyObject_GetAttr(callable, Shiboken::PyMagicName::func())); + +if (func_ob.isNull() && PyObject_HasAttr(callable, Shiboken::PyMagicName::code())) { + // variable `callable` is a function + fc = PyObject_GetAttr(callable, Shiboken::PyMagicName::code()); +} else { + // variable `callable` is a class method + fc = PyObject_GetAttr(func_ob, Shiboken::PyMagicName::code()); + classMethod = true; +} + +if (fc) { + PyObject* ac = PyObject_GetAttrString(fc, "co_argcount"); + if (ac) { + count = PyLong_AsLong(ac); + Py_DECREF(ac); + } + Py_DECREF(fc); +} + +if ((classMethod && (count > 2)) || (!classMethod && (count > 1))) { + qWarning("Functor of %FUNCTION_NAME must either have QPermission object as argument or none." + "The QPermission object store the result of requestPermission()"); + return {}; +} + +bool arg_qpermission = (classMethod && (count == 2)) || (!classMethod && (count == 1)); + +auto callback = [callable, count, arg_qpermission](const QPermission &permission) -> void +{ + Shiboken::GilState state; + if (arg_qpermission) { + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist.object(), 0, %CONVERTTOPYTHON[QPermission](permission)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + } else { + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, nullptr)); + } + Py_DECREF(callable); +}; +Py_INCREF(callable); + +Py_BEGIN_ALLOW_THREADS +%CPPSELF.%FUNCTION_NAME(permission, %2, callback); +Py_END_ALLOW_THREADS +// @snippet qcoreapplication-requestpermission + +// @snippet qlockfile-getlockinfo +qint64 pid{}; +QString hostname, appname; +%CPPSELF.%FUNCTION_NAME(&pid, &hostname, &appname); +%PYARG_0 = PyTuple_New(3); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[qint64](pid)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](hostname)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[QString](appname)); +// @snippet qlockfile-getlockinfo + +// @snippet darwin_permission_plugin +#ifdef Q_OS_DARWIN +#include<QtCore/qplugin.h> +// register the static plugin and setup its metadata +Q_IMPORT_PLUGIN(QDarwinCameraPermissionPlugin) +Q_IMPORT_PLUGIN(QDarwinMicrophonePermissionPlugin) +Q_IMPORT_PLUGIN(QDarwinBluetoothPermissionPlugin) +Q_IMPORT_PLUGIN(QDarwinContactsPermissionPlugin) +Q_IMPORT_PLUGIN(QDarwinCalendarPermissionPlugin) +#endif +// @snippet darwin_permission_plugin + +// @snippet qt-modifier +PyObject *_inputDict = PyDict_New(); +// Note: The builtins line is no longer needed since Python 3.10. Undocumented! +PyDict_SetItemString(_inputDict, "__builtins__", PyEval_GetBuiltins()); +PyDict_SetItemString(_inputDict, "QtCore", module); +PyDict_SetItemString(_inputDict, "Qt", reinterpret_cast<PyObject *>(pyType)); +// Explicitly not dereferencing the result. +PyRun_String(R"PY(if True: + from enum import Flag + from textwrap import dedent + from warnings import warn + # QtCore and Qt come as globals. + + def func_or(self, other): + if isinstance(self, Flag) and isinstance(other, Flag): + # this is normal or-ing flags together + return Qt.KeyboardModifier(self.value | other.value) + return QtCore.QKeyCombination(self, other) + + def func_add(self, other): + warn(dedent(f""" + The "+" operator is deprecated in Qt For Python 6.0 . + Please use "|" instead."""), stacklevel=2) + return func_or(self, other) + + Qt.KeyboardModifier.__or__ = func_or + Qt.KeyboardModifier.__ror__ = func_or + Qt.Modifier.__or__ = func_or + Qt.Modifier.__ror__ = func_or + Qt.KeyboardModifier.__add__ = func_add + Qt.KeyboardModifier.__radd__ = func_add + Qt.Modifier.__add__ = func_add + Qt.Modifier.__radd__ = func_add + +)PY", Py_file_input, _inputDict, _inputDict); +// @snippet qt-modifier diff --git a/sources/pyside6/PySide6/glue/qtdatavisualization.cpp b/sources/pyside6/PySide6/glue/qtdatavisualization.cpp new file mode 100644 index 000000000..3a179cb17 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtdatavisualization.cpp @@ -0,0 +1,90 @@ +// 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 + +// @snippet releaseownership +Shiboken::Object::releaseOwnership(%PYARG_1); +// @snippet releaseownership + +// @snippet qcustom3dvolume-settexturedata +using VectorType = decltype(%1); +%CPPSELF.setTextureData(new VectorType(%1)); +// @snippet qcustom3dvolume-settexturedata + +// @snippet dataproxy-addrow +using ListType = decltype(%1); +%RETURN_TYPE %0 = %CPPSELF.addRow(new ListType(%1)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet dataproxy-addrow + +// @snippet dataproxy-addrow-string +using ListType = decltype(%1); +%RETURN_TYPE %0 = %CPPSELF.addRow(new ListType(%1), %2); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet dataproxy-addrow-string + +// @snippet dataproxy-insertrow +using ListType = decltype(%2); +%CPPSELF.insertRow(%1, new ListType(%2)); +// @snippet dataproxy-insertrow + +// @snippet dataproxy-insertrow-string +using ListType = decltype(%2); +%CPPSELF.insertRow(%1, new ListType(%2), %3); +// @snippet dataproxy-insertrow-string + +// @snippet dataproxy-setrow +using ListType = decltype(%2); +%CPPSELF.setRow(%1, new ListType(%2)); +// @snippet dataproxy-setrow + +// @snippet dataproxy-setrow-string +using ListType = decltype(%2); +%CPPSELF.setRow(%1, new ListType(%2), %3); +// @snippet dataproxy-setrow-string + +// @snippet dataproxy-resetarray +using ListType = decltype(%1); +%CPPSELF.resetArray(new ListType(%1)); +// @snippet dataproxy-resetarray + +// @snippet dataproxy-resetarray2 +using ListType = decltype(%1); +%CPPSELF.resetArray(new ListType(%1), %2, %3); +// @snippet dataproxy-resetarray2 + +// @snippet scatterdataproxy-resetarray +%CPPSELF.resetArray(new QScatterDataArray(*%1)); +// @snippet scatterdataproxy-resetarray + +// @snippet qsurfacedataproxy-resetarraynp +auto *data = QtDataVisualizationHelper::surfaceDataFromNp(%1, %2, %3, %4, %5); +// %CPPSELF.%FUNCTION_NAME +%CPPSELF.resetArray(data); +// @snippet qsurfacedataproxy-resetarraynp + +// @snippet qvalue3daxisformatter-friend +class QFriendlyValue3DAxisFormatter : public QValue3DAxisFormatter +{ +public: +using QValue3DAxisFormatter::gridPositions; +using QValue3DAxisFormatter::labelPositions; +using QValue3DAxisFormatter::labelStrings; +}; + +static inline QFriendlyValue3DAxisFormatter *friendlyFormatter(QValue3DAxisFormatter *f) +{ + return static_cast<QFriendlyValue3DAxisFormatter *>(f); +} +// @snippet qvalue3daxisformatter-friend + +// @snippet qvalue3daxisformatter-setgridpositions +friendlyFormatter(%CPPSELF)->gridPositions() = %1; +// @snippet qvalue3daxisformatter-setgridpositions + +// @snippet qvalue3daxisformatter-setlabelpositions +friendlyFormatter(%CPPSELF)->labelPositions() = %1; +// @snippet qvalue3daxisformatter-setlabelpositions + +// @snippet qvalue3daxisformatter-setlabelstrings +friendlyFormatter(%CPPSELF)->labelStrings() = %1; +// @snippet qvalue3daxisformatter-setlabelstrings diff --git a/sources/pyside6/PySide6/glue/qtdesigner.cpp b/sources/pyside6/PySide6/glue/qtdesigner.cpp new file mode 100644 index 000000000..d26d9f857 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtdesigner.cpp @@ -0,0 +1,7 @@ +// Copyright (C) 2021 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 + +// @snippet qtdesigner-registercustomwidget +if (!QPyDesignerCustomWidgetCollection::_registerCustomWidgetHelper(%PYARG_1, kwds)) + return {}; +// @snippet qtdesigner-registercustomwidget diff --git a/sources/pyside6/PySide6/glue/qtgraphs.cpp b/sources/pyside6/PySide6/glue/qtgraphs.cpp new file mode 100644 index 000000000..b5a5db799 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtgraphs.cpp @@ -0,0 +1,8 @@ +// Copyright (C) 2023 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 + +// @snippet graphs-qsurfacedataproxy-resetarraynp +auto data = QtGraphsHelper::surfaceDataFromNp(%1, %2, %3, %4, %5); +// %CPPSELF.%FUNCTION_NAME +%CPPSELF.resetArray(data); +// @snippet graphs-qsurfacedataproxy-resetarraynp diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp new file mode 100644 index 000000000..5c860a2bf --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtgui.cpp @@ -0,0 +1,947 @@ +// 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)) { + %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result); +} else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qtransform-quadtoquad + +// @snippet qtransform-quadtosquare +QTransform _result; +if (QTransform::quadToSquare(%1, _result)) { + %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result); +} else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qtransform-quadtosquare + +// @snippet qtransform-squaretoquad +QTransform _result; +if (QTransform::squareToQuad(%1, _result)) { + %PYARG_0 = %CONVERTTOPYTHON[QTransform](_result); +} else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qtransform-squaretoquad + +// @snippet qbitmap-fromdata +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 + +// @snippet qtextline-cursortox +%RETURN_TYPE %0 = %CPPSELF->::%TYPE::%FUNCTION_NAME(&%1, %2); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](%0)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%ARG1_TYPE](%1)); +// @snippet qtextline-cursortox + +// @snippet qkeysequence-getitem +if (_i < 0 || _i >= %CPPSELF.count()) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; +} +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 + +// @snippet qtextblock-setuserdata +const QTextDocument *doc = %CPPSELF.document(); +if (doc) { + Shiboken::AutoDecRef pyDocument(%CONVERTTOPYTHON[QTextDocument *](doc)); + Shiboken::Object::setParent(pyDocument, %PYARG_1); +} +// @snippet qtextblock-setuserdata + +// @snippet qtextblock-userdata +const QTextDocument *doc = %CPPSELF.document(); +if (doc) { + Shiboken::AutoDecRef pyDocument(%CONVERTTOPYTHON[QTextDocument *](doc)); + Shiboken::Object::setParent(pyDocument, %PYARG_0); +} +// @snippet qtextblock-userdata + +// @snippet qpolygon-reduce +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{x, y}; + PyList_SET_ITEM(points, i, %CONVERTTOPYTHON[QPoint](pt)); +} +// @snippet qpolygon-reduce + +// @snippet qpolygon-operatorlowerlower +// %FUNCTION_NAME() +*%CPPSELF << %1; +%PYARG_0 = %CONVERTTOPYTHON[QPolygon *](%CPPSELF); +// @snippet qpolygon-operatorlowerlower + +// @snippet qpixmap +%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 + +// @snippet qimage-bits +// byteCount() is only available on Qt4.7, so we use bytesPerLine * height +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(), %CPPSELF.bytesPerLine() * %CPPSELF.height(), Shiboken::Buffer::ReadWrite); +// @snippet qimage-bits + +// @snippet qimage-constscanline +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine()); +// @snippet qimage-constscanline + +// @snippet qimage-scanline +%PYARG_0 = Shiboken::Buffer::newObject(%CPPSELF.%FUNCTION_NAME(%1), %CPPSELF.bytesPerLine(), Shiboken::Buffer::ReadWrite); +// @snippet qimage-scanline + +// @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, nullptr); +// @snippet qcolor-setstate + +// @snippet qcolor-reduce +switch (%CPPSELF.spec()) { + case QColor::Rgb: + { + float r, g, b, a; + %CPPSELF.getRgbF(&r, &g, &b, &a); + %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0), + "setRgbF", r, g, b, a); + break; + } + case QColor::Hsv: + { + float h, s, v, a; + %CPPSELF.getHsvF(&h, &s, &v, &a); + %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0), + "setHsvF", h, s, v, a); + break; + } + case QColor::Cmyk: + { + float c, m, y, k, a; + %CPPSELF.getCmykF(&c, &m, &y, &k, &a); + %PYARG_0 = Py_BuildValue("(ON(s(fffff)))", Py_TYPE(%PYSELF), PyTuple_New(0), + "setCmykF", c, m, y, k, a); + break; + } + case QColor::Hsl: + { + float h, s, l, a; + %CPPSELF.getHslF(&h, &s, &l, &a); + %PYARG_0 = Py_BuildValue("(ON(s(ffff)))", Py_TYPE(%PYSELF), PyTuple_New(0), + "setHslF", h, s, l, a); + break; + } + default: + { + %PYARG_0 = Py_BuildValue("(N(O))", PyObject_Type(%PYSELF), Py_None); + } +} +// @snippet qcolor-reduce + +// @snippet qcolor-totuple +switch (%CPPSELF.spec()) { + case QColor::Rgb: + { + int r, g, b, a; + %CPPSELF.getRgb(&r, &g, &b, &a); + %PYARG_0 = Py_BuildValue("iiii", r, g, b, a); + break; + } + case QColor::Hsv: + { + int h, s, v, a; + %CPPSELF.getHsv(&h, &s, &v, &a); + %PYARG_0 = Py_BuildValue("iiii", h, s, v, a); + break; + } + case QColor::Cmyk: + { + int c, m, y, k, a; + %CPPSELF.getCmyk(&c, &m, &y, &k, &a); + %PYARG_0 = Py_BuildValue("iiiii", c, m, y, k, a); + break; + } + case QColor::Hsl: + { + int h, s, l, a; + %CPPSELF.getHsl(&h, &s, &l, &a); + %PYARG_0 = Py_BuildValue("iiii", h, s, l, a); + break; + } + default: + { + %PYARG_0 = 0; + } +} +// @snippet qcolor-totuple + +// @snippet qcolor +if (%1.type() == QVariant::Color) + %0 = new %TYPE(%1.value<QColor>()); +else + PyErr_SetString(PyExc_TypeError, "QVariant must be holding a QColor"); +// @snippet qcolor + +// @snippet qfontmetricsf-boundingrect +int *array = nullptr; +bool errorOccurred = false; + +if (numArgs == 5) { + array = Shiboken::sequenceToIntArray(%PYARG_5, true); + if (PyErr_Occurred()) { + delete [] array; + errorOccurred = true; + } +} + +if (!errorOccurred) { + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, array); + + delete [] array; + + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); +} +// @snippet qfontmetricsf-boundingrect + +// @snippet qfontmetricsf-size +int *array = nullptr; +bool errorOccurred = false; + +if (numArgs == 4) { + array = Shiboken::sequenceToIntArray(%PYARG_4, true); + if (PyErr_Occurred()) { + delete [] array; + errorOccurred = true; + } +} + +if (!errorOccurred) { + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, array); + + delete [] array; + + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); +} +// @snippet qfontmetricsf-size + +// @snippet qfontmetrics-boundingrect-1 +int *array = nullptr; +bool errorOccurred = false; + +if (numArgs == 8) { + array = Shiboken::sequenceToIntArray(%PYARG_8, true); + if (PyErr_Occurred()) { + delete [] array; + errorOccurred = true; + } +} + +if (!errorOccurred) { + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, %5, %6, %7, array); + + delete [] array; + + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); +} +// @snippet qfontmetrics-boundingrect-1 + +// @snippet qfontmetrics-boundingrect-2 +int *array = nullptr; +bool errorOccurred = false; + +if (numArgs == 5) { + array = Shiboken::sequenceToIntArray(%PYARG_5, true); + if (PyErr_Occurred()) { + delete [] array; + errorOccurred = true; + } +} + +if (!errorOccurred) { + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, array); + + delete [] array; + + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); +} +// @snippet qfontmetrics-boundingrect-2 + +// @snippet qfontmetrics-size +int *array = nullptr; +bool errorOccurred = false; + +if (numArgs == 4) { + array = Shiboken::sequenceToIntArray(%PYARG_4, true); + if (PyErr_Occurred()) { + delete [] array; + errorOccurred = true; + } +} + +if (!errorOccurred) { + %RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, array); + + delete [] array; + + %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval); +} +// @snippet qfontmetrics-size + +// @snippet qpixmapcache-find +QPixmap p; +if (%CPPSELF.%FUNCTION_NAME(%1, &p)) { + %PYARG_0 = %CONVERTTOPYTHON[QPixmap](p); +} else { + %PYARG_0 = Py_None; + Py_INCREF(%PYARG_0); +} +// @snippet qpixmapcache-find + +// @snippet qstandarditem-setchild-1 +// Clear parent from the old child +QStandardItem *_i = %CPPSELF->child(%1, %2); +if (_i) { + PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i); + Shiboken::Object::setParent(nullptr, _pyI); +} +// @snippet qstandarditem-setchild-1 + +// @snippet qstandarditem-setchild-2 +// Clear parent from the old child +QStandardItem *_i = %CPPSELF->child(%1); +if (_i) { + PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i); + Shiboken::Object::setParent(nullptr, _pyI); +} +// @snippet qstandarditem-setchild-2 + +// @snippet qkeyevent-operatornotequal +bool ret = !(&%CPPSELF == %1); +%PYARG_0 = %CONVERTTOPYTHON[bool](ret); +// @snippet qkeyevent-operatornotequal + +// @snippet qstandarditemmodel-setitem-1 +// Clear parent from the old child +QStandardItem *_i = %CPPSELF->item(%1, %2); +if (_i) { + PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i); + Shiboken::Object::setParent(nullptr, _pyI); +} +// @snippet qstandarditemmodel-setitem-1 + +// @snippet qstandarditemmodel-setitem-2 +// Clear parent from the old child +QStandardItem *_i = %CPPSELF->item(%1); +if (_i) { + PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i); + Shiboken::Object::setParent(nullptr, _pyI); +} +// @snippet qstandarditemmodel-setitem-2 + +// @snippet qstandarditemmodel-setverticalheaderitem +// Clear parent from the old child +QStandardItem *_i = %CPPSELF->verticalHeaderItem(%1); +if (_i) { + PyObject *_pyI = %CONVERTTOPYTHON[QStandardItem *](_i); + Shiboken::Object::setParent(nullptr, _pyI); +} +// @snippet qstandarditemmodel-setverticalheaderitem + +// @snippet qstandarditemmodel-clear +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +SbkObject *pyRoot = bm.retrieveWrapper(%CPPSELF.invisibleRootItem()); +if (pyRoot) { + Shiboken::Object::destroy(pyRoot, %CPPSELF.invisibleRootItem()); +} + +for (int r=0, r_max = %CPPSELF.rowCount(); r < r_max; r++) { + QList<QStandardItem *> ri = %CPPSELF.takeRow(0); + + PyObject *pyResult = %CONVERTTOPYTHON[QList<QStandardItem * >](ri); + Shiboken::Object::setParent(Py_None, pyResult); + Py_XDECREF(pyResult); +} +// @snippet qstandarditemmodel-clear + +// @snippet qclipboard-text +%BEGIN_ALLOW_THREADS +%RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(%1, %2); +%END_ALLOW_THREADS +%PYARG_0 = PyTuple_New(2); +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.constData(), %1.size(), %2); +// @snippet qpainter-drawpolygon + +// @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 (Py_ssize_t i = 0; i < 16; ++i) { + PyObject *pv = PySequence_Fast_GET_ITEM(seq.object(), i); + values[i] = PyFloat_AsDouble(pv); + } + + %0 = new %TYPE(values[0], values[1], values[2], values[3], + values[4], values[5], values[6], values[7], + values[8], values[9], values[10], values[11], + values[12], values[13], values[14], values[15]); +} +// @snippet qmatrix4x4 + +// @snippet qmatrix4x4-copydatato +float values[16]; +%CPPSELF.%FUNCTION_NAME(values); +%PYARG_0 = PyTuple_New(16); +for (Py_ssize_t i = 0; i < 16; ++i) { + PyObject *v = PyFloat_FromDouble(values[i]); + PyTuple_SET_ITEM(%PYARG_0, i, v); +} +// @snippet qmatrix4x4-copydatato + +// @snippet qmatrix4x4-mgetitem +if (PySequence_Check(_key)) { + Shiboken::AutoDecRef key(PySequence_Fast(_key, "Invalid matrix index.")); + 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 = PyLong_AsSsize_t(posx); + Py_ssize_t y = PyLong_AsSsize_t(posy); + float ret = (*%CPPSELF)(x,y); + return %CONVERTTOPYTHON[float](ret); + } +} +PyErr_SetString(PyExc_IndexError, "Invalid matrix index."); +return 0; +// @snippet qmatrix4x4-mgetitem + +// @snippet qguiapplication-init +static void QGuiApplicationConstructor(PyObject *self, PyObject *pyargv, QGuiApplicationWrapper **cptr) +{ + static int argc; + static char **argv; + PyObject *stringlist = PyTuple_GET_ITEM(pyargv, 0); + if (Shiboken::listToArgcArgv(stringlist, &argc, &argv, "PySideApp")) { + *cptr = new QGuiApplicationWrapper(argc, argv, 0); + Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(self)); + PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); + } +} +// @snippet qguiapplication-init + +// @snippet qguiapplication-1 +QGuiApplicationConstructor(%PYSELF, args, &%0); +// @snippet qguiapplication-1 + +// @snippet qguiapplication-2 +PyObject *empty = PyTuple_New(2); +if (!PyTuple_SetItem(empty, 0, PyList_New(0))) { + QGuiApplicationConstructor(%PYSELF, empty, &%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 + ********************************************************************/ + +// @snippet conversion-pylong +%out = reinterpret_cast<%OUTTYPE>(PyLong_AsVoidPtr(%in)); +// @snippet conversion-pylong + +/********************************************************************* + * NATIVE TO TARGET CONVERSIONS + ********************************************************************/ + +// @snippet return-pylong-voidptr +return PyLong_FromVoidPtr(reinterpret_cast<void *>(%in)); +// @snippet return-pylong-voidptr diff --git a/sources/pyside6/PySide6/glue/qtmultimedia.cpp b/sources/pyside6/PySide6/glue/qtmultimedia.cpp new file mode 100644 index 000000000..ac8434b97 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtmultimedia.cpp @@ -0,0 +1,28 @@ +// 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 + +// @snippet qvideoframe-bits +#include "object.h" +%BEGIN_ALLOW_THREADS +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1); +%END_ALLOW_THREADS +const auto size = %CPPSELF.mappedBytes(%1); +%PYARG_0 = Shiboken::Buffer::newObject(%0, size, Shiboken::Buffer::ReadWrite); +// @snippet qvideoframe-bits + +// @snippet qaudiobuffer-data +unsigned char *data = %CPPSELF.%FUNCTION_NAME<unsigned char>(); +const auto size = %CPPSELF.byteCount(); +%PYARG_0 = Shiboken::Buffer::newObject(data, size, Shiboken::Buffer::ReadWrite); +// @snippet qaudiobuffer-data + +// @snippet qaudiobuffer-const-data +const unsigned char *data = %CPPSELF.%FUNCTION_NAME<unsigned char>(); +const auto size = %CPPSELF.byteCount(); +%PYARG_0 = Shiboken::Buffer::newObject(data, size); +// @snippet qaudiobuffer-const-data + +// @snippet qtaudio-namespace-compatibility-alias +Py_INCREF(pyType); +PyModule_AddObject(module, "QtAudio", reinterpret_cast<PyObject *>(pyType)); +// @snippet qtaudio-namespace-compatibility-alias diff --git a/sources/pyside6/PySide6/glue/qtnetwork.cpp b/sources/pyside6/PySide6/glue/qtnetwork.cpp new file mode 100644 index 000000000..f635f4671 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtnetwork.cpp @@ -0,0 +1,130 @@ +// 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 + +// @snippet qudpsocket-readdatagram +Shiboken::AutoArrayPointer<char> data(%ARGUMENT_NAMES); +QHostAddress ha; +quint16 port; +%BEGIN_ALLOW_THREADS +%RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(data, %ARGUMENT_NAMES, &ha, &port); +%END_ALLOW_THREADS +QByteArray ba(data, retval); +%PYARG_0 = PyTuple_New(3); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[QByteArray](ba)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QHostAddress](ha)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[quint16](port)); +// @snippet qudpsocket-readdatagram + +// @snippet qhostinfo-lookuphost-functor +struct QHostInfoFunctor : public Shiboken::PyObjectHolder +{ +public: + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(const QHostInfo &hostInfo); +}; + +void QHostInfoFunctor::operator()(const QHostInfo &hostInfo) +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + auto *pyHostInfo = %CONVERTTOPYTHON[QHostInfo](hostInfo); + PyTuple_SET_ITEM(arglist.object(), 0, pyHostInfo); + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); + release(); // single shot +} +// @snippet qhostinfo-lookuphost-functor + +// @snippet qhostinfo-lookuphost-callable +%CPPSELF.%FUNCTION_NAME(%1, QHostInfoFunctor(%PYARG_2)); +// @snippet qhostinfo-lookuphost-callable + +// @snippet qipv6address-len +return 16; +// @snippet qipv6address-len + +// @snippet qipv6address-getitem +if (_i >= 16) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return 0; +} +if (_i < 0) + _i = 16 - qAbs(_i); + +uint item = %CPPSELF.c[_i]; +return %CONVERTTOPYTHON[uint](item); +// @snippet qipv6address-getitem + +// @snippet qipv6address-setitem +if (_i >= 16) { + PyErr_SetString(PyExc_IndexError, "index out of bounds"); + return -1; +} +if (_i < 0) + _i = 16 - qAbs(_i); +quint8 item = %CONVERTTOCPP[quint8](_value); +%CPPSELF.c[_i] = item; +return 0; +// @snippet qipv6address-setitem + +// @snippet qrestaccessmanager-functor +class QRestFunctor +{ +public: + explicit QRestFunctor(PyObject *callable) noexcept : m_callable(callable) + { + Py_INCREF(callable); + } + + void operator()(QRestReply &restReply); + +private: + PyObject *m_callable; +}; + +void QRestFunctor::operator()(QRestReply &restReply) +{ + Q_ASSERT(m_callable); + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + auto *restReplyPtr = &restReply; + auto *pyRestReply = %CONVERTTOPYTHON[QRestReply*](restReplyPtr); + PyTuple_SET_ITEM(arglist.object(), 0, pyRestReply); + Shiboken::AutoDecRef ret(PyObject_CallObject(m_callable, arglist)); + Py_DECREF(m_callable); + m_callable = nullptr; +} +// @snippet qrestaccessmanager-functor + +// @snippet qrestaccessmanager-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, QRestFunctor(%PYARG_3)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-callback + +// @snippet qrestaccessmanager-data-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, QRestFunctor(%PYARG_4)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-data-callback + +// @snippet qrestaccessmanager-method-data-callback +auto *networkReply = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, QRestFunctor(%PYARG_5)); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](networkReply); +// @snippet qrestaccessmanager-method-data-callback + +// @snippet qrestreply-readjson +QJsonParseError jsonParseError; +std::optional<QJsonDocument> documentOptional = %CPPSELF.%FUNCTION_NAME(&jsonParseError); + +PyObject *pyDocument{}; +if (documentOptional.has_value()) { + const auto &document = documentOptional.value(); + pyDocument = %CONVERTTOPYTHON[QJsonDocument](document); +} else { + pyDocument = Py_None; + Py_INCREF(Py_None); +} + +%PYARG_0 = PyTuple_New(2); +PyTuple_SetItem(%PYARG_0, 0, pyDocument); +PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QJsonParseError](jsonParseError)); +// @snippet qrestreply-readjson diff --git a/sources/pyside6/PySide6/glue/qtnetworkauth.cpp b/sources/pyside6/PySide6/glue/qtnetworkauth.cpp new file mode 100644 index 000000000..7877a8dd5 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtnetworkauth.cpp @@ -0,0 +1,44 @@ +// Copyright (C) 2022 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 + +// @snippet qabstractoauth-lookuphost-functor +struct QAbstractOAuthModifyFunctor : public Shiboken::PyObjectHolder +{ +public: + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant>* dictPointer); +}; + +void QAbstractOAuthModifyFunctor::operator()(QAbstractOAuth::Stage stage, + QMultiMap<QString, QVariant>* dictPointer) +{ + auto *callable = object(); + if (!PyCallable_Check(callable)) { + qWarning("Argument 1 of setModifyParametersFunction() must be a callable."); + return; + } + Shiboken::GilState state; + QMultiMap<QString, QVariant> dict = *dictPointer; + Shiboken::AutoDecRef arglist(PyTuple_New(2)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QAbstractOAuth::Stage](stage)); + PyTuple_SET_ITEM(arglist, 1, %CONVERTTOPYTHON[QMultiMap<QString, QVariant>](dict)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + + if (!ret.isNull() && PyDict_Check(ret.object()) != 0) { + PyObject *key{}; + PyObject *value{}; + Py_ssize_t pos = 0; + while (PyDict_Next(ret.object(), &pos, &key, &value)) { + QString cppKey = %CONVERTTOCPP[QString](key); + QVariant cppValue = %CONVERTTOCPP[QVariant](value); + dictPointer->replace(cppKey, cppValue); + } + } +} +// @snippet qabstractoauth-lookuphost-functor + +// @snippet qabstractoauth-setmodifyparametersfunction +%CPPSELF.%FUNCTION_NAME(QAbstractOAuthModifyFunctor(%PYARG_1)); +// @snippet qabstractoauth-setmodifyparametersfunction + diff --git a/sources/pyside6/PySide6/glue/qtopengl.cpp b/sources/pyside6/PySide6/glue/qtopengl.cpp new file mode 100644 index 000000000..cdfaafb3b --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtopengl.cpp @@ -0,0 +1,89 @@ +// Copyright (C) 2021 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 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 qopenglversionfunctionsfactory-get +QAbstractOpenGLFunctions *af = %CPPSELF.%FUNCTION_NAME(%1, %2); +if (auto *f = dynamic_cast<QOpenGLFunctions_4_5_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_5_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_5_Compatibility *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_5_Compatibility *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_4_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_4_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_4_Compatibility *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_4_Compatibility *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_3_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_3_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_2_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_2_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_1_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_1_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_0_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_0_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_4_0_Compatibility *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_4_0_Compatibility *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_3_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_3_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_3_Compatibility *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_3_Compatibility *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_2_Core *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_2_Core *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_2_Compatibility *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_2_Compatibility *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_1 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_1 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_3_0 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_3_0 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_2_1 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_2_1 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_2_0 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_2_0 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_5 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_5 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_4 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_4 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_3 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_3 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_2 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_2 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_1 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_1 *](f); +} else if (auto *f = dynamic_cast<QOpenGLFunctions_1_0 *>(af)) { + %PYARG_0 = %CONVERTTOPYTHON[QOpenGLFunctions_1_0 *](f); +} else { + QString message; + QDebug(&message) << "No OpenGL functions could be obtained for" << %1; + PyErr_SetString(PyExc_RuntimeError, message.toUtf8().constData()); + %PYARG_0 = Py_None; +} +// @snippet qopenglversionfunctionsfactory-get + +// @snippet glgetvreturnsize_declaration +int glGetVReturnSize(GLenum pname); +// @snippet glgetvreturnsize_declaration + +// @snippet glgeti-vreturnsize_declaration +int glGetI_VReturnSize(GLenum pname); +// @snippet glgeti-vreturnsize_declaration + +// @snippet vao-binder-enter +Py_INCREF(%PYSELF); +pyResult = %PYSELF; +// @snippet vao-binder-enter + +// @snippet vao-binder-exit +%CPPSELF.release(); +// @snippet vao-binder-exit diff --git a/sources/pyside6/PySide6/glue/qtpositioning.cpp b/sources/pyside6/PySide6/glue/qtpositioning.cpp new file mode 100644 index 000000000..91c331c74 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtpositioning.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2024 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 darwin_location_permission_plugin +#ifdef Q_OS_DARWIN +#include<QtCore/qplugin.h> +// register the static plugin and setup its metadata +Q_IMPORT_PLUGIN(QDarwinLocationPermissionPlugin) +#endif +// @snippet darwin_location_permission_plugin diff --git a/sources/pyside6/PySide6/glue/qtprintsupport.cpp b/sources/pyside6/PySide6/glue/qtprintsupport.cpp new file mode 100644 index 000000000..39672c62a --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtprintsupport.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2019 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 + +// @snippet setpagesize +bool out = %CPPSELF.setPageSize(%1); +%PYARG_0 = %CONVERTTOPYTHON[bool](out); +// @snippet setpagesize + +// @snippet 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 exec diff --git a/sources/pyside6/PySide6/glue/qtqml.cpp b/sources/pyside6/PySide6/glue/qtqml.cpp new file mode 100644 index 000000000..a56db8de6 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtqml.cpp @@ -0,0 +1,90 @@ +// 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 + +// @snippet qmlerrror-repr +const QByteArray message = %CPPSELF.toString().toUtf8(); +%PYARG_0 = Shiboken::String::fromCString(message.constData()); +// @snippet qmlerrror-repr + +// @snippet qmlattachedpropertiesobject +auto *%0 = PySide::Qml::qmlAttachedPropertiesObject(%ARGUMENT_NAMES); +%PYARG_0 = %CONVERTTOPYTHON[QObject*](%0); +// @snippet qmlattachedpropertiesobject + +// @snippet qmlregistertype +int %0 = PySide::Qml::qmlRegisterType(%ARGUMENT_NAMES); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregistertype + +// @snippet qmlregistersingletontype_qobject_callback +int %0 = PySide::Qml::qmlRegisterSingletonType(%ARGUMENT_NAMES, true, true); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregistersingletontype_qobject_callback + +// @snippet qmlregistersingletontype_qobject_nocallback +int %0 = PySide::Qml::qmlRegisterSingletonType(%ARGUMENT_NAMES, nullptr, true, false); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregistersingletontype_qobject_nocallback + +// @snippet qmlregistersingletontype_qjsvalue +int %0 = PySide::Qml::qmlRegisterSingletonType(nullptr, %ARGUMENT_NAMES, false, true); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregistersingletontype_qjsvalue + +// @snippet qmlregistersingletoninstance +int %0 = PySide::Qml::qmlRegisterSingletonInstance(%ARGUMENT_NAMES); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregistersingletoninstance + +// @snippet qmlregisteruncreatabletype +int %0 = PySide::Qml::qmlRegisterType(%ARGUMENT_NAMES, false); +%PYARG_0 = %CONVERTTOPYTHON[int](%0); +// @snippet qmlregisteruncreatabletype + +// @snippet init +PySide::Qml::init(module); +initQtQmlVolatileBool(module); +// @snippet init + +// @snippet qjsengine-toscriptvalue +%RETURN_TYPE retval = %CPPSELF.%FUNCTION_NAME(%1); +return %CONVERTTOPYTHON[%RETURN_TYPE](retval); +// @snippet qjsengine-toscriptvalue + +// @snippet qmlelement +%PYARG_0 = PySide::Qml::qmlElementMacro(%ARGUMENT_NAMES); +// @snippet qmlelement + +// @snippet qmlanonymous +%PYARG_0 = PySide::Qml::qmlAnonymousMacro(%ARGUMENT_NAMES); +// @snippet qmlanonymous + +// @snippet qmlsingleton +%PYARG_0 = PySide::Qml::qmlSingletonMacro(%ARGUMENT_NAMES); +// @snippet qmlsingleton + +// @snippet qqmlengine-singletoninstance-qmltypeid +QJSValue instance = %CPPSELF.singletonInstance<QJSValue>(%1); +if (instance.isNull()) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} else if (instance.isQObject()) { + QObject *result = instance.toQObject(); + %PYARG_0 = %CONVERTTOPYTHON[QObject *](result); +} else { + %PYARG_0 = %CONVERTTOPYTHON[QJSValue](instance); +} +// @snippet qqmlengine-singletoninstance-qmltypeid + +// @snippet qqmlengine-singletoninstance-typename +QJSValue instance = %CPPSELF.singletonInstance<QJSValue>(%1, %2); +if (instance.isNull()) { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} else if (instance.isQObject()) { + QObject *result = instance.toQObject(); + %PYARG_0 = %CONVERTTOPYTHON[QObject *](result); +} else { + %PYARG_0 = %CONVERTTOPYTHON[QJSValue](instance); +} +// @snippet qqmlengine-singletoninstance-typename diff --git a/sources/pyside6/PySide6/glue/qtquick.cpp b/sources/pyside6/PySide6/glue/qtquick.cpp new file mode 100644 index 000000000..060418faf --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtquick.cpp @@ -0,0 +1,27 @@ +// 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 + +// @snippet qtquick +PySide::initQuickSupport(module); +// @snippet qtquick + +// @snippet qsgeometry-vertexdataaspoint2d +auto *points = %CPPSELF->vertexDataAsPoint2D(); +const Py_ssize_t vertexCount = %CPPSELF->vertexCount(); +%PYARG_0 = PyList_New(vertexCount); +for (Py_ssize_t i = 0; i < vertexCount; ++i) { + QSGGeometry::Point2D p = points[i]; + PyList_SET_ITEM(%PYARG_0, i, %CONVERTTOPYTHON[QSGGeometry::Point2D](p)); +} +// @snippet qsgeometry-vertexdataaspoint2d + +// @snippet qsgeometry-setvertexdataaspoint2d +const qsizetype vertexCount = %CPPSELF->vertexCount(); +if (vertexCount != %1.size()) { + PyErr_SetString(PyExc_RuntimeError, "size mismatch"); + return {}; +} + +QSGGeometry::Point2D *points = %CPPSELF->vertexDataAsPoint2D(); +std::copy(%1.cbegin(), %1.cend(), points); +// @snippet qsgeometry-setvertexdataaspoint2d diff --git a/sources/pyside6/PySide6/glue/qtquicktest.cpp b/sources/pyside6/PySide6/glue/qtquicktest.cpp new file mode 100644 index 000000000..f41735ddf --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtquicktest.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2023 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 call-quick-test-main +static int callQuickTestMain(const QString &name, QObject *setup, + QStringList argv, QString dir) +{ + if (dir.isEmpty()) + dir = QDir::currentPath(); + if (argv.isEmpty()) + argv.append(name); + + std::vector<QByteArray> argvB; + std::vector<char *> argvC; + const auto argc = argv.size(); + argvB.reserve(argc); + argvC.reserve(argc); + for (const auto &arg : argv) { + argvB.emplace_back(arg.toUtf8()); + argvC.push_back(argvB.back().data()); + } + + return quick_test_main_with_setup(int(argc), argvC.data(), + name.toUtf8().constData(), + dir.toUtf8().constData(), setup); +} +// @snippet call-quick-test-main + +// @snippet quick-test-main +const int exitCode = callQuickTestMain(%1, nullptr, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[int](exitCode); +// @snippet quick-test-main + +// @snippet quick-test-main_with_setup +Shiboken::AutoDecRef pySetupObject(PyObject_CallObject(reinterpret_cast<PyObject *>(%2), nullptr)); +if (pySetupObject.isNull() || PyErr_Occurred() != nullptr) + return nullptr; + +/// Convenience to convert a PyObject to QObject +QObject *setupObject = PySide::convertToQObject(pySetupObject.object(), true /* raiseError */); +if (setupObject == nullptr) + return nullptr; + +const int exitCode = callQuickTestMain(%1, setupObject, %3, %4); +%PYARG_0 = %CONVERTTOPYTHON[int](exitCode); +// @snippet quick-test-main_with_setup diff --git a/sources/pyside6/PySide6/glue/qtserialbus.cpp b/sources/pyside6/PySide6/glue/qtserialbus.cpp new file mode 100644 index 000000000..b5b491f49 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtserialbus.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2022 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 qcanbus-available-devices +QString errorMessage; +const QList<QCanBusDeviceInfo> result = %CPPSELF.%FUNCTION_NAME(%1, &errorMessage); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[QList<QCanBusDeviceInfo>](result)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorMessage)); +// @snippet qcanbus-available-devices + +// @snippet qcanbus-createdevice +PyObject *pyDevice{}; +QString errorMessage; +if (auto *device = %CPPSELF.%FUNCTION_NAME(%1, %2, &errorMessage)) { + pyDevice = %CONVERTTOPYTHON[%RETURN_TYPE](device); + // Ownership transferences (target) + Shiboken::Object::getOwnership(pyDevice); +} else { + pyDevice = Py_None; + Py_INCREF(pyDevice); +} +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, pyDevice); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorMessage)); +// @snippet qcanbus-createdevice diff --git a/sources/pyside6/PySide6/glue/qtsql.cpp b/sources/pyside6/PySide6/glue/qtsql.cpp new file mode 100644 index 000000000..ff0d7a7a4 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtsql.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2021 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 + + +// @snippet simple-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +bool cppResult = %CPPSELF.exec(); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +// @snippet simple-exec + + +// @snippet qsqldatabase-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +QSqlQuery cppResult = %CPPSELF.exec(%1); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[QSqlQuery](cppResult); +// @snippet qsqldatabase-exec + +// @snippet qsqlquery-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +bool cppResult = %CPPSELF.exec(%1); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +// @snippet qsqlquery-exec + +// @snippet qsqlresult-exec +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +#ifndef AVOID_PROTECTED_HACK +bool cppResult = %CPPSELF.exec(); +#else +bool cppResult = static_cast<::QSqlResultWrapper *>(cppSelf)->QSqlResultWrapper::exec_protected(); +#endif +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[bool](cppResult); +// @snippet qsqlresult-exec diff --git a/sources/pyside6/PySide6/glue/qtstatemachine.cpp b/sources/pyside6/PySide6/glue/qtstatemachine.cpp new file mode 100644 index 000000000..098200b14 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtstatemachine.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2021 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 qsignaltransition +if (PyObject_TypeCheck(%1, PySideSignalInstance_TypeF())) { + auto *signalInstance = reinterpret_cast<PySideSignalInstance *>(%PYARG_1); + PyObject *dataSource = PySide::Signal::getObject(signalInstance); + Shiboken::AutoDecRef obType(PyObject_Type(dataSource)); + QObject * sender = %CONVERTTOCPP[QObject *](dataSource); + //XXX /|\ omitting this space crashes shiboken! + if (sender) { + const char *dataSignature = PySide::Signal::getSignature(signalInstance); + QByteArray signature(dataSignature); // Append SIGNAL flag (2) + signature.prepend('2'); + %0 = new QSignalTransitionWrapper(sender, signature, %2); + } +} +// @snippet qsignaltransition + +// @snippet qstate-addtransition-1 +QByteArray signalName(%2); +signalName.remove(0, 1); +if (PySide::SignalManager::registerMetaMethod(%1, signalName.constData(), + QMetaMethod::Signal)) { + QSignalTransition *%0 = %CPPSELF->addTransition(%1, %2, %3); + %PYARG_0 = %CONVERTTOPYTHON[QSignalTransition *](%0); +} else { + Py_INCREF(Py_None); + %PYARG_0 = Py_None; +} +// @snippet qstate-addtransition-1 + +// @snippet qstate-addtransition-2 +// Obviously the label used by the following goto is a very awkward solution, +// since it refers to a name very tied to the generator implementation. +// Check bug #362 for more information on this +// http://bugs.openbossa.org/show_bug.cgi?id=362 +// PYSIDE-2256: The label was removed +if (!PyObject_TypeCheck(%1, PySideSignalInstance_TypeF())) + return Shiboken::returnWrongArguments(args, fullName, errInfo); +PySideSignalInstance *signalInstance = reinterpret_cast<PySideSignalInstance *>(%1); +auto sender = %CONVERTTOCPP[QObject *](PySide::Signal::getObject(signalInstance)); +QSignalTransition *%0 = %CPPSELF->%FUNCTION_NAME(sender, PySide::Signal::getSignature(signalInstance),%2); +%PYARG_0 = %CONVERTTOPYTHON[QSignalTransition *](%0); +// @snippet qstate-addtransition-2 + +// @snippet qstatemachine-configuration +%PYARG_0 = PySet_New(0); +for (auto *abs_state : %CPPSELF.configuration()) { + Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractState *](abs_state)); + Shiboken::Object::setParent(self, obj); + PySet_Add(%PYARG_0, obj); +} +// @snippet qstatemachine-configuration + +// @snippet qstatemachine-defaultanimations +%PYARG_0 = PyList_New(0); +for (auto *abs_anim : %CPPSELF.defaultAnimations()) { + Shiboken::AutoDecRef obj(%CONVERTTOPYTHON[QAbstractAnimation *](abs_anim)); + Shiboken::Object::setParent(self, obj); + PyList_Append(%PYARG_0, obj); +} +// @snippet qstatemachine-defaultanimations diff --git a/sources/pyside6/PySide6/glue/qttest.cpp b/sources/pyside6/PySide6/glue/qttest.cpp new file mode 100644 index 000000000..626cc1608 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qttest.cpp @@ -0,0 +1,24 @@ +// Copyright (C) 2021 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 qsignalspy-signal +auto *signalInst = reinterpret_cast<PySideSignalInstance *>(%PYARG_1); +PyObject *emitterPyObject = PySide::Signal::getObject(signalInst); +QObject* emitter = %CONVERTTOCPP[QObject *](emitterPyObject); +QByteArray signature = PySide::Signal::getSignature(signalInst); +if (!signature.isEmpty()) + signature.prepend('2'); // SIGNAL() macro + +if (emitter == nullptr || signature.isEmpty()) { + QByteArray error = QByteArrayLiteral("Wrong parameter (") + + (%PYARG_1)->ob_type->tp_name + + QByteArrayLiteral(") passed, QSignalSpy requires a signal."); + PyErr_SetString(PyExc_ValueError, error.constData()); + return -1; +} +%0 = new QSignalSpyWrapper(emitter, signature.constData()); +// @snippet qsignalspy-signal diff --git a/sources/pyside6/PySide6/glue/qtuitools.cpp b/sources/pyside6/PySide6/glue/qtuitools.cpp new file mode 100644 index 000000000..1835ed096 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtuitools.cpp @@ -0,0 +1,212 @@ +// 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 +// @snippet uitools-loadui +/* + * Based on code provided by: + * Antonio Valentino <antonio.valentino at tiscali.it> + * Frédéric <frederic.mantegazza at gbiloba.org> + */ + +#include <shiboken.h> + +#include <QtUiTools/QUiLoader> +#include <QtWidgets/QWidget> +#include <QtCore/QFile> + +static void createChildrenNameAttributes(PyObject *root, QObject *object) +{ + for (auto *child : object->children()) { + const QByteArray name = child->objectName().toLocal8Bit(); + + if (!name.isEmpty() && !name.startsWith("_") && !name.startsWith("qt_")) { + Shiboken::AutoDecRef attrName(Py_BuildValue("s", name.constData())); + if (!PyObject_HasAttr(root, attrName)) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QObject *](child)); + PyObject_SetAttr(root, attrName, pyChild); + } + createChildrenNameAttributes(root, child); + } + createChildrenNameAttributes(root, child); + } +} + +static PyObject *QUiLoadedLoadUiFromDevice(QUiLoader *self, QIODevice *dev, QWidget *parent) +{ + QWidget *wdg = self->load(dev, parent); + + if (wdg) { + PyObject *pyWdg = %CONVERTTOPYTHON[QWidget *](wdg); + createChildrenNameAttributes(pyWdg, wdg); + if (parent) { + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](parent)); + Shiboken::Object::setParent(pyParent, pyWdg); + } + return pyWdg; + } + + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to open/read ui device"); + return nullptr; +} + +static PyObject *QUiLoaderLoadUiFromFileName(QUiLoader *self, const QString &uiFile, QWidget *parent) +{ + QFile fd(uiFile); + return QUiLoadedLoadUiFromDevice(self, &fd, parent); +} +// @snippet uitools-loadui + +// @snippet quiloader +Q_IMPORT_PLUGIN(PyCustomWidgets); +// @snippet quiloader + +// @snippet quiloader-registercustomwidget +registerCustomWidget(%PYARG_1); +%CPPSELF.addPluginPath(QString{}); // force reload widgets +// @snippet quiloader-registercustomwidget + +// @snippet quiloader-load-1 +// Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() +%PYARG_0 = QUiLoadedLoadUiFromDevice(%CPPSELF, %1, %2); +// @snippet quiloader-load-1 + +// @snippet quiloader-load-2 +// Avoid calling the original function: %CPPSELF.%FUNCTION_NAME() +auto str = PySide::pyPathToQString(%1); +%PYARG_0 = QUiLoaderLoadUiFromFileName(%CPPSELF, str, %2); +// @snippet quiloader-load-2 + +// @snippet loaduitype +/* +Arguments: + %PYARG_1 (uifile) +*/ +// 1. Generate the Python code from the UI file +PyObject *strObj = PyUnicode_AsUTF8String(%PYARG_1); +char *arg1 = PyBytes_AsString(strObj); +QByteArray uiFileName(arg1); +Py_DECREF(strObj); + +if (uiFileName.isEmpty()) { + qCritical() << "Error converting the UI filename to QByteArray"; + Py_RETURN_NONE; +} + +QFile uiFile(QString::fromUtf8(uiFileName)); + +if (!uiFile.exists()) { + qCritical().noquote() << "File" << uiFileName << "does not exist"; + Py_RETURN_NONE; +} + +// Use the 'pyside6-uic' wrapper instead of 'uic' +// This approach is better than rely on 'uic' since installing +// the wheels cover this case. +QString uicBin(QStringLiteral("pyside6-uic")); +QStringList uicArgs = {QString::fromUtf8(uiFileName)}; + +QProcess uicProcess; +uicProcess.start(uicBin, uicArgs); +if (!uicProcess.waitForStarted()) { + qCritical().noquote() << "Cannot run '" << uicBin << "': " + << uicProcess.errorString() << " - Check if 'pyside6-uic' is in PATH"; + Py_RETURN_NONE; +} + +if (!uicProcess.waitForFinished() + || uicProcess.exitStatus() != QProcess::NormalExit + || uicProcess.exitCode() != 0) { + qCritical().noquote() << '\'' << uicBin << "' failed: " + << uicProcess.errorString() << " - Exit status " << uicProcess.exitStatus() + << " (" << uicProcess.exitCode() << ")\n"; + Py_RETURN_NONE; +} + +QByteArray uiFileContent = uicProcess.readAllStandardOutput(); +QByteArray errorOutput = uicProcess.readAllStandardError(); + +if (!errorOutput.isEmpty()) { + qCritical().noquote() << '\'' << uicBin << "' failed: " << errorOutput; + Py_RETURN_NONE; +} + +// 2. Obtain the 'classname' and the Qt base class. +QByteArray className; +QByteArray baseClassName; + +// Problem +// The generated Python file doesn't have the Qt Base class information. + +// Solution +// Use the XML file +if (!uiFile.open(QIODevice::ReadOnly)) + Py_RETURN_NONE; + +// This will look for the first <widget> tag, e.g.: +// <widget class="QWidget" name="ThemeWidgetForm"> +// and then extract the information from "class", and "name", +// to get the baseClassName and className respectively +QXmlStreamReader reader(&uiFile); +while (!reader.atEnd() && baseClassName.isEmpty() && className.isEmpty()) { + auto token = reader.readNext(); + if (token == QXmlStreamReader::StartElement && reader.name() == u"widget") { + baseClassName = reader.attributes().value(QLatin1StringView("class")).toUtf8(); + className = reader.attributes().value(QLatin1StringView("name")).toUtf8(); + } +} + +uiFile.close(); + +if (className.isEmpty() || baseClassName.isEmpty() || reader.hasError()) { + qCritical() << "An error occurred when parsing the UI file while looking for the class info " + << reader.errorString(); + Py_RETURN_NONE; +} + +QByteArray pyClassName("Ui_"+className); + +PyObject *module = PyImport_ImportModule("__main__"); +PyObject *loc = PyModule_GetDict(module); + +// 3. exec() the code so the class exists in the context: exec(uiFileContent) +// The context of PyRun_SimpleString is __main__. +// 'Py_file_input' is the equivalent to using exec(), since it will execute +// the code, without returning anything. +Shiboken::AutoDecRef codeUi(Py_CompileString(uiFileContent.constData(), "<stdin>", Py_file_input)); +if (codeUi.isNull()) { + qCritical() << "Error while compiling the generated Python file"; + Py_RETURN_NONE; +} +PyObject *uiObj = PyEval_EvalCode(codeUi, loc, loc); + +if (uiObj == nullptr) { + qCritical() << "Error while running exec() on the generated code"; + Py_RETURN_NONE; +} + +// 4. eval() the name of the class on a variable to return +// 'Py_eval_input' is the equivalent to using eval(), since it will just +// evaluate an expression. +Shiboken::AutoDecRef codeClass(Py_CompileString(pyClassName.constData(),"<stdin>", Py_eval_input)); +if (codeClass.isNull()) { + qCritical() << "Error while compiling the Python class"; + Py_RETURN_NONE; +} + +Shiboken::AutoDecRef codeBaseClass(Py_CompileString(baseClassName.constData(), "<stdin>", Py_eval_input)); +if (codeBaseClass.isNull()) { + qCritical() << "Error while compiling the base class"; + Py_RETURN_NONE; +} + +PyObject *classObj = PyEval_EvalCode(codeClass, loc, loc); +PyObject *baseClassObj = PyEval_EvalCode(codeBaseClass, loc, loc); + +%PYARG_0 = PyTuple_New(2); +if (%PYARG_0 == nullptr) { + qCritical() << "Error while creating the return Tuple"; + Py_RETURN_NONE; +} +PyTuple_SET_ITEM(%PYARG_0, 0, classObj); +PyTuple_SET_ITEM(%PYARG_0, 1, baseClassObj); +// @snippet loaduitype diff --git a/sources/pyside6/PySide6/glue/qtwebenginecore.cpp b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp new file mode 100644 index 000000000..76a7c6d73 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtwebenginecore.cpp @@ -0,0 +1,64 @@ +// Copyright (C) 2022 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 + +// @snippet qwebenginecookiestore-functor +struct QWebEngineCookieFilterFunctor : public Shiboken::PyObjectHolder +{ + using Shiboken::PyObjectHolder::PyObjectHolder; + + bool operator()(const QWebEngineCookieStore::FilterRequest& filterRequest) const; +}; + +bool QWebEngineCookieFilterFunctor::operator()(const QWebEngineCookieStore::FilterRequest & + filterRequest) const +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, + %CONVERTTOPYTHON[QWebEngineCookieStore::FilterRequest](filterRequest)); + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); + return ret.object() == Py_True; +} +// @snippet qwebenginecookiestore-functor + +// @snippet qwebenginecookiestore-setcookiefilter +%CPPSELF.%FUNCTION_NAME(QWebEngineCookieFilterFunctor(%PYARG_1)); +// @snippet qwebenginecookiestore-setcookiefilter + +// @snippet qwebengineprofile-functor +struct QWebEngineNotificationFunctor : public Shiboken::PyObjectHolder +{ + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(std::unique_ptr<QWebEngineNotification> webEngineNotification); +}; + +void QWebEngineNotificationFunctor::operator() + (std::unique_ptr<QWebEngineNotification> webEngineNotification) +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + auto *notification = webEngineNotification.release(); + PyTuple_SET_ITEM(arglist.object(), 0, + %CONVERTTOPYTHON[QWebEngineNotification*](notification)); + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); +}; +// @snippet qwebengineprofile-functor + +// @snippet qwebengineprofile-setnotificationpresenter +%CPPSELF.%FUNCTION_NAME(QWebEngineNotificationFunctor(%PYARG_1)); +// @snippet qwebengineprofile-setnotificationpresenter + +// @snippet qwebenginepage-javascriptprompt-virtual-redirect +std::pair<bool, QString> resultPair = javaScriptPromptPyOverride(gil, pyOverride.object(), securityOrigin, msg, defaultValue); +result->assign(resultPair.second); +return resultPair.first; +// @snippet qwebenginepage-javascriptprompt-virtual-redirect + +// @snippet qwebenginepage-javascriptprompt-return +QString str; +%RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, &str); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](str)); +// @snippet qwebenginepage-javascriptprompt-return diff --git a/sources/pyside6/PySide6/glue/qtwebenginewidgets.cpp b/sources/pyside6/PySide6/glue/qtwebenginewidgets.cpp new file mode 100644 index 000000000..af15130a4 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtwebenginewidgets.cpp @@ -0,0 +1,121 @@ +// Copyright (C) 2020 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 + +// @snippet qwebenginepage-findtext +auto callable = %PYARG_3; +auto callback = [callable](const QWebEngineFindTextResult &result) +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 3 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QWebEngineFindTextResult](result)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); + +}; +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(%1, %2, callback); +// @snippet qwebenginepage-findtext + +// @snippet qwebenginepage-print +auto printer = %PYARG_1; +auto callable = %PYARG_2; +auto callback = [printer, callable](bool succeeded) +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 2 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[bool](succeeded)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); + Py_DECREF(printer); + +}; +Py_INCREF(printer); // Add a reference to the printer until asynchronous printing has finished +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(%1, callback); +// @snippet qwebenginepage-print + +// @snippet qwebenginepage-convertto +auto callable = %PYARG_1; +auto callback = [callable](const QString &text) +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 1 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QString](text)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); +}; + +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(callback); +// @snippet qwebenginepage-convertto + +// @snippet qwebenginepage-runjavascript +auto callable = %PYARG_3; +auto callback = [callable](const QVariant &result) +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 3 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + switch (result.type()) { + case QVariant::Bool: { + const bool value = result.toBool(); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QString](value)); + } + break; + case QVariant::Int: + case QVariant::UInt: + case QVariant::LongLong: + case QVariant::ULongLong: + case QVariant::Double: { + const double number = result.toDouble(); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[double](number)); + } + break; + default: { + const QString value = result.toString(); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QString](value)); + } + break; + } + // PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[bool](found)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); +}; + +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(%1, %2, callback); +// @snippet qwebenginepage-runjavascript + +// @snippet qwebenginepage-printtopdf +auto callable = %PYARG_1; +auto callback = [callable](const QByteArray &pdf) +{ + if (!PyCallable_Check(callable)) { + qWarning("Argument 1 of %FUNCTION_NAME must be a callable."); + return; + } + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + PyTuple_SET_ITEM(arglist, 0, %CONVERTTOPYTHON[QByteArray](pdf)); + Shiboken::AutoDecRef ret(PyObject_CallObject(callable, arglist)); + Py_DECREF(callable); +}; + +Py_INCREF(callable); +%CPPSELF.%FUNCTION_NAME(callback, %2); +// @snippet qwebenginepage-printtopdf diff --git a/sources/pyside6/PySide6/glue/qtwidgets.cpp b/sources/pyside6/PySide6/glue/qtwidgets.cpp new file mode 100644 index 000000000..f886106cf --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtwidgets.cpp @@ -0,0 +1,818 @@ +// 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 qtreewidgetitemiterator-next +if (**%CPPSELF) { + QTreeWidgetItemIterator *%0 = new QTreeWidgetItemIterator((*%CPPSELF)++); + %PYARG_0 = %CONVERTTOPYTHON[QTreeWidgetItemIterator *](%0); +} +// @snippet qtreewidgetitemiterator-next + +// @snippet qtreewidgetitemiterator-value +QTreeWidgetItem *%0 = %CPPSELF.operator *(); +%PYARG_0 = %CONVERTTOPYTHON[QTreeWidgetItem *](%0); +Shiboken::Object::releaseOwnership(%PYARG_0); +// @snippet qtreewidgetitemiterator-value + +// @snippet qgraphicsitem +PyObject *userTypeConstant = PyLong_FromLong(QGraphicsItem::UserType); +tpDict.reset(PepType_GetDict(Sbk_QGraphicsItem_TypeF())); +PyDict_SetItemString(tpDict.object(), "UserType", userTypeConstant); +// @snippet qgraphicsitem + +// @snippet qgraphicsitem-scene-return-parenting +if (%0) { + QObject *parent = %0->parent(); + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QObject *](parent)); + Shiboken::Object::setParent(pyParent, %PYARG_0); +} +// @snippet qgraphicsitem-scene-return-parenting + +// @snippet qgraphicsitem-isblockedbymodalpanel +QGraphicsItem *item_ = nullptr; +%RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(&item_); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QGraphicsItem *](item_)); +// @snippet qgraphicsitem-isblockedbymodalpanel + +// @snippet qitemeditorfactory-registereditor +Shiboken::Object::releaseOwnership(%PYARG_2); +// @snippet qitemeditorfactory-registereditor + +// @snippet qitemeditorfactory-setdefaultfactory +//this function is static we need keep ref to default value, to be able to call python virtual functions +static PyObject *_defaultValue = nullptr; +%CPPSELF.%FUNCTION_NAME(%1); +Py_INCREF(%PYARG_1); +if (_defaultValue) + Py_DECREF(_defaultValue); + +_defaultValue = %PYARG_1; +// @snippet qitemeditorfactory-setdefaultfactory + +// @snippet qformlayout-fix-args +int _row; +QFormLayout::ItemRole _role; +%CPPSELF->%FUNCTION_NAME(%ARGUMENT_NAMES, &_row, &_role); +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](_row)); +// On the C++ side, *rolePtr is not set if row == -1, in which case on +// the Python side this gets converted to a random value outside the +// enum range. Fix this by setting _role to a default value here. +if (_row == -1) + _role = QFormLayout::LabelRole; +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QFormLayout::ItemRole](_role)); +// @snippet qformlayout-fix-args + +// @snippet qfiledialog-return +%BEGIN_ALLOW_THREADS +%RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(%1, %2, %3, %4, &%5, %6); +%END_ALLOW_THREADS +%PYARG_0 = PyTuple_New(2); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](%5)); +// @snippet qfiledialog-return + +// @snippet qwidget-addaction-glue +static PyObject *connectAction(QAction *action, PyObject *callback) +{ + PyObject *pyAct = %CONVERTTOPYTHON[QAction *](action); + Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", + pyAct, + SIGNAL(triggered()), callback)); + if (result.isNull()) { + Py_DECREF(pyAct); + return nullptr; + } + return pyAct; +} + +static inline PyObject *addActionWithPyObject(QWidget *self, const QString &text, + PyObject *callback) +{ + QAction *act = self->addAction(text); + return connectAction(act, callback); +} + +static inline PyObject *addActionWithPyObject(QWidget *self, const QIcon &icon, const QString &text, + PyObject *callback) +{ + auto *act = self->addAction(icon, text); + return connectAction(act, callback); +} + +static inline PyObject *addActionWithPyObject(QWidget *self, const QString &text, + const QKeySequence &shortcut, + PyObject *callback) +{ + QAction *act = self->addAction(text, shortcut); + return connectAction(act, callback); +} + +static inline PyObject *addActionWithPyObject(QWidget *self, const QIcon &icon, + const QString &text, + const QKeySequence &shortcut, + PyObject *callback) +{ + QAction *act = self->addAction(icon, text, shortcut); + return connectAction(act, callback); +} +// @snippet qwidget-addaction-glue + +// FIXME PYSIDE7: Remove in favor of widgets methods +// @snippet qmenu-glue +inline PyObject *addMenuActionWithPyObject(QMenu *self, const QIcon &icon, + const QString &text, PyObject *callback, + const QKeySequence &shortcut) +{ + QAction *act = self->addAction(text); + + if (!icon.isNull()) + act->setIcon(icon); + + if (!shortcut.isEmpty()) + act->setShortcut(shortcut); + + self->addAction(act); + + PyObject *pyAct = %CONVERTTOPYTHON[QAction *](act); + Shiboken::AutoDecRef result(PyObject_CallMethod(pyAct, "connect", "OsO", + pyAct, + SIGNAL(triggered()), callback)); + if (result.isNull()) { + Py_DECREF(pyAct); + return nullptr; + } + + return pyAct; +} +// @snippet qmenu-glue + +// addAction(QString,PyObject*,QKeySequence) FIXME PYSIDE7 deprecated +// @snippet qmenu-addaction-1 +%PYARG_0 = addMenuActionWithPyObject(%CPPSELF, QIcon(), %1, %2, %3); +// @snippet qmenu-addaction-1 + +// addAction(QIcon,QString,PyObject*,QKeySequence) FIXME PYSIDE7 deprecated +// @snippet qmenu-addaction-2 +%PYARG_0 = addMenuActionWithPyObject(%CPPSELF, %1, %2, %3, %4); +// @snippet qmenu-addaction-2 + +// @snippet qmenu-addaction-3 +%CPPSELF.addAction(%1); +// @snippet qmenu-addaction-3 + +// addAction(QString,PyObject*) +// @snippet qwidget-addaction-2 +%PYARG_0 = addActionWithPyObject(%CPPSELF, %1, %2); +// @snippet qwidget-addaction-2 + +// addAction(QString,QKeySequence,PyObject*) or addAction(QIcon,QString,PyObject*) +// @snippet qwidget-addaction-3 +%PYARG_0 = addActionWithPyObject(%CPPSELF, %1, %2, %3); +// @snippet qwidget-addaction-3 + +// addAction(QIcon,QString,QKeySequence,PyObject*) +// @snippet qwidget-addaction-4 +%PYARG_0 = addActionWithPyObject(%CPPSELF, %1, %2, %3, %4); +// @snippet qwidget-addaction-4 + +// @snippet qmenu-clear +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +const auto &actions = %CPPSELF.actions(); +for (auto *act : actions) { + if (auto wrapper = bm.retrieveWrapper(act)) { + auto pyObj = reinterpret_cast<PyObject *>(wrapper); + Py_INCREF(pyObj); + Shiboken::Object::setParent(nullptr, pyObj); + Shiboken::Object::invalidate(pyObj); + Py_DECREF(pyObj); + } +} +// @snippet qmenu-clear + +// @snippet qmenubar-clear +const auto &actions = %CPPSELF.actions(); +for (auto *act : actions) { + Shiboken::AutoDecRef pyAct(%CONVERTTOPYTHON[QAction *](act)); + Shiboken::Object::setParent(nullptr, pyAct); + Shiboken::Object::invalidate(pyAct); +} +// @snippet qmenubar-clear + +// @snippet qtoolbox-removeitem +QWidget *_widget = %CPPSELF.widget(%1); +if (_widget) { + Shiboken::AutoDecRef pyWidget(%CONVERTTOPYTHON[QWidget *](_widget)); + Shiboken::Object::setParent(0, pyWidget); +} +// @snippet qtoolbox-removeitem + +// @snippet qlayout-help-functions +#ifndef _QLAYOUT_HELP_FUNCTIONS_ +#define _QLAYOUT_HELP_FUNCTIONS_ // Guard for jumbo builds + +static const char msgInvalidParameterAdd[] = + "Invalid parameter None passed to addLayoutOwnership()."; +static const char msgInvalidParameterRemoval[] = + "Invalid parameter None passed to removeLayoutOwnership()."; + +void addLayoutOwnership(QLayout *layout, QLayoutItem *item); +void removeLayoutOwnership(QLayout *layout, QWidget *widget); + +inline void addLayoutOwnership(QLayout *layout, QWidget *widget) +{ + if (layout == nullptr || widget == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterAdd); + return; + } + + //transfer ownership to parent widget + QWidget *lw = layout->parentWidget(); + QWidget *pw = widget->parentWidget(); + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); + + //Transfer parent to layout widget + if (pw && lw && pw != lw) + Shiboken::Object::setParent(nullptr, pyChild); + + if (!lw && !pw) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](layout)); + Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(pyParent.object()), + retrieveObjectName(pyParent).constData(), + pyChild, true); + } else { + if (!lw) + lw = pw; + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](lw)); + Shiboken::Object::setParent(pyParent, pyChild); + } +} + +inline void addLayoutOwnership(QLayout *layout, QLayout *other) +{ + if (layout == nullptr || other == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterAdd); + return; + } + + //transfer all children widgets from other to layout parent widget + QWidget *parent = layout->parentWidget(); + if (!parent) { + //keep the reference while the layout is orphan + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout *](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout *](other)); + Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(pyParent.object()), + retrieveObjectName(pyParent).constData(), + pyChild, true); + return; + } + + for (int i = 0, i_max = other->count(); i < i_max; ++i) { + QLayoutItem *item = other->itemAt(i); + if (PyErr_Occurred() || !item) + return; + addLayoutOwnership(layout, item); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout *](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout *](other)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +inline void addLayoutOwnership(QLayout *layout, QLayoutItem *item) +{ + + if (layout == nullptr || item == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterAdd); + return; + } + + if (QWidget *w = item->widget()) { + addLayoutOwnership(layout, w); + } else { + if (QLayout *l = item->layout()) + addLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QLayout *](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem *](item)); + Shiboken::Object::setParent(pyParent, pyChild); +} + +static void removeWidgetFromLayout(QLayout *layout, QWidget *widget) +{ + if (layout == nullptr || widget == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterRemoval); + return; + } + + if (QWidget *parent = widget->parentWidget()) { + //give the ownership to parent + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](parent)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); + Shiboken::Object::setParent(pyParent, pyChild); + } else { + //remove reference on layout + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](layout)); + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](widget)); + Shiboken::Object::removeReference(reinterpret_cast<SbkObject *>(pyParent.object()), + retrieveObjectName(pyParent).constData(), + pyChild); + } +} + +inline void removeLayoutOwnership(QLayout *layout, QLayoutItem *item) +{ + if (layout == nullptr || item == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterRemoval); + return; + } + + if (QWidget *w = item->widget()) { + removeWidgetFromLayout(layout, w); + } else { + QLayout *l = item->layout(); + if (l && item != l) + removeLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayoutItem *](item)); + Shiboken::Object::invalidate(pyChild); + Shiboken::Object::setParent(0, pyChild); +} + +inline void removeLayoutOwnership(QLayout *layout, QWidget *widget) +{ + if (layout == nullptr || widget == nullptr) { + PyErr_SetString(PyExc_RuntimeError, msgInvalidParameterRemoval); + return; + } + + for (int i = 0, i_max = layout->count(); i < i_max; ++i) { + QLayoutItem *item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + if (item->widget() == widget) + removeLayoutOwnership(layout, item); + } +} +#endif // _QLAYOUT_HELP_FUNCTIONS_ +// @snippet qlayout-help-functions + +// @snippet qlayout-setalignment +%CPPSELF.setAlignment(%1); +// @snippet qlayout-setalignment + +// @snippet addownership-item-at +if (%0 != nullptr) + addLayoutOwnership(%CPPSELF, %0); +// @snippet addownership-item-at + +// @snippet addownership-1 +addLayoutOwnership(%CPPSELF, %1); +// @snippet addownership-1 + +// @snippet addownership-2 +addLayoutOwnership(%CPPSELF, %2); +// @snippet addownership-2 + +// @snippet removeownership-1 +removeLayoutOwnership(%CPPSELF, %1); +// @snippet removeownership-1 + +// @snippet qgridlayout-getitemposition +int a, b, c, d; +%CPPSELF.%FUNCTION_NAME(%1, &a, &b, &c, &d); +%PYARG_0 = PyTuple_New(4); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[int](a)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[int](b)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[int](c)); +PyTuple_SET_ITEM(%PYARG_0, 3, %CONVERTTOPYTHON[int](d)); +// @snippet qgridlayout-getitemposition + +// @snippet qgraphicsscene-destroyitemgroup +QGraphicsItem *parentItem = %1->parentItem(); +Shiboken::AutoDecRef parent(%CONVERTTOPYTHON[QGraphicsItem *](parentItem)); +const auto &childItems = %1->childItems(); +for (auto *item : childItems) + Shiboken::Object::setParent(parent, %CONVERTTOPYTHON[QGraphicsItem *](item)); +%CPPSELF.%FUNCTION_NAME(%1); +// the arg was destroyed by Qt. +Shiboken::Object::invalidate(%PYARG_1); +// @snippet qgraphicsscene-destroyitemgroup + +// @snippet qgraphicsscene-addwidget +%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(%1, %2); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(%PYARG_0), "setWidget(QWidget*)1", %PYARG_1); +// @snippet qgraphicsscene-addwidget + +// @snippet qgraphicsscene-clear +const QList<QGraphicsItem *> items = %CPPSELF.items(); +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +for (auto *item : items) { + SbkObject *obj = bm.retrieveWrapper(item); + if (obj) { + if (Py_REFCNT(reinterpret_cast<PyObject *>(obj)) > 1) // If the refcnt is 1 the object will vannish anyway. + Shiboken::Object::invalidate(obj); + Shiboken::Object::removeParent(obj); + } +} +%CPPSELF.%FUNCTION_NAME(); +// @snippet qgraphicsscene-clear + +// @snippet qtreewidget-clear +QTreeWidgetItem *rootItem = %CPPSELF.invisibleRootItem(); +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); + +// PYSIDE-1251: +// Since some objects can be created with a parent and without +// being saved on a local variable (refcount = 1), they will be +// deleted when setting the parent to nullptr, so we change the loop +// to do this from the last child to the first, to avoid the case +// when the child(1) points to the original child(2) in case the +// first one was removed. +for (int i = rootItem->childCount() - 1; i >= 0; --i) { + QTreeWidgetItem *item = rootItem->child(i); + if (SbkObject *wrapper = bm.retrieveWrapper(item)) + Shiboken::Object::setParent(nullptr, reinterpret_cast<PyObject *>(wrapper)); +} +// @snippet qtreewidget-clear + +// @snippet qtreewidgetitem +// Only call the parent function if this return some value +// the parent can be the TreeWidget +if (%0) + Shiboken::Object::setParent(%PYARG_0, %PYSELF); +// @snippet qtreewidgetitem + +// @snippet qlistwidget-clear +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +for (int i = 0, count = %CPPSELF.count(); i < count; ++i) { + QListWidgetItem *item = %CPPSELF.item(i); + if (auto wrapper = bm.retrieveWrapper(item)) { + auto pyObj = reinterpret_cast<PyObject *>(wrapper); + Py_INCREF(pyObj); + Shiboken::Object::setParent(nullptr, pyObj); + Shiboken::Object::invalidate(pyObj); + Py_DECREF(pyObj); + } +} +%CPPSELF.%FUNCTION_NAME(); +// @snippet qlistwidget-clear + +// @snippet qwidget-retrieveobjectname +#ifndef _RETRIEVEOBJECTNAME_ +#define _RETRIEVEOBJECTNAME_ // Guard for jumbo builds +static QByteArray retrieveObjectName(PyObject *obj) +{ + Shiboken::AutoDecRef objName(PyObject_Str(obj)); + return Shiboken::String::toCString(objName); +} +#endif +// @snippet qwidget-retrieveobjectname + +// @snippet qwidget-glue + +// Transfer objects ownership from layout to widget +static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout) +{ + Shiboken::AutoDecRef pyParent(%CONVERTTOPYTHON[QWidget *](parent)); + + for (int i=0, i_count = layout->count(); i < i_count; i++) { + QLayoutItem *item = layout->itemAt(i); + if (PyErr_Occurred() || !item) + return; + + if (QWidget *w = item->widget()) { + QWidget *pw = w->parentWidget(); + if (pw != parent) { + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QWidget *](w)); + Shiboken::Object::setParent(pyParent, pyChild); + } + } else { + if (QLayout *l = item->layout()) + qwidgetReparentLayout(parent, l); + } + } + + Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[QLayout *](layout)); + Shiboken::Object::setParent(pyParent, pyChild); + //remove previous references + Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(pyChild.object()), + retrieveObjectName(pyChild).constData(), + Py_None); +} + +static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) +{ + if (!layout || self->layout()) + return; + + QObject *oldParent = layout->parent(); + if (oldParent && oldParent != self) { + if (oldParent->isWidgetType()) { + // remove old parent policy + Shiboken::AutoDecRef pyLayout(%CONVERTTOPYTHON[QLayout *](layout)); + Shiboken::Object::setParent(Py_None, pyLayout); + } else { + PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", + qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); + return; + } + } + + if (oldParent != self) { + qwidgetReparentLayout(self, layout); + if (PyErr_Occurred()) + return; + + self->setLayout(layout); + } +} +// @snippet qwidget-glue + +// @snippet qwidget-setstyle +Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(%PYSELF), "__style__", %PYARG_1); +// @snippet qwidget-setstyle + +// @snippet qwidget-style +QStyle *myStyle = %CPPSELF->style(); +if (myStyle && qApp) { + bool keepReference = true; + %PYARG_0 = %CONVERTTOPYTHON[QStyle *](myStyle); + QStyle *appStyle = qApp->style(); + if (appStyle == myStyle) { + Shiboken::AutoDecRef pyApp(%CONVERTTOPYTHON[QApplication *](qApp)); + // Do not set parentship when qApp is embedded + if (Shiboken::Object::wasCreatedByPython(reinterpret_cast<SbkObject *>(pyApp.object()))) { + Shiboken::Object::setParent(pyApp, %PYARG_0); + Shiboken::Object::releaseOwnership(%PYARG_0); + keepReference = false; + } + } + if (keepReference) + Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(%PYSELF), "__style__", %PYARG_0); +} +// @snippet qwidget-style + +// @snippet qapplication-init +static void QApplicationConstructor(PyObject *self, PyObject *pyargv, QApplicationWrapper **cptr) +{ + static int argc; + static char **argv; + PyObject *stringlist = PyTuple_GET_ITEM(pyargv, 0); + if (Shiboken::listToArgcArgv(stringlist, &argc, &argv, "PySideApp")) { + *cptr = new QApplicationWrapper(argc, argv, 0); + Shiboken::Object::releaseOwnership(reinterpret_cast<SbkObject *>(self)); + PySide::registerCleanupFunction(&PySide::destroyQCoreApplication); + } +} +// @snippet qapplication-init + +// @snippet qapplication-setStyle +if (qApp) { + Shiboken::AutoDecRef pyApp(%CONVERTTOPYTHON[QApplication *](qApp)); + Shiboken::Object::setParent(pyApp, %PYARG_1); + Shiboken::Object::releaseOwnership(%PYARG_1); +} +// @snippet qapplication-setStyle + +// @snippet qwidget-setlayout +qwidgetSetLayout(%CPPSELF, %1); +// %FUNCTION_NAME() - disable generation of function call. +// @snippet qwidget-setlayout + +// @snippet qtabwidget-removetab +QWidget *tab = %CPPSELF.widget(%1); +if (tab) { + Shiboken::AutoDecRef pyWidget(%CONVERTTOPYTHON[QWidget *](tab)); + %CPPSELF.%FUNCTION_NAME(%1); +} +// @snippet qtabwidget-removetab + +// @snippet qtabwidget-clear +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +for (int i = 0, count = %CPPSELF.count(); i < count; ++i) { + QWidget *widget = %CPPSELF.widget(i); + if (bm.hasWrapper(widget)) { + Shiboken::AutoDecRef pyWidget(%CONVERTTOPYTHON[QWidget *](widget)); + Shiboken::Object::releaseOwnership(pyWidget); + } +} +%CPPSELF.%FUNCTION_NAME(); +// @snippet qtabwidget-clear + +// @snippet qlineedit-addaction +%CPPSELF.addAction(%1); +// @snippet qlineedit-addaction + +// addAction(QIcon,QString,const QObject*,const char*,Qt::ConnectionType) +// @snippet qwidget-addaction-1 +QAction *action = %CPPSELF.addAction(%1, %2); +%PYARG_0 = %CONVERTTOPYTHON[QAction *](action); +Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, + "connect", "OsO", + %PYARG_0, SIGNAL(triggered()), %PYARG_3) +); +// @snippet qwidget-addaction-1 + +// addAction(QString,const QObject*,const char*,Qt::ConnectionType) +// @snippet qwidget-addaction-2 +QAction *action = %CPPSELF.addAction(%1); +%PYARG_0 = %CONVERTTOPYTHON[QAction *](action); +Shiboken::AutoDecRef result(PyObject_CallMethod(%PYARG_0, + "connect", "OsO", + %PYARG_0, SIGNAL(triggered()), %PYARG_2) +); +// @snippet qwidget-addaction-2 + +// @snippet qtoolbar-clear +QList<PyObject *> lst; +Shiboken::BindingManager &bm = Shiboken::BindingManager::instance(); +const auto &toolButtonChildren = %CPPSELF.findChildren<QToolButton *>(); +for (auto *child : toolButtonChildren) { + if (bm.hasWrapper(child)) { + PyObject *pyChild = %CONVERTTOPYTHON[QToolButton *](child); + Shiboken::Object::setParent(nullptr, pyChild); + lst << pyChild; + } +} + +//Remove actions +const auto &actions = %CPPSELF.actions(); +for (auto *act : actions) { + Shiboken::AutoDecRef pyAct(%CONVERTTOPYTHON[QAction *](act)); + Shiboken::Object::setParent(nullptr, pyAct); + Shiboken::Object::invalidate(pyAct); +} + +%CPPSELF.clear(); +for (auto *obj : std::as_const(lst)) { + Shiboken::Object::invalidate(reinterpret_cast<SbkObject *>(obj)); + Py_XDECREF(obj); +} +// @snippet qtoolbar-clear + +// @snippet qapplication-1 +QApplicationConstructor(%PYSELF, args, &%0); +// @snippet qapplication-1 + +// @snippet qapplication-2 +PyObject *empty = PyTuple_New(2); +if (!PyTuple_SetItem(empty, 0, PyList_New(0))) + QApplicationConstructor(%PYSELF, empty, &%0); +// @snippet qapplication-2 + +// @snippet qgraphicsproxywidget-setwidget +QWidget *_old = %CPPSELF.widget(); +if (_old) + Shiboken::Object::setParent(nullptr, %CONVERTTOPYTHON[QWidget *](_old)); +%CPPSELF.%FUNCTION_NAME(%1); +Shiboken::Object::setParent(%PYSELF, %PYARG_1); +// @snippet qgraphicsproxywidget-setwidget + +// @snippet qapplication-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 qapplication-exec + +// @snippet qmenu-exec-1 +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +QAction *cppResult = %CPPSELF.exec(); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[QAction*](cppResult); +// @snippet qmenu-exec-1 + +// @snippet qmenu-exec-2 +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +QAction *cppResult = %CPPSELF.exec(%1, %2); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[QAction*](cppResult); +// @snippet qmenu-exec-2 + +// @snippet qmenu-exec-3 +if (PyErr_WarnEx(PyExc_DeprecationWarning, + "'exec_' will be removed in the future. " + "Use 'exec' instead.", + 1)) { + return nullptr; +} +%BEGIN_ALLOW_THREADS +QAction *cppResult = %CPPSELF.exec(%1, %2, %3, %4); +%END_ALLOW_THREADS +%PYARG_0 = %CONVERTTOPYTHON[QAction*](cppResult); +// @snippet qmenu-exec-3 + +// @snippet qstyleoption-typename +const char *styleOptionType(const QStyleOption *o) +{ + switch (o->type) { + case QStyleOption::SO_Default: + break; + case QStyleOption::SO_FocusRect: + return "QStyleOptionFocusRect"; + case QStyleOption::SO_Button: + return "QStyleOptionButton"; + case QStyleOption::SO_Tab: + return "QStyleOptionTab"; + case QStyleOption::SO_MenuItem: + return "QStyleOptionMenuItem"; + case QStyleOption::SO_Frame: + return "QStyleOptionFrame"; + case QStyleOption::SO_ProgressBar: + return "QStyleOptionProgressBar"; + case QStyleOption::SO_ToolBox: + return "QStyleOptionToolBox"; + case QStyleOption::SO_Header: + return "QStyleOptionHeader"; + case QStyleOption::SO_DockWidget: + return "QStyleOptionDockWidget"; + case QStyleOption::SO_ViewItem: + return "QStyleOptionViewItem"; + case QStyleOption::SO_TabWidgetFrame: + return "QStyleOptionTabWidgetFrame"; + case QStyleOption::SO_TabBarBase: + return "QStyleOptionTabBarBase"; + case QStyleOption::SO_RubberBand: + return "QStyleOptionRubberBand"; + case QStyleOption::SO_ToolBar: + return "QStyleOptionToolBar"; + case QStyleOption::SO_GraphicsItem: + return "QStyleOptionGraphicsItem"; + case QStyleOption::SO_Slider: + return "QStyleOptionSlider"; + case QStyleOption::SO_SpinBox: + return "QStyleOptionSpinBox"; + case QStyleOption::SO_ToolButton: + return "QStyleOptionToolButton"; + case QStyleOption::SO_ComboBox: + return "QStyleOptionComboBox"; + case QStyleOption::SO_TitleBar: + return "QStyleOptionTitleBar"; + case QStyleOption::SO_GroupBox: + return "QStyleOptionGroupBox"; + case QStyleOption::SO_SizeGrip: + return "QStyleOptionSizeGrip"; + default: + break; + } + return "QStyleOption"; +} +// @snippet qstyleoption-typename + +// @snippet qwizardpage-registerfield +auto *signalInst = reinterpret_cast<PySideSignalInstance *>(%PYARG_4); +const auto data = PySide::Signal::getEmitterData(signalInst); +if (data.methodIndex == -1) + return PyErr_Format(PyExc_RuntimeError, "QWizardPage::registerField(): Unable to retrieve signal emitter."); +const auto method = data.emitter->metaObject()->method(data.methodIndex); +const QByteArray signature = QByteArrayLiteral("2") + method.methodSignature(); +%BEGIN_ALLOW_THREADS +%CPPSELF.%FUNCTION_NAME(%1, %2, %3, signature.constData()); +%END_ALLOW_THREADS +// @snippet qwizardpage-registerfield + +// The constructor heuristics generate setting a parent-child relationship +// when creating a QDialog with parent. This causes the dialog to leak +// when it synchronous exec() is used instead of asynchronous show(). +// In that case, remove the parent-child relationship. +// @snippet qdialog-exec-remove-parent-relation +Shiboken::Object::removeParent(reinterpret_cast<SbkObject *>(%PYSELF)); +// @snippet qdialog-exec-remove-parent-relation + +/********************************************************************* + * CONVERSIONS + ********************************************************************/ + +/********************************************************************* + * NATIVE TO TARGET CONVERSIONS + ********************************************************************/ diff --git a/sources/pyside6/PySide6/glue/qtxml.cpp b/sources/pyside6/PySide6/glue/qtxml.cpp new file mode 100644 index 000000000..120579927 --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtxml.cpp @@ -0,0 +1,17 @@ +// 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 + +// @snippet qdomdocument-setcontent +QString _errorMsg_; +int _errorLine_ = 0; +int _errorColumn_ = 0; +%BEGIN_ALLOW_THREADS +bool _ret_ = %CPPSELF.%FUNCTION_NAME(%ARGUMENT_NAMES, &_errorMsg_, &_errorLine_, + &_errorColumn_); +%END_ALLOW_THREADS +%PYARG_0 = PyTuple_New(4); +PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[bool](_ret_)); +PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QString](_errorMsg_)); +PyTuple_SET_ITEM(%PYARG_0, 2, %CONVERTTOPYTHON[int](_errorLine_)); +PyTuple_SET_ITEM(%PYARG_0, 3, %CONVERTTOPYTHON[int](_errorColumn_)); +// @snippet qdomdocument-setcontent |