summaryrefslogtreecommitdiffstats
path: root/libpyside
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-10-14 14:00:18 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-10-28 17:04:29 -0200
commitf9a7144f53aa2e1c4f29b19436c9b9b1cc02833a (patch)
tree8517716f556bc54a37cc76d8d094c6e5cec259be /libpyside
parent3b70d65b9c866beadb334263f0c40474377f0967 (diff)
downloadpyside-f9a7144f53aa2e1c4f29b19436c9b9b1cc02833a.tar.gz
pyside-f9a7144f53aa2e1c4f29b19436c9b9b1cc02833a.tar.xz
pyside-f9a7144f53aa2e1c4f29b19436c9b9b1cc02833a.zip
Creates QFlags types at runtime.
Diffstat (limited to 'libpyside')
-rw-r--r--libpyside/pysideqflags.cpp30
-rw-r--r--libpyside/pysideqflags.h14
2 files changed, 42 insertions, 2 deletions
diff --git a/libpyside/pysideqflags.cpp b/libpyside/pysideqflags.cpp
index 2794520..f7ab7d6 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 6eb91d3..496e84b 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);
}
}