Helpviewer/History/HistoryModel.py

changeset 7
c679fb30c8f3
parent 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
6:52e8c820d0dd 7:c679fb30c8f3
75 Public method to get the header data. 75 Public method to get the header data.
76 76
77 @param section section number (integer) 77 @param section section number (integer)
78 @param orientation header orientation (Qt.Orientation) 78 @param orientation header orientation (Qt.Orientation)
79 @param role data role (integer) 79 @param role data role (integer)
80 @return header data (QVariant) 80 @return header data
81 """ 81 """
82 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 82 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
83 try: 83 try:
84 return QVariant(self.__headers[section]) 84 return self.__headers[section]
85 except IndexError: 85 except IndexError:
86 pass 86 pass
87 return QAbstractTableModel.headerData(self, section, orientation, role) 87 return QAbstractTableModel.headerData(self, section, orientation, role)
88 88
89 def data(self, index, role = Qt.DisplayRole): 89 def data(self, index, role = Qt.DisplayRole):
90 """ 90 """
91 Public method to get data from the model. 91 Public method to get data from the model.
92 92
93 @param index index of history entry to get data for (QModelIndex) 93 @param index index of history entry to get data for (QModelIndex)
94 @param role data role (integer) 94 @param role data role (integer)
95 @return history entry data (QVariant) 95 @return history entry data
96 """ 96 """
97 lst = self.__historyManager.history() 97 lst = self.__historyManager.history()
98 if index.row() < 0 or index.row() > len(lst): 98 if index.row() < 0 or index.row() > len(lst):
99 return QVariant() 99 return None
100 100
101 itm = lst[index.row()] 101 itm = lst[index.row()]
102 if role == self.DateTimeRole: 102 if role == self.DateTimeRole:
103 return QVariant(itm.dateTime) 103 return itm.dateTime
104 elif role == self.DateRole: 104 elif role == self.DateRole:
105 return QVariant(itm.dateTime.date()) 105 return itm.dateTime.date()
106 elif role == self.UrlRole: 106 elif role == self.UrlRole:
107 return QVariant(QUrl(itm.url)) 107 return QUrl(itm.url)
108 elif role == self.UrlStringRole: 108 elif role == self.UrlStringRole:
109 return QVariant(itm.url) 109 return itm.url
110 elif role == self.TitleRole: 110 elif role == self.TitleRole:
111 return QVariant(itm.userTitle()) 111 return itm.userTitle()
112 elif role in [Qt.DisplayRole, Qt.EditRole]: 112 elif role in [Qt.DisplayRole, Qt.EditRole]:
113 if index.column() == 0: 113 if index.column() == 0:
114 return QVariant(itm.userTitle()) 114 return itm.userTitle()
115 elif index.column() == 1: 115 elif index.column() == 1:
116 return QVariant(itm.url) 116 return itm.url
117 elif role == Qt.DecorationRole: 117 elif role == Qt.DecorationRole:
118 if index.column() == 0: 118 if index.column() == 0:
119 return QVariant(Helpviewer.HelpWindow.HelpWindow.icon(QUrl(itm.url))) 119 return Helpviewer.HelpWindow.HelpWindow.icon(QUrl(itm.url))
120 120
121 return QVariant() 121 return None
122 122
123 def columnCount(self, parent = QModelIndex()): 123 def columnCount(self, parent = QModelIndex()):
124 """ 124 """
125 Public method to get the number of columns. 125 Public method to get the number of columns.
126 126

eric ide

mercurial