Fix bug 1036 - "Qt.KeyboardModifiers always evaluates to zero"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
parent
b50186e9f3
commit
8060e3ee87
2 changed files with 17 additions and 1 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "pysideqflags.h"
|
#include "pysideqflags.h"
|
||||||
#include <sbkenum.h>
|
#include <sbkenum.h>
|
||||||
|
#include <autodecref.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
struct SbkConverter;
|
struct SbkConverter;
|
||||||
|
|
@ -39,8 +40,21 @@ extern "C" {
|
||||||
|
|
||||||
PyObject* PySideQFlagsNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PyObject* PySideQFlagsNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
|
long val = 0;
|
||||||
|
if (PyTuple_GET_SIZE(args)) {
|
||||||
|
PyObject* arg = PyTuple_GET_ITEM(args, 0);
|
||||||
|
if (Shiboken::isShibokenEnum(arg)) {// faster call
|
||||||
|
val = Shiboken::Enum::getValue(arg);
|
||||||
|
} else 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 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
PySideQFlagsObject* self = PyObject_New(PySideQFlagsObject, type);
|
PySideQFlagsObject* self = PyObject_New(PySideQFlagsObject, type);
|
||||||
self->ob_value = 0;
|
self->ob_value = val;
|
||||||
return reinterpret_cast<PyObject*>(self);
|
return reinterpret_cast<PyObject*>(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ class QFlagOperatorTest(unittest.TestCase):
|
||||||
flag_type = (flags & Qt.WindowType_Mask)
|
flag_type = (flags & Qt.WindowType_Mask)
|
||||||
self.assertEqual(flag_type, Qt.Window)
|
self.assertEqual(flag_type, Qt.Window)
|
||||||
|
|
||||||
|
self.assertEqual(Qt.KeyboardModifiers(Qt.ControlModifier), Qt.ControlModifier)
|
||||||
|
|
||||||
def testOperatorBetweenFlags(self):
|
def testOperatorBetweenFlags(self):
|
||||||
'''QFlags & QFlags'''
|
'''QFlags & QFlags'''
|
||||||
flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable
|
flags = Qt.NoItemFlags | Qt.ItemIsUserCheckable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue