28 def __init__(self, statistics, parent=None): |
28 def __init__(self, statistics, parent=None): |
29 """ |
29 """ |
30 Constructor |
30 Constructor |
31 |
31 |
32 @param statistics dictionary with the statistical data |
32 @param statistics dictionary with the statistical data |
33 @param parent reference to the parent widget (QWidget) |
33 @type dict |
|
34 @param parent reference to the parent widget |
|
35 @type QWidget |
34 """ |
36 """ |
35 super(CodeStyleStatisticsDialog, self).__init__(parent) |
37 super(CodeStyleStatisticsDialog, self).__init__(parent) |
36 self.setupUi(self) |
38 self.setupUi(self) |
37 |
39 |
38 stats = statistics.copy() |
40 stats = statistics.copy() |
39 filesCount = stats["_FilesCount"] |
41 filesCount = stats["_FilesCount"] |
40 filesIssues = stats["_FilesIssues"] |
42 filesIssues = stats["_FilesIssues"] |
41 fixesCount = stats["_IssuesFixed"] |
43 fixesCount = stats["_IssuesFixed"] |
42 ignoresCount = stats["_IgnoredErrors"] |
|
43 securityOk = stats["_SecurityOK"] |
44 securityOk = stats["_SecurityOK"] |
44 del stats["_FilesCount"] |
45 del stats["_FilesCount"] |
45 del stats["_FilesIssues"] |
46 del stats["_FilesIssues"] |
46 del stats["_IssuesFixed"] |
47 del stats["_IssuesFixed"] |
47 del stats["_IgnoredErrors"] |
|
48 del stats["_SecurityOK"] |
48 del stats["_SecurityOK"] |
49 |
49 |
50 totalIssues = 0 |
50 totalIssues = 0 |
|
51 ignoresCount = 0 |
51 |
52 |
52 textWrapper = textwrap.TextWrapper(width=80) |
53 textWrapper = textwrap.TextWrapper(width=80) |
53 |
54 |
54 for code in sorted(stats.keys()): |
55 for code in sorted(stats.keys()): |
55 message = getTranslatedMessage(code, [], example=True) |
56 message = getTranslatedMessage(code, [], example=True) |
56 if message is None: |
57 if message is None: |
57 continue |
58 continue |
58 |
59 |
59 self.__createItem(stats[code], code, |
60 self.__createItem(stats[code], code, |
60 "\n".join(textWrapper.wrap(message))) |
61 "\n".join(textWrapper.wrap(message))) |
61 totalIssues += stats[code] |
62 totalIssues += stats[code]["total"] |
|
63 ignoresCount += stats[code]["ignored"] |
62 |
64 |
63 self.totalIssues.setText( |
65 self.totalIssues.setText( |
64 self.tr("%n issue(s) found", "", totalIssues)) |
66 self.tr("%n issue(s) found", "", totalIssues)) |
65 self.ignoredIssues.setText( |
67 self.ignoredIssues.setText( |
66 self.tr("%n issue(s) ignored", "", ignoresCount)) |
68 self.tr("%n issue(s) ignored", "", ignoresCount)) |
73 self.securityOk.setText( |
75 self.securityOk.setText( |
74 self.tr("%n security issue(s) acknowledged", "", securityOk)) |
76 self.tr("%n security issue(s) acknowledged", "", securityOk)) |
75 |
77 |
76 self.statisticsList.resizeColumnToContents(0) |
78 self.statisticsList.resizeColumnToContents(0) |
77 self.statisticsList.resizeColumnToContents(1) |
79 self.statisticsList.resizeColumnToContents(1) |
|
80 self.statisticsList.resizeColumnToContents(2) |
78 |
81 |
79 def __createItem(self, count, code, message): |
82 def __createItem(self, counts, code, message): |
80 """ |
83 """ |
81 Private method to create an entry in the result list. |
84 Private method to create an entry in the result list. |
82 |
85 |
83 @param count occurrences of the issue (integer) |
86 @param counts dictionary containing the total and ignored occurrences |
84 @param code of a code style issue message (string) |
87 of the issue |
85 @param message code style issue message to be shown (string) |
88 @type dict |
|
89 @param code of a code style issue message |
|
90 @type str |
|
91 @param message code style issue message to be shown |
|
92 @type str |
86 """ |
93 """ |
87 itm = QTreeWidgetItem(self.statisticsList, [ |
94 itm = QTreeWidgetItem(self.statisticsList, [ |
88 "{0:6d}".format(count), code, message]) |
95 code, "{0:6d}".format(counts["total"] - counts["ignored"]), |
|
96 "{0:6d}".format(counts["ignored"]), message]) |
89 if code.startswith(("W", "C", "M")): |
97 if code.startswith(("W", "C", "M")): |
90 itm.setIcon(1, UI.PixmapCache.getIcon("warning")) |
98 itm.setIcon(0, UI.PixmapCache.getIcon("warning")) |
91 elif code.startswith("E"): |
99 elif code.startswith("E"): |
92 itm.setIcon(1, UI.PixmapCache.getIcon("syntaxError")) |
100 itm.setIcon(0, UI.PixmapCache.getIcon("syntaxError")) |
93 elif code.startswith("N"): |
101 elif code.startswith("N"): |
94 itm.setIcon(1, UI.PixmapCache.getIcon("namingError")) |
102 itm.setIcon(0, UI.PixmapCache.getIcon("namingError")) |
95 elif code.startswith("D"): |
103 elif code.startswith("D"): |
96 itm.setIcon(1, UI.PixmapCache.getIcon("docstringError")) |
104 itm.setIcon(0, UI.PixmapCache.getIcon("docstringError")) |
97 elif code.startswith("S"): |
105 elif code.startswith("S"): |
98 itm.setIcon(1, UI.PixmapCache.getIcon("securityLow")) |
106 itm.setIcon(0, UI.PixmapCache.getIcon("securityLow")) |
99 elif code.startswith("P"): |
107 elif code.startswith("P"): |
100 itm.setIcon(1, UI.PixmapCache.getIcon("dirClosed")) |
108 itm.setIcon(0, UI.PixmapCache.getIcon("dirClosed")) |
101 elif code.startswith("Y"): |
109 elif code.startswith("Y"): |
102 itm.setIcon(1, UI.PixmapCache.getIcon("filePython")) |
110 itm.setIcon(0, UI.PixmapCache.getIcon("filePython")) |
103 |
111 |
104 itm.setTextAlignment( |
112 itm.setTextAlignment( |
105 0, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) |
113 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) |
106 itm.setTextAlignment( |
114 itm.setTextAlignment( |
107 1, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) |
115 1, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) |
|
116 itm.setTextAlignment( |
|
117 2, Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter) |