diff -r 5f206edea27e -r 62ffe3d426e5 RadonMetrics/CyclomaticComplexityDialog.py --- a/RadonMetrics/CyclomaticComplexityDialog.py Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/CyclomaticComplexityDialog.py Sun Sep 20 12:16:27 2015 +0200 @@ -24,7 +24,7 @@ from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale from PyQt5.QtWidgets import ( QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, - QApplication + QApplication, QMenu ) from .Ui_CyclomaticComplexityDialog import Ui_CyclomaticComplexityDialog @@ -98,6 +98,16 @@ "</table>" )) + self.__mappedType = { + "class": "C", + "function": "F", + "method": "M", + } + self.__typeColors = { + "class": Qt.blue, + "function": Qt.darkCyan, + "method": Qt.magenta, + } self.__rankColors = { "A": Qt.green, "B": Qt.green, @@ -106,6 +116,14 @@ "E": Qt.red, "F": Qt.red, } + + self.__menu = QMenu(self) + self.__menu.addAction(self.tr("Collapse all"), + self.__resultCollapse) + self.__menu.addAction(self.tr("Expand all"), self.__resultExpand) + self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) + self.resultList.customContextMenuRequested.connect( + self.__showContextMenu) def __resizeResultColumns(self): """ @@ -149,8 +167,10 @@ itm.setTextAlignment(2, Qt.Alignment(Qt.AlignRight)) itm.setTextAlignment(3, Qt.Alignment(Qt.AlignHCenter)) itm.setTextAlignment(4, Qt.Alignment(Qt.AlignRight)) - if values["rank"] in ["A", "B", "C", "D", "E", "F"]: + if values["rank"] in self.__rankColors: itm.setBackground(3, self.__rankColors[values["rank"]]) + if values["type"] in self.__typeColors: + itm.setForeground(0, self.__typeColors[values["type"]]) if "methods" in values: itm.setExpanded(True) @@ -252,12 +272,6 @@ self.__ccSum = 0 self.__ccCount = 0 - self.__mappedType = { - "class": "C", - "function": "F", - "method": "M", - } - if len(self.files) > 0: # disable updates of the list for speed self.resultList.setUpdatesEnabled(False) @@ -425,8 +439,9 @@ if not self.__finished: self.__finished = True - # reenable updates of the list + # re-enable updates of the list self.resultList.setSortingEnabled(True) + self.resultList.sortItems(0, Qt.AscendingOrder) self.resultList.sortItems(1, Qt.AscendingOrder) self.resultList.setUpdatesEnabled(True) @@ -511,3 +526,26 @@ [f for f in fileList if not fnmatch.fnmatch(f, filter)] self.start(fileList) + + def __showContextMenu(self, coord): + """ + Private slot to show the context menu of the resultlist. + + @param coord the position of the mouse pointer (QPoint) + """ + if self.resultList.topLevelItemCount() > 0: + self.__menu.popup(self.mapToGlobal(coord)) + + def __resultCollapse(self): + """ + Private slot to collapse all entries of the resultlist. + """ + for index in range(self.resultList.topLevelItemCount()): + self.resultList.topLevelItem(index).setExpanded(False) + + def __resultExpand(self): + """ + Private slot to expand all entries of the resultlist. + """ + for index in range(self.resultList.topLevelItemCount()): + self.resultList.topLevelItem(index).setExpanded(True)