treeview_models

Classes for handling models in tree and graph views.

authors:
  1. Marin (KTH)
date:

28.6.2019

Module Contents

class treeview_models.ObjectClassListModel(graph_view_form)[source]

Bases: PySide2.QtGui.QStandardItemModel

A class to list object classes in the GraphViewForm.

populate_list(self)[source]

Populate model.

add_object_class(self, object_class)[source]

Add object class item to model.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index.

class treeview_models.RelationshipClassListModel(graph_view_form)[source]

Bases: PySide2.QtGui.QStandardItemModel

A class to list relationship classes in the GraphViewForm.

populate_list(self)[source]

Populate model.

add_relationship_class(self, relationship_class)[source]

Add relationship class.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index.

class treeview_models.ObjectTreeModel(parent, flat=False)[source]

Bases: PySide2.QtGui.QStandardItemModel

A class to display Spine data structure in a treeview with object classes at the outer level.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index.

static backward_sweep(index, call=None)[source]

Sweep the tree from the given index towards the root, and apply call on each.

forward_sweep(self, index, call=None)[source]

Sweep the tree from the given index towards the leaves, and apply call on each.

hasChildren(self, parent)[source]

Return True if not fetched, so the user can try and expand it.

canFetchMore(self, parent)[source]

Return True if not fetched.

fetchMore(self, parent)[source]

Build the deeper levels of the tree

build_tree(self, flat=False)[source]

Build the first level of the tree

new_object_class_row(self, db_map, object_class)[source]

Returns new object class item.

new_object_row(self, db_map, object_)[source]

Returns new object item.

new_relationship_class_row(self, db_map, relationship_class)[source]

Returns new relationship class item.

new_relationship_row(self, db_map, relationship)[source]

Returns new relationship item.

add_object_classes(self, db_map, object_classes)[source]

Add object class items to given db.

add_objects(self, db_map, objects)[source]

Add object items to the given db.

add_relationship_classes(self, db_map, relationship_classes)[source]

Add relationship class items to model.

add_relationships(self, db_map, relationships)[source]

Add relationship items to model.

add_objects_to_class(self, db_map, objects, object_class_item)[source]
add_relationships_classes_to_object(self, db_map, relationship_classes, object_item)[source]
add_relationships_to_class(self, db_map, relationships, rel_cls_item)[source]
update_object_classes(self, db_map, object_classes)[source]

Update object classes in the model. This of course means updating the object class name in relationship class items.

update_objects(self, db_map, objects)[source]

Update object in the model. This of course means updating the object name in relationship items.

update_relationship_classes(self, db_map, relationship_classes)[source]

Update relationship classes in the model.

update_relationships(self, db_map, relationships)[source]

Update relationships in the model. Move rows if the objects in the relationship change.

remove_object_class_rows(self, db_map, removed_rows)[source]
remove_object_rows(self, db_map, removed_rows, object_class_item)[source]
remove_relationship_class_rows(self, db_map, removed_rows, object_item)[source]
remove_relationship_rows(self, db_map, removed_rows, rel_cls_item)[source]
remove_object_classes(self, db_map, removed_ids)[source]

Remove object classes and their childs.

remove_objects(self, db_map, removed_ids)[source]

Remove objects and their childs.

remove_relationship_classes(self, db_map, removed_ids)[source]

Remove relationship classes and their childs.

remove_relationships(self, db_map, removed_ids)[source]

Remove relationships.

next_relationship_index(self, index)[source]

Find and return next ocurrence of relationship item.

class treeview_models.RelationshipTreeModel(parent)[source]

Bases: PySide2.QtGui.QStandardItemModel

A class to display Spine data structure in a treeview with relationship classes at the outer level.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index.

hasChildren(self, parent)[source]

Return True if not fetched, so the user can try and expand it.

canFetchMore(self, parent)[source]

Return True if not fetched.

fetchMore(self, parent)[source]

Build the deeper level of the tree

build_tree(self)[source]

Build the first level of the tree

new_relationship_class_row(self, db_map, relationship_class)[source]

Returns new relationship class item.

new_relationship_row(self, db_map, relationship)[source]

Returns new relationship item.

add_relationship_classes(self, db_map, relationship_classes)[source]

Add relationship class items to the model.

add_relationships(self, db_map, relationships)[source]

Add relationship items to model.

add_relationships_to_class(self, db_map, relationships, rel_cls_item)[source]
update_object_classes(self, db_map, object_classes)[source]

Update object classes in the model. This just means updating the object class name in relationship class items.

update_objects(self, db_map, objects)[source]

Update object in the model. This just means updating the object name in relationship items.

