exe 依赖添加

This commit is contained in:
Neo
2026-01-27 23:19:54 +08:00
parent 8b1200383e
commit ba00654ac5
3443 changed files with 754994 additions and 51 deletions

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -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 qaudio-convertvolume
const float result = QtAudio::convertVolume(%1, %2, %3);
%PYARG_0 = %CONVERTTOPYTHON[float](result);
// @snippet qaudio-convertvolume

View File

@@ -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::ArrayPointer<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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[QByteArray](ba));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QHostAddress](ha));
PyTuple_SetItem(%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_SetItem(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 nullptr;
}
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_SetItem(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

View File

@@ -0,0 +1,43 @@
// 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_SetItem(arglist, 0, %CONVERTTOPYTHON[QAbstractOAuth::Stage](stage));
PyTuple_SetItem(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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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_SetItem(%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

View File

@@ -0,0 +1,21 @@
// 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 qquick3dinstancing-getinstancebuffer-virtual-redirect
std::pair<QByteArray, int> resultPair = getInstanceBufferOverride(gil, pyOverride.object());
if (instanceCount != nullptr)
*instanceCount = resultPair.second;
return resultPair.first;
// @snippet qquick3dinstancing-getinstancebuffer-virtual-redirect
// @snippet qquick3dinstancing-getinstancebuffer-return
int count{};
%RETURN_TYPE retval_ = %CPPSELF.%FUNCTION_NAME(&count);
%PYARG_0 = PyTuple_New(2);
PyTuple_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[int](count));
// @snippet qquick3dinstancing-getinstancebuffer-return

View File

@@ -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

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2024 Ford Motor Company
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// @snippet qtro-init
PySide::RemoteObjects::init(module);
// @snippet qtro-init
// @snippet node-acquire
auto *typeObject = reinterpret_cast<PyTypeObject*>(%PYARG_1);
if (!PySide::inherits(typeObject, SbkPySide6_QtRemoteObjectsTypeStructs[SBK_QRemoteObjectReplica_IDX].fullName)) {
PyErr_SetString(PyExc_TypeError, "First argument must be a type deriving from QRemoteObjectReplica.");
return nullptr;
}
static PyObject *pyConstructWithNode = Shiboken::Enum::newItem(
Shiboken::Module::get(SbkPySide6_QtRemoteObjectsTypeStructs[SBK_QRemoteObjectReplica_ConstructorType_IDX]),
1 /* protected QRemoteObjectReplica::ConstructorType::ConstructWithNode */
);
Shiboken::AutoDecRef args;
if (pyArgs[1])
args.reset(PyTuple_Pack(3, %PYSELF, pyConstructWithNode, pyArgs[1]));
else
args.reset(PyTuple_Pack(2, %PYSELF, pyConstructWithNode));
PyObject *instance = PyObject_CallObject(%PYARG_1, args.object());
if (!instance)
return nullptr; // Propagate the exception
%PYARG_0 = instance;
// @snippet node-acquire

View File

@@ -0,0 +1,38 @@
// 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(&errorMessage);
%PYARG_0 = PyTuple_New(2);
PyTuple_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[QList<QCanBusDeviceInfo>](result));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorMessage));
// @snippet qcanbus-available-devices
// @snippet qcanbus-available-devices-plugin
QString errorMessage;
const QList<QCanBusDeviceInfo> result = %CPPSELF.%FUNCTION_NAME(%1, &errorMessage);
%PYARG_0 = PyTuple_New(2);
PyTuple_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[QList<QCanBusDeviceInfo>](result));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorMessage));
// @snippet qcanbus-available-devices-plugin
// @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_SetItem(%PYARG_0, 0, pyDevice);
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QString](errorMessage));
// @snippet qcanbus-createdevice

View File

@@ -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

View File

@@ -0,0 +1,68 @@
// 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, "addTransition", errInfo,
SbkPySide6_QtStateMachineTypeStructs[SBK_QAbstractTransition_IDX]);
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

View File

@@ -0,0 +1,30 @@
// 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 (")
+ PepType_GetFullyQualifiedNameStr(Py_TYPE(%PYARG_1))
+ QByteArrayLiteral(") passed, QSignalSpy requires a signal.");
PyErr_SetString(PyExc_ValueError, error.constData());
return -1;
}
// PySide::Signal::getObject() increments the refcount for emitterPyObject,
// but there is nothing that decrements the count when the spy goes out of
// scope. It doesn't seem like QSignalSpy should prevent the target object
// from being garbage collected. So we need to decrement the refcount here.
Py_DECREF(emitterPyObject);
%0 = new QSignalSpy(emitter, signature.constData());
// @snippet qsignalspy-signal

View File

