diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-28 14:28:41 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-28 19:46:59 +0200 |
| commit | 6e26532b6b8430ba4d8a56aebeea5adf73501faf (patch) | |
| tree | a46bb0ec2f18fe94a90555bb175be18474d5a096 /sources/pyside6/libpyside | |
| parent | 882cc75ad73de727fe185d8355b6b450989d0fba (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/libpyside')
| -rw-r--r-- | sources/pyside6/libpyside/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | sources/pyside6/libpyside/pyside.cpp | 14 | ||||
| -rw-r--r-- | sources/pyside6/libpyside/pysidemetatype.h | 62 |
3 files changed, 77 insertions, 0 deletions
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 |
