Helpviewer/History/HistoryMenu.py

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

eric ide

mercurial