Model Related Classes
The models
module contains QT Models and model related classes that
are useful when building MVC setups and when you need to filter data in
various ways.
HierarchicalFilteringProxyModel
- class models.HierarchicalFilteringProxyModel(parent=None)[source]
Bases:
QSortFilterProxyModel
Inherited from a
QSortFilterProxyModel
, this class implements filtering across all levels of a hierarchy in a hierarchical (tree-based) model and provides a simple interface for derived classes so that all they need to do is filter a single item as requested.- Parameters:
parent (
QWidget
) – The parent QObject to use for this instance
- enable_caching(enable=True)[source]
Allow control over enabling/disabling of the accepted cache used to accelerate filtering. Can be used for debug purposes to ensure the caching isn’t the cause of incorrect filtering/sorting or instability!
- Parameters:
enable – True if caching should be enabled, False if it should be disabled.
- _is_row_accepted(src_row, src_parent_idx, parent_accepted)[source]
Override this method to decide if the specified row should be accepted or not by the filter.
This should be overridden instead of filterAcceptsRow in derived classes
- Parameters:
src_row – The row in the source model to filter
src_parent_idx – The parent QModelIndex instance to filter
parent_accepted – True if a parent item has been accepted by the filter
- Returns:
True if this index should be accepted, otherwise False
ShotgunSortFilterProxyModel
- class models.ShotgunSortFilterProxyModel(parent)[source]
Bases:
QSortFilterProxyModel
A sort/filter proxy model that handles sorting and filtering data in a ShotgunModel by given Shotgun fields on the entities stored therein.
Initializes a new ShotgunSortFilterProxyModel.
- Parameters:
parent – The Qt parent of the proxy model.
- lessThan(left, right)[source]
Returns True if “left” is less than “right”, otherwise False. This sort is handled based on the data pulled from Shotgun for the current sort_by_field registered with this proxy model.
- Parameters:
left – The QModelIndex of the left-hand item to compare.
right – The QModelIndex of the right-hand item to compare against.
- Returns:
Whether “left” is less than “right”.
- Return type:
- filterAcceptsRow(row, source_parent)[source]
Returns True if the model index should be shown, and False if it should not. This is determined based on whether the proxy model’s filter is found in the Shotgun data for the fields specified in the filter_by_fields list registered with the proxy model.
- Parameters:
row – The row being processed.
source_parent – The parent index from the source model.
- Returns:
Whether the row is accepted.
- Return type:
- _get_processable_field_data(sg_data, field, sortable=False)[source]
For a given entity dictionary and field name, returns sortable and/or searchable data.
- Parameters:
sg_data – An entity dictionary.
field – A string Shotgun field to process.
sortable – If True, sortable data will be returned. If not, data better suited to searching/filtering will be returned. Default is False.
- Returns:
The given Shotgun data in a form that is processable as part of a filtering and/or sorting operation.