Added a context menu to the result list of the cyclomatic complexity dialog.

Sun, 20 Sep 2015 12:16:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 20 Sep 2015 12:16:27 +0200
changeset 15
62ffe3d426e5
parent 14
5f206edea27e
child 16
644b53d1b250

Added a context menu to the result list of the cyclomatic complexity dialog.

RadonMetrics/CyclomaticComplexityDialog.py file | annotate | diff | comparison | revisions
RadonMetrics/Documentation/source/Plugin_Metrics_Radon.RadonMetrics.CyclomaticComplexityDialog.html file | annotate | diff | comparison | revisions
RadonMetrics/MaintainabilityIndexDialog.py file | annotate | diff | comparison | revisions
RadonMetrics/i18n/radon_de.qm file | annotate | diff | comparison | revisions
RadonMetrics/i18n/radon_de.ts file | annotate | diff | comparison | revisions
RadonMetrics/i18n/radon_en.ts file | annotate | diff | comparison | revisions
RadonMetrics/i18n/radon_es.ts file | annotate | diff | comparison | revisions
RadonMetrics/i18n/radon_ru.ts file | annotate | diff | comparison | revisions
--- 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):
Binary file RadonMetrics/i18n/radon_de.qm has changed
--- 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>&lt;table&gt;&lt;tr&gt;&lt;td colspan=2&gt;&lt;b&gt;Typ:&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Klasse&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Funktion&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;M&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Methode&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</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>&lt;b&gt;Summary:&lt;/b&gt;&lt;br/&gt;{0} blocks (classes, functions, methods) analyzed.&lt;br/&gt;Average complexity: {7} ({8})&lt;table&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;A&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{1} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;B&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{2} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{3} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;D&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{4} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;E&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{5} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{6} blocks&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</source>
         <translation>&lt;b&gt;Zusammenfassung:&lt;/b&gt;&lt;br/&gt;{0} Blöcke (Klassen, Funktionen, Methoden) analysiert.&lt;br/&gt;Mittlere Komplexität: {7} ({8})&lt;table&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;A&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{1} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;B&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{2} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{3} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;D&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{4} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;E&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{5} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{6} Blöcke&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</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>&lt;b&gt;Summary:&lt;/b&gt;&lt;br/&gt;{0} blocks (classes, functions, methods) analyzed.&lt;br/&gt;Average complexity: {7} ({8})&lt;table&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;A&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{1} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;B&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{2} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{3} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;D&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{4} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;E&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{5} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{6} blocks&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</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>&lt;b&gt;Summary:&lt;/b&gt;&lt;br/&gt;{0} blocks (classes, functions, methods) analyzed.&lt;br/&gt;Average complexity: {7} ({8})&lt;table&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;A&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{1} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;B&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{2} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{3} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;D&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{4} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;E&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{5} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{6} blocks&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</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>&lt;b&gt;Summary:&lt;/b&gt;&lt;br/&gt;{0} blocks (classes, functions, methods) analyzed.&lt;br/&gt;Average complexity: {7} ({8})&lt;table&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;A&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{1} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;B&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{2} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;C&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{3} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;D&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{4} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;E&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{5} blocks&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width=30&gt;&lt;b&gt;F&lt;/b&gt;&lt;/td&gt;&lt;td&gt;{6} blocks&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</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>

eric ide

mercurial