18 QTreeWidgetItem, QApplication |
18 QTreeWidgetItem, QApplication |
19 ) |
19 ) |
20 |
20 |
21 from .Ui_RawMetricsDialog import Ui_RawMetricsDialog |
21 from .Ui_RawMetricsDialog import Ui_RawMetricsDialog |
22 |
22 |
|
23 from E5Gui.E5Application import e5App |
|
24 |
23 import Preferences |
25 import Preferences |
24 import Utilities |
26 import Utilities |
25 |
27 |
26 |
28 # TODO: add summary table |
|
29 # TODO: add column explanations |
27 class RawMetricsDialog(QDialog, Ui_RawMetricsDialog): |
30 class RawMetricsDialog(QDialog, Ui_RawMetricsDialog): |
28 """ |
31 """ |
29 Class implementing a dialog to show raw code metrics. |
32 Class implementing a dialog to show raw code metrics. |
30 """ |
33 """ |
31 def __init__(self, radonService, parent=None): |
34 def __init__(self, radonService, parent=None): |
50 self.radonService.metricsDone.connect(self.__processResult) |
53 self.radonService.metricsDone.connect(self.__processResult) |
51 self.radonService.metricsError.connect(self.__processError) |
54 self.radonService.metricsError.connect(self.__processError) |
52 self.radonService.batchFinished.connect(self.__batchFinished) |
55 self.radonService.batchFinished.connect(self.__batchFinished) |
53 |
56 |
54 self.cancelled = False |
57 self.cancelled = False |
|
58 |
|
59 self.__project = e5App().getObject("Project") |
55 |
60 |
56 self.__menu = QMenu(self) |
61 self.__menu = QMenu(self) |
57 self.__menu.addAction(self.tr("Collapse all"), |
62 self.__menu.addAction(self.tr("Collapse all"), |
58 self.__resultCollapse) |
63 self.__resultCollapse) |
59 self.__menu.addAction(self.tr("Expand all"), self.__resultExpand) |
64 self.__menu.addAction(self.tr("Expand all"), self.__resultExpand) |
60 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) |
65 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) |
61 self.resultList.customContextMenuRequested.connect( |
66 self.resultList.customContextMenuRequested.connect( |
62 self.__showContextMenu) |
67 self.__showContextMenu) |
63 |
68 |
64 self.__fileList = [] |
69 self.__fileList = [] |
65 self.__project = None |
|
66 self.filterFrame.setVisible(False) |
70 self.filterFrame.setVisible(False) |
67 |
71 |
68 def __resizeResultColumns(self): |
72 def __resizeResultColumns(self): |
69 """ |
73 """ |
70 Private method to resize the list columns. |
74 Private method to resize the list columns. |
74 |
78 |
75 def __createResultItem(self, filename, values): |
79 def __createResultItem(self, filename, values): |
76 """ |
80 """ |
77 Private slot to create a new item in the result list. |
81 Private slot to create a new item in the result list. |
78 |
82 |
79 @param parent parent of the new item |
83 @param filename name of the file |
80 @type QTreeWidget or QTreeWidgetItem |
84 @type str |
81 @param values values to be displayed |
85 @param values values to be displayed |
82 @type list |
86 @type dict |
83 @return the generated item |
87 """ |
84 @rtype QTreeWidgetItem |
88 data = [self.__project.getRelativePath(filename)] |
85 """ |
89 for key in ['loc', 'sloc', 'lloc', 'comments', 'multi', 'blank']: |
86 data = [filename] |
|
87 for value in values: |
|
88 try: |
90 try: |
89 data.append("{0:5}".format(int(value))) |
91 data.append("{0:5}".format(int(values[key]))) |
90 except ValueError: |
92 except ValueError: |
91 data.append(value) |
93 data.append(values[key]) |
|
94 except KeyError: |
|
95 data.append("") |
|
96 data.append("{0:3.0%}".format( |
|
97 values["comments"] / (float(values["loc"]) or 1))) |
|
98 data.append("{0:3.0%}".format( |
|
99 values["comments"] / (float(values["sloc"]) or 1))) |
|
100 data.append("{0:3.0%}".format( |
|
101 (values["comments"] + values["multi"]) / |
|
102 (float(values["loc"]) or 1))) |
92 itm = QTreeWidgetItem(self.resultList, data) |
103 itm = QTreeWidgetItem(self.resultList, data) |
93 for col in range(1, 6): |
104 for col in range(1, 10): |
94 itm.setTextAlignment(col, Qt.Alignment(Qt.AlignRight)) |
105 itm.setTextAlignment(col, Qt.Alignment(Qt.AlignRight)) |
95 return itm |
106 |
|
107 def __createErrorItem(self, filename, message): |
|
108 """ |
|
109 Private slot to create a new error item in the result list. |
|
110 |
|
111 @param filename name of the file |
|
112 @type str |
|
113 @param message error message |
|
114 @type str |
|
115 """ |
|
116 # TODO: implement this |
96 |
117 |
97 def prepare(self, fileList, project): |
118 def prepare(self, fileList, project): |
98 """ |
119 """ |
99 Public method to prepare the dialog with a list of filenames. |
120 Public method to prepare the dialog with a list of filenames. |
100 |
121 |
147 for f in self.files[:]: |
168 for f in self.files[:]: |
148 if not os.path.exists(f): |
169 if not os.path.exists(f): |
149 self.files.remove(f) |
170 self.files.remove(f) |
150 |
171 |
151 if len(self.files) > 0: |
172 if len(self.files) > 0: |
|
173 # disable updates of the list for speed |
|
174 self.resultList.setUpdatesEnabled(False) |
|
175 self.resultList.setSortingEnabled(False) |
|
176 |
152 self.checkProgress.setMaximum(len(self.files)) |
177 self.checkProgress.setMaximum(len(self.files)) |
153 self.checkProgress.setVisible(len(self.files) > 1) |
178 self.checkProgress.setVisible(len(self.files) > 1) |
154 self.checkProgressLabel.setVisible(len(self.files) > 1) |
179 self.checkProgressLabel.setVisible(len(self.files) > 1) |
155 QApplication.processEvents() |
180 QApplication.processEvents() |
156 |
181 |
157 # now go through all the files |
182 # now go through all the files |
158 self.progress = 0 |
183 self.progress = 0 |
159 self.files.sort() |
184 self.files.sort() |
160 if len(self.files) == 1: |
185 if len(self.files) == 1 or not self.radonService.hasBatch: |
161 self.__batch = False |
186 self.__batch = False |
162 self.rawMetrics() |
187 self.rawMetrics() |
163 else: |
188 else: |
164 self.__batch = True |
189 self.__batch = True |
165 self.rawMetricsBatch() |
190 self.rawMetricsBatch() |
259 Private slot called after perfoming a code metrics calculation on one |
284 Private slot called after perfoming a code metrics calculation on one |
260 file. |
285 file. |
261 |
286 |
262 @param fn filename of the file |
287 @param fn filename of the file |
263 @type str |
288 @type str |
264 @param result result list |
289 @param result result dict |
265 @type list |
290 @type dict |
266 """ |
291 """ |
267 if self.__finished: |
292 if self.__finished: |
268 return |
293 return |
269 |
294 |
270 # Check if it's the requested file, otherwise ignore signal if not |
295 # Check if it's the requested file, otherwise ignore signal if not |
271 # in batch mode |
296 # in batch mode |
272 if not self.__batch and fn != self.filename: |
297 if not self.__batch and fn != self.filename: |
273 return |
298 return |
274 |
299 |
275 self.__createResultItem(fn, result) |
300 if "error" in result: |
|
301 self.__createErrorItem(fn, result["error"]) |
|
302 else: |
|
303 self.__createResultItem(fn, result) |
276 |
304 |
277 self.progress += 1 |
305 self.progress += 1 |
278 |
306 |
279 self.checkProgress.setValue(self.progress) |
307 self.checkProgress.setValue(self.progress) |
280 self.checkProgressLabel.setPath(fn) |
308 self.checkProgressLabel.setPath(fn) |
287 """ |
315 """ |
288 Private slot called when the action or the user pressed the button. |
316 Private slot called when the action or the user pressed the button. |
289 """ |
317 """ |
290 if not self.__finished: |
318 if not self.__finished: |
291 self.__finished = True |
319 self.__finished = True |
|
320 |
|
321 # reenable updates of the list |
|
322 self.resultList.setSortingEnabled(True) |
|
323 self.resultList.setUpdatesEnabled(True) |
292 |
324 |
293 self.cancelled = True |
325 self.cancelled = True |
294 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
326 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
295 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
327 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
296 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
328 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |