diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-10-07 10:26:16 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-10-07 15:35:40 +0200 |
| commit | 732fdd80b363a714fadeed75981a7f8bf7b4032a (patch) | |
| tree | bf5819339ffb911097f32c132f2d4e28379eb482 /sources/pyside6/PySide6/QtWebEngineCore | |
| parent | b8d46ca7a028612ecd64f7a4ceb8d8471132d341 (diff) | |
PySide6: Fix overloads of QWebEnginePage::runJavaScript()
Adapt them to C++, where:
void QWebEnginePage::runJavaScript(QString scriptSource,
std::function<void (QVariant)> resultCallback)
and
void QWebEnginePage::runJavaScript(QString scriptSource,
quint32 worldId = 0,
std::function<void (QVariant)> =resultCallback = {})
exist.
Introduce a functor as static source to be able to share code with other
classes to be added.
Task-number: PYSIDE-2883
Change-Id: I61f913a38e761df18ce5a5f3ea43478b7dceace2
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtWebEngineCore')
4 files changed, 83 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt b/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt index 149d1f8bc..86662a38c 100644 --- a/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt +++ b/sources/pyside6/PySide6/QtWebEngineCore/CMakeLists.txt @@ -3,6 +3,11 @@ project(QtWebEngineCore) +set(QtWebEngineCore_static_sources + "${QtWebEngineCore_SOURCE_DIR}/glue/webenginepage_functors.cpp" + "${QtWebEngineCore_SOURCE_DIR}/glue/webenginepage_functors.h" +) + set(QtWebEngineCore_SRC ${QtWebEngineCore_GEN_DIR}/qwebenginecertificateerror_wrapper.cpp ${QtWebEngineCore_GEN_DIR}/qwebengineclientcertificateselection_wrapper.cpp @@ -69,6 +74,7 @@ set(QtWebEngineCore_deps QtCore QtGui QtNetwork QtPrintSupport QtWebChannel) create_pyside_module(NAME QtWebEngineCore INCLUDE_DIRS QtWebEngineCore_include_dirs + STATIC_SOURCES QtWebEngineCore_static_sources LIBRARIES QtWebEngineCore_libraries DEPS QtWebEngineCore_deps TYPESYSTEM_PATH QtWebEngineCore_SOURCE_DIR diff --git a/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.cpp b/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.cpp new file mode 100644 index 000000000..b836e8047 --- /dev/null +++ b/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.cpp @@ -0,0 +1,43 @@ +// 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 + +#include "webenginepage_functors.h" + +#include "autodecref.h" +#include "gilstate.h" + +#include "pysideutils.h" + +#include <QtCore/qvariant.h> + +QT_BEGIN_NAMESPACE + +void RunJavascriptFunctor::operator()(const QVariant &result) +{ + Shiboken::GilState state; + Shiboken::AutoDecRef arglist(PyTuple_New(1)); + switch (result.typeId()) { + case QMetaType::Bool: { + PyObject *pyValue = result.toBool() ? Py_True : Py_False; + Py_INCREF(pyValue); + PyTuple_SET_ITEM(arglist, 0, pyValue); + } + break; + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::LongLong: + case QMetaType::ULongLong: + case QMetaType::Double: + PyTuple_SET_ITEM(arglist, 0, PyFloat_FromDouble(result.toDouble())); + break; + default: { + const QString value = result.toString(); + PyTuple_SET_ITEM(arglist, 0, PySide::qStringToPyUnicode(value)); + } + break; + } + Shiboken::AutoDecRef ret(PyObject_CallObject(object(), arglist)); + release(); // single shot +} + +QT_END_NAMESPACE diff --git a/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.h b/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.h new file mode 100644 index 000000000..bc0b88749 --- /dev/null +++ b/sources/pyside6/PySide6/QtWebEngineCore/glue/webenginepage_functors.h @@ -0,0 +1,24 @@ +// 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 + +#ifndef WEBENGINEPAGE_FUNCTORS_H +#define WEBENGINEPAGE_FUNCTORS_H + +#include "pyobjectholder.h" + +#include <QtCore/QtClassHelperMacros> + +QT_FORWARD_DECLARE_CLASS(QVariant) + +QT_BEGIN_NAMESPACE + +struct RunJavascriptFunctor : public Shiboken::PyObjectHolder +{ + using Shiboken::PyObjectHolder::PyObjectHolder; + + void operator()(const QVariant &result); +}; + +QT_END_NAMESPACE + +#endif // WEBENGINEPAGE_FUNCTORS_H diff --git a/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml b/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml index 8c3e994db..c0a5d6f68 100644 --- a/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml +++ b/sources/pyside6/PySide6/QtWebEngineCore/typesystem_webenginecore.xml @@ -74,6 +74,9 @@ <object-type name="QWebEngineNotification"/> <object-type name="QWebEnginePage"> + <extra-includes> + <include file-name="glue/webenginepage_functors.h" location="global"/> + </extra-includes> <enum-type name="LifecycleState"/> <enum-type name="WebAction"/> <enum-type name="FindFlag" flags="FindFlags"/> @@ -106,9 +109,14 @@ <inject-code class="target" position="beginning" file="../glue/qtwebenginecore.cpp" snippet="qwebenginepage-convertto"/> </add-function> - <add-function signature="runJavaScript(const QString &@scriptSource@,quint32@worldId@,PyCallable*@resultCallback@)"> + <modify-function signature="^runJavaScript\(.*\)$" remove="yes"/> + <add-function signature="runJavaScript(const QString &@scriptSource@,PyCallable*@resultCallback@)"> <inject-code class="target" position="beginning" file="../glue/qtwebenginecore.cpp" - snippet="qwebenginepage-runjavascript"/> + snippet="qwebenginepage-runjavascript-2"/> + </add-function> + <add-function signature="runJavaScript(const QString &@scriptSource@,quint32@worldId@=0,PyCallable*@resultCallback@={})"> + <inject-code class="target" position="beginning" file="../glue/qtwebenginecore.cpp" + snippet="qwebenginepage-runjavascript-3"/> </add-function> </object-type> |
