diff options
| author | Christian Tismer <tismer@stackless.com> | 2023-06-30 14:27:42 +0200 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2023-07-03 09:48:49 +0200 |
| commit | 7605aaa9e8d6a669c45ae3ea72a3db80f81ecadd (patch) | |
| tree | 004ce4d6cd8516fbe79819e7ee16e6ea8952ef10 /sources/pyside6 | |
| parent | 483308a17fb8466061f6b318b667758fb5d27d03 (diff) | |
PyEnum: Get rid of the no longer needed flags type
As a welcome unexpected gift, we now even get rid of the flags class.
The builtin Qt flags are still touched when creating properties.
This needs an extra registration of the single flag converter name
but no extra functions.
See testQObjectProperty of qlabel_test.py .
[ChangeLog][PySide6] After removal of the old enums, also the
complex flags structure could be removed.
Change-Id: Ie531a7470330af41eb491e8b1e37939f1afcb9a0
Task-number: PYSIDE-1735
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6')
| -rw-r--r-- | sources/pyside6/PySide6/QtCore/typesystem_core_common.xml | 2 | ||||
| -rw-r--r-- | sources/pyside6/libpyside/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sources/pyside6/libpyside/pysideqflags.cpp | 200 | ||||
| -rw-r--r-- | sources/pyside6/libpyside/pysideqflags.h | 43 |
4 files changed, 0 insertions, 247 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index b1557af87..3548b33b9 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -443,7 +443,6 @@ <container-type name="QHash" type="hash"> <include file-name="QHash" location="global"/> <!-- Include to make enum flags work. --> - <include file-name="pysideqflags.h" location="global"/> <conversion-rule> <native-to-target> <insert-template name="shiboken_conversion_qmap_to_pydict"/> @@ -459,7 +458,6 @@ <container-type name="QMultiHash" type="multi-hash"> <include file-name="QMultiHash" location="global"/> <!-- Include to make enum flags work. --> - <include file-name="pysideqflags.h" location="global"/> <conversion-rule> <native-to-target> <insert-template name="shiboken_conversion_qmultihash_to_pydict"/> diff --git a/sources/pyside6/libpyside/CMakeLists.txt b/sources/pyside6/libpyside/CMakeLists.txt index 78bf24c80..01a0a66b0 100644 --- a/sources/pyside6/libpyside/CMakeLists.txt +++ b/sources/pyside6/libpyside/CMakeLists.txt @@ -27,7 +27,6 @@ set(libpyside_HEADERS # installed below pysideproperty_p.h pysideqapp.h pysideqenum.h - pysideqflags.h pysideqhash.h pysideqmetatype.h pysideqobject.h @@ -54,7 +53,6 @@ set(libpyside_SRC pysidesignal.cpp pysideslot.cpp pysideproperty.cpp - pysideqflags.cpp pysideweakref.cpp pyside.cpp pyside_numpy.cpp diff --git a/sources/pyside6/libpyside/pysideqflags.cpp b/sources/pyside6/libpyside/pysideqflags.cpp deleted file mode 100644 index bff061bca..000000000 --- a/sources/pyside6/libpyside/pysideqflags.cpp +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (C) 2016 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 "pysideqflags.h" - -#include <autodecref.h> -#include <sbkenum.h> -#include <sbkconverter.h> - -extern "C" { - struct SbkConverter; - - struct PySideQFlagsTypePrivate : public SbkQFlagsTypePrivate - { - // PYSIDE-1735: These fields are just there for comatibility with the enumstructure. - // We need to switch between flags and enum at runtine. - // This will vanish completely when we no longer support two implementations. - const char *_cppName; - PyTypeObject *_replacementType; - }; - /** - * Type of all QFlags - */ - struct PySideQFlagsType - { - PyTypeObject type; - }; - - #define PYSIDE_QFLAGS(X) reinterpret_cast<PySideQFlagsObject *>(X) - - PyObject *PySideQFlags_tp_new(PyTypeObject *type, PyObject *args, PyObject * /* kwds */) - { - long val = 0; - if (PyTuple_GET_SIZE(args)) { - PyObject *arg = PyTuple_GET_ITEM(args, 0); - if (PyNumber_Check(arg)) { - Shiboken::AutoDecRef number(PyNumber_Long(arg)); - val = PyLong_AsLong(number); - } else { - PyErr_SetString(PyExc_TypeError,"QFlags must be created using enums or numbers."); - return nullptr; - } - } - PySideQFlagsObject *self = PyObject_New(PySideQFlagsObject, type); - self->ob_value = val; - return reinterpret_cast<PyObject *>(self); - } - - static long getNumberValue(PyObject *v) - { - Shiboken::AutoDecRef number(PyNumber_Long(v)); - return PyLong_AsLong(number); - } - - static PyObject *qflag_nb_int(PyObject *self) - { - return PyLong_FromLong(reinterpret_cast<PySideQFlagsObject*>(self)->ob_value); - } - - PyObject *PySideQFlags_tp_richcompare(PyObject *self, PyObject *other, int op) - { - int result = 0; - if (!PyNumber_Check(other)) { - switch (op) { - case Py_EQ: - Py_RETURN_FALSE; - case Py_NE: - Py_RETURN_TRUE; - default: - Py_RETURN_NOTIMPLEMENTED; - } - } - - if (self == other) { - switch (op) { - case Py_EQ: - case Py_LE: - case Py_GE: - result = 1; - break; - } - } else { - const long valA = PYSIDE_QFLAGS(self)->ob_value; - const long valB = getNumberValue(other); - switch (op) { - case Py_EQ: - result = (valA == valB); - break; - case Py_NE: - result = (valA != valB); - break; - case Py_LE: - result = (valA <= valB); - break; - case Py_GE: - result = (valA >= valB); - break; - case Py_LT: - result = (valA < valB); - break; - case Py_GT: - result = (valA > valB); - break; - default: - PyErr_BadArgument(); - return nullptr; - } - } - if (result) - Py_RETURN_TRUE; - Py_RETURN_FALSE; - } - - static void PySideQFlags_tp_dealloc(PyObject *self) - { - auto *flagsType = reinterpret_cast<PySideQFlagsType *>(self); - PepType_PFTP_delete(flagsType); - Sbk_object_dealloc(self); - } - - /// PYSIDE-1735: Support for redirection to the new Python enum.Flag . - static PyTypeObject *getEnumMeta() - { - static auto *mod = PyImport_ImportModule("enum"); - if (mod) { - static auto *EnumMeta = PyObject_GetAttrString(mod, "EnumMeta"); - if (EnumMeta) - return reinterpret_cast<PyTypeObject *>(EnumMeta); - } - Py_FatalError("Python module 'enum' not found"); - return nullptr; - } -} - -namespace PySide -{ -namespace QFlagsSupport -{ - static PyType_Slot SbkNewQFlagsType_slots[] = { - {Py_nb_bool, nullptr}, - {Py_nb_invert, nullptr}, - {Py_nb_and, nullptr}, - {Py_nb_xor, nullptr}, - {Py_nb_or, nullptr}, - {Py_nb_int, reinterpret_cast<void*>(qflag_nb_int)}, - {Py_nb_index, reinterpret_cast<void*>(qflag_nb_int)}, // same as nb_int - {Py_tp_new, reinterpret_cast<void *>(PySideQFlags_tp_new)}, - {Py_tp_richcompare, reinterpret_cast<void *>(PySideQFlags_tp_richcompare)}, - {Py_tp_dealloc, reinterpret_cast<void *>(PySideQFlags_tp_dealloc)}, - {0, nullptr} - }; - static PyType_Spec SbkNewQFlagsType_spec = { - "missing QFlags name", // to be inserted later - sizeof(PySideQFlagsObject), - 0, - Py_TPFLAGS_DEFAULT, - SbkNewQFlagsType_slots, - }; - - PyTypeObject *create(const char *name, PyType_Slot numberMethods[]) - { - char qualname[200]; - // PYSIDE-747: Here we insert now the full class name. - strcpy(qualname, name); - // Careful: SbkType_FromSpec does not allocate the string. - PyType_Spec newspec; - newspec.name = strdup(qualname); - newspec.basicsize = SbkNewQFlagsType_spec.basicsize; - newspec.itemsize = SbkNewQFlagsType_spec.itemsize; - newspec.flags = SbkNewQFlagsType_spec.flags; - int idx = -1; - while (numberMethods[++idx].slot) { - assert(SbkNewQFlagsType_slots[idx].slot == numberMethods[idx].slot); - SbkNewQFlagsType_slots[idx].pfunc = numberMethods[idx].pfunc; - } - newspec.slots = SbkNewQFlagsType_spec.slots; - return SbkType_FromSpec(&newspec); - } - - PySideQFlagsObject *newObject(long value, PyTypeObject *type) - { - // PYSIDE-1735: In case of a new Python enum, we must redirect to the - // enum.Flag implementation. - static PyTypeObject *enumMeta = getEnumMeta(); - if (Py_TYPE(type) == enumMeta) { - // We are cheating: This is an enum type. - auto *flag_enum = PyObject_CallFunction(reinterpret_cast<PyObject *>(type), "i", value); - return reinterpret_cast<PySideQFlagsObject *>(flag_enum); - } - PySideQFlagsObject *qflags = PyObject_New(PySideQFlagsObject, type); - qflags->ob_value = value; - return qflags; - } - - long getValue(PySideQFlagsObject *self) - { - return self->ob_value; - } -} -} diff --git a/sources/pyside6/libpyside/pysideqflags.h b/sources/pyside6/libpyside/pysideqflags.h deleted file mode 100644 index 7263ae5fc..000000000 --- a/sources/pyside6/libpyside/pysideqflags.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2016 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 PYSIDE_QFLAGS_H -#define PYSIDE_QFLAGS_H - -#include <sbkpython.h> -#include "pysidemacros.h" - - -extern "C" -{ - struct PYSIDE_API PySideQFlagsObject { - PyObject_HEAD - long ob_value; - }; - - PYSIDE_API PyObject* PySideQFlags_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); - PYSIDE_API PyObject* PySideQFlags_tp_richcompare(PyObject *self, PyObject *other, int op); -} - - -namespace PySide -{ -namespace QFlagsSupport -{ - /** - * Creates a new QFlags type. - */ - PYSIDE_API PyTypeObject *create(const char* name, PyType_Slot *numberMethods); - /** - * Creates a new QFlags instance of type \p type and value \p value. - */ - PYSIDE_API PySideQFlagsObject* newObject(long value, PyTypeObject* type); - /** - * Returns the value held by a QFlag. - */ - PYSIDE_API long getValue(PySideQFlagsObject* self); -} -} - -#endif - |