update_relationship_classes(self, db_map, relationship_classes)[source]

Update relationship classes in the model.

update_relationships(self, db_map, relationships)[source]

Update relationships in the model.

remove_relationship_class_rows(self, db_map, removed_rows)[source]
remove_relationship_rows(self, db_map, removed_rows, rel_cls_item)[source]
remove_object_classes(self, db_map, removed_ids)[source]

Remove object classes and their childs.

remove_objects(self, db_map, removed_ids)[source]

Remove objects and their childs.

remove_relationship_classes(self, db_map, removed_ids)[source]

Remove relationship classes and their childs.

remove_relationships(self, db_map, removed_ids)[source]

Remove relationships.

class treeview_models.SubParameterModel(parent)[source]

Bases: models.MinimalTableModel

A parameter model which corresponds to a slice of the entire table. The idea is to combine several of these into one big model. Allows specifying set of columns that are non-editable (e.g., object_class_name) TODO: how column insertion/removal impacts fixed_columns?

flags(self, index)[source]

Make fixed indexes non-editable.

data(self, index, role=Qt.DisplayRole)[source]

Paint background of fixed indexes gray.

batch_set_data(self, indexes, data)[source]

Batch set data for indexes. Try and update data in the database first, and if successful set data in the model.

items_to_update(self, indexes, data)[source]

A list of items (dict) to update in the database.

update_items_in_db(self, items_to_update)[source]

A list of ids of items updated in the database.

class treeview_models.SubParameterValueModel(parent)[source]

Bases: treeview_models.SubParameterModel

A parameter model which corresponds to a slice of an entire parameter value table. The idea is to combine several of these into one big model.

items_to_update(self, indexes, data)[source]

A list of items (dict) for updating in the database.

update_items_in_db(self, items_to_update)[source]

Try and update parameter values in database.

data(self, index, role=Qt.DisplayRole)[source]

Limit the display of JSON data.

class treeview_models.SubParameterDefinitionModel(parent)[source]

Bases: treeview_models.SubParameterModel

A parameter model which corresponds to a slice of an entire parameter definition table. The idea is to combine several of these into one big model.

items_to_update(self, indexes, data)[source]

A list of items (dict) for updating in the database.

update_items_in_db(self, items_to_update)[source]

Try and update parameter definitions in database.

data(self, index, role=Qt.DisplayRole)[source]

Limit the display of JSON data.

class treeview_models.EmptyParameterModel(parent)[source]

Bases: models.EmptyRowModel

An empty parameter model. It implements bath_set_data for all ‘EmptyParameter’ models.

batch_set_data(self, indexes, data)[source]

Batch set data for indexes. Set data in model first, then check if the database needs to be updated as well. Extend set of indexes as additional data is set (for emitting dataChanged at the end).

items_to_add(self, indexes)[source]
add_items_to_db(self, items_to_add)[source]
class treeview_models.EmptyParameterValueModel(parent)[source]

Bases: treeview_models.EmptyParameterModel

An empty parameter value model. Implements add_items_to_db for both EmptyObjectParameterValueModel and EmptyRelationshipParameterValueModel.

add_items_to_db(self, items_to_add)[source]

Add parameter values to database.

class treeview_models.EmptyObjectParameterValueModel(parent)[source]

Bases: treeview_models.EmptyParameterValueModel

An empty object parameter value model. Implements items_to_add.

items_to_add(self, indexes)[source]

A dictionary of rows (int) to items (dict) to add to the db. Extend set of indexes as additional data is set.

class treeview_models.EmptyRelationshipParameterValueModel(parent)[source]

Bases: treeview_models.EmptyParameterValueModel

An empty relationship parameter value model. Reimplements alsmot all methods from the super class EmptyParameterModel.

batch_set_data(self, indexes, data)[source]

Batch set data for indexes. A little different from the base class implementation, since here we need to support creating relationships on the fly.

relationships_on_the_fly(self, indexes)[source]

A dict of row (int) to relationship item (KeyedTuple), which can be either retrieved or added on the fly. Extend set of indexes as additional data is set.

add_relationships(self, relationships_to_add)[source]

Add relationships to database on the fly and return them.

items_to_add(self, indexes, relationships_on_the_fly)[source]

A dictionary of rows (int) to items (dict) to add to the db. Extend set of indexes as additional data is set.

class treeview_models.EmptyParameterDefinitionModel(parent)[source]

Bases: treeview_models.EmptyParameterModel

An empty parameter definition model.

add_items_to_db(self, items_to_add)[source]

Add parameter definitions to database.

class treeview_models.EmptyObjectParameterDefinitionModel(parent)[source]

