RefactoringRope/MatchesDialog.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 396
933b8fcd854f
equal deleted inserted replaced
388:cb044ec27c24 389:4f53795beff0
6 """ 6 """
7 Module implementing a dialog to show matching references/definitions. 7 Module implementing a dialog to show matching references/definitions.
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot, Qt 10 from PyQt6.QtCore import pyqtSlot, Qt
11 from PyQt6.QtWidgets import ( 11 from PyQt6.QtWidgets import QDialog, QTreeWidgetItem, QDialogButtonBox, QHeaderView
12 QDialog, QTreeWidgetItem, QDialogButtonBox, QHeaderView
13 )
14 12
15 from EricWidgets.EricApplication import ericApp 13 from EricWidgets.EricApplication import ericApp
16 14
17 from .Ui_MatchesDialog import Ui_MatchesDialog 15 from .Ui_MatchesDialog import Ui_MatchesDialog
18 16
19 17
20 class MatchesDialog(QDialog, Ui_MatchesDialog): 18 class MatchesDialog(QDialog, Ui_MatchesDialog):
21 """ 19 """
22 Class implementing a dialog to show matching references/definitions. 20 Class implementing a dialog to show matching references/definitions.
23 """ 21 """
22
24 FilePathRole = Qt.ItemDataRole.UserRole 23 FilePathRole = Qt.ItemDataRole.UserRole
25 24
26 def __init__(self, ui, showConfidence, parent=None, name=None): 25 def __init__(self, ui, showConfidence, parent=None, name=None):
27 """ 26 """
28 Constructor 27 Constructor
29 28
30 @param ui reference to the UI object 29 @param ui reference to the UI object
31 @type UI.UserInterface 30 @type UI.UserInterface
32 @param showConfidence flag indicating the display of the 31 @param showConfidence flag indicating the display of the
33 confidence column 32 confidence column
34 @type bool 33 @type bool
39 """ 38 """
40 QDialog.__init__(self, parent) 39 QDialog.__init__(self, parent)
41 if name: 40 if name:
42 self.setObjectName(name) 41 self.setObjectName(name)
43 self.setupUi(self) 42 self.setupUi(self)
44 43
45 self.buttonBox.button( 44 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
46 QDialogButtonBox.StandardButton.Close).setDefault(True) 45
47
48 self.ui = ui 46 self.ui = ui
49 self.__showConfidence = showConfidence 47 self.__showConfidence = showConfidence
50 self.__e5project = ericApp().getObject("Project") 48 self.__e5project = ericApp().getObject("Project")
51 49
52 if not self.__showConfidence: 50 if not self.__showConfidence:
53 self.matchesList.setColumnHidden(2, True) 51 self.matchesList.setColumnHidden(2, True)
54 self.matchesList.header().setSortIndicator( 52 self.matchesList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder)
55 0, Qt.SortOrder.AscendingOrder) 53
56
57 def __resort(self): 54 def __resort(self):
58 """ 55 """
59 Private method to resort the tree. 56 Private method to resort the tree.
60 """ 57 """
61 self.matchesList.sortItems( 58 self.matchesList.sortItems(
62 self.matchesList.sortColumn(), 59 self.matchesList.sortColumn(),
63 self.matchesList.header().sortIndicatorOrder()) 60 self.matchesList.header().sortIndicatorOrder(),
64 61 )
62
65 def __resizeColumns(self): 63 def __resizeColumns(self):
66 """ 64 """
67 Private method to resize the list columns. 65 Private method to resize the list columns.
68 """ 66 """
69 self.matchesList.header().resizeSections( 67 self.matchesList.header().resizeSections(
70 QHeaderView.ResizeMode.ResizeToContents) 68 QHeaderView.ResizeMode.ResizeToContents
69 )
71 self.matchesList.header().setStretchLastSection(True) 70 self.matchesList.header().setStretchLastSection(True)
72 71
73 @pyqtSlot(QTreeWidgetItem, int) 72 @pyqtSlot(QTreeWidgetItem, int)
74 def on_matchesList_itemActivated(self, item, column): 73 def on_matchesList_itemActivated(self, item, column):
75 """ 74 """
76 Private slot to handle the itemActivated signal of the list. 75 Private slot to handle the itemActivated signal of the list.
77 76
78 @param item reference to the activated item 77 @param item reference to the activated item
79 @type QTreeWidgetItem 78 @type QTreeWidgetItem
80 @param column column the item was activated in 79 @param column column the item was activated in
81 @type int 80 @type int
82 """ 81 """
83 lineno = int(item.text(1)) 82 lineno = int(item.text(1))
84 fn = item.data(0, MatchesDialog.FilePathRole) 83 fn = item.data(0, MatchesDialog.FilePathRole)
85 ericApp().getObject("ViewManager").openSourceFile(fn, lineno) 84 ericApp().getObject("ViewManager").openSourceFile(fn, lineno)
86 85
87 def addEntry(self, filename, lineno, unsure=False): 86 def addEntry(self, filename, lineno, unsure=False):
88 """ 87 """
89 Public slot to add an entry to the list. 88 Public slot to add an entry to the list.
90 89
91 @param filename full path of the matched file 90 @param filename full path of the matched file
92 @type str 91 @type str
93 @param lineno line number of the match 92 @param lineno line number of the match
94 @type int 93 @type int
95 @param unsure flag indicating an unsure match 94 @param unsure flag indicating an unsure match
96 @type bool 95 @type bool
97 """ 96 """
98 conf = 50 if unsure else 100 97 conf = 50 if unsure else 100
99 itm = QTreeWidgetItem( 98 itm = QTreeWidgetItem(
100 self.matchesList, 99 self.matchesList,
101 [self.__e5project.getRelativePath(filename), 100 [
102 " {0:5d}".format(lineno), 101 self.__e5project.getRelativePath(filename),
103 " {0:5d}%".format(conf)]) 102 " {0:5d}".format(lineno),
103 " {0:5d}%".format(conf),
104 ],
105 )
104 itm.setData(0, MatchesDialog.FilePathRole, filename) 106 itm.setData(0, MatchesDialog.FilePathRole, filename)
105 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) 107 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
106 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) 108 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
107 self.__resort() 109 self.__resort()
108 self.__resizeColumns() 110 self.__resizeColumns()

eric ide

mercurial