Helpviewer/History/HistoryMenu.py

changeset 3002
6ffc581f00f1
parent 2403
e3d7a861547c
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
3001:3674ff5fa8f8 3002:6ffc581f00f1
73 73
74 if not parent.isValid(): 74 if not parent.isValid():
75 folders = self.sourceModel().rowCount() 75 folders = self.sourceModel().rowCount()
76 bumpedItems = self.bumpedRows() 76 bumpedItems = self.bumpedRows()
77 if bumpedItems <= self.MOVEDROWS and \ 77 if bumpedItems <= self.MOVEDROWS and \
78 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)): 78 bumpedItems == self.sourceModel().rowCount(
79 self.sourceModel().index(0, 0)):
79 folders -= 1 80 folders -= 1
80 return bumpedItems + folders 81 return bumpedItems + folders
81 82
82 if parent.internalId() == sys.maxsize: 83 if parent.internalId() == sys.maxsize:
83 if parent.row() < self.bumpedRows(): 84 if parent.row() < self.bumpedRows():
96 97
97 @param sourceIndex reference to a source model index (QModelIndex) 98 @param sourceIndex reference to a source model index (QModelIndex)
98 @return proxy model index (QModelIndex) 99 @return proxy model index (QModelIndex)
99 """ 100 """
100 sourceRow = self.__treeModel.mapToSource(sourceIndex).row() 101 sourceRow = self.__treeModel.mapToSource(sourceIndex).row()
101 return self.createIndex(sourceIndex.row(), sourceIndex.column(), sourceRow) 102 return self.createIndex(
103 sourceIndex.row(), sourceIndex.column(), sourceRow)
102 104
103 def mapToSource(self, proxyIndex): 105 def mapToSource(self, proxyIndex):
104 """ 106 """
105 Public method to map an index to the source model index. 107 Public method to map an index to the source model index.
106 108
111 return QModelIndex() 113 return QModelIndex()
112 114
113 if proxyIndex.internalId() == sys.maxsize: 115 if proxyIndex.internalId() == sys.maxsize:
114 bumpedItems = self.bumpedRows() 116 bumpedItems = self.bumpedRows()
115 if proxyIndex.row() < bumpedItems: 117 if proxyIndex.row() < bumpedItems:
116 return self.__treeModel.index(proxyIndex.row(), proxyIndex.column(), 118 return self.__treeModel.index(
119 proxyIndex.row(), proxyIndex.column(),
117 self.__treeModel.index(0, 0)) 120 self.__treeModel.index(0, 0))
118 if bumpedItems <= self.MOVEDROWS and \ 121 if bumpedItems <= self.MOVEDROWS and \
119 bumpedItems == self.sourceModel().rowCount(self.__treeModel.index(0, 0)): 122 bumpedItems == self.sourceModel().rowCount(
123 self.__treeModel.index(0, 0)):
120 bumpedItems -= 1 124 bumpedItems -= 1
121 return self.__treeModel.index(proxyIndex.row() - bumpedItems, 125 return self.__treeModel.index(proxyIndex.row() - bumpedItems,
122 proxyIndex.column()) 126 proxyIndex.column())
123 127
124 historyIndex = self.__treeModel.sourceModel()\ 128 historyIndex = self.__treeModel.sourceModel()\
147 treeIndexParent = self.mapToSource(parent) 151 treeIndexParent = self.mapToSource(parent)
148 152
149 bumpedItems = 0 153 bumpedItems = 0
150 if treeIndexParent == self.sourceModel().index(0, 0): 154 if treeIndexParent == self.sourceModel().index(0, 0):
151 bumpedItems = self.bumpedRows() 155 bumpedItems = self.bumpedRows()
152 treeIndex = self.__treeModel.index(row + bumpedItems, column, treeIndexParent) 156 treeIndex = self.__treeModel.index(
157 row + bumpedItems, column, treeIndexParent)
153 historyIndex = self.__treeModel.mapToSource(treeIndex) 158 historyIndex = self.__treeModel.mapToSource(treeIndex)
154 historyRow = historyIndex.row() 159 historyRow = historyIndex.row()
155 if historyRow == -1: 160 if historyRow == -1:
156 historyRow = treeIndex.row() 161 historyRow = treeIndex.row()
157 return self.createIndex(row, column, historyRow) 162 return self.createIndex(row, column, historyRow)
165 """ 170 """
166 offset = index.internalId() 171 offset = index.internalId()
167 if offset == sys.maxsize or not index.isValid(): 172 if offset == sys.maxsize or not index.isValid():
168 return QModelIndex() 173 return QModelIndex()
169 174
170 historyIndex = self.__treeModel.sourceModel().index(index.internalId(), 0) 175 historyIndex = self.__treeModel.sourceModel().index(
176 index.internalId(), 0)
171 treeIndex = self.__treeModel.mapFromSource(historyIndex) 177 treeIndex = self.__treeModel.mapFromSource(historyIndex)
172 treeIndexParent = treeIndex.parent() 178 treeIndexParent = treeIndex.parent()
173 179
174 sourceRow = self.sourceModel().mapToSource(treeIndexParent).row() 180 sourceRow = self.sourceModel().mapToSource(treeIndexParent).row()
175 bumpedItems = self.bumpedRows() 181 bumpedItems = self.bumpedRows()
176 if bumpedItems <= self.MOVEDROWS and \ 182 if bumpedItems <= self.MOVEDROWS and \
177 bumpedItems == self.sourceModel().rowCount(self.sourceModel().index(0, 0)): 183 bumpedItems == self.sourceModel().rowCount(
184 self.sourceModel().index(0, 0)):
178 bumpedItems -= 1 185 bumpedItems -= 1
179 186
180 return self.createIndex(bumpedItems + treeIndexParent.row(), 187 return self.createIndex(bumpedItems + treeIndexParent.row(),
181 treeIndexParent.column(), 188 treeIndexParent.column(),
182 sourceRow) 189 sourceRow)
230 frequency_R = \ 237 frequency_R = \
231 self.sourceModel().data(right, HistoryFilterModel.FrequencyRole) 238 self.sourceModel().data(right, HistoryFilterModel.FrequencyRole)
232 dateTime_R = \ 239 dateTime_R = \
233 self.sourceModel().data(right, HistoryModel.DateTimeRole) 240 self.sourceModel().data(right, HistoryModel.DateTimeRole)
234 241
235 # Sort results in descending frequency-derived score. If frequencies are equal, 242 # Sort results in descending frequency-derived score. If frequencies
236 # sort on most recently viewed 243 # are equal, sort on most recently viewed
237 if frequency_R == frequency_L: 244 if frequency_R == frequency_L:
238 return dateTime_R < dateTime_L 245 return dateTime_R < dateTime_L
239 246
240 return frequency_R < frequency_L 247 return frequency_R < frequency_L
241 248
266 self.__historyMenuModel = None 273 self.__historyMenuModel = None
267 self.__initialActions = [] 274 self.__initialActions = []
268 self.__mostVisitedMenu = None 275 self.__mostVisitedMenu = None
269 276
270 self.__closedTabsMenu = QMenu(self.trUtf8("Closed Tabs")) 277 self.__closedTabsMenu = QMenu(self.trUtf8("Closed Tabs"))
271 self.__closedTabsMenu.aboutToShow.connect(self.__aboutToShowClosedTabsMenu) 278 self.__closedTabsMenu.aboutToShow.connect(
279 self.__aboutToShowClosedTabsMenu)
272 self.__tabWidget.closedTabsManager().closedTabAvailable.connect( 280 self.__tabWidget.closedTabsManager().closedTabAvailable.connect(
273 self.__closedTabAvailable) 281 self.__closedTabAvailable)
274 282
275 self.setMaxRows(7) 283 self.setMaxRows(7)
276 284
298 306
299 @return flag indicating if any actions were added (boolean) 307 @return flag indicating if any actions were added (boolean)
300 """ 308 """
301 if self.__historyManager is None: 309 if self.__historyManager is None:
302 import Helpviewer.HelpWindow 310 import Helpviewer.HelpWindow
303 self.__historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager() 311 self.__historyManager = \
304 self.__historyMenuModel = \ 312 Helpviewer.HelpWindow.HelpWindow.historyManager()
305 HistoryMenuModel(self.__historyManager.historyTreeModel(), self) 313 self.__historyMenuModel = HistoryMenuModel(
314 self.__historyManager.historyTreeModel(), self)
306 self.setModel(self.__historyMenuModel) 315 self.setModel(self.__historyMenuModel)
307 316
308 # initial actions 317 # initial actions
309 for act in self.__initialActions: 318 for act in self.__initialActions:
310 self.addAction(act) 319 self.addAction(act)
339 self.trUtf8("Clear History...")) 348 self.trUtf8("Clear History..."))
340 act.triggered[()].connect(self.__clearHistoryDialog) 349 act.triggered[()].connect(self.__clearHistoryDialog)
341 350
342 def setInitialActions(self, actions): 351 def setInitialActions(self, actions):
343 """ 352 """
344 Public method to set the list of actions that should appear first in the menu. 353 Public method to set the list of actions that should appear first in
354 the menu.
345 355
346 @param actions list of initial actions (list of QAction) 356 @param actions list of initial actions (list of QAction)
347 """ 357 """
348 self.__initialActions = actions[:] 358 self.__initialActions = actions[:]
349 for act in self.__initialActions: 359 for act in self.__initialActions:
449 @return flag indicating if any actions were added (boolean) 459 @return flag indicating if any actions were added (boolean)
450 """ 460 """
451 if self.__historyMenuModel is None: 461 if self.__historyMenuModel is None:
452 import Helpviewer.HelpWindow 462 import Helpviewer.HelpWindow
453 historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager() 463 historyManager = Helpviewer.HelpWindow.HelpWindow.historyManager()
454 self.__historyMenuModel = \ 464 self.__historyMenuModel = HistoryMostVisitedMenuModel(
455 HistoryMostVisitedMenuModel(historyManager.historyFilterModel(), self) 465 historyManager.historyFilterModel(), self)
456 self.setModel(self.__historyMenuModel) 466 self.setModel(self.__historyMenuModel)
457 self.__historyMenuModel.sort(0) 467 self.__historyMenuModel.sort(0)
458 468
459 return False 469 return False

eric ide

mercurial