Bases: treeview_models.EmptyParameterDefinitionModel

An empty object parameter definition model.

items_to_add(self, indexes)[source]

Return a dictionary of rows (int) to items (dict) to add to the db.

class treeview_models.EmptyRelationshipParameterDefinitionModel(parent)[source]

Bases: treeview_models.EmptyParameterDefinitionModel

An empty relationship parameter definition model.

items_to_add(self, indexes)[source]

Return a dictionary of rows (int) to items (dict) to add to the db. Extend set of indexes as additional data is set.

class treeview_models.ObjectParameterModel(parent=None)[source]

Bases: models.MinimalTableModel

A model that concatenates several ‘sub’ object parameter models, one per object class.

flags(self, index)[source]

Return flags for given index. Depending on the index’s row we will land on a specific model. Models whose object class id is not selected are skipped.

data(self, index, role=Qt.DisplayRole)[source]

Return data for given index and role. Depending on the index’s row we will land on a specific model. Models whose object class id is not selected are skipped.

rowCount(self, parent=QModelIndex())[source]

Return the sum of rows in all models. Skip models whose object class id is not selected.

batch_set_data(self, indexes, data)[source]

Batch set data for indexes. Distribute indexes and data among the different submodels and call batch_set_data on each of them.

insertRows(self, row, count, parent=QModelIndex())[source]

Find the right sub-model (or the empty model) and call insertRows on it.

removeRows(self, row, count, parent=QModelIndex())[source]

Find the right sub-models (or empty model) and call removeRows on them.

_handle_empty_rows_inserted(self, parent, first, last)[source]
invalidate_filter(self)[source]

Invalidate filter.

auto_filter_values(self, column)[source]

Return values to populate the auto filter of given column. Each ‘row’ in the returned value consists of: 1) The ‘checked’ state, True if the value hasn’t been filtered out 2) The value itself (an object name, a parameter name, a numerical value…) 3) A set of object class ids where the value is found.

set_filtered_out_values(self, column, values)[source]

Set values that need to be filtered out.

clear_filtered_out_values(self)[source]

Clear the set of values that need to be filtered out.

rename_object_classes(self, db_map, object_classes)[source]

Rename object classes in model.

rename_parameter_tags(self, db_map, parameter_tags)[source]

Rename parameter tags in model.

remove_object_classes(self, db_map, object_classes)[source]

Remove object classes from model.

remove_parameter_tags(self, db_map, parameter_tag_ids)[source]

Remove parameter tags from model.

_emit_data_changed_for_column(self, column)[source]

Emits data changed for an entire column. Used by rename_ and some remove_ methods where it’s too difficult to find out the exact rows that changed, especially because of filter status.

class treeview_models.ObjectParameterValueModel(parent=None)[source]

Bases: treeview_models.ObjectParameterModel

A model that concatenates several ‘sub’ object parameter value models, one per object class.

reset_model(self, main_data=None)[source]

Reset model data. Each sub-model is filled with parameter value data for a different object class.

update_filter(self)[source]

Update filter.

rename_objects(self, db_map, objects)[source]

Rename objects in model.

rename_parameter(self, db_map, parameter)[source]

Rename single parameter in model.

remove_objects(self, db_map, objects)[source]

Remove objects from model.

remove_parameters(self, db_map, parameters)[source]

Remove parameters from model.

move_rows_to_sub_models(self, rows)[source]

Move rows from empty row model to the a new sub_model. Called when the empty row model succesfully inserts new data in the db.

class treeview_models.ObjectParameterDefinitionModel(parent=None)[source]

Bases: treeview_models.ObjectParameterModel

A model that concatenates several object parameter definition models (one per object class) vertically.

reset_model(self, main_data=None)[source]

Reset model data. Each sub-model is filled with parameter definition data for a different object class.

update_filter(self)[source]

Update filter.

move_rows_to_sub_models(self, rows)[source]

Move rows from empty row model to a new sub_model. Called when the empty row model succesfully inserts new data in the db.

clear_parameter_value_lists(self, db_map, value_list_ids)[source]

Clear parameter value_lists from model.

rename_parameter_value_lists(self, db_map, value_lists)[source]

Rename parameter value_lists in model.

class treeview_models.RelationshipParameterModel(parent=None)[source]

Bases: models.MinimalTableModel

A model that combines several relationship parameter models (one per relationship class), one on top of the other.

add_object_class_id_lists(self, db_map, wide_relationship_class_list)[source]

Populate a dictionary of object class id lists per relationship class.

flags(self, index)[source]

