Fixed QVariant conversions for user type.
This commit is contained in:
parent
c7f6b49e1e
commit
66ff085861
2 changed files with 14 additions and 5 deletions
|
|
@ -20,15 +20,16 @@ struct Converter<QVariant>
|
||||||
Shiboken::SbkBaseWrapperType *sbkType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(type);
|
Shiboken::SbkBaseWrapperType *sbkType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(type);
|
||||||
const char* typeName = sbkType->original_name;
|
const char* typeName = sbkType->original_name;
|
||||||
|
|
||||||
// Do not resolve types to value type
|
|
||||||
if (!QByteArray(typeName).endsWith("*"))
|
|
||||||
return QByteArray();
|
|
||||||
|
|
||||||
int obTypeId = QMetaType::type(typeName);
|
int obTypeId = QMetaType::type(typeName);
|
||||||
if (obTypeId) {
|
if (obTypeId) {
|
||||||
typeId = obTypeId;
|
typeId = obTypeId;
|
||||||
return QByteArray(typeName);
|
return QByteArray(typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Do not resolve types to value type
|
||||||
|
if (!QByteArray(typeName).endsWith("*"))
|
||||||
|
return QByteArray();
|
||||||
|
|
||||||
// find in base types
|
// find in base types
|
||||||
if (type->tp_base) {
|
if (type->tp_base) {
|
||||||
return resolveMetaType(type->tp_base, typeId);
|
return resolveMetaType(type->tp_base, typeId);
|
||||||
|
|
@ -80,7 +81,7 @@ struct Converter<QVariant>
|
||||||
return convertToVariantList(pyObj);
|
return convertToVariantList(pyObj);
|
||||||
} else {
|
} else {
|
||||||
// a class supported by QVariant?
|
// a class supported by QVariant?
|
||||||
if (Shiboken::isShibokenType(pyObj)) {
|
if (Shiboken::isShibokenType(pyObj) && !Shiboken::isUserType(pyObj)) {
|
||||||
Shiboken::SbkBaseWrapperType *objType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(pyObj->ob_type);
|
Shiboken::SbkBaseWrapperType *objType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>(pyObj->ob_type);
|
||||||
int typeCode = 0;
|
int typeCode = 0;
|
||||||
QByteArray typeName = resolveMetaType(reinterpret_cast<PyTypeObject*>(objType), typeCode);
|
QByteArray typeName = resolveMetaType(reinterpret_cast<PyTypeObject*>(objType), typeCode);
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,14 @@ class PropertyCase(unittest.TestCase):
|
||||||
|
|
||||||
self.assertTrue(obj.property('foo') is mysize)
|
self.assertTrue(obj.property('foo') is mysize)
|
||||||
|
|
||||||
|
def testValueType(self):
|
||||||
|
rect = QRect(1, 2, 3, 4)
|
||||||
|
obj = QObject()
|
||||||
|
obj.setProperty('rect', rect)
|
||||||
|
'''Value types when converted to QVariant is copyed'''
|
||||||
|
self.assertFalse(obj.property('rect') is rect)
|
||||||
|
self.assertEqual(obj.property('rect'), rect)
|
||||||
|
|
||||||
class PropertyWithConstructorCase(unittest.TestCase):
|
class PropertyWithConstructorCase(unittest.TestCase):
|
||||||
'''Test case for QObject properties set using named arguments in the constructor.'''
|
'''Test case for QObject properties set using named arguments in the constructor.'''
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue