diff options
Diffstat (limited to 'sources')
22 files changed, 535 insertions, 140 deletions
diff --git a/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp b/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp index 86cfec1f8..5af0b804a 100644 --- a/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp +++ b/sources/pyside6/PySide6/QtCore/glue/core_snippets.cpp @@ -38,7 +38,7 @@ ****************************************************************************/ #include "core_snippets_p.h" -#include "pyside.h" +#include "pysideqobject.h" #include "shiboken.h" #include "basewrapper.h" diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 346e902fd..5a3217f14 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -668,6 +668,9 @@ </extra-includes> </object-type> <value-type name="QLine" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <add-function signature="__repr__" return-type="PyObject*"> <inject-code class="target" position="beginning"> <insert-template name="repr_code"> @@ -769,6 +772,9 @@ <enum-type identified-by-value="Unspecified"/> </value-type> <value-type name="QDate" hash-function="PySide::hash" > + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <inject-code class="native" position="beginning"> <insert-template name="pydatetime_importandcheck_function"> <replace from="$DATETIMETYPE" to="PyDate"/> @@ -829,6 +835,9 @@ </modify-function> </value-type> <value-type name="QDateTime" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <enum-type name="YearRange" since="5.14"/> <inject-code class="native" position="beginning"> <insert-template name="pydatetime_importandcheck_function"> @@ -909,6 +918,9 @@ </value-type> <value-type name="QPoint" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <add-function signature="__repr__" return-type="PyObject*"> <inject-code class="target" position="beginning"> <insert-template name="repr_code"> @@ -976,6 +988,9 @@ <!--### --> </value-type> <value-type name="QRect" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <add-function signature="__repr__" return-type="PyObject*"> <inject-code class="target" position="beginning"> <insert-template name="repr_code"> @@ -1107,6 +1122,9 @@ </modify-function> </value-type> <value-type name="QSize" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <add-function signature="__repr__" return-type="PyObject*"> <inject-code class="target" position="beginning"> <insert-template name="repr_code"> @@ -1175,6 +1193,9 @@ </value-type> <value-type name="QTime" hash-function="PySide::hash"> + <extra-includes> + <include file-name="pysideqhash.h" location="global"/> + </extra-includes> <inject-code class="native" position="beginning"> <insert-template name="pydatetime_importandcheck_function"> <replace from="$DATETIMETYPE" to="PyTime"/> @@ -1749,6 +1770,7 @@ <enum-type name="ParsingMode"/> <extra-includes> <include file-name="QStringList" location="global"/> + <include file-name="pysideqhash.h" location="global"/> </extra-includes> <add-function signature="__repr__" return-type="PyObject*"> <inject-code class="target" position="beginning"> @@ -2424,6 +2446,8 @@ <extra-includes> <include file-name="QStringList" location="global"/> <include file-name="QTranslator" location="global"/> + <include file-name="pysidecleanup.h" location="global"/> + <include file-name="pysideqapp.h" location="global"/> </extra-includes> <!-- constructor documentation --> <inject-documentation format="target" mode="append"> diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index caecca7bf..4ba90f58d 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -2552,6 +2552,8 @@ <include file-name="QPalette" location="global"/> <include file-name="QIcon" location="global"/> <include file-name="QLocale" location="global"/> + <include file-name="pysideqapp.h" location="global"/> + <include file-name="pysidecleanup.h" location="global"/> </extra-includes> <modify-function signature="QGuiApplication(int&,char**,int)" access="private"/> <add-function signature="QGuiApplication(QStringList)"> diff --git a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp index f7f1b2375..84fec16b6 100644 --- a/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp +++ b/sources/pyside6/PySide6/QtQml/pysideqmlregistertype.cpp @@ -49,6 +49,7 @@ // pyside #include <pyside.h> +#include <pysideqobject.h> #include <pyside_p.h> #include <QtCore/QMutex> diff --git a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml index ae309ca70..aceadd2b7 100644 --- a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml +++ b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml @@ -2831,6 +2831,8 @@ <include file-name="QIcon" location="global"/> <include file-name="QLocale" location="global"/> <include file-name="QStyle" location="global"/> + <include file-name="pysideqapp.h" location="global"/> + <include file-name="pysidecleanup.h" location="global"/> </extra-includes> <modify-function signature="QApplication(int&,char**,int)" access="private"/> <add-function signature="QApplication(QStringList)"> diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index 692062637..4a25e435a 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -42,7 +42,7 @@ ********************************************************************/ // @snippet include-pyside -#include <pyside.h> +#include <pysideinit.h> #include <limits> #include "glue/core_snippets_p.h" // @snippet include-pyside diff --git a/sources/pyside6/libpyside/CMakeLists.txt b/sources/pyside6/libpyside/CMakeLists.txt index 74104263c..b51d9ae62 100644 --- a/sources/pyside6/libpyside/CMakeLists.txt +++ b/sources/pyside6/libpyside/CMakeLists.txt @@ -91,13 +91,20 @@ set(libpyside_HEADERS dynamicqmetaobject.h feature_select.h pysideclassinfo.h + pysidecleanup.h + pysideinit.h + pysideqapp.h pysideqenum.h + pysideqhash.h + pysideqmetatype.h + pysideqobject.h pysidemacros.h signalmanager.h pyside.h pysidestaticstrings.h pysidemetafunction.h pysidesignal.h + pysideutils.h pysideproperty.h pysideqflags.h pysideweakref.h diff --git a/sources/pyside6/libpyside/class_property.cpp b/sources/pyside6/libpyside/class_property.cpp index 5dbb4e4f7..bf08d0448 100644 --- a/sources/pyside6/libpyside/class_property.cpp +++ b/sources/pyside6/libpyside/class_property.cpp @@ -37,10 +37,9 @@ ** ****************************************************************************/ -#include "pyside.h" +#include "class_property.h" #include "pysidestaticstrings.h" #include "feature_select.h" -#include "class_property.h" #include <shiboken.h> #include <sbkstaticstrings.h> diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp index fb8762a0a..90090018f 100644 --- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp +++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp @@ -39,6 +39,7 @@ #include "dynamicqmetaobject.h" #include "dynamicqmetaobject_p.h" +#include "pysideqobject.h" #include "pysidesignal.h" #include "pysidesignal_p.h" #include "pysideproperty.h" @@ -47,7 +48,6 @@ #include "pysideqenum.h" #include <shiboken.h> -#include <pyside.h> #include <QtCore/QByteArray> #include <QtCore/QObject> diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp index c82cccce1..f0cc4f416 100644 --- a/sources/pyside6/libpyside/feature_select.cpp +++ b/sources/pyside6/libpyside/feature_select.cpp @@ -38,7 +38,8 @@ ****************************************************************************/ #include "feature_select.h" -#include "pyside.h" +#include "pysidecleanup.h" +#include "pysideqobject.h" #include "pysidestaticstrings.h" #include "class_property.h" @@ -46,6 +47,8 @@ #include <sbkfeature_base.h> #include <signature_p.h> +#include <QtCore/QStringList> + ////////////////////////////////////////////////////////////////////////////// // // PYSIDE-1019: Support switchable extensions diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp index e3e9128c2..567a5ea3a 100644 --- a/sources/pyside6/libpyside/pyside.cpp +++ b/sources/pyside6/libpyside/pyside.cpp @@ -38,6 +38,11 @@ ****************************************************************************/ #include "pyside.h" +#include "pysideinit.h" +#include "pysidecleanup.h" +#include "pysideqapp.h" +#include "pysideqobject.h" +#include "pysideutils.h" #include "pyside_numpy.h" #include "pyside_p.h" #include "signalmanager.h" diff --git a/sources/pyside6/libpyside/pyside.h b/sources/pyside6/libpyside/pyside.h index 39fbef3cc..9e0f6d1a6 100644 --- a/sources/pyside6/libpyside/pyside.h +++ b/sources/pyside6/libpyside/pyside.h @@ -44,8 +44,10 @@ #include <pysidemacros.h> -#include <QtCore/QMetaType> -#include <QtCore/QHash> +#include "pysideinit.h" +#include "pysideqapp.h" +#include "pysideqobject.h" +#include "pysideutils.h" namespace QQmlPrivate { @@ -55,106 +57,6 @@ struct RegisterType; namespace PySide { -PYSIDE_API void init(PyObject *module); - -/** - * Hash function used to enable hash on objects not supported on native Qt library which has toString function. - */ -template<class T> -inline Py_ssize_t hash(const T& value) -{ - return qHash(value.toString()); -} - -/** - * Fill QObject properties and do signal connections using the values found in \p kwds dictonary. - * \param qObj PyObject fot the QObject. - * \param metaObj QMetaObject of \p qObj. - * \param kwds key->value dictonary. - * \return True if everything goes well, false with a Python error setted otherwise. - */ -PYSIDE_API bool fillQtProperties(PyObject *qObj, const QMetaObject *metaObj, PyObject *kwds); - -/** -* If the type \p T was registered on Qt meta type system with Q_DECLARE_METATYPE macro, this class will initialize -* the meta type. -* -* Initialize a meta type means register it on Qt meta type system, Qt itself only do this on the first call of -* qMetaTypeId, and this is exactly what we do to init it. If we don't do that, calls to QMetaType::type("QMatrix2x2") -* could return zero, causing QVariant to not recognize some C++ types, like QMatrix2x2. -*/ -template<typename T, bool OK = QMetaTypeId<T>::Defined > -struct initQtMetaType { - initQtMetaType() - { - qMetaTypeId<T>(); - } -}; - -// Template specialization to do nothing when the type wasn't registered on Qt meta type system. -template<typename T> -struct initQtMetaType<T, false> { -}; - -PYSIDE_API void initDynamicMetaObject(PyTypeObject *type, const QMetaObject *base, - std::size_t cppObjSize); -PYSIDE_API void initQObjectSubType(PyTypeObject *type, PyObject *args, PyObject *kwds); -PYSIDE_API void initQApp(); - -/// Return the size in bytes of a type that inherits QObject. -PYSIDE_API std::size_t getSizeOfQObject(PyTypeObject *type); - -/* Check if a PyTypeObject or its bases contains a QObject - * \param pyType is the PyTypeObject to check - * \param raiseError controls if a TypeError is raised when an object does not - * inherits from QObject - */ -PYSIDE_API bool isQObjectDerived(PyTypeObject *pyType, bool raiseError); - -/// Convenience to convert a PyObject to QObject -PYSIDE_API QObject *convertToQObject(PyObject *object, bool raiseError); - -typedef void (*CleanupFunction)(void); - -/** - * Register a function to be called before python die - */ -PYSIDE_API void registerCleanupFunction(CleanupFunction func); -PYSIDE_API void runCleanupFunctions(); - -/** - * Destroy a QCoreApplication taking care of destroy all instances of QObject first. - */ -PYSIDE_API void destroyQCoreApplication(); - -/** - * Check for properties and signals registered on MetaObject and return these - * \param cppSelf Is the QObject which contains the metaobject - * \param self Python object of cppSelf - * \param name Name of the argument which the function will try retrieve from MetaData - * \return The Python object which contains the Data obtained in metaObject or the Python attribute related with name - */ -PYSIDE_API PyObject *getMetaDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *name); - -/** - * Check if self inherits from class_name - * \param self Python object - * \param class_name strict with the class name - * \return Returns true if self object inherits from class_name, otherwise returns false - */ -PYSIDE_API bool inherits(PyTypeObject *self, const char *class_name); - -PYSIDE_API void *nextQObjectMemoryAddr(); -PYSIDE_API void setNextQObjectMemoryAddr(void *addr); - -PYSIDE_API PyObject *getWrapperForQObject(QObject *cppSelf, PyTypeObject *sbk_type); - -/// Return the best-matching type for a QObject (Helper for QObject.findType()) -/// \param cppSelf QObject instance -/// \return type object -PYSIDE_API PyTypeObject *getTypeForQObject(const QObject *cppSelf); - - // Used by QtQuick module to notify QtQml that custom QtQuick items can be registered. using QuickRegisterItemFunction = bool (*)(PyObject *pyObj, const char *uri, int versionMajor, @@ -164,26 +66,6 @@ using QuickRegisterItemFunction = PYSIDE_API QuickRegisterItemFunction getQuickRegisterItemFunction(); PYSIDE_API void setQuickRegisterItemFunction(QuickRegisterItemFunction function); -/** - * Given A PyObject repesenting ASCII or Unicode data, returns an equivalent QString. - */ -PYSIDE_API QString pyStringToQString(PyObject *str); - -/** - * Provide an efficient, correct PathLike interface. - */ -PYSIDE_API QString pyPathToQString(PyObject *path); - -/** - * Registers a dynamic "qt.conf" file with the Qt resource system. - * - * This is used in a standalone build, to inform QLibraryInfo of the Qt prefix (where Qt libraries - * are installed) so that plugins can be successfully loaded. - */ -PYSIDE_API bool registerInternalQtConf(); - - } //namespace PySide - #endif // PYSIDE_H diff --git a/sources/pyside6/libpyside/pysidecleanup.h b/sources/pyside6/libpyside/pysidecleanup.h new file mode 100644 index 000000000..666740641 --- /dev/null +++ b/sources/pyside6/libpyside/pysidecleanup.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDECLEANUP_H +#define PYSIDECLEANUP_H + +#include <pysidemacros.h> + +namespace PySide +{ + +using CleanupFunction = void(*)(); + +/// Register a function to be called before python dies +PYSIDE_API void registerCleanupFunction(CleanupFunction func); +PYSIDE_API void runCleanupFunctions(); + +} //namespace PySide + +#endif // PYSIDECLEANUP_H diff --git a/sources/pyside6/libpyside/pysideinit.h b/sources/pyside6/libpyside/pysideinit.h new file mode 100644 index 000000000..d20a60cb7 --- /dev/null +++ b/sources/pyside6/libpyside/pysideinit.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEINIT_H +#define PYSIDEINIT_H + +#include <sbkpython.h> + +#include <pysidemacros.h> + +namespace PySide +{ + +PYSIDE_API void init(PyObject *module); + +/// Registers a dynamic "qt.conf" file with the Qt resource system. +/// +/// This is used in a standalone build, to inform QLibraryInfo of the Qt prefix +/// (where Qt libraries are installed) so that plugins can be successfully loaded. +PYSIDE_API bool registerInternalQtConf(); + +} //namespace PySide + +#endif // PYSIDEINIT_H diff --git a/sources/pyside6/libpyside/pysideqapp.h b/sources/pyside6/libpyside/pysideqapp.h new file mode 100644 index 000000000..2c2e116da --- /dev/null +++ b/sources/pyside6/libpyside/pysideqapp.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEQAPP_H +#define PYSIDEQAPP_H + +#include <pysidemacros.h> + +namespace PySide +{ + +PYSIDE_API void initQApp(); + +/// Destroy a QCoreApplication taking care of destroy all instances of QObject first. +PYSIDE_API void destroyQCoreApplication(); + +} //namespace PySide + +#endif // PYSIDEQPP_H diff --git a/sources/pyside6/libpyside/pysideqhash.h b/sources/pyside6/libpyside/pysideqhash.h new file mode 100644 index 000000000..d7f82c598 --- /dev/null +++ b/sources/pyside6/libpyside/pysideqhash.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEQHASH_H +#define PYSIDEQHASH_H + +#include <sbkpython.h> + +#include <QtCore/QHash> + +namespace PySide +{ + +/// Hash function used to enable hash on objects not supported by the native Qt +/// library which have a toString() function. +template<class T> +inline Py_ssize_t hash(const T& value) +{ + return qHash(value.toString()); +} + +} //namespace PySide + +#endif // PYSIDEQHASH_H diff --git a/sources/pyside6/libpyside/pysideqmetatype.h b/sources/pyside6/libpyside/pysideqmetatype.h new file mode 100644 index 000000000..020225da9 --- /dev/null +++ b/sources/pyside6/libpyside/pysideqmetatype.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEQMETATYPE_H +#define PYSIDEQMETATYPE_H + +#include <QtCore/QMetaType> + +namespace PySide +{ + +/// If the type \p T was registered on Qt meta type system with Q_DECLARE_METATYPE macro, +/// this class will initialize the meta type. +/// +/// Initialize a meta type means register it on Qt meta type system, Qt itself only do this +/// on the first call of qMetaTypeId, and this is exactly what we do to init it. If we don't +/// do that, calls to QMetaType::type("QMatrix2x2") could return zero, causing QVariant to +/// not recognize some C++ types, like QMatrix2x2. + +template<typename T, bool OK = QMetaTypeId<T>::Defined > +struct initQtMetaType { + initQtMetaType() + { + qMetaTypeId<T>(); + } +}; + +// Template specialization to do nothing when the type wasn't registered on Qt meta type system. +template<typename T> +struct initQtMetaType<T, false> { +}; + +} //namespace PySide + +#endif // PYSIDEQMETATYPE_H diff --git a/sources/pyside6/libpyside/pysideqobject.h b/sources/pyside6/libpyside/pysideqobject.h new file mode 100644 index 000000000..19e603bb7 --- /dev/null +++ b/sources/pyside6/libpyside/pysideqobject.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEQOBJECT_H +#define PYSIDEQOBJECT_H + +#include <sbkpython.h> + +#include <pysidemacros.h> + +#include <QtCore/QtGlobal> + +QT_FORWARD_DECLARE_CLASS(QObject) +QT_FORWARD_DECLARE_STRUCT(QMetaObject) + +namespace PySide +{ + +/// Fill QObject properties and do signal connections using the values found in \p kwds dictionary. +/// \param qObj PyObject fot the QObject. +/// \param metaObj QMetaObject of \p qObj. +/// \param kwds key->value dictonary. +/// \return True if everything goes well, false with a Python error set otherwise. +PYSIDE_API bool fillQtProperties(PyObject *qObj, const QMetaObject *metaObj, PyObject *kwds); + +PYSIDE_API void initDynamicMetaObject(PyTypeObject *type, const QMetaObject *base, + std::size_t cppObjSize); +PYSIDE_API void initQObjectSubType(PyTypeObject *type, PyObject *args, PyObject *kwds); + +/// Return the size in bytes of a type that inherits QObject. +PYSIDE_API std::size_t getSizeOfQObject(PyTypeObject *type); + +/// Check if a PyTypeObject or its bases contains a QObject +/// \param pyType is the PyTypeObject to check +/// \param raiseError controls if a TypeError is raised when an object does not +/// inherit QObject +PYSIDE_API bool isQObjectDerived(PyTypeObject *pyType, bool raiseError); + +/// Convenience to convert a PyObject to QObject +PYSIDE_API QObject *convertToQObject(PyObject *object, bool raiseError); + +/// Check for properties and signals registered on MetaObject and return these +/// \param cppSelf Is the QObject which contains the metaobject +/// \param self Python object of cppSelf +/// \param name Name of the argument which the function will try retrieve from MetaData +/// \return The Python object which contains the Data obtained in metaObject or the Python +/// attribute related with name +PYSIDE_API PyObject *getMetaDataFromQObject(QObject *cppSelf, PyObject *self, PyObject *name); + +PYSIDE_API void *nextQObjectMemoryAddr(); +PYSIDE_API void setNextQObjectMemoryAddr(void *addr); + +PYSIDE_API PyObject *getWrapperForQObject(QObject *cppSelf, PyTypeObject *sbk_type); + +/// Return the best-matching type for a QObject (Helper for QObject.findType()) +/// \param cppSelf QObject instance +/// \return type object +PYSIDE_API PyTypeObject *getTypeForQObject(const QObject *cppSelf); + +} //namespace PySide + +#endif // PYSIDEQOBJECT_H diff --git a/sources/pyside6/libpyside/pysideutils.h b/sources/pyside6/libpyside/pysideutils.h new file mode 100644 index 000000000..570fbe952 --- /dev/null +++ b/sources/pyside6/libpyside/pysideutils.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 PYSIDEUTILS_H +#define PYSIDEUTILS_H + +#include <sbkpython.h> + +#include <pysidemacros.h> + +#include <QtCore/QtGlobal> + +QT_FORWARD_DECLARE_CLASS(QString) + +namespace PySide +{ + +/// Check if self inherits from class_name +/// \param self Python object +/// \param class_name strict with the class name +/// \return Returns true if self object inherits from class_name, otherwise returns false +PYSIDE_API bool inherits(PyTypeObject *self, const char *class_name); + +/// Given A PyObject repesenting ASCII or Unicode data, returns an equivalent QString. +PYSIDE_API QString pyStringToQString(PyObject *str); + +/// Provide an efficient, correct PathLike interface. +PYSIDE_API QString pyPathToQString(PyObject *path); + +} //namespace PySide + +#endif // PYSIDESTRING_H diff --git a/sources/pyside6/libpyside/qobjectconnect.cpp b/sources/pyside6/libpyside/qobjectconnect.cpp index fb9660e0a..bad0589a2 100644 --- a/sources/pyside6/libpyside/qobjectconnect.cpp +++ b/sources/pyside6/libpyside/qobjectconnect.cpp @@ -38,7 +38,7 @@ ****************************************************************************/ #include "qobjectconnect.h" -#include "pyside.h" +#include "pysideqobject.h" #include "pysidesignal.h" #include "signalmanager.h" diff --git a/sources/pyside6/libpyside/signalmanager.cpp b/sources/pyside6/libpyside/signalmanager.cpp index f85a63b31..c1147bb3c 100644 --- a/sources/pyside6/libpyside/signalmanager.cpp +++ b/sources/pyside6/libpyside/signalmanager.cpp @@ -42,7 +42,7 @@ #include "pysidesignal.h" #include "pysideproperty.h" #include "pysideproperty_p.h" -#include "pyside.h" +#include "pysidecleanup.h" #include "pyside_p.h" #include "dynamicqmetaobject.h" #include "pysidemetafunction_p.h" diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 4370556ab..eb48b1b10 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -353,7 +353,7 @@ static const char includeQDebug[] = "#ifndef QT_NO_VERSION_TAGGING\n" "# define QT_NO_VERSION_TAGGING\n" "#endif\n" -"#include <QDebug>\n"; +"#include <QtCore/QDebug>\n"; static QString chopType(QString s) { @@ -428,19 +428,21 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon s << "#include <shiboken.h>\n"; if (usePySideExtensions()) { s << includeQDebug; - s << "#include <pysidesignal.h>\n" - << "#include <pysideproperty.h>\n" - << "#include <pyside.h>\n" - << "#include <pysideqenum.h>\n" + if (metaClass->isQObject()) { + s << "#include <pysideqobject.h>\n" + << "#include <pysidesignal.h>\n" + << "#include <pysideproperty.h>\n" + << "#include <signalmanager.h>\n" + << "#include <pysidemetafunction.h>\n"; + } + s << "#include <pysideqenum.h>\n" + << "#include <pysideqmetatype.h>\n" + << "#include <pysideutils.h>\n" << "#include <feature_select.h>\n" << "QT_WARNING_DISABLE_DEPRECATED\n\n"; } s << "#include <typeinfo>\n"; - if (usePySideExtensions() && metaClass->isQObject()) { - s << "#include <signalmanager.h>\n"; - s << "#include <pysidemetafunction.h>\n"; - } // The multiple inheritance initialization function // needs the 'set' class from C++ STL. @@ -6313,7 +6315,7 @@ bool CppGenerator::finishGeneration() if (usePySideExtensions()) { s << includeQDebug; - s << R"(#include <pyside.h> + s << R"(#include <pysidecleanup.h> #include <pysideqenum.h> #include <feature_select.h> )"; |