Return flags for given index. Depending on the index’s row we will land on a specific model. Models whose relationship class id is not selected are skipped. Models whose object class id list doesn’t intersect the selected ones are also skipped.

data(self, index, role=Qt.DisplayRole)[source]

Return data for given index and role. Depending on the index’s row we will land on a specific model. Models whose relationship class id is not selected are skipped. Models whose object class id list doesn’t intersect the selected ones are also skipped.

rowCount(self, parent=QModelIndex())[source]

Return the sum of rows in all models. Models whose relationship class id is not selected are skipped. Models whose object class id list doesn’t intersect the selected ones are also skipped.

batch_set_data(self, indexes, data)[source]

Batch set data for indexes. Distribute indexes and data among the different submodels and call batch_set_data on each of them.

insertRows(self, row, count, parent=QModelIndex())[source]

Find the right sub-model (or the empty model) and call insertRows on it.

removeRows(self, row, count, parent=QModelIndex())[source]

Find the right sub-models (or empty model) and call removeRows on them.

_handle_empty_rows_inserted(self, parent, first, last)[source]
invalidate_filter(self)[source]

Invalidate filter.

auto_filter_values(self, column)[source]

Return values to populate the auto filter of given column. Each ‘row’ in the returned value consists of: 1) The ‘checked’ state, True if the value hasn’t been filtered out 2) The value itself (an object name, a parameter name, a numerical value…) 3) A set of relationship class ids where the value is found.

set_filtered_out_values(self, column, values)[source]

Set values that need to be filtered out.

clear_filtered_out_values(self)[source]

Clear the set of filtered out values.

rename_object_classes(self, db_map, object_classes)[source]

Rename object classes in model.

rename_relationship_classes(self, db_map, relationship_classes)[source]

Rename relationship classes in model.

rename_parameter_tags(self, db_map, parameter_tags)[source]

Rename parameter tags in model.

remove_object_classes(self, db_map, object_classes)[source]

Remove object classes from model.

remove_relationship_classes(self, db_map, relationship_classes)[source]

Remove relationship classes from model.

remove_parameter_tags(self, db_map, parameter_tag_ids)[source]

Remove parameter tags from model.

_emit_data_changed_for_column(self, column)[source]

Emits data changed for an entire column. Used by rename_ and some remove_ methods where it’s too difficult to find out the exact rows that changed, especially because of filter status.

class treeview_models.RelationshipParameterValueModel(parent=None)[source]

Bases: treeview_models.RelationshipParameterModel

A model that combines several relationship parameter value models (one per relationship class), one on top of the other.

reset_model(self, main_data=None)[source]

Reset model data. Each sub-model is filled with parameter value data for a different relationship class.

update_filter(self)[source]

Update filter.

move_rows_to_sub_models(self, rows)[source]

Move rows from empty row model to a new sub_model. Called when the empty row model succesfully inserts new data in the db.

rename_objects(self, db_map, objects)[source]

Rename objects in model.

remove_objects(self, db_map, objects)[source]

Remove objects from model.

remove_relationships(self, db_map, relationships)[source]

Remove relationships from model.

rename_parameter(self, db_map, parameter)[source]

Rename single parameter in model.

remove_parameters(self, db_map, parameters)[source]

Remove parameters from model.

class treeview_models.RelationshipParameterDefinitionModel(parent=None)[source]

Bases: treeview_models.RelationshipParameterModel

A model that combines several relationship parameter definition models (one per relationship class), one on top of the other.

reset_model(self, main_data=None)[source]

Reset model data. Each sub-model is filled with parameter definition data for a different relationship class.

update_filter(self)[source]

Update filter.

move_rows_to_sub_models(self, rows)[source]

Move rows from empty row model to a new sub_model. Called when the empty row model succesfully inserts new data in the db.

clear_parameter_value_lists(self, db_map, value_list_ids)[source]

Clear parameter value_lists from model.

rename_parameter_value_lists(self, db_map, value_lists)[source]

Rename parameter value_lists in model.

class treeview_models.ObjectParameterDefinitionFilterProxyModel(parent, parameter_definition_id_column)[source]

Bases: PySide2.QtCore.QSortFilterProxyModel

A filter proxy model for object parameter models.

update_filter(self, parameter_definition_ids)[source]

Update filter.

set_filtered_out_values(self, column, values)[source]

Set values that need to be filtered out.

clear_filtered_out_values(self)[source]

Clear the filtered out values.

auto_filter_accepts_row(self, source_row, source_parent, ignored_columns=None)[source]

Accept or reject row.

main_filter_accepts_row(self, source_row, source_parent)[source]

Accept or reject row.

filterAcceptsRow(self, source_row, source_parent)[source]

