code: def filterAcceptsRow(self, source_row, source_parent):
          
          source_index = self.sourceModel().index(source_row, 0, source_parent)
          item = self.sourceModel().dataItem(source_index)
  
          if item.metaObject().className() not in [
                  'QgsPGRootItem',
                  'QgsPGConnectionItem',
                  'QgsPGSchemaItem',
                  'QgsPGLayerItem',
                  'QgsFavoritesItem',
                  'QgsDirectoryItem',
                  'QgsLayerItem',
                  'QgsGdalLayerItem',
                  'QgsOgrLayerItem']:
              return False
  
          if item.path().endswith('.xml'):
              return False
  
          return True
docs: The filter method
  
          .. note:: This filter hides top-level items of unsupported branches
                    and also leaf items containing xml files.
  
             Enabled root items: QgsDirectoryItem, QgsFavouritesItem,
             QgsPGRootItem.
  
             Disabled root items: QgsMssqlRootItem, QgsSLRootItem,
             QgsOWSRootItem, QgsWCSRootItem, QgsWFSRootItem, QgsWMSRootItem.
  
             Disabled leaf items: QgsLayerItem and QgsOgrLayerItem with path
             ending with '.xml'
  
          :param source_row: Parent widget of the model
          :type source_row: int
  
          :param source_parent: Parent item index
          :type source_parent: QModelIndex
  
          :returns: Item validation result
          :rtype: bool