67ffb084d460126245ae0acbb78df8dac13d85bd
[bertos.git] / wizard / qvariant_converter_old.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 """
13 Awful module for the conversion from python types to qvariant, for make the wizard compatible with older version of pyqt (<= 4.4.3)
14 """
15
16 from PyQt4.QtCore import *
17 import pickle
18
19 def getString(qvariant):
20     if type(qvariant) == str or type(qvariant) == unicode:
21         string = qvariant
22     else:
23         string = unicode(qvariant.toString())
24     return string
25
26 def convertString(string):
27     return QVariant(string)
28
29 def getStringList(qvariant):
30     string_list = []
31     if type(qvariant) == list:
32         string_list = qvariant
33     else:
34         for element in qvariant.toStringList():
35             string_list.append(unicode(element))
36     return string_list
37
38 def convertStringList(string_list):
39     result = []
40     for element in string_list:
41         result.append(QString(element))
42     return QVariant(QStringList(result))
43
44 def getStringDict(qvariant):
45     a = str(qvariant.toByteArray())
46     if len(a) == 0:
47         dict_str_str = {}
48     else:
49         dict_str_str = pickle.loads(a)
50     return dict_str_str
51
52 def convertStringDict(dict_str_str):
53     a = pickle.dumps(dict_str_str)
54     return QVariant(QByteArray(a))
55
56 def getBool(qvariant):
57     return qvariant.toBool()
58
59 def convertBool(boolean):
60     return QVariant(boolean)
61
62 def getBoolDict(qvariant):
63     a = str(qvariant.toByteArray())
64     if len(a) == 0:
65         dict_str_bool = {}
66     else:
67         dict_str_bool = pickle.loads(a)
68     return dict_str_bool
69
70 def convertBoolDict(dict_str_bool):
71     a = pickle.dumps(dict_str_bool)
72     return QVariant(QByteArray(a))
73
74 def getDict(qvariant):
75     a = str(qvariant.toByteArray())
76     if len(a) == 0:
77         dict_str_bool = {}
78     else:
79         dict_str_bool = pickle.loads(a)
80     return dict_str_bool
81
82 def convertDict(dict_str_variant):
83     a = pickle.dumps(dict_str_variant)
84     return QVariant(QByteArray(a))