src/eric7/EricWidgets/EricTreeView.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9653
e67609152c5e
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
13 13
14 class EricTreeView(QTreeView): 14 class EricTreeView(QTreeView):
15 """ 15 """
16 Class implementing a tree view supporting removal of entries. 16 Class implementing a tree view supporting removal of entries.
17 """ 17 """
18
18 def keyPressEvent(self, evt): 19 def keyPressEvent(self, evt):
19 """ 20 """
20 Protected method implementing special key handling. 21 Protected method implementing special key handling.
21 22
22 @param evt reference to the event (QKeyEvent) 23 @param evt reference to the event (QKeyEvent)
23 """ 24 """
24 if ( 25 if (
25 evt.key() in [Qt.Key.Key_Delete, Qt.Key.Key_Backspace] and 26 evt.key() in [Qt.Key.Key_Delete, Qt.Key.Key_Backspace]
26 self.model() is not None 27 and self.model() is not None
27 ): 28 ):
28 self.removeSelected() 29 self.removeSelected()
29 evt.setAccepted(True) 30 evt.setAccepted(True)
30 else: 31 else:
31 super().keyPressEvent(evt) 32 super().keyPressEvent(evt)
32 33
33 def removeSelected(self): 34 def removeSelected(self):
34 """ 35 """
35 Public method to remove the selected entries. 36 Public method to remove the selected entries.
36 """ 37 """
37 if ( 38 if (
38 self.model() is None or 39 self.model() is None
39 self.selectionModel() is None or 40 or self.selectionModel() is None
40 not self.selectionModel().hasSelection() 41 or not self.selectionModel().hasSelection()
41 ): 42 ):
42 # no models available or nothing selected 43 # no models available or nothing selected
43 return 44 return
44 45
45 selectedRows = self.selectionModel().selectedRows() 46 selectedRows = self.selectionModel().selectedRows()
46 for idx in sorted(selectedRows, reverse=True): 47 for idx in sorted(selectedRows, reverse=True):
47 self.model().removeRow(idx.row(), idx.parent()) 48 self.model().removeRow(idx.row(), idx.parent())
48 49
49 def removeAll(self): 50 def removeAll(self):
50 """ 51 """
51 Public method to clear the view. 52 Public method to clear the view.
52 """ 53 """
53 if self.model() is not None: 54 if self.model() is not None:
54 self.model().removeRows(0, self.model().rowCount(self.rootIndex()), 55 self.model().removeRows(
55 self.rootIndex()) 56 0, self.model().rowCount(self.rootIndex()), self.rootIndex()
57 )

eric ide

mercurial