src/eric7/WebBrowser/History/HistoryMenu.py

branch
eric7
changeset 10436
f6881d10e995
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
40 40
41 def __init__(self, sourceModel, parent=None): 41 def __init__(self, sourceModel, parent=None):
42 """ 42 """
43 Constructor 43 Constructor
44 44
45 @param sourceModel reference to the source model (QAbstractItemModel) 45 @param sourceModel reference to the source model
46 @param parent reference to the parent object (QObject) 46 @type QAbstractItemModel
47 @param parent reference to the parent object
48 @type QObject
47 """ 49 """
48 super().__init__(parent) 50 super().__init__(parent)
49 51
50 self.__treeModel = sourceModel 52 self.__treeModel = sourceModel
51 53
53 55
54 def bumpedRows(self): 56 def bumpedRows(self):
55 """ 57 """
56 Public method to determine the number of rows moved to the root. 58 Public method to determine the number of rows moved to the root.
57 59
58 @return number of rows moved to the root (integer) 60 @return number of rows moved to the root
61 @rtype int
59 """ 62 """
60 first = self.__treeModel.index(0, 0) 63 first = self.__treeModel.index(0, 0)
61 if not first.isValid(): 64 if not first.isValid():
62 return 0 65 return 0
63 return min(self.__treeModel.rowCount(first), self.MOVEDROWS) 66 return min(self.__treeModel.rowCount(first), self.MOVEDROWS)
64 67
65 def columnCount(self, parent=None): 68 def columnCount(self, parent=None):
66 """ 69 """
67 Public method to get the number of columns. 70 Public method to get the number of columns.
68 71
69 @param parent index of parent (QModelIndex) 72 @param parent index of parent
70 @return number of columns (integer) 73 @type QModelIndex
74 @return number of columns
75 @rtype int
71 """ 76 """
72 if parent is None: 77 if parent is None:
73 parent = QModelIndex() 78 parent = QModelIndex()
74 79
75 return self.__treeModel.columnCount(self.mapToSource(parent)) 80 return self.__treeModel.columnCount(self.mapToSource(parent))
76 81
77 def rowCount(self, parent=None): 82 def rowCount(self, parent=None):
78 """ 83 """
79 Public method to determine the number of rows. 84 Public method to determine the number of rows.
80 85
81 @param parent index of parent (QModelIndex) 86 @param parent index of parent
82 @return number of rows (integer) 87 @type QModelIndex
88 @return number of rows
89 @rtype int
83 """ 90 """
84 if parent is None: 91 if parent is None:
85 parent = QModelIndex() 92 parent = QModelIndex()
86 93
87 if parent.column() > 0: 94 if parent.column() > 0:
110 117
111 def mapFromSource(self, sourceIndex): 118 def mapFromSource(self, sourceIndex):
112 """ 119 """
113 Public method to map an index to the proxy model index. 120 Public method to map an index to the proxy model index.
114 121
115 @param sourceIndex reference to a source model index (QModelIndex) 122 @param sourceIndex reference to a source model index
116 @return proxy model index (QModelIndex) 123 @type QModelIndex
124 @return proxy model index
125 @rtype QModelIndex
117 """ 126 """
118 sourceRow = self.__treeModel.mapToSource(sourceIndex).row() 127 sourceRow = self.__treeModel.mapToSource(sourceIndex).row()
119 return self.createIndex(sourceIndex.row(), sourceIndex.column(), sourceRow) 128 return self.createIndex(sourceIndex.row(), sourceIndex.column(), sourceRow)
120 129
121 def mapToSource(self, proxyIndex): 130 def mapToSource(self, proxyIndex):
122 """ 131 """
123 Public method to map an index to the source model index. 132 Public method to map an index to the source model index.
124 133
125 @param proxyIndex reference to a proxy model index (QModelIndex) 134 @param proxyIndex reference to a proxy model index
126 @return source model index (QModelIndex) 135 @type QModelIndex
136 @return source model index
137 @rtype QModelIndex
127 """ 138 """
128 if not proxyIndex.isValid(): 139 if not proxyIndex.isValid():
129 return QModelIndex() 140 return QModelIndex()
130 141
131 if proxyIndex.internalId() == sys.maxsize: 142 if proxyIndex.internalId() == sys.maxsize:
152 163
153 def index(self, row, column, parent=None): 164 def index(self, row, column, parent=None):
154 """ 165 """
155 Public method to create an index. 166 Public method to create an index.
156 167
157 @param row row number for the index (integer) 168 @param row row number for the index
158 @param column column number for the index (integer) 169 @type int
159 @param parent index of the parent item (QModelIndex) 170 @param column column number for the index
160 @return requested index (QModelIndex) 171 @type int
172 @param parent index of the parent item
173 @type QModelIndex
174 @return requested index
175 @rtype QModelIndex
161 """ 176 """
162 if parent is None: 177 if parent is None:
163 parent = QModelIndex() 178 parent = QModelIndex()
164 179
165 if ( 180 if (
187 202
188 def parent(self, index): 203 def parent(self, index):
189 """ 204 """
190 Public method to get the parent index. 205 Public method to get the parent index.
191 206
192 @param index index of item to get parent (QModelIndex) 207 @param index index of item to get parent
193 @return index of parent (QModelIndex) 208 @type QModelIndex
209 @return index of parent
210 @rtype QModelIndex
194 """ 211 """
195 offset = index.internalId() 212 offset = index.internalId()
196 if offset == sys.maxsize or not index.isValid(): 213 if offset == sys.maxsize or not index.isValid():
197 return QModelIndex() 214 return QModelIndex()
198 215
213 230
214 def mimeData(self, indexes): 231 def mimeData(self, indexes):
215 """ 232 """
216 Public method to return the mime data. 233 Public method to return the mime data.
217 234
218 @param indexes list of indexes (QModelIndexList) 235 @param indexes list of indexes
219 @return mime data (QMimeData) 236 @type QModelIndexList
237 @return mime data
238 @rtype QMimeData
220 """ 239 """
221 urls = [] 240 urls = []
222 for index in indexes: 241 for index in indexes:
223 url = index.data(HistoryModel.UrlRole) 242 url = index.data(HistoryModel.UrlRole)
224 urls.append(url) 243 urls.append(url)
235 254
236 def __init__(self, sourceModel, parent=None): 255 def __init__(self, sourceModel, parent=None):
237 """ 256 """
238 Constructor 257 Constructor
239 258
240 @param sourceModel reference to the source model (QAbstractItemModel) 259 @param sourceModel reference to the source model
241 @param parent reference to the parent object (QObject) 260 @type QAbstractItemModel
261 @param parent reference to the parent object
262 @type QObject
242 """ 263 """
243 super().__init__(parent) 264 super().__init__(parent)
244 265
245 self.setDynamicSortFilter(True) 266 self.setDynamicSortFilter(True)
246 self.setSourceModel(sourceModel) 267 self.setSourceModel(sourceModel)
247 268
248 def lessThan(self, left, right): 269 def lessThan(self, left, right):
249 """ 270 """
250 Public method used to sort the displayed items. 271 Public method used to sort the displayed items.
251 272
252 @param left index of left item (QModelIndex) 273 @param left index of left item
253 @param right index of right item (QModelIndex) 274 @type QModelIndex
254 @return true, if left is less than right (boolean) 275 @param right index of right item
276 @type QModelIndex
277 @return true, if left is less than right
278 @rtype bool
255 """ 279 """
256 from .HistoryFilterModel import HistoryFilterModel 280 from .HistoryFilterModel import HistoryFilterModel
257 281
258 frequency_L = self.sourceModel().data(left, HistoryFilterModel.FrequencyRole) 282 frequency_L = self.sourceModel().data(left, HistoryFilterModel.FrequencyRole)
259 dateTime_L = self.sourceModel().data(left, HistoryModel.DateTimeRole) 283 dateTime_L = self.sourceModel().data(left, HistoryModel.DateTimeRole)
289 313
290 def __init__(self, parent=None, tabWidget=None): 314 def __init__(self, parent=None, tabWidget=None):
291 """ 315 """
292 Constructor 316 Constructor
293 317
294 @param parent reference to the parent widget (QWidget) 318 @param parent reference to the parent widget
319 @type QWidget
295 @param tabWidget reference to the tab widget managing the browser 320 @param tabWidget reference to the tab widget managing the browser
296 tabs (HelpTabWidget 321 tabs
322 @type WebBrowserTabWidget
297 """ 323 """
298 EricModelMenu.__init__(self, parent) 324 EricModelMenu.__init__(self, parent)
299 325
300 self.__tabWidget = tabWidget 326 self.__tabWidget = tabWidget
301 self.__mw = parent 327 self.__mw = parent
318 344
319 def __activated(self, idx): 345 def __activated(self, idx):
320 """ 346 """
321 Private slot handling the activated signal. 347 Private slot handling the activated signal.
322 348
323 @param idx index of the activated item (QModelIndex) 349 @param idx index of the activated item
350 @type QModelIndex
324 """ 351 """
325 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: 352 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier:
326 self.newTab.emit( 353 self.newTab.emit(
327 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) 354 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole)
328 ) 355 )
337 364
338 def prePopulated(self): 365 def prePopulated(self):
339 """ 366 """
340 Public method to add any actions before the tree. 367 Public method to add any actions before the tree.
341 368
342 @return flag indicating if any actions were added (boolean) 369 @return flag indicating if any actions were added
370 @rtype bool
343 """ 371 """
344 if self.__historyManager is None: 372 if self.__historyManager is None:
345 self.__historyManager = WebBrowserWindow.historyManager() 373 self.__historyManager = WebBrowserWindow.historyManager()
346 self.__historyMenuModel = HistoryMenuModel( 374 self.__historyMenuModel = HistoryMenuModel(
347 self.__historyManager.historyTreeModel(), self 375 self.__historyManager.historyTreeModel(), self
390 def setInitialActions(self, actions): 418 def setInitialActions(self, actions):
391 """ 419 """
392 Public method to set the list of actions that should appear first in 420 Public method to set the list of actions that should appear first in
393 the menu. 421 the menu.
394 422
395 @param actions list of initial actions (list of QAction) 423 @param actions list of initial actions
424 @type list of QAction
396 """ 425 """
397 self.__initialActions = actions[:] 426 self.__initialActions = actions[:]
398 for act in self.__initialActions: 427 for act in self.__initialActions:
399 self.addAction(act) 428 self.addAction(act)
400 429
451 480
452 def __closedTabAvailable(self, avail): 481 def __closedTabAvailable(self, avail):
453 """ 482 """
454 Private slot to handle changes of the availability of closed tabs. 483 Private slot to handle changes of the availability of closed tabs.
455 484
456 @param avail flag indicating the availability of closed tabs (boolean) 485 @param avail flag indicating the availability of closed tabs
486 @type bool
457 """ 487 """
458 self.__closedTabsMenu.setEnabled(avail) 488 self.__closedTabsMenu.setEnabled(avail)
459 489
460 490
461 class HistoryMostVisitedMenu(EricModelMenu): 491 class HistoryMostVisitedMenu(EricModelMenu):
479 509
480 def __init__(self, count, parent=None): 510 def __init__(self, count, parent=None):
481 """ 511 """
482 Constructor 512 Constructor
483 513
484 @param count maximum number of entries to be shown (integer) 514 @param count maximum number of entries to be shown
485 @param parent reference to the parent widget (QWidget) 515 @type int
516 @param parent reference to the parent widget
517 @type QWidget
486 """ 518 """
487 EricModelMenu.__init__(self, parent) 519 EricModelMenu.__init__(self, parent)
488 520
489 self.__historyMenuModel = None 521 self.__historyMenuModel = None
490 522
494 526
495 def __activated(self, idx): 527 def __activated(self, idx):
496 """ 528 """
497 Private slot handling the activated signal. 529 Private slot handling the activated signal.
498 530
499 @param idx index of the activated item (QModelIndex) 531 @param idx index of the activated item
532 @type QModelIndex
500 """ 533 """
501 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier: 534 if self._keyboardModifiers & Qt.KeyboardModifier.ControlModifier:
502 self.newTab.emit( 535 self.newTab.emit(
503 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) 536 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole)
504 ) 537 )
513 546
514 def prePopulated(self): 547 def prePopulated(self):
515 """ 548 """
516 Public method to add any actions before the tree. 549 Public method to add any actions before the tree.
517 550
518 @return flag indicating if any actions were added (boolean) 551 @return flag indicating if any actions were added
552 @rtype bool
519 """ 553 """
520 if self.__historyMenuModel is None: 554 if self.__historyMenuModel is None:
521 historyManager = WebBrowserWindow.historyManager() 555 historyManager = WebBrowserWindow.historyManager()
522 self.__historyMenuModel = HistoryMostVisitedMenuModel( 556 self.__historyMenuModel = HistoryMostVisitedMenuModel(
523 historyManager.historyFilterModel(), self 557 historyManager.historyFilterModel(), self

eric ide

mercurial