Helpviewer/CookieJar/CookieExceptionsModel.py

changeset 7
c679fb30c8f3
parent 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
6:52e8c820d0dd 7:c679fb30c8f3
46 """ 46 """
47 if role == Qt.SizeHintRole: 47 if role == Qt.SizeHintRole:
48 fm = QFontMetrics(QFont()) 48 fm = QFontMetrics(QFont())
49 height = fm.height() + fm.height() / 3 49 height = fm.height() + fm.height() / 3
50 width = \ 50 width = \
51 fm.width(self.headerData(section, orientation, Qt.DisplayRole).toString()) 51 fm.width(self.headerData(section, orientation, Qt.DisplayRole))
52 return QVariant(QSize(width, height)) 52 return QSize(width, height)
53 53
54 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 54 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
55 try: 55 try:
56 return QVariant(self.__headers[section]) 56 return self.__headers[section]
57 except IndexError: 57 except IndexError:
58 return QVariant() 58 return None
59 59
60 return QAbstractTableModel.headerData(self, section, orientation, role) 60 return QAbstractTableModel.headerData(self, section, orientation, role)
61 61
62 def data(self, index, role): 62 def data(self, index, role):
63 """ 63 """
66 @param index index to get data for (QModelIndex) 66 @param index index to get data for (QModelIndex)
67 @param role role of the data to retrieve (integer) 67 @param role role of the data to retrieve (integer)
68 @return requested data 68 @return requested data
69 """ 69 """
70 if index.row() < 0 or index.row() >= self.rowCount(): 70 if index.row() < 0 or index.row() >= self.rowCount():
71 return QVariant() 71 return None
72 72
73 if role in (Qt.DisplayRole, Qt.EditRole): 73 if role in (Qt.DisplayRole, Qt.EditRole):
74 row = index.row() 74 row = index.row()
75 if row < len(self.__allowedCookies): 75 if row < len(self.__allowedCookies):
76 if index.column() == 0: 76 if index.column() == 0:
77 return QVariant(self.__allowedCookies[row]) 77 return self.__allowedCookies[row]
78 elif index.column() == 1: 78 elif index.column() == 1:
79 return QVariant(self.trUtf8("Allow")) 79 return self.trUtf8("Allow")
80 else: 80 else:
81 return QVariant() 81 return None
82 82
83 row -= len(self.__allowedCookies) 83 row -= len(self.__allowedCookies)
84 if row < len(self.__blockedCookies): 84 if row < len(self.__blockedCookies):
85 if index.column() == 0: 85 if index.column() == 0:
86 return QVariant(self.__blockedCookies[row]) 86 return self.__blockedCookies[row]
87 elif index.column() == 1: 87 elif index.column() == 1:
88 return QVariant(self.trUtf8("Block")) 88 return self.trUtf8("Block")
89 else: 89 else:
90 return QVariant() 90 return None
91 91
92 row -= len(self.__blockedCookies) 92 row -= len(self.__blockedCookies)
93 if row < len(self.__sessionCookies): 93 if row < len(self.__sessionCookies):
94 if index.column() == 0: 94 if index.column() == 0:
95 return QVariant(self.__sessionCookies[row]) 95 return self.__sessionCookies[row]
96 elif index.column() == 1: 96 elif index.column() == 1:
97 return QVariant(self.trUtf8("Allow For Session")) 97 return self.trUtf8("Allow For Session")
98 else: 98 else:
99 return QVariant() 99 return None
100 100
101 return QVariant() 101 return None
102 102
103 return QVariant() 103 return None
104 104
105 def columnCount(self, parent = QModelIndex()): 105 def columnCount(self, parent = QModelIndex()):
106 """ 106 """
107 Public method to get the number of columns of the model. 107 Public method to get the number of columns of the model.
108 108

eric ide

mercurial