Class: Ruber::OpenFileInProjectDlg::FilterModel
- Inherits:
-
Qt::SortFilterProxyModel
- Object
- Qt::SortFilterProxyModel
- Ruber::OpenFileInProjectDlg::FilterModel
- Defined in:
- lib/ruber/main_window/open_file_in_project_dlg.rb
Overview
Class implementing the filter for the OpenFileInProjectDlg class.
Instance Method Summary (collapse)
-
- (Object) filter(value)
Changes the regexp used to filter the files, then re-applies the filter.
-
- (Object) filterAcceptsRow(r, parent)
protected
Reimplementation of Qt::SortFilterProxyModel#filterAcceptsRow which returns.
-
- (FilterModel) initialize(parent = nil)
constructor
Returns a new FilterModel.
Methods inherited from Qt::SortFilterProxyModel
Constructor Details
- (FilterModel) initialize(parent = nil)
Returns a new FilterModel. =Arguments parent:: the Qt::Object parent of the filter
58 59 60 61 62 |
# File 'lib/ruber/main_window/open_file_in_project_dlg.rb', line 58 def initialize parent = nil super @filter = nil @role = Qt::DisplayRole end |
Instance Method Details
- (Object) filter=(value)
Changes the regexp used to filter the files, then re-applies the filter calling the invalidate method. =Arguments value:: the new regexp. It can be nil or a regexp. In the first case, the filter won’t be applied. =TODO On Windows, allow to also use the ‘\’ character as pattern separator. The problem is that that character is also the escape character in a regexp, so things may become complicated.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruber/main_window/open_file_in_project_dlg.rb', line 75 def filter= value @filter = value # TODO This doesn't work #on windows, where one can also use \ as separator. The problem is that in regexp #it's the escape character, so one must use something like #value.include?(File::SEPARATOR) || (File::ALT_SEPARATOR and value.match(/\\{2})) @role = if @filter and !value.source.include?(File::SEPARATOR) then Qt::UserRole + 1 else Qt::DisplayRole end invalidate end |
- (Object) filterAcceptsRow(r, parent) (protected)
Reimplementation of Qt::SortFilterProxyModel#filterAcceptsRow which returns true if the file matches the regexp and false otherwise (if the regexp is nil, this method always returns true).
If the source of the regexp contains the pattern separator, the whole filename is tested, otherwise only the name of the file will be tested.
97 98 99 100 101 102 |
# File 'lib/ruber/main_window/open_file_in_project_dlg.rb', line 97 def filterAcceptsRow r, parent return true unless @filter idx = source_model.index r, 0, parent res = idx.data(@role).to_string.match @filter res.to_bool #It seems that it's required to return true or false - other objects don't work end |