RadonMetrics/CyclomaticComplexityDialog.py

changeset 18
58ce8a433422
parent 15
62ffe3d426e5
child 21
fe094e33a295
equal deleted inserted replaced
17:97c15db4a7c1 18:58ce8a433422
37 class CyclomaticComplexityDialog(QDialog, Ui_CyclomaticComplexityDialog): 37 class CyclomaticComplexityDialog(QDialog, Ui_CyclomaticComplexityDialog):
38 """ 38 """
39 Class implementing a dialog to show the cyclomatic complexity (McCabe 39 Class implementing a dialog to show the cyclomatic complexity (McCabe
40 complexity). 40 complexity).
41 """ 41 """
42 FilePathRole = Qt.UserRole + 1
43 LineNumberRole = Qt.UserRole + 2
44
42 def __init__(self, radonService, parent=None): 45 def __init__(self, radonService, parent=None):
43 """ 46 """
44 Constructor 47 Constructor
45 48
46 @param radonService reference to the service 49 @param radonService reference to the service
144 itm = QTreeWidgetItem( 147 itm = QTreeWidgetItem(
145 self.resultList, 148 self.resultList,
146 [self.__project.getRelativePath(filename)]) 149 [self.__project.getRelativePath(filename)])
147 itm.setExpanded(True) 150 itm.setExpanded(True)
148 itm.setFirstColumnSpanned(True) 151 itm.setFirstColumnSpanned(True)
152 itm.setData(0, self.FilePathRole, filename)
153 itm.setData(0, self.LineNumberRole, 1)
149 return itm 154 return itm
150 155
151 def __createResultItem(self, parentItem, values): 156 def __createResultItem(self, parentItem, values):
152 """ 157 """
153 Private slot to create a new item in the result list. 158 Private slot to create a new item in the result list.
169 itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight)) 174 itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight))
170 if values["rank"] in self.__rankColors: 175 if values["rank"] in self.__rankColors:
171 itm.setBackground(3, self.__rankColors[values["rank"]]) 176 itm.setBackground(3, self.__rankColors[values["rank"]])
172 if values["type"] in self.__typeColors: 177 if values["type"] in self.__typeColors:
173 itm.setForeground(0, self.__typeColors[values["type"]]) 178 itm.setForeground(0, self.__typeColors[values["type"]])
179 itm.setData(0, self.FilePathRole,
180 parentItem.data(0, self.FilePathRole))
181 itm.setData(0, self.LineNumberRole, values["lineno"])
174 182
175 if "methods" in values: 183 if "methods" in values:
176 itm.setExpanded(True) 184 itm.setExpanded(True)
177 for method in values["methods"]: 185 for method in values["methods"]:
178 self.__createResultItem(itm, method) 186 self.__createResultItem(itm, method)
236 the cyclomatic complexity for 244 the cyclomatic complexity for
237 @type str or list of str 245 @type str or list of str
238 """ 246 """
239 self.__errorItem = None 247 self.__errorItem = None
240 self.resultList.clear() 248 self.resultList.clear()
249 self.summaryLabel.clear()
241 self.cancelled = False 250 self.cancelled = False
251 QApplication.processEvents()
252
242 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 253 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
243 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 254 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
244 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 255 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
245 QApplication.processEvents() 256 QApplication.processEvents()
246 257
547 """ 558 """
548 Private slot to expand all entries of the resultlist. 559 Private slot to expand all entries of the resultlist.
549 """ 560 """
550 for index in range(self.resultList.topLevelItemCount()): 561 for index in range(self.resultList.topLevelItemCount()):
551 self.resultList.topLevelItem(index).setExpanded(True) 562 self.resultList.topLevelItem(index).setExpanded(True)
563
564 def clear(self):
565 """
566 Public method to clear all results.
567 """
568 self.resultList.clear()
569 self.summaryLabel.clear()
570
571 @pyqtSlot(QTreeWidgetItem, int)
572 def on_resultList_itemActivated(self, item, column):
573 """
574 Private slot to handle the activation of a result item.
575 """
576 filename = item.data(0, self.FilePathRole)
577 lineno = item.data(0, self.LineNumberRole)
578 if filename:
579 vm = e5App().getObject("ViewManager")
580 vm.openSourceFile(filename, lineno)

eric ide

mercurial