diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-10-14 14:00:18 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:56:15 -0300 |
commit | b50186e9f3e7bed94707707870e0d9faec828454 (patch) | |
tree | bb07779f25a0e16512e531d3ae990323ad76bb07 /libpyside | |
parent | 4ba7cd90d6799400cd3abf8741c0327835e3bdb6 (diff) |
Creates QFlags types at runtime.
Diffstat (limited to 'libpyside')
-rw-r--r-- | libpyside/pysideqflags.cpp | 30 | ||||
-rw-r--r-- | libpyside/pysideqflags.h | 14 |
2 files changed, 42 insertions, 2 deletions
diff --git a/libpyside/pysideqflags.cpp b/libpyside/pysideqflags.cpp index 2794520f6..f7ab7d630 100644 --- a/libpyside/pysideqflags.cpp +++ b/libpyside/pysideqflags.cpp @@ -21,8 +21,20 @@ */ #include "pysideqflags.h" +#include <sbkenum.h> extern "C" { + struct SbkConverter; + + /** + * Type of all QFlags + */ + struct PySideQFlagsType + { + PyHeapTypeObject super; + SbkConverter* converter; + }; + #define PYSIDE_QFLAGS(X) reinterpret_cast<PySideQFlagsObject*>(X) PyObject* PySideQFlagsNew(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -89,6 +101,24 @@ namespace PySide { namespace QFlags { + PyTypeObject* create(const char* name, PyNumberMethods* numberMethods) + { + PyTypeObject* type = reinterpret_cast<PyTypeObject*>(new PySideQFlagsType); + ::memset(type, 0, sizeof(PySideQFlagsType)); + Py_TYPE(type) = &PyType_Type; + type->tp_basicsize = sizeof(PySideQFlagsObject); + type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES; + type->tp_name = name; + type->tp_new = &PySideQFlagsNew; + type->tp_as_number = numberMethods; + type->tp_richcompare = &PySideQFlagsRichCompare; + + if (PyType_Ready(type) < 0) + return 0; + + return type; + } + PySideQFlagsObject* newObject(long value, PyTypeObject* type) { PySideQFlagsObject* qflags = PyObject_New(PySideQFlagsObject, type); diff --git a/libpyside/pysideqflags.h b/libpyside/pysideqflags.h index 6eb91d319..496e84b94 100644 --- a/libpyside/pysideqflags.h +++ b/libpyside/pysideqflags.h @@ -24,10 +24,10 @@ #define PYSIDE_QFLAGS_H #include <sbkpython.h> -#include <pysidemacros.h> +#include "pysidemacros.h" -extern "C" +extern "C" { struct PYSIDE_API PySideQFlagsObject { PyObject_HEAD @@ -43,7 +43,17 @@ namespace PySide { namespace QFlags { + /** + * Creates a new QFlags type. + */ + PYSIDE_API PyTypeObject* create(const char* name, PyNumberMethods* 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); } } |