eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py

changeset 8199
f6db89b067e7
parent 8195
db7f2badd374
child 8204
fd477cded1c1
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Sat Apr 03 16:02:33 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCheckerDialog.py	Sat Apr 03 16:54:10 2021 +0200
@@ -38,7 +38,6 @@
     basestring = str    # define for Python3
 
 
-# TODO: add a code filter to the results page
 class CodeStyleCheckerDialog(QDialog, Ui_CodeStyleCheckerDialog):
     """
     Class implementing a dialog to show the results of the code style check.
@@ -199,6 +198,7 @@
         self.__statistics = {}
         self.__onlyFixes = {}
         self.__noFixCodesList = []
+        self.__detectedCodes = []
         
         self.on_loadDefaultButton_clicked()
         
@@ -279,6 +279,7 @@
             self.__lastFileItem.setData(0, self.filenameRole, filename)
         
         msgCode = result["code"].split(".", 1)[0]
+        self.__detectedCodes.append(msgCode)
         
         fixable = False
         itm = QTreeWidgetItem(
@@ -1066,6 +1067,12 @@
                 QHeaderView.ResizeMode.ResizeToContents)
             self.resultList.header().setStretchLastSection(True)
             
+            if self.__detectedCodes:
+                self.filterComboBox.addItem("")
+                self.filterComboBox.addItems(sorted(set(self.__detectedCodes)))
+                self.filterComboBox.setEnabled(True)
+                self.filterButton.setEnabled(True)
+            
             self.checkProgress.setVisible(False)
             self.checkProgressLabel.setVisible(False)
             
@@ -1170,6 +1177,10 @@
         self.resultList.clear()
         self.results = CodeStyleCheckerDialog.noResults
         self.cancelled = False
+        self.__detectedCodes.clear()
+        self.filterComboBox.clear()
+        self.filterComboBox.setEnabled(False)
+        self.filterButton.setEnabled(False)
         
         self.start(self.__fileOrFileList)
     
@@ -2029,3 +2040,28 @@
             row = self.whitelistWidget.row(itm)
             self.whitelistWidget.takeItem(row)
             del itm
+    
+    @pyqtSlot()
+    def on_filterButton_clicked(self):
+        """
+        Private slot to filter the list of messages based on selected message
+        code.
+        """
+        selectedMessageCode = self.filterComboBox.currentText()
+        print(selectedMessageCode)
+        
+        for topRow in range(self.resultList.topLevelItemCount()):
+            topItem = self.resultList.topLevelItem(topRow)
+            visibleChildren = topItem.childCount()
+            for childIndex in range(topItem.childCount()):
+                childItem = topItem.child(childIndex)
+                if selectedMessageCode:
+                    hideChild = (
+                        childItem.data(0, self.codeRole) != selectedMessageCode
+                    )
+                else:
+                    hideChild = False
+                childItem.setHidden(hideChild)
+                if hideChild:
+                    visibleChildren -= 1
+            topItem.setHidden(visibleChildren == 0)

eric ide

mercurial