Sun, 20 Sep 2015 12:16:27 +0200
Added a context menu to the result list of the cyclomatic complexity dialog.
--- 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)
--- a/RadonMetrics/Documentation/source/Plugin_Metrics_Radon.RadonMetrics.CyclomaticComplexityDialog.html Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/Documentation/source/Plugin_Metrics_Radon.RadonMetrics.CyclomaticComplexityDialog.html Sun Sep 20 12:16:27 2015 +0200 @@ -86,6 +86,15 @@ <td><a href="#CyclomaticComplexityDialog.__resizeResultColumns">__resizeResultColumns</a></td> <td>Private method to resize the list columns.</td> </tr><tr> +<td><a href="#CyclomaticComplexityDialog.__resultCollapse">__resultCollapse</a></td> +<td>Private slot to collapse all entries of the resultlist.</td> +</tr><tr> +<td><a href="#CyclomaticComplexityDialog.__resultExpand">__resultExpand</a></td> +<td>Private slot to expand all entries of the resultlist.</td> +</tr><tr> +<td><a href="#CyclomaticComplexityDialog.__showContextMenu">__showContextMenu</a></td> +<td>Private slot to show the context menu of the resultlist.</td> +</tr><tr> <td><a href="#CyclomaticComplexityDialog.cyclomaticComplexity">cyclomaticComplexity</a></td> <td>Public method to start a cyclomatic complexity calculation for one Python file.</td> </tr><tr> @@ -218,7 +227,27 @@ <b>__resizeResultColumns</b>(<i></i>) <p> Private method to resize the list columns. -</p><a NAME="CyclomaticComplexityDialog.cyclomaticComplexity" ID="CyclomaticComplexityDialog.cyclomaticComplexity"></a> +</p><a NAME="CyclomaticComplexityDialog.__resultCollapse" ID="CyclomaticComplexityDialog.__resultCollapse"></a> +<h4>CyclomaticComplexityDialog.__resultCollapse</h4> +<b>__resultCollapse</b>(<i></i>) +<p> + Private slot to collapse all entries of the resultlist. +</p><a NAME="CyclomaticComplexityDialog.__resultExpand" ID="CyclomaticComplexityDialog.__resultExpand"></a> +<h4>CyclomaticComplexityDialog.__resultExpand</h4> +<b>__resultExpand</b>(<i></i>) +<p> + Private slot to expand all entries of the resultlist. +</p><a NAME="CyclomaticComplexityDialog.__showContextMenu" ID="CyclomaticComplexityDialog.__showContextMenu"></a> +<h4>CyclomaticComplexityDialog.__showContextMenu</h4> +<b>__showContextMenu</b>(<i>coord</i>) +<p> + Private slot to show the context menu of the resultlist. +</p><dl> +<dt><i>coord</i></dt> +<dd> +the position of the mouse pointer (QPoint) +</dd> +</dl><a NAME="CyclomaticComplexityDialog.cyclomaticComplexity" ID="CyclomaticComplexityDialog.cyclomaticComplexity"></a> <h4>CyclomaticComplexityDialog.cyclomaticComplexity</h4> <b>cyclomaticComplexity</b>(<i>codestring=''</i>) <p>
--- a/RadonMetrics/MaintainabilityIndexDialog.py Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/MaintainabilityIndexDialog.py Sun Sep 20 12:16:27 2015 +0200 @@ -108,10 +108,10 @@ 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"]: + if values["rank"] in self.__rankColors: itm.setBackground(2, self.__rankColors[values["rank"]]) - if values["rank"] in ["A", "B", "C"]: + if values["rank"] in self.__summary: self.__summary[values["rank"]] += 1 def __createErrorItem(self, filename, message):
--- a/RadonMetrics/i18n/radon_de.ts Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/i18n/radon_de.ts Sun Sep 20 12:16:27 2015 +0200 @@ -65,17 +65,17 @@ <translation><table><tr><td colspan=2><b>Typ:</b></td></tr><tr><td><b>C</b></td><td>Klasse</td></tr><tr><td><b>F</b></td><td>Funktion</td></tr><tr><td><b>M</b></td><td>Methode</td></tr></table></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="175"/> + <location filename="../CyclomaticComplexityDialog.py" line="195"/> <source>Errors</source> <translation>Fehler</translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="327"/> + <location filename="../CyclomaticComplexityDialog.py" line="341"/> <source>Preparing files...</source> <translation>Bereite Dateien vor...</translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="449"/> + <location filename="../CyclomaticComplexityDialog.py" line="464"/> <source><b>Summary:</b><br/>{0} blocks (classes, functions, methods) analyzed.<br/>Average complexity: {7} ({8})<table><tr><td width=30><b>A</b></td><td>{1} blocks</td></tr><tr><td width=30><b>B</b></td><td>{2} blocks</td></tr><tr><td width=30><b>C</b></td><td>{3} blocks</td></tr><tr><td width=30><b>D</b></td><td>{4} blocks</td></tr><tr><td width=30><b>E</b></td><td>{5} blocks</td></tr><tr><td width=30><b>F</b></td><td>{6} blocks</td></tr></table></source> <translation><b>Zusammenfassung:</b><br/>{0} Blöcke (Klassen, Funktionen, Methoden) analysiert.<br/>Mittlere Komplexität: {7} ({8})<table><tr><td width=30><b>A</b></td><td>{1} Blöcke</td></tr><tr><td width=30><b>B</b></td><td>{2} Blöcke</td></tr><tr><td width=30><b>C</b></td><td>{3} Blöcke</td></tr><tr><td width=30><b>D</b></td><td>{4} Blöcke</td></tr><tr><td width=30><b>E</b></td><td>{5} Blöcke</td></tr><tr><td width=30><b>F</b></td><td>{6} Blöcke</td></tr></table></translation> </message> @@ -94,6 +94,16 @@ <source>Begin</source> <translation>Anfang</translation> </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="121"/> + <source>Collapse all</source> + <translation>Alle Zuklappen</translation> + </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="123"/> + <source>Expand all</source> + <translation>Alle Aufklappen</translation> + </message> </context> <context> <name>MaintainabilityIndexDialog</name>
--- a/RadonMetrics/i18n/radon_en.ts Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/i18n/radon_en.ts Sun Sep 20 12:16:27 2015 +0200 @@ -64,17 +64,17 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="175"/> + <location filename="../CyclomaticComplexityDialog.py" line="195"/> <source>Errors</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="327"/> + <location filename="../CyclomaticComplexityDialog.py" line="341"/> <source>Preparing files...</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="449"/> + <location filename="../CyclomaticComplexityDialog.py" line="464"/> <source><b>Summary:</b><br/>{0} blocks (classes, functions, methods) analyzed.<br/>Average complexity: {7} ({8})<table><tr><td width=30><b>A</b></td><td>{1} blocks</td></tr><tr><td width=30><b>B</b></td><td>{2} blocks</td></tr><tr><td width=30><b>C</b></td><td>{3} blocks</td></tr><tr><td width=30><b>D</b></td><td>{4} blocks</td></tr><tr><td width=30><b>E</b></td><td>{5} blocks</td></tr><tr><td width=30><b>F</b></td><td>{6} blocks</td></tr></table></source> <translation type="unfinished"></translation> </message> @@ -93,6 +93,16 @@ <source>Shows the progress of the calculation</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="121"/> + <source>Collapse all</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="123"/> + <source>Expand all</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>MaintainabilityIndexDialog</name>
--- a/RadonMetrics/i18n/radon_es.ts Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/i18n/radon_es.ts Sun Sep 20 12:16:27 2015 +0200 @@ -64,17 +64,17 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="175"/> + <location filename="../CyclomaticComplexityDialog.py" line="195"/> <source>Errors</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="327"/> + <location filename="../CyclomaticComplexityDialog.py" line="341"/> <source>Preparing files...</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="449"/> + <location filename="../CyclomaticComplexityDialog.py" line="464"/> <source><b>Summary:</b><br/>{0} blocks (classes, functions, methods) analyzed.<br/>Average complexity: {7} ({8})<table><tr><td width=30><b>A</b></td><td>{1} blocks</td></tr><tr><td width=30><b>B</b></td><td>{2} blocks</td></tr><tr><td width=30><b>C</b></td><td>{3} blocks</td></tr><tr><td width=30><b>D</b></td><td>{4} blocks</td></tr><tr><td width=30><b>E</b></td><td>{5} blocks</td></tr><tr><td width=30><b>F</b></td><td>{6} blocks</td></tr></table></source> <translation type="unfinished"></translation> </message> @@ -93,6 +93,16 @@ <source>Shows the progress of the calculation</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="121"/> + <source>Collapse all</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="123"/> + <source>Expand all</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>MaintainabilityIndexDialog</name>
--- a/RadonMetrics/i18n/radon_ru.ts Sat Sep 19 20:00:54 2015 +0200 +++ b/RadonMetrics/i18n/radon_ru.ts Sun Sep 20 12:16:27 2015 +0200 @@ -64,17 +64,17 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="175"/> + <location filename="../CyclomaticComplexityDialog.py" line="195"/> <source>Errors</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="327"/> + <location filename="../CyclomaticComplexityDialog.py" line="341"/> <source>Preparing files...</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../CyclomaticComplexityDialog.py" line="449"/> + <location filename="../CyclomaticComplexityDialog.py" line="464"/> <source><b>Summary:</b><br/>{0} blocks (classes, functions, methods) analyzed.<br/>Average complexity: {7} ({8})<table><tr><td width=30><b>A</b></td><td>{1} blocks</td></tr><tr><td width=30><b>B</b></td><td>{2} blocks</td></tr><tr><td width=30><b>C</b></td><td>{3} blocks</td></tr><tr><td width=30><b>D</b></td><td>{4} blocks</td></tr><tr><td width=30><b>E</b></td><td>{5} blocks</td></tr><tr><td width=30><b>F</b></td><td>{6} blocks</td></tr></table></source> <translation type="unfinished"></translation> </message> @@ -93,6 +93,16 @@ <source>Shows the progress of the calculation</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="121"/> + <source>Collapse all</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../CyclomaticComplexityDialog.py" line="123"/> + <source>Expand all</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>MaintainabilityIndexDialog</name>