Class: Ruber::FilteredOutputWidget::FilterModel

Inherits:
Qt::SortFilterProxyModel show all
Defined in:
lib/ruber/filtered_output_widget.rb

Overview

Filter model derived from Qt::SortFilterProxyModel which better integrate with FilteredOutputWidget.

The differences between this class and Qt::SortFilterProxyModel are the following

  • it has the ability to ignore the filter (see FilteredOutputWidget)
  • it provides an easy way to always accept some kind of items (see exclude and exclude_from_filtering?)
  • it emits a signal when the filter reg exp is changed

Note: this class is meant to be used with a regexp filter, not with a string filter.

=Signals ===filter_changed(QString reg) Signal emitted when the regexp used for filtering changes (including when the filter is removed). reg is a string containing the source of the regexp.

Direct Known Subclasses

RSpec::FilterModel

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Qt::SortFilterProxyModel

#each

Signal Summary

Constructor Details

- (FilterModel) initialize(parent = nil, exclude = nil)

Creates a new FilterModel.

parent is the parent object, while exclude is the initial value of the exclude attribute (which can be changed later).



265
266
267
268
269
# File 'lib/ruber/filtered_output_widget.rb', line 265

def initialize parent = nil, exclude = nil
  super parent
  @exclude = exclude
  @ignore_filter = false
end

Instance Attribute Details

- (Object) exclude

The kind of items to exclude from filtering. See exclude_from_filtering?



257
258
259
# File 'lib/ruber/filtered_output_widget.rb', line 257

def exclude
  @exclude
end

Instance Method Details

- (Boolean) exclude_from_filtering?(r, parent) (protected)

Tells the filter whether the filter should be applied to the given row and parent or whether it should always be accepted, according to the value of exclude. In particular:

  • if exclude is :toplevel, then the filter will be applied only to child items (toplevel items will always be accepted)
  • if exclude is :children, then the filter will be applied only to toplevel items (child items will always be accepted)
  • any other value will cause the filter to be applied to all items

Derived classes can modify this behaviour by overriding this method. The arguments have the same meaning as sin filterAcceptsRow

Returns:

  • (Boolean)


329
330
331
332
333
334
335
# File 'lib/ruber/filtered_output_widget.rb', line 329

def exclude_from_filtering? r, parent
  case @exclude
  when :toplevel then !parent.valid?
  when :children then parent.valid?
  else false
  end
end

- (Boolean) filter_ignored?

Tells whether the object has been instructed to ignore the filter

Returns:

  • (Boolean)


274
275
276
# File 'lib/ruber/filtered_output_widget.rb', line 274

def filter_ignored?
  @ignore_filter
end

- (Object) filter_reg_exp=(str)

Override of Qt::SortFilterProxyModel#filter_reg_exp= which, after changing the regexp ( and invalidating the model) emits the filter_changed(QString) signal



291
292
293
294
# File 'lib/ruber/filtered_output_widget.rb', line 291

def filter_reg_exp= str
  super
  emit filter_changed(str)
end

- (Object) filterAcceptsRow(r, parent) (protected)

Override of Qt::SortFilterProxyModel#filterAcceptsRow which also takes into account the setting for filter_ignored? and exclude. In particular, if filter_ignored? is true or if exclude_from_filtering? returns true for the given row and parent, then it will always return true. Otherwise, it behaves like Qt::SortFilterProxyModel#filterAcceptsRow



310
311
312
313
314
# File 'lib/ruber/filtered_output_widget.rb', line 310

def filterAcceptsRow r, parent
  return true if @ignore_filter
  return true if exclude_from_filtering? r, parent
  super
end

- (Object) ignore_filter=(val)

Instructs the model to ignore or not the filter, according to val. This method always invalidate the model



282
283
284
285
# File 'lib/ruber/filtered_output_widget.rb', line 282

def ignore_filter= val
  @ignore_filter = val
  invalidate
end

Signal Details

- filter_changed(QString arg1)