aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-28 14:28:41 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-28 19:46:59 +0200
commit6e26532b6b8430ba4d8a56aebeea5adf73501faf (patch)
treea46bb0ec2f18fe94a90555bb175be18474d5a096 /sources/pyside6
parent882cc75ad73de727fe185d8355b6b450989d0fba (diff)
libpyside: Add function to convert a PyTypeObject to a QMetaType
Move the snippet into the library for further use. Task-number: PYSIDE-1898 Change-Id: If04da23cb0a4890474810ca762cc2ee29de480f6 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml3
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp11
-rw-r--r--sources/pyside6/libpyside/CMakeLists.txt1
-rw-r--r--sources/pyside6/libpyside/pyside.cpp14
-rw-r--r--sources/pyside6/libpyside/pysidemetatype.h62
5 files changed, 81 insertions, 10 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index e1f677841..807dd9b5b 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -332,6 +332,9 @@
<value-type name="QKeyCombination"/>
<value-type name="QMetaType">
+ <extra-includes>
+ <include file-name="pysidemetatype.h" location="global"/>
+ </extra-includes>
<enum-type name="Type"/>
<enum-type name="TypeFlag" flags="TypeFlags"/>
<conversion-rule>
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index b5f4f429d..8f1a6bb21 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -129,16 +129,7 @@ else {
// @snippet conversion-pytypeobject-qmetatype
auto *pyType = reinterpret_cast<PyTypeObject *&>(%in);
-if (Shiboken::String::checkType(pyType))
- %out = QMetaType(QMetaType::QString);
-else if (%in == reinterpret_cast<PyObject *>(&PyFloat_Type))
- %out = QMetaType(QMetaType::Double);
-else if (%in == reinterpret_cast<PyObject *>(&PyLong_Type))
- %out = QMetaType(QMetaType::Int);
-else if (Py_TYPE(%in) == SbkObjectType_TypeF())
- %out = QMetaType::fromName(Shiboken::ObjectType::getOriginalName(pyType));
-else
- %out = QMetaType::fromName(pyType->tp_name);
+%out = PySide::qMetaTypeFromPyType(pyType);
// @snippet conversion-pytypeobject-qmetatype
// @snippet conversion-qmetatype-pytypeobject
diff --git a/sources/pyside6/libpyside/CMakeLists.txt b/sources/pyside6/libpyside/CMakeLists.txt
index 0b2f7a097..1e006440e 100644
--- a/sources/pyside6/libpyside/CMakeLists.txt
+++ b/sources/pyside6/libpyside/CMakeLists.txt
@@ -103,6 +103,7 @@ set(libpyside_HEADERS
pysideqmetatype.h
pysideqobject.h
pysidemacros.h
+ pysideqmetatype.h
signalmanager.h
pyside.h
pysidestaticstrings.h
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 39b20120d..4abb2da98 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -40,6 +40,7 @@
#include "pyside.h"
#include "pysideinit.h"
#include "pysidecleanup.h"
+#include "pysidemetatype.h"
#include "pysideqapp.h"
#include "pysideqobject.h"
#include "pysideutils.h"
@@ -932,5 +933,18 @@ QObject *convertToQObject(PyObject *object, bool raiseError)
return reinterpret_cast<QObject*>(ptr);
}
+QMetaType qMetaTypeFromPyType(PyTypeObject *pyType)
+{
+ if (Shiboken::String::checkType(pyType))
+ return QMetaType(QMetaType::QString);
+ if (pyType == &PyFloat_Type)
+ return QMetaType(QMetaType::Double);
+ if (pyType == &PyLong_Type)
+ return QMetaType(QMetaType::Int);
+ if (pyType == SbkObjectType_TypeF())
+ return QMetaType::fromName(Shiboken::ObjectType::getOriginalName(pyType));
+ return QMetaType::fromName(pyType->tp_name);
+}
+
} //namespace PySide
diff --git a/sources/pyside6/libpyside/pysidemetatype.h b/sources/pyside6/libpyside/pysidemetatype.h
new file mode 100644
index 000000000..62f519fc7
--- /dev/null
+++ b/sources/pyside6/libpyside/pysidemetatype.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PYSIDEMETATYPE_H
+#define PYSIDEMETATYPE_H
+
+#include <sbkpython.h>
+
+#include <pysidemacros.h>
+
+#include <QtCore/QtGlobal>
+
+QT_FORWARD_DECLARE_CLASS(QMetaType)
+
+namespace PySide
+{
+
+/// Returns the QMetaType matching a PyTypeObject
+/// \param
+/// \param type TypeObject
+/// \return QMetaType
+PYSIDE_API QMetaType qMetaTypeFromPyType(PyTypeObject *type);
+
+} //namespace PySide
+
+#endif // PYSIDEMETATYPE_H