Attempt to resolve the QVariant conversion problems on pyqt <= 4.4.3
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 12 Jan 2009 17:40:03 +0000 (17:40 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 12 Jan 2009 17:40:03 +0000 (17:40 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2160 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/qvariant_converter_old.py

index 0a41919d78e56d0563d9ccfea796a16863feca55..7d3afe0f117aaa8aae72cc0f4a23e2a0f181a666 100644 (file)
 from PyQt4.QtCore import *
 
 def getString(qvariant):
-    string = qvariant.toPyObject()
+    string = unicode(qvariant.toString())
     return string
 
 def convertString(string):
     return QVariant(string)
 
 def getStringList(qvariant):
-    string_list = qvariant.toPyObject()
+    string_list = []
+    for element in qvariant.toStringList():
+        string_list.append(unicode(element))
     return string_list
 
 def convertStringList(string_list):
-    return QVariant(string_list)
+    result = []
+    for element in string_list:
+        result.append(QString(element))
+    return QVariant(QStringList(result))
 
 def getStringDict(qvariant):
-    dict_str_str = qvariant.toPyObject()
+    dict_str_str = {}
+    qvariant_item = qvariant.toPyObject()
+    if qvariant_item == NotImplemented:
+        qvariant_item = {}
+    for key, value in qvariant_item.items():
+        dict_str_str[unicode(key)] = unicode(value.toString())
     return dict_str_str
 
 def convertStringDict(string_dict):
-    return QVariant(string_dict)
+    result = {}
+    for key, value in string_dict.items():
+        result[QString(key)] = QVariant(QString(value))
+    return QVariant(result)
 
 def getBool(qvariant):
     return qvariant.toBool()
@@ -39,15 +52,36 @@ def convertBool(boolean):
     return QVariant(boolean)
 
 def getBoolDict(qvariant):
-    dict_str_bool = qvariant.toPyObject()
+    dict_str_bool = {}
+    qvariant_item = qvariant.toPyObject()
+    if qvariant_item == NotImplemented:
+        qvariant_item = {}
+    for key, value in qvariant_item.items():
+        dict_str_bool[unicode(key)] = value.toBool()
     return dict_str_bool
 
 def convertBoolDict(dict_str_bool):
-    return QVariant(dict_str_bool)
+    result = {}
+    for key, value in dict_str_bool:
+        result[QString(key)] = QVariant(value)
+    return QVariant(result)
 
 def getDict(qvariant):
-    dict_str_variant = qvariant.toPyObject()
+    dict_str_variant = {}
+    qvariant_item = qvariant.toPyObject()
+    if qvariant_item == NotImplemented:
+        qvariant_item = {}
+    for key, value in qvariant_item.items():
+        dict_str_variant[unicode(key)] = value
     return dict_str_variant
 
 def convertDict(dict_str_variant):
-    return QVariant(dict_str_variant)
+    result = {}
+    for key, value in dict_str_variant.items():
+        if type(value) == str or type(value) == unicode:
+            result[QString(key)] = QVariant(QString(value))
+        elif type(value) == list:
+            result[QString(key)] = QVariant(QStringList(value))
+        elif type(value) == dict:
+            result[QString(key)] = QVariant(convertDict(value))
+    return QVariant(result)