diff -r 7f6e04213998 -r 8b1920a22df3 RadonMetrics/MaintainabilityIndexDialog.py --- a/RadonMetrics/MaintainabilityIndexDialog.py Thu Sep 17 19:57:14 2015 +0200 +++ b/RadonMetrics/MaintainabilityIndexDialog.py Fri Sep 18 19:46:57 2015 +0200 @@ -18,6 +18,7 @@ import fnmatch from PyQt5.QtCore import pyqtSlot, qVersion, Qt, QTimer, QLocale +from PyQt5.QtGui import QColor from PyQt5.QtWidgets import ( QDialog, QDialogButtonBox, QAbstractButton, QHeaderView, QTreeWidgetItem, QApplication @@ -63,6 +64,7 @@ self.__project = e5App().getObject("Project") self.__locale = QLocale() self.__finished = True + self.__errorItem = None self.__fileList = [] self.filterFrame.setVisible(False) @@ -75,6 +77,11 @@ "<tr><td><b>C</b></td><td>score ≤ 9</td></tr>" "</table>" )) + self.__rankColors = { + "A": Qt.green, + "B": Qt.yellow, #QColor("orange"), + "C": Qt.red, + } def __resizeResultColumns(self): """ @@ -92,16 +99,18 @@ @param values values to be displayed @type dict """ - # TODO: colorize the rank column according to rank (green, orange, red) data = [self.__project.getRelativePath(filename)] try: - data.append(self.__locale.toString(float(values["mi"]), "f", 2)) + data.append("{0:>6}".format( + self.__locale.toString(float(values["mi"]), "f", 2))) except ValueError: data.append(values["mi"]) data.append(values["rank"]) itm = QTreeWidgetItem(self.resultList, data) itm.setTextAlignment(1, Qt.Alignment(Qt.AlignRight)) itm.setTextAlignment(2, Qt.Alignment(Qt.AlignHCenter)) + if values["rank"] in ["A", "B", "C"]: + itm.setBackground(2, self.__rankColors[values["rank"]]) if values["rank"] in ["A", "B", "C"]: self.__summary[values["rank"]] += 1 @@ -115,13 +124,18 @@ @param message error message @type str """ - itm = QTreeWidgetItem(self.resultList, [ - "{0} ({1})".format(self.__project.getRelativePath(filename), - message)]) - itm.setFirstColumnSpanned(True) - font = itm.font(0) - font.setItalic(True) - itm.setFont(0, font) + if self.__errorItem is None: + self.__errorItem = QTreeWidgetItem(self.resultList, [ + self.tr("Errors")]) + self.__errorItem.setExpanded(True) + self.__errorItem.setForeground(0, Qt.red) + + msg = "{0} ({1})".format(self.__project.getRelativePath(filename), + message) + if not self.resultList.findItems(msg, Qt.MatchExactly): + itm = QTreeWidgetItem(self.__errorItem, [msg]) + itm.setForeground(0, Qt.red) + itm.setFirstColumnSpanned(True) def prepare(self, fileList, project): """ @@ -275,25 +289,32 @@ self.__finished = False self.radonService.maintainabilityIndexBatch(argumentsList) - def __batchFinished(self): + def __batchFinished(self, type_): """ Private slot handling the completion of a batch job. + + @param type_ type of the calculated metrics + @type str, one of ["raw", "mi", "cc"] """ - self.checkProgressLabel.setPath("") - self.checkProgress.setMaximum(1) - self.checkProgress.setValue(1) - self.__finish() + if type_ == "mi": + self.checkProgressLabel.setPath("") + self.checkProgress.setMaximum(1) + self.checkProgress.setValue(1) + self.__finish() - def __processError(self, fn, msg): + def __processError(self, type_, fn, msg): """ Private slot to process an error indication from the service. + @param type_ type of the calculated metrics + @type str, one of ["raw", "mi", "cc"] @param fn filename of the file @type str @param msg error message @type str """ - self.__createErrorItem(fn, msg) + if type_ == "mi": + self.__createErrorItem(fn, msg) def __processResult(self, fn, result): """ @@ -321,7 +342,7 @@ self.progress += 1 self.checkProgress.setValue(self.progress) - self.checkProgressLabel.setPath(fn) + self.checkProgressLabel.setPath(self.__project.getRelativePath(fn)) QApplication.processEvents() if not self.__batch: @@ -404,6 +425,7 @@ fileList = \ [f for f in fileList if not fnmatch.fnmatch(f, filter)] + self.__errorItem = None self.resultList.clear() self.cancelled = False self.start(fileList)