@@ -0,0 +1,213 @@
// 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 <sbkpython.h>
#include <sbkconverter.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_SetItem(%PYARG_0, 0, classObj);
PyTuple_SetItem(%PYARG_0, 1, baseClassObj);
// @snippet loaduitype

View File

@@ -0,0 +1,159 @@
// 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_SetItem(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_SetItem(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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QString](str));
// @snippet qwebenginepage-javascriptprompt-return
// @snippet qwebenginepage-findtext
auto callable = %PYARG_3;
auto callback = [callable](const QWebEngineFindTextResult &result)
{
Shiboken::GilState state;
Shiboken::AutoDecRef arglist(PyTuple_New(1));
PyTuple_SetItem(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_SetItem(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)
{
Shiboken::GilState state;
Shiboken::AutoDecRef arglist(PyTuple_New(1));
PyTuple_SetItem(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-2
using RunJavascriptCallback = std::function<void(const QVariant &)>;
if (%PYARG_2 != nullptr && %PYARG_2 != Py_None) {
%CPPSELF.%FUNCTION_NAME(%1, RunJavascriptCallback(RunJavascriptFunctor(%PYARG_2)));
} else {
%CPPSELF.%FUNCTION_NAME(%1, 0, RunJavascriptCallback{});
}
// @snippet qwebenginepage-runjavascript-2
// @snippet qwebenginepage-runjavascript-3
using RunJavascriptCallback = std::function<void(const QVariant &)>;
if (%PYARG_3 != nullptr && %PYARG_3 != Py_None) {
%CPPSELF.%FUNCTION_NAME(%1, %2, RunJavascriptCallback(RunJavascriptFunctor(%PYARG_3)));
} else {
%CPPSELF.%FUNCTION_NAME(%1, %2, RunJavascriptCallback{});
}
// @snippet qwebenginepage-runjavascript-3
// @snippet qwebenginepage-printtopdf
using PrintToPdfCallback = std::function<void(const QByteArray &)>;
%CPPSELF.%FUNCTION_NAME(PrintToPdfCallback(PrintToPdfFunctor(%PYARG_1)), %2, %3);
// @snippet qwebenginepage-printtopdf
// @snippet qwebenginepage-findframebyname
auto frameOptional = %CPPSELF.%FUNCTION_NAME(%1);
if (frameOptional.has_value()) {
const %RETURN_TYPE &frame = frameOptional.value();
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](frame);
} else {
Py_INCREF(Py_None);
%PYARG_0 = Py_None;
}
// @snippet qwebenginepage-findframebyname
// @snippet qwebengineframe-printtopdf
using PrintToPdfCallback = std::function<void(const QByteArray &)>;
%CPPSELF.%FUNCTION_NAME(PrintToPdfCallback(PrintToPdfFunctor(%PYARG_1)));
// @snippet qwebengineframe-printtopdf

View File

@@ -0,0 +1,834 @@
// 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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
PyTuple_SetItem(%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_SetItem(%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_SetItem(%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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[%RETURN_TYPE](retval_));
PyTuple_SetItem(%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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[int](a));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[int](b));
PyTuple_SetItem(%PYARG_0, 2, %CONVERTTOPYTHON[int](c));
PyTuple_SetItem(%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_GetItem(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
// @snippet qmessagebox-open-connect-accept
if (!PySide::callConnect(%PYSELF, SIGNAL(accepted()), %PYARG_1))
return nullptr;
%CPPSELF.%FUNCTION_NAME();
// @snippet qmessagebox-open-connect-accept
// @snippet replace-widget-child
$CHILD_TYPE* oldChild = %CPPSELF.$FUNCTION_GET_OLD();
if (oldChild != nullptr && oldChild != $CPPARG) {
Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[$CHILD_TYPE*](oldChild));
Shiboken::Object::setParent(nullptr, pyChild);
Shiboken::Object::releaseOwnership(pyChild);
}
Shiboken::Object::setParent(%PYSELF, $PYARG);
// @snippet replace-widget-child
/*********************************************************************
* CONVERSIONS
********************************************************************/
/*********************************************************************
* NATIVE TO TARGET CONVERSIONS
********************************************************************/

View File

@@ -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_SetItem(%PYARG_0, 0, %CONVERTTOPYTHON[bool](_ret_));
PyTuple_SetItem(%PYARG_0, 1, %CONVERTTOPYTHON[QString](_errorMsg_));
PyTuple_SetItem(%PYARG_0, 2, %CONVERTTOPYTHON[int](_errorLine_));
PyTuple_SetItem(%PYARG_0, 3, %CONVERTTOPYTHON[int](_errorColumn_));
// @snippet qdomdocument-setcontent