9 |
9 |
10 from PyQt4.QtCore import * |
10 from PyQt4.QtCore import * |
11 |
11 |
12 import Helpviewer.HelpWindow |
12 import Helpviewer.HelpWindow |
13 |
13 |
|
14 |
14 class HistoryModel(QAbstractTableModel): |
15 class HistoryModel(QAbstractTableModel): |
15 """ |
16 """ |
16 Class implementing the history model. |
17 Class implementing the history model. |
17 """ |
18 """ |
18 DateRole = Qt.UserRole + 1 |
19 DateRole = Qt.UserRole + 1 |
20 UrlRole = Qt.UserRole + 3 |
21 UrlRole = Qt.UserRole + 3 |
21 UrlStringRole = Qt.UserRole + 4 |
22 UrlStringRole = Qt.UserRole + 4 |
22 TitleRole = Qt.UserRole + 5 |
23 TitleRole = Qt.UserRole + 5 |
23 MaxRole = TitleRole |
24 MaxRole = TitleRole |
24 |
25 |
25 def __init__(self, historyManager, parent = None): |
26 def __init__(self, historyManager, parent=None): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param historyManager reference to the history manager object (HistoryManager) |
30 @param historyManager reference to the history manager object (HistoryManager) |
30 @param parent reference to the parent object (QObject) |
31 @param parent reference to the parent object (QObject) |
32 QAbstractTableModel.__init__(self, parent) |
33 QAbstractTableModel.__init__(self, parent) |
33 |
34 |
34 self.__historyManager = historyManager |
35 self.__historyManager = historyManager |
35 |
36 |
36 self.__headers = [ |
37 self.__headers = [ |
37 self.trUtf8("Title"), |
38 self.trUtf8("Title"), |
38 self.trUtf8("Address"), |
39 self.trUtf8("Address"), |
39 ] |
40 ] |
40 |
41 |
41 self.__historyManager.historyReset.connect(self.historyReset) |
42 self.__historyManager.historyReset.connect(self.historyReset) |
42 self.__historyManager.entryRemoved.connect(self.historyReset) |
43 self.__historyManager.entryRemoved.connect(self.historyReset) |
43 self.__historyManager.entryAdded.connect(self.entryAdded) |
44 self.__historyManager.entryAdded.connect(self.entryAdded) |
63 @param row row number of the updated entry (integer) |
64 @param row row number of the updated entry (integer) |
64 """ |
65 """ |
65 idx = self.index(row, 0) |
66 idx = self.index(row, 0) |
66 self.dataChanged.emit(idx, idx) |
67 self.dataChanged.emit(idx, idx) |
67 |
68 |
68 def headerData(self, section, orientation, role = Qt.DisplayRole): |
69 def headerData(self, section, orientation, role=Qt.DisplayRole): |
69 """ |
70 """ |
70 Public method to get the header data. |
71 Public method to get the header data. |
71 |
72 |
72 @param section section number (integer) |
73 @param section section number (integer) |
73 @param orientation header orientation (Qt.Orientation) |
74 @param orientation header orientation (Qt.Orientation) |
79 return self.__headers[section] |
80 return self.__headers[section] |
80 except IndexError: |
81 except IndexError: |
81 pass |
82 pass |
82 return QAbstractTableModel.headerData(self, section, orientation, role) |
83 return QAbstractTableModel.headerData(self, section, orientation, role) |
83 |
84 |
84 def data(self, index, role = Qt.DisplayRole): |
85 def data(self, index, role=Qt.DisplayRole): |
85 """ |
86 """ |
86 Public method to get data from the model. |
87 Public method to get data from the model. |
87 |
88 |
88 @param index index of history entry to get data for (QModelIndex) |
89 @param index index of history entry to get data for (QModelIndex) |
89 @param role data role (integer) |
90 @param role data role (integer) |
113 if index.column() == 0: |
114 if index.column() == 0: |
114 return Helpviewer.HelpWindow.HelpWindow.icon(QUrl(itm.url)) |
115 return Helpviewer.HelpWindow.HelpWindow.icon(QUrl(itm.url)) |
115 |
116 |
116 return None |
117 return None |
117 |
118 |
118 def columnCount(self, parent = QModelIndex()): |
119 def columnCount(self, parent=QModelIndex()): |
119 """ |
120 """ |
120 Public method to get the number of columns. |
121 Public method to get the number of columns. |
121 |
122 |
122 @param parent index of parent (QModelIndex) |
123 @param parent index of parent (QModelIndex) |
123 @return number of columns (integer) |
124 @return number of columns (integer) |
125 if parent.isValid(): |
126 if parent.isValid(): |
126 return 0 |
127 return 0 |
127 else: |
128 else: |
128 return len(self.__headers) |
129 return len(self.__headers) |
129 |
130 |
130 def rowCount(self, parent = QModelIndex()): |
131 def rowCount(self, parent=QModelIndex()): |
131 """ |
132 """ |
132 Public method to determine the number of rows. |
133 Public method to determine the number of rows. |
133 |
134 |
134 @param parent index of parent (QModelIndex) |
135 @param parent index of parent (QModelIndex) |
135 @return number of rows (integer) |
136 @return number of rows (integer) |
137 if parent.isValid(): |
138 if parent.isValid(): |
138 return 0 |
139 return 0 |
139 else: |
140 else: |
140 return len(self.__historyManager.history()) |
141 return len(self.__historyManager.history()) |
141 |
142 |
142 def removeRows(self, row, count, parent = QModelIndex()): |
143 def removeRows(self, row, count, parent=QModelIndex()): |
143 """ |
144 """ |
144 Public method to remove history entries from the model. |
145 Public method to remove history entries from the model. |
145 |
146 |
146 @param row row of the first history entry to remove (integer) |
147 @param row row of the first history entry to remove (integer) |
147 @param count number of history entries to remove (integer) |
148 @param count number of history entries to remove (integer) |