From a623a57d0660e4490c370da7167db3a794f5162e Mon Sep 17 00:00:00 2001 From: renatofilho Date: Wed, 10 Nov 2010 12:53:28 -0300 Subject: Fixed QVariant conversions for object types. Reviewer: Marcelo Lira Luciano Wolf --- PySide/QtCore/qvariant_conversions.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/PySide/QtCore/qvariant_conversions.h b/PySide/QtCore/qvariant_conversions.h index b47e3892d..9363a25c5 100644 --- a/PySide/QtCore/qvariant_conversions.h +++ b/PySide/QtCore/qvariant_conversions.h @@ -18,7 +18,12 @@ struct Converter { if (PyObject_TypeCheck(type, &Shiboken::SbkBaseWrapperType_Type)) { Shiboken::SbkBaseWrapperType *sbkType = reinterpret_cast(type); - const char* typeName = sbkType->original_name; + QByteArray typeName(sbkType->original_name); + bool valueType = !typeName.endsWith("*"); + + // Do not convert user type of value + if (valueType && sbkType->is_user_type) + return QByteArray(); int obTypeId = QMetaType::type(typeName); if (obTypeId) { @@ -27,7 +32,7 @@ struct Converter } // Do not resolve types to value type - if (!QByteArray(typeName).endsWith("*")) + if (valueType) return QByteArray(); // find in base types @@ -81,7 +86,7 @@ struct Converter return convertToVariantList(pyObj); } else { // a class supported by QVariant? - if (Shiboken::isShibokenType(pyObj) && !Shiboken::isUserType(pyObj)) { + if (Shiboken::isShibokenType(pyObj)) { Shiboken::SbkBaseWrapperType *objType = reinterpret_cast(pyObj->ob_type); int typeCode = 0; QByteArray typeName = resolveMetaType(reinterpret_cast(objType), typeCode); -- cgit v1.2.3 From 2ef14fcc12f003620f85a30f6a4b00e8fee654d2 Mon Sep 17 00:00:00 2001 From: renatofilho Date: Wed, 10 Nov 2010 12:54:23 -0300 Subject: Created unit test for qvariant conversion for object type. Reviewer: Marcelo Lira Luciano Wolf --- tests/QtDeclarative/CMakeLists.txt | 10 ++++----- tests/QtDeclarative/qdeclarativeview_test.py | 33 ++++++++++++++++++++++++++-- tests/QtDeclarative/viewmodel.qml | 14 ++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 tests/QtDeclarative/viewmodel.qml diff --git a/tests/QtDeclarative/CMakeLists.txt b/tests/QtDeclarative/CMakeLists.txt index 277384987..5ceba4224 100644 --- a/tests/QtDeclarative/CMakeLists.txt +++ b/tests/QtDeclarative/CMakeLists.txt @@ -1,5 +1,5 @@ -PYSIDE_TEST(bug_451.py FALSE) -PYSIDE_TEST(bug_456.py FALSE) -PYSIDE_TEST(qdeclarativenetwork_test.py FALSE) -PYSIDE_TEST(qdeclarativeview_test.py FALSE) -PYSIDE_TEST(connect_python_qml.py FALSE) +PYSIDE_TEST(bug_451.py) +PYSIDE_TEST(bug_456.py) +PYSIDE_TEST(qdeclarativenetwork_test.py) +PYSIDE_TEST(qdeclarativeview_test.py) +PYSIDE_TEST(connect_python_qml.py) diff --git a/tests/QtDeclarative/qdeclarativeview_test.py b/tests/QtDeclarative/qdeclarativeview_test.py index 7a2b657e1..f8f3a549b 100644 --- a/tests/QtDeclarative/qdeclarativeview_test.py +++ b/tests/QtDeclarative/qdeclarativeview_test.py @@ -2,11 +2,26 @@ import unittest -from PySide.QtCore import QUrl +from PySide.QtCore import QUrl, QObject, Property, Slot from PySide.QtDeclarative import QDeclarativeView from helper import adjust_filename, TimedQApplication +class MyObject(QObject): + def __init__(self, text, parent=None): + QObject.__init__(self, parent) + self._text = text + + def getText(self): + return self._text + + + @Slot(str) + def qmlText(self, text): + self._qmlText = text + + title = Property(str, getText) + class TestQDeclarativeView(TimedQApplication): @@ -24,7 +39,21 @@ class TestQDeclarativeView(TimedQApplication): self.assertEqual(view.status(), QDeclarativeView.Ready) - self.app.exec_() + + def testModelExport(self): + print "TEST" + view = QDeclarativeView() + dataList = [MyObject("Item 1"), MyObject("Item 2"), MyObject("Item 3"), MyObject("Item 4")] + + ctxt = view.rootContext() + ctxt.setContextProperty("myModel", dataList) + + url = QUrl.fromLocalFile(adjust_filename('viewmodel.qml', __file__)) + view.setSource(url) + view.show() + + self.assertEqual(view.status(), QDeclarativeView.Ready) + if __name__ == '__main__': unittest.main() diff --git a/tests/QtDeclarative/viewmodel.qml b/tests/QtDeclarative/viewmodel.qml new file mode 100644 index 000000000..badce7de2 --- /dev/null +++ b/tests/QtDeclarative/viewmodel.qml @@ -0,0 +1,14 @@ +import Qt 4.7 + +ListView { + width: 100; height: 100 + anchors.fill: parent + + model: myModel + delegate: Rectangle { + height: 25 + width: 100 + Text { text: title } + } +} + -- cgit v1.2.3