Accept or reject row.

batch_set_data(self, indexes, data)[source]
class treeview_models.ObjectParameterValueFilterProxyModel(parent, parameter_definition_id_column, object_id_column, db_column)[source]

Bases: treeview_models.ObjectParameterDefinitionFilterProxyModel

A filter proxy model for object parameter value models.

update_filter(self, parameter_definition_ids, object_ids)[source]

Update filter.

main_filter_accepts_row(self, source_row, source_parent)[source]

Accept or reject row.

class treeview_models.RelationshipParameterDefinitionFilterProxyModel(parent, parameter_definition_id_column)[source]

Bases: PySide2.QtCore.QSortFilterProxyModel

A filter proxy model for relationship parameter definition models.

update_filter(self, parameter_definition_ids)[source]

Update filter.

set_filtered_out_values(self, column, values)[source]

Set values that need to be filtered out.

clear_filtered_out_values(self)[source]

Clear the set of values that need to be filtered out.

auto_filter_accepts_row(self, source_row, source_parent, ignored_columns=None)[source]

Accept or reject row.

main_filter_accepts_row(self, source_row, source_parent)[source]

Accept or reject row.

filterAcceptsRow(self, source_row, source_parent)[source]

Accept or reject row.

batch_set_data(self, indexes, data)[source]
class treeview_models.RelationshipParameterValueFilterProxyModel(parent, parameter_definition_id_column, object_id_list_column, db_column)[source]

Bases: treeview_models.RelationshipParameterDefinitionFilterProxyModel

A filter proxy model for relationship parameter value models.

update_filter(self, parameter_definition_ids, object_ids, object_id_lists)[source]

Update filter.

main_filter_accepts_row(self, source_row, source_parent)[source]

Accept or reject row.

class treeview_models.TreeNode(parent, row, text=None, level=None, identifier=None)[source]

A helper class to use as the internalPointer of indexes in ParameterValueListModel.

Attributes
parent (TreeNode): the parent node row (int): the row, needed by ParameterValueListModel.parent() text (str, NoneType): the text to show level (int, NoneType): the level in the tree id (int, NoneType): the id from the db table
class treeview_models.ParameterValueListModel(parent)[source]

Bases: PySide2.QtCore.QAbstractItemModel

A class to display parameter value list data in a treeview.

build_tree(self)[source]

Initialize the internal data structure of TreeNode instances.

index(self, row, column, parent=QModelIndex())[source]

Returns the index of the item in the model specified by the given row, column and parent index. Toplevel indexes get their pointer from the _root_nodes attribute; whereas inner indexes get their pointer from the child_nodes attribute of the parent node.

parent(self, index)[source]

Returns the parent of the model item with the given index. Use the internal pointer to retrieve the parent node and use it to create the parent index.

rowCount(self, parent=QModelIndex())[source]

Returns the number of rows under the given parent. Get it from the lenght of the appropriate list.

columnCount(self, parent=QModelIndex())[source]

Returns the number of columns under the given parent. Always 1.

data(self, index, role=Qt.DisplayRole)[source]

Returns the data stored under the given role for the item referred to by the index. Bold toplevel items. Get the DisplayRole from the text attribute of the internal pointer.

flags(self, index)[source]

Returns the item flags for the given index.

setData(self, index, value, role=Qt.EditRole)[source]

Sets the role data for the item at index to value. Returns True if successful; otherwise returns False. Basically just update the text attribute of the internal pointer.

appendRows(self, count, parent=QModelIndex())[source]

Append count rows into the model. Items in the new row will be children of the item represented by the parent model index.

_handle_data_changed(self, top_left, bottom_right, roles=None)[source]

Called when data in the model changes.

append_empty_rows(self, index)[source]

Append emtpy rows if index is the last children, so the user can continue editing the model.

items_to_add_and_update(self, first, last, parent)[source]

Return list of items to add and update in the db.

batch_set_data(self, indexes, values)[source]

Set edit role for indexes to values in batch.

removeRow(self, row, parent=QModelIndex())[source]

Remove row under parent, but never the last row (which is the empty one)

class treeview_models.LazyLoadingArrayModel(parent, stride=256)[source]

Bases: models.EmptyRowModel

A model of array data, used by TreeViewForm.

parent

the parent widget

Type:JSONEditor
stride

The number of elements to fetch

Type:int
reset_model(self, data)[source]

Store given array into the _orig_data attribute. Initialize first _stride rows of the model.

canFetchMore(self, parent)[source]
fetchMore(self, parent)[source]

Pop data from the _orig_data attribute and add it to the model.

all_data(self)[source]

Return all data into a list.