summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-09-02 20:33:00 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2010-09-03 10:59:43 -0300
commit823eec81c245f56cd2baf7c9fe0b1bf006500561 (patch)
tree9f9577ee6252f6d9cce086cffb20f2ff86ef3d12
parentf024b0d8840b00da4f3a703db5b22c70cf8b26ee (diff)
downloadshiboken-823eec81c245f56cd2baf7c9fe0b1bf006500561.tar.gz
shiboken-823eec81c245f56cd2baf7c9fe0b1bf006500561.tar.xz
shiboken-823eec81c245f56cd2baf7c9fe0b1bf006500561.zip
Fix bug#320 - "OR'ing Qt alignments doesn't work; adding them does"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--PySide/QtCore/qvariant_conversions.h2
-rw-r--r--libpyside/pysideconversions.h17
-rw-r--r--tests/QtCore/qflags_test.py15
3 files changed, 22 insertions, 12 deletions
diff --git a/PySide/QtCore/qvariant_conversions.h b/PySide/QtCore/qvariant_conversions.h
index a471ce64..1e1c7057 100644
--- a/PySide/QtCore/qvariant_conversions.h
+++ b/PySide/QtCore/qvariant_conversions.h
@@ -34,7 +34,7 @@ struct Converter<QVariant>
} else if (PyFloat_CheckExact(pyObj)) {
// QVariant(double)
return QVariant(Converter<double>::toCpp(pyObj));
- } else if (PyInt_CheckExact(pyObj)) {
+ } else if (PyInt_Check(pyObj)) {
// QVariant(int)
return QVariant(Converter<int>::toCpp(pyObj));
} else if (PyLong_CheckExact(pyObj)) {
diff --git a/libpyside/pysideconversions.h b/libpyside/pysideconversions.h
index c7fdcb51..35fa687d 100644
--- a/libpyside/pysideconversions.h
+++ b/libpyside/pysideconversions.h
@@ -237,19 +237,24 @@ struct QFlagsConverter
|| PyObject_TypeCheck(pyObj, Shiboken::SbkType<typename T::enum_type>());
}
- static inline PyObject* toPython(void* cppobj)
+ static inline PyObject* toPython(void* cppObj)
{
- return toPython(*reinterpret_cast<T*>(cppobj));
+ return toPython(*reinterpret_cast<T*>(cppObj));
}
- static inline PyObject* toPython(T cppenum)
+ static inline PyObject* toPython(const T& cppObj)
{
- return Shiboken::SbkEnumObject_New(Shiboken::SbkType<T>(), (long) cppenum);
+ PyObject* qflags = Shiboken::SbkType<T>()->tp_alloc(Shiboken::SbkType<T>(), 0);
+ reinterpret_cast<PyIntObject*>(qflags)->ob_ival = cppObj;
+ return qflags;
}
- static inline T toCpp(PyObject* pyobj)
+ static inline T toCpp(PyObject* pyObj)
{
- return T(QFlag(reinterpret_cast<Shiboken::SbkEnumObject*>(pyobj)->ob_ival));
+ if (Shiboken::isShibokenEnum(pyObj))
+ return T(QFlag(reinterpret_cast<Shiboken::SbkEnumObject*>(pyObj)->ob_ival));
+ else
+ return T(QFlag(reinterpret_cast<PyIntObject*>(pyObj)->ob_ival));
}
};
diff --git a/tests/QtCore/qflags_test.py b/tests/QtCore/qflags_test.py
index 8b3a4881..3ecaa2f2 100644
--- a/tests/QtCore/qflags_test.py
+++ b/tests/QtCore/qflags_test.py
@@ -2,7 +2,7 @@
'''Test cases for QFlags'''
import unittest
-from PySide.QtCore import QIODevice, Qt, QFile, QTemporaryFile
+from PySide.QtCore import *
class QFlagTest(unittest.TestCase):
'''Test case for usage of flags'''
@@ -28,15 +28,15 @@ class QFlagOperatorTest(unittest.TestCase):
def testInvert(self):
'''QFlags ~ (invert) operator'''
- self.assert_(isinstance(~QIODevice.ReadOnly, QIODevice.OpenMode))
+ self.assertEqual(type(~QIODevice.ReadOnly), QIODevice.OpenMode)
def testOr(self):
'''QFlags | (or) operator'''
- self.assert_(isinstance(QIODevice.ReadOnly | QIODevice.WriteOnly, QIODevice.OpenMode))
+ self.assertEqual(type(QIODevice.ReadOnly | QIODevice.WriteOnly), QIODevice.OpenMode)
def testAnd(self):
'''QFlags & (and) operator'''
- self.assert_(isinstance(QIODevice.ReadOnly & QIODevice.WriteOnly, QIODevice.OpenMode))
+ self.assertEqual(type(QIODevice.ReadOnly & QIODevice.WriteOnly), QIODevice.OpenMode)
def testIOr(self):
'''QFlags |= (ior) operator'''
@@ -47,7 +47,7 @@ class QFlagOperatorTest(unittest.TestCase):
def testInvertOr(self):
'''QFlags ~ (invert) operator over the result of an | (or) operator'''
- self.assert_(isinstance(~(Qt.ItemIsSelectable | Qt.ItemIsEditable), Qt.ItemFlags))
+ self.assertEqual(type(~(Qt.ItemIsSelectable | Qt.ItemIsEditable)), Qt.ItemFlags)
def testEqual(self):
'''QFlags == operator'''
@@ -56,6 +56,11 @@ class QFlagOperatorTest(unittest.TestCase):
flag_type = (flags & Qt.WindowType_Mask)
self.assertEqual(flag_type, Qt.Window)
+class QFlagsOnQVariant(unittest.TestCase):
+ def testQFlagsOnQVariant(self):
+ o = QObject()
+ o.setProperty("foo", QIODevice.ReadOnly | QIODevice.WriteOnly)
+ self.assertEqual(type(o.property("foo")), int)
if __name__ == '__main__':
unittest.main()