Class: Ruber::ProjectBrowser::ToolWidget::FilterModel

Inherits:
KDE::DirSortFilterProxyModel
  • Object
show all
Defined in:
plugins/project_browser/project_browser.rb

Overview

TODO:

currently, directories containing only non-project files are still shown. This

Filter used by the tree view to hide non-project files. It also allow to turn off filtering, which is used when the user choose to display all files.

is because of how the filtering is done: filtering the parent object is done before filtering child objects, so there’s no direct way to remove empty items. See whether something can be done about it

Instance Method Summary (collapse)

Constructor Details

- (FilterModel) initialize(parent = nil)

A new instance of FilterModel

Parameters:

  • parent (Qt::Object) (defaults to: nil)

    the parent object



55
56
57
58
59
60
# File 'plugins/project_browser/project_browser.rb', line 55

def initialize parent = nil
  super
  @project = nil
  @do_filtering = true
  self.dynamic_sort_filter = true
end

Instance Method Details

- (Boolean) do_filtering=(val)

Tells whether to exclude files not belonging to the project or to accept all items

Parameters:

  • val (Boolean)

    whether or not to accept all files

Returns:

  • (Boolean)

    val



96
97
98
99
# File 'plugins/project_browser/project_browser.rb', line 96

def do_filtering= val
  @do_filtering = val
  invalidate_filter
end

- (Boolean) filterAcceptsRow(row, parent)

Override of KDE::DirSortFilterProxyModel#filterAcceptsRow which rejects all files not belonging to the project, unless filtering has been turned off.

been set, otherwise true if row corresponds to a directory or to a file belonging to the project and false otherwise

Parameters:

  • row (Integer)

    the number of the row to be filtered (in the source model)

  • parent (Qt::ModelIndex)

    the parent of the row to be filtered (in the source model)

Returns:

  • (Boolean)

    always true if filtering has been turned off or no project has



73
74
75
76
77
78
# File 'plugins/project_browser/project_browser.rb', line 73

def filterAcceptsRow row, parent
  return true if @project.nil? or !@do_filtering
  it = source_model.item_for_index source_model.index(row,0,parent)
  return true if it.dir?
  @project.file_in_project? it.local_path
end

- (nil) invalidate_filter

Override of KDE::DirSortFilterProxyModel#filterAcceptsRow which works as the parent method but is public

Returns:

  • (nil)


106
107
108
# File 'plugins/project_browser/project_browser.rb', line 106

def invalidate_filter
  super
end

- (nil) project=(prj)

Changes the project to use for filtering and invalidates the filter items will be accepted)

Parameters:

  • prj (Ruber::Project, nil)

    the project to use for filtering (if nil, all

Returns:

  • (nil)


86
87
88
89
# File 'plugins/project_browser/project_browser.rb', line 86

def project= prj
  @project = prj
  invalidate_filter
end