Thu, 03 Sep 2015 19:15:51 +0200
Some corrections to the code metrics dialog and parser.
(grafted from 2f51c66b312031b402c2b1daa60db3b5466fc82a)
DataViews/CodeMetrics.py | file | annotate | diff | comparison | revisions | |
DataViews/CodeMetricsDialog.py | file | annotate | diff | comparison | revisions |
--- a/DataViews/CodeMetrics.py Thu Sep 03 18:38:19 2015 +0200 +++ b/DataViews/CodeMetrics.py Thu Sep 03 19:15:51 2015 +0200 @@ -244,9 +244,13 @@ stats.inc('nloc') elif tok.type == COMMENT: stats.inc('comments') + if tok.line.strip() == tok.text: + stats.inc('commentlines') elif tok.type == EMPTY: if parser.tokenlist[idx - 1].type == token.OP: stats.inc('nloc') + elif parser.tokenlist[idx - 1].type == COMMENT: + continue else: stats.inc('empty') elif tok.type == INDENT: @@ -261,6 +265,8 @@ summarize(total, 'lines', parser.lines) summarize(total, 'bytes', len(text)) summarize(total, 'comments', stats.getCounter('TOTAL ', 'comments')) + summarize(total, 'commentlines', + stats.getCounter('TOTAL ', 'commentlines')) summarize(total, 'empty lines', stats.getCounter('TOTAL ', 'empty')) summarize(total, 'non-commentary lines', stats.getCounter('TOTAL ', 'nloc'))
--- a/DataViews/CodeMetricsDialog.py Thu Sep 03 18:38:19 2015 +0200 +++ b/DataViews/CodeMetricsDialog.py Thu Sep 03 19:15:51 2015 +0200 @@ -75,9 +75,13 @@ @param values values to be displayed (list) @return the generated item """ - itm = QTreeWidgetItem(parent) - for col in range(len(values)): - itm.setData(col, Qt.DisplayRole, values[col]) + data = [values[0]] + for value in values[1:]: + try: + data.append("{0:5}".format(int(value))) + except ValueError: + data.append(value) + itm = QTreeWidgetItem(parent, data) for col in range(1, 7): itm.setTextAlignment(col, Qt.Alignment(Qt.AlignRight)) return itm @@ -186,8 +190,6 @@ self.__resizeResultColumns() # now do the summary stuff - docstrings = total['lines'] - total['comments'] - \ - total['empty lines'] - total['non-commentary lines'] self.__createSummaryItem(self.tr("files"), loc.toString(total['files'])) self.__createSummaryItem(self.tr("lines"), @@ -196,12 +198,12 @@ loc.toString(total['bytes'])) self.__createSummaryItem(self.tr("comments"), loc.toString(total['comments'])) + self.__createSummaryItem(self.tr("comment lines"), + loc.toString(total['commentlines'])) self.__createSummaryItem(self.tr("empty lines"), loc.toString(total['empty lines'])) self.__createSummaryItem(self.tr("non-commentary lines"), loc.toString(total['non-commentary lines'])) - self.__createSummaryItem(self.tr("documentation lines"), - loc.toString(docstrings)) self.__resizeSummaryColumns() self.__finish() @@ -216,7 +218,7 @@ """ counters = stats.counters.get(identifier, {}) v = [] - for key in ('start', 'end', 'lines', 'nloc', 'comments', 'empty'): + for key in ('start', 'end', 'lines', 'nloc', 'commentlines', 'empty'): if counters.get(key, 0): v.append(loc.toString(counters[key])) else: