RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
gui.repository_model.RepositoryModel Class Reference

An implementation of a Qt model object to handle repositories accessible via RepositoryControl, i.e. More...

Inheritance diagram for gui.repository_model.RepositoryModel:

Public Member Functions

 __init__ (self, RepositoryControl repo, *args, **kwargs)
 
 get_repo_control (self)
 Return the repository control object this model was constructed with.
 
 set_repo_control (self, RepositoryControl repo)
 Replace the active repository control, reconnect its signals, and reinitialize the model state.
 
bool has_pending_requests (self)
 Returns True if there are any pending asynchronous requests started by the fetchMore or commit methods.
 
 cancel_pending_requests (self)
 This method will cancel any pending asynchronous fetchMore/commit requests.
 
QModelIndex index_from_datapoint_path (self, DataPointPath path)
 Returns the index that holds the given datapoint path, otherwise an invalid index if the path cannot be found.
 
int rowCount (self, QModelIndex parent=QModelIndex())
 Returns the number of children for a given parent.
 
int columnCount (self, QModelIndex parent=QModelIndex())
 Returns the number of data columns each child has for a given parent.
 
QModelIndex index (self, int row, int column, QModelIndex parent=QModelIndex())
 Creates a child model index for a given row and column of the indicated parent.
 
QModelIndex parent (self, QModelIndex index)
 Return the model index of the corresponding parent tree node for the given model index.
 
bool hasChildren (self, QModelIndex parent=QModelIndex())
 Returns True if the parent tree node has any children, otherwise False.
 
Qt.ItemFlags flags (self, QModelIndex index)
 Returns the flags applicable for a particular tree node's model index.
 
 data (self, QModelIndex index, int role=Qt.DisplayRole)
 Return the appropriately interpreted data from the model for a given role.
 
bool setData (self, QModelIndex index, value, int role=Qt.EditRole)
 When data is updated using the EditRole, the underlying node object is updated and we return True.
 
 headerData (self, int column, Qt.Orientation orientation, int role=Qt.DisplayRole)
 Returns the header string for display for a specific column.
 
bool setHeaderData (self, int column, Qt.Orientation orientation, value, int role=Qt.EditRole)
 Allows to change the header string for a particular column.
 
bool insertRow (self, int position, QModelIndex parent=QModelIndex(), bool is_leaf=False, type=RtcString)
 Insert a single row at the given position under the parent index of the tree.
 
bool insertRows (self, int position, int rows, QModelIndex parent=QModelIndex(), bool is_leaf=False, type=RtcString)
 Inserts multiple rows at the given position under the parent index of the tree.
 
bool removeRows (self, int position, int rows, QModelIndex parent=QModelIndex())
 Removes one or more rows from an initial position.
 
Qt.DropActions supportedDropActions (self)
 Returns the drop actions supported by this model.
 
list mimeTypes (self)
 Returns the MIME types supported by this model for drag and drop.
 
bool dropMimeData (self, QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
 Handles data provided by a drag and drop action for the tree model.
 
bool canFetchMore (self, QModelIndex parent)
 Returns True if there is more data to be fetched for the given parent tree node, i.e.
 
 fetchMore (self, QModelIndex parent)
 Retrieves additional data for the given parent tree node in an asynchronous manner.
 
 commit (self)
 Slot method to trigger asynchronous committing of all cached data.
 
 load_data (self)
 Reads all datapoints from the repository into the model.
 
 save_data (self)
 Writes all cached datapoints in the model back to the repository directly.
 
 on_get_children_complete (self, path, dppaths, subpaths, completion)
 Completion handler for successful get_children requests that dispatches the invocation to the completion object.
 
 on_get_children_failed (self, path, exception, completion)
 Completion handler for failed get_children requests that dispatches the invocation to the completion object.
 
 on_data_point_exists_complete (self, path, exists, completion)
 Completion handler for successful data_point_exists requests that dispatches the invocation to the completion object.
 
 on_data_point_exists_failed (self, path, exception, completion)
 Completion handler for failed data_point_exists requests that dispatches the invocation to the completion object.
 
 on_create_data_point_complete (self, path, completion)
 Completion handler for successful create_data_point requests that dispatches the invocation to the completion object.
 
 on_create_data_point_failed (self, path, exception, completion)
 Completion handler for failed create_data_point requests that dispatches the invocation to the completion object.
 
 on_delete_data_point_complete (self, path, completion)
 Completion handler for successful delete_data_point requests that dispatches the invocation to the completion object.
 
 on_delete_data_point_failed (self, path, exception, completion)
 Completion handler for failed delete_data_point requests that dispatches the invocation to the completion object.
 
 on_read_meta_data_complete (self, path, metadata, completion)
 Completion handler for successful read_meta_data requests that dispatches the invocation to the completion object.
 
 on_read_meta_data_failed (self, path, exception, completion)
 Completion handler for failed read_meta_data requests that dispatches the invocation to the completion object.
 
 on_read_data_point_complete (self, path, completion)
 Completion handler for successful read_data_point requests that dispatches the invocation to the completion object.
 
 on_read_data_point_failed (self, path, exception, completion)
 Completion handler for failed read_data_point requests that dispatches the invocation to the completion object.
 
 on_data_point_updated (self, path, value, completion)
 Completion handler for data_point_updated signals that dispatches the invocation to the completion object.
 
 on_write_meta_data_complete (self, path, completion)
 Completion handler for successful write_meta_data requests that dispatches the invocation to the completion object.
 
 on_write_meta_data_failed (self, path, exception, completion)
 Completion handler for failed write_meta_data requests that dispatches the invocation to the completion object.
 
 on_write_data_point_complete (self, path, completion)
 Completion handler for successful write_data_point requests that dispatches the invocation to the completion object.
 
 on_write_data_point_failed (self, path, exception, completion)
 Completion handler for failed write_data_point requests that dispatches the invocation to the completion object.
 

Public Attributes

 on_get_children_complete = repo
 
 on_get_children_failed
 
 on_data_point_exists_failed
 
 on_create_data_point_failed
 
 on_delete_data_point_failed
 
 on_read_meta_data_complete
 
 on_read_meta_data_failed
 
 on_read_data_point_complete
 
 on_read_data_point_failed
 
 on_data_point_updated
 
 on_write_meta_data_complete
 
 on_write_meta_data_failed
 
 on_write_data_point_failed
 
 on_data_point_exists_complete
 
 on_create_data_point_complete
 
 on_delete_data_point_complete
 
 on_write_data_point_complete
 

Static Public Attributes

 new_cached_values = Signal()
 Signal indicating that the model has been modified and contains new cached values, i.e.
 
 commit_complete = Signal(object)
 Signal indicating that a commit request has completed.
 

Protected Member Functions

TreeNode _index_to_tree_node (self, QModelIndex index)
 Fetch the internal tree node corresponding to the model index, or the root node if the index is invalid.
 
QModelIndex _tree_node_to_index (self, TreeNode node, int column=0)
 Construct a model index for the given internal tree node.
 

Protected Attributes

 _repo_control = None
 
 _headers = list(self._default_headers)
 
 _rootnode = TreeNode(DataPointPath("/"))
 
 _pending_request_completions = set()
 
list _nodes_pending_deletion = []
 

Static Protected Attributes

tuple _default_headers
 
dict _conversion_function_map_display_role
 
dict _conversion_function_map_edit_role_read
 
dict _conversion_function_map_edit_role_write
 

Detailed Description

An implementation of a Qt model object to handle repositories accessible via RepositoryControl, i.e.

implementing RepositoryIf.

Data is lazy loaded and cached such that only the parts of the data that GUI view widgets actually request is fetched.

Constructor & Destructor Documentation

◆ __init__()

gui.repository_model.RepositoryModel.__init__ ( self,
RepositoryControl repo,
* args,
** kwargs )

Member Function Documentation

◆ _index_to_tree_node()

TreeNode gui.repository_model.RepositoryModel._index_to_tree_node ( self,
QModelIndex index )
protected

Fetch the internal tree node corresponding to the model index, or the root node if the index is invalid.

◆ _tree_node_to_index()

QModelIndex gui.repository_model.RepositoryModel._tree_node_to_index ( self,
TreeNode node,
int column = 0 )
protected

Construct a model index for the given internal tree node.

If the node refers to the root node then an invalid index is returned.

◆ cancel_pending_requests()

gui.repository_model.RepositoryModel.cancel_pending_requests ( self)

This method will cancel any pending asynchronous fetchMore/commit requests.

Note that this method will not attempt any kind of rollback. i.e. the internal data representation may be partially complete or the repository may only be partially updated. Therefore, care needs to be taken when using this method. Normally it should only be used in special cases or in combination with load_data and save_data.

◆ canFetchMore()

bool gui.repository_model.RepositoryModel.canFetchMore ( self,
QModelIndex parent )

Returns True if there is more data to be fetched for the given parent tree node, i.e.

the node or one of its children/descendants is marked as stale.

◆ columnCount()

int gui.repository_model.RepositoryModel.columnCount ( self,
QModelIndex parent = QModelIndex() )

Returns the number of data columns each child has for a given parent.

By convention the parent's index column value should be zero.

◆ commit()

gui.repository_model.RepositoryModel.commit ( self)

Slot method to trigger asynchronous committing of all cached data.

Completion of the requests is further handled in the various slot methods that will be signaled by the RepositoryControl object to indicate completion.

Once the commit has completed the commit_complete signal is sent. In case of an error the signal is sent with an exception object indicating the error. Otherwise None is sent to indicate success.

The method attempts to progress as much as possible if errors occur. However, this may arise in inconsistencies between the internal cached data and the actual repository state. The user may want to simply reset the model in that case.

◆ data()

gui.repository_model.RepositoryModel.data ( self,
QModelIndex index,
int role = Qt.DisplayRole )

Return the appropriately interpreted data from the model for a given role.

In the case of the EditRole the following is returned for the various columns: "Datapoint Path" - The datapoint short name, i.e. not the full path. "Value" - The datapoint value as a common Python type mapping to standard Qt edit widgets. "Type" - The type class identifying the datapoint type. Similarly for the UserRole we return the following: "Datapoint Path" - The full path as a DataPointPath object. "Value" - The underlying datapoint value, i.e. not converted to a common Python type. "Type" - The type class identifying the datapoint type.

◆ dropMimeData()

bool gui.repository_model.RepositoryModel.dropMimeData ( self,
QMimeData data,
Qt.DropAction action,
int row,
int column,
QModelIndex parent )

Handles data provided by a drag and drop action for the tree model.

Currently just defaults to QAbstractItemModel.

◆ fetchMore()

gui.repository_model.RepositoryModel.fetchMore ( self,
QModelIndex parent )

Retrieves additional data for the given parent tree node in an asynchronous manner.

Completion of the requests is further handled in the various slot methods that will be signaled by the RepositoryControl object to indicate completion.

The method attempts to progress as much as possible if errors occur. However, this may arise in inconsistencies between the internal cached data and the actual repository state. The user may want to simply reset the model in that case.

◆ flags()

Qt.ItemFlags gui.repository_model.RepositoryModel.flags ( self,
QModelIndex index )

Returns the flags applicable for a particular tree node's model index.

◆ get_repo_control()

gui.repository_model.RepositoryModel.get_repo_control ( self)

Return the repository control object this model was constructed with.

◆ has_pending_requests()

bool gui.repository_model.RepositoryModel.has_pending_requests ( self)

Returns True if there are any pending asynchronous requests started by the fetchMore or commit methods.

Otherwise, False is returned if there are no pending requests.

◆ hasChildren()

bool gui.repository_model.RepositoryModel.hasChildren ( self,
QModelIndex parent = QModelIndex() )

Returns True if the parent tree node has any children, otherwise False.

By convention the parent's index column value should be zero.

◆ headerData()

gui.repository_model.RepositoryModel.headerData ( self,
int column,
Qt.Orientation orientation,
int role = Qt.DisplayRole )

Returns the header string for display for a specific column.

Only the horizontal headers are supported. 'None' is returned for all unsupported columns, orientations and roles.

◆ index()

QModelIndex gui.repository_model.RepositoryModel.index ( self,
int row,
int column,
QModelIndex parent = QModelIndex() )

Creates a child model index for a given row and column of the indicated parent.

By convention the parent's index column value should be zero.

Parameters
rowCorresponds to the child number within the list of the parent's children.
columnThe column or data field being referred to for the child.
parentThe parent tree node's model index.

◆ index_from_datapoint_path()

QModelIndex gui.repository_model.RepositoryModel.index_from_datapoint_path ( self,
DataPointPath path )

Returns the index that holds the given datapoint path, otherwise an invalid index if the path cannot be found.

◆ insertRow()

bool gui.repository_model.RepositoryModel.insertRow ( self,
int position,
QModelIndex parent = QModelIndex(),
bool is_leaf = False,
type = RtcString )

Insert a single row at the given position under the parent index of the tree.

If parent index is invalid the row is inserted under the root of the tree.

◆ insertRows()

bool gui.repository_model.RepositoryModel.insertRows ( self,
int position,
int rows,
QModelIndex parent = QModelIndex(),
bool is_leaf = False,
type = RtcString )

Inserts multiple rows at the given position under the parent index of the tree.

If parent index is invalid the rows are inserted under the root of the tree.

◆ load_data()

gui.repository_model.RepositoryModel.load_data ( self)

Reads all datapoints from the repository into the model.

This skips the repository control interface. If there is a lot of data to read, this method can take a significant amount of time to complete and block the GUI. Therefore it should typically not be used directly. One can use recursive calls to fetchMore instead.

A RuntimeError is raised if there are pending fetchMore or commit requests.

◆ mimeTypes()

list gui.repository_model.RepositoryModel.mimeTypes ( self)

Returns the MIME types supported by this model for drag and drop.

Currently just defaults to QAbstractItemModel.

◆ on_create_data_point_complete()

gui.repository_model.RepositoryModel.on_create_data_point_complete ( self,
path,
completion )

Completion handler for successful create_data_point requests that dispatches the invocation to the completion object.

◆ on_create_data_point_failed()

gui.repository_model.RepositoryModel.on_create_data_point_failed ( self,
path,
exception,
completion )

Completion handler for failed create_data_point requests that dispatches the invocation to the completion object.

◆ on_data_point_exists_complete()

gui.repository_model.RepositoryModel.on_data_point_exists_complete ( self,
path,
exists,
completion )

Completion handler for successful data_point_exists requests that dispatches the invocation to the completion object.

◆ on_data_point_exists_failed()

gui.repository_model.RepositoryModel.on_data_point_exists_failed ( self,
path,
exception,
completion )

Completion handler for failed data_point_exists requests that dispatches the invocation to the completion object.

◆ on_data_point_updated()

gui.repository_model.RepositoryModel.on_data_point_updated ( self,
path,
value,
completion )

Completion handler for data_point_updated signals that dispatches the invocation to the completion object.

◆ on_delete_data_point_complete()

gui.repository_model.RepositoryModel.on_delete_data_point_complete ( self,
path,
completion )

Completion handler for successful delete_data_point requests that dispatches the invocation to the completion object.

◆ on_delete_data_point_failed()

gui.repository_model.RepositoryModel.on_delete_data_point_failed ( self,
path,
exception,
completion )

Completion handler for failed delete_data_point requests that dispatches the invocation to the completion object.

◆ on_get_children_complete()

gui.repository_model.RepositoryModel.on_get_children_complete ( self,
path,
dppaths,
subpaths,
completion )

Completion handler for successful get_children requests that dispatches the invocation to the completion object.

◆ on_get_children_failed()

gui.repository_model.RepositoryModel.on_get_children_failed ( self,
path,
exception,
completion )

Completion handler for failed get_children requests that dispatches the invocation to the completion object.

◆ on_read_data_point_complete()

gui.repository_model.RepositoryModel.on_read_data_point_complete ( self,
path,
completion )

Completion handler for successful read_data_point requests that dispatches the invocation to the completion object.

◆ on_read_data_point_failed()

gui.repository_model.RepositoryModel.on_read_data_point_failed ( self,
path,
exception,
completion )

Completion handler for failed read_data_point requests that dispatches the invocation to the completion object.

◆ on_read_meta_data_complete()

gui.repository_model.RepositoryModel.on_read_meta_data_complete ( self,
path,
metadata,
completion )

Completion handler for successful read_meta_data requests that dispatches the invocation to the completion object.

◆ on_read_meta_data_failed()

gui.repository_model.RepositoryModel.on_read_meta_data_failed ( self,
path,
exception,
completion )

Completion handler for failed read_meta_data requests that dispatches the invocation to the completion object.

◆ on_write_data_point_complete()

gui.repository_model.RepositoryModel.on_write_data_point_complete ( self,
path,
completion )

Completion handler for successful write_data_point requests that dispatches the invocation to the completion object.

◆ on_write_data_point_failed()

gui.repository_model.RepositoryModel.on_write_data_point_failed ( self,
path,
exception,
completion )

Completion handler for failed write_data_point requests that dispatches the invocation to the completion object.

◆ on_write_meta_data_complete()

gui.repository_model.RepositoryModel.on_write_meta_data_complete ( self,
path,
completion )

Completion handler for successful write_meta_data requests that dispatches the invocation to the completion object.

◆ on_write_meta_data_failed()

gui.repository_model.RepositoryModel.on_write_meta_data_failed ( self,
path,
exception,
completion )

Completion handler for failed write_meta_data requests that dispatches the invocation to the completion object.

◆ parent()

QModelIndex gui.repository_model.RepositoryModel.parent ( self,
QModelIndex index )

Return the model index of the corresponding parent tree node for the given model index.

◆ removeRows()

bool gui.repository_model.RepositoryModel.removeRows ( self,
int position,
int rows,
QModelIndex parent = QModelIndex() )

Removes one or more rows from an initial position.

The removed rows corresponding to the tree node children of the parent tree node indicated by the parent model index.

◆ rowCount()

int gui.repository_model.RepositoryModel.rowCount ( self,
QModelIndex parent = QModelIndex() )

Returns the number of children for a given parent.

By convention the parent's index column value should be zero.

◆ save_data()

gui.repository_model.RepositoryModel.save_data ( self)

Writes all cached datapoints in the model back to the repository directly.

This skips the repository control interface. If there is a lot of data to write back, this method can take a significant amount of time to complete and block the GUI. Therefore it should typically not be used directly. Use the commit method instead.

A RuntimeError is raised if there are pending fetchMore or commit requests.

◆ set_repo_control()

gui.repository_model.RepositoryModel.set_repo_control ( self,
RepositoryControl repo )

Replace the active repository control, reconnect its signals, and reinitialize the model state.

Warning
This method is not safe to call if has_pending_requests returns True.

◆ setData()

bool gui.repository_model.RepositoryModel.setData ( self,
QModelIndex index,
value,
int role = Qt.EditRole )

When data is updated using the EditRole, the underlying node object is updated and we return True.

If the column corresponding to the datapoint's name is being edited then the node and all child nodes are appropriately renamed. If the node cannot be updated for the given index and role then False is returned.

◆ setHeaderData()

bool gui.repository_model.RepositoryModel.setHeaderData ( self,
int column,
Qt.Orientation orientation,
value,
int role = Qt.EditRole )

Allows to change the header string for a particular column.

Only the horizontal orientation is supported for the EditRole.

◆ supportedDropActions()

Qt.DropActions gui.repository_model.RepositoryModel.supportedDropActions ( self)

Returns the drop actions supported by this model.

Currently just defaults to QAbstractItemModel.

Member Data Documentation

◆ _conversion_function_map_display_role

dict gui.repository_model.RepositoryModel._conversion_function_map_display_role
staticprotected

◆ _conversion_function_map_edit_role_read

dict gui.repository_model.RepositoryModel._conversion_function_map_edit_role_read
staticprotected

◆ _conversion_function_map_edit_role_write

dict gui.repository_model.RepositoryModel._conversion_function_map_edit_role_write
staticprotected

◆ _default_headers

tuple gui.repository_model.RepositoryModel._default_headers
staticprotected

◆ _headers

gui.repository_model.RepositoryModel._headers = list(self._default_headers)
protected

◆ _nodes_pending_deletion

list gui.repository_model.RepositoryModel._nodes_pending_deletion = []
protected

◆ _pending_request_completions

gui.repository_model.RepositoryModel._pending_request_completions = set()
protected

◆ _repo_control

gui.repository_model.RepositoryModel._repo_control = None
protected

◆ _rootnode

gui.repository_model.RepositoryModel._rootnode = TreeNode(DataPointPath("/"))
protected

◆ commit_complete

gui.repository_model.RepositoryModel.commit_complete = Signal(object)
static

Signal indicating that a commit request has completed.

The received arguments is either None to indicate a successful completion or a list of exception objects indicating failure.

◆ new_cached_values

gui.repository_model.RepositoryModel.new_cached_values = Signal()
static

Signal indicating that the model has been modified and contains new cached values, i.e.

one can call the commit method to write these back to the repository.

◆ on_create_data_point_complete

gui.repository_model.RepositoryModel.on_create_data_point_complete

◆ on_create_data_point_failed

gui.repository_model.RepositoryModel.on_create_data_point_failed

◆ on_data_point_exists_complete

gui.repository_model.RepositoryModel.on_data_point_exists_complete

◆ on_data_point_exists_failed

gui.repository_model.RepositoryModel.on_data_point_exists_failed

◆ on_data_point_updated

gui.repository_model.RepositoryModel.on_data_point_updated

◆ on_delete_data_point_complete

gui.repository_model.RepositoryModel.on_delete_data_point_complete

◆ on_delete_data_point_failed

gui.repository_model.RepositoryModel.on_delete_data_point_failed

◆ on_get_children_complete

gui.repository_model.RepositoryModel.on_get_children_complete = repo

◆ on_get_children_failed

gui.repository_model.RepositoryModel.on_get_children_failed

◆ on_read_data_point_complete

gui.repository_model.RepositoryModel.on_read_data_point_complete

◆ on_read_data_point_failed

gui.repository_model.RepositoryModel.on_read_data_point_failed

◆ on_read_meta_data_complete

gui.repository_model.RepositoryModel.on_read_meta_data_complete

◆ on_read_meta_data_failed

gui.repository_model.RepositoryModel.on_read_meta_data_failed

◆ on_write_data_point_complete

gui.repository_model.RepositoryModel.on_write_data_point_complete

◆ on_write_data_point_failed

gui.repository_model.RepositoryModel.on_write_data_point_failed

◆ on_write_meta_data_complete

gui.repository_model.RepositoryModel.on_write_meta_data_complete

◆ on_write_meta_data_failed

gui.repository_model.RepositoryModel.on_write_meta_data_failed

The documentation for this class was generated from the following file: