collection_proxy

Proxy representing a collection of entities that live in the model thread.

The proxy represents them in the gui thread and provides access to the data with zero delay. If the data is not yet present in the proxy, dummy data is returned and an update signal is emitted when the correct data is available.

class camelot.view.proxy.collection_proxy.CollectionProxy(admin, max_number_of_rows=10, flush_changes=True, cache_collection_proxy=None)[source]

The CollectionProxy contains a limited copy of the data in the actual collection, usable for fast visualisation in a QtWidgets.QTableView

The behavior of the QtWidgets.QTableView, such as what happens when the user clicks on a row is defined in the ObjectAdmin class.

append_object(obj)[source]

Append an object to this collection

Parameters:obj – the object to be added to the collection
Returns:the new number of rows in the collection
data(index, role=0)[source]
Returns:the data at index for the specified role

This function will return ValueLoading when the data has not yet been fetched from the underlying model. It will then send a request to the model thread to fetch this data. Once the data is readily available, the dataChanged signal will be emitted

Using Qt.UserRole as a role will return all the field attributes of the index.

Using Qt.UserRole+1 will return the object of which an attribute is displayed in that specific cell

flags(index)[source]

Returns the item flags for the given index

get_admin()[source]

Get the admin object associated with this model

handleRowUpdate(row)[source]

Handles the update of a row when this row might be out of date

handle_entity_create(sender, entity)[source]

Handles the entity signal, indicating that the model is out of date

handle_entity_delete(sender, obj)[source]

Handles the entity signal, indicating that the model is out of date

handle_entity_update(sender, entity)[source]

Handles the entity signal, indicating that the model is out of date

hasUnflushedRows()[source]

The model has rows that have not been flushed to the database yet, because the row is invalid

headerData(section, orientation, role)[source]

In case the columns have not been set yet, don’t even try to get information out of them

map_to_source(sorted_row_number)[source]

Converts a sorted row number to a row number of the source collection

max_number_of_rows[source]

The maximum number of rows to be displayed at once

setData(index, value, role=2)[source]

Value should be a function taking no arguments that returns the data to be set

This function will then be called in the model_thread

setRowCount(rows)[source]

Callback method to set the number of rows @param rows the new number of rows

set_columns(columns)[source]

Callback method to set the columns

Parameters:columns – a list with fields to be displayed of the form [(‘field_name’, field_attributes), ...] as

returned by the get_columns method of the EntityAdmin class

set_value(collection)[source]
Parameters:collection – the list of objects to display
sort(column, order)[source]

reimplementation of the QtGui.QAbstractItemModel its sort function

class camelot.view.proxy.collection_proxy.ProxyDict[source]

Subclass of dictionary to fool the Qt Variant object and prevent it from converting dictionary keys to whatever Qt object, but keep everything python

class camelot.view.proxy.collection_proxy.RowModelContext[source]

A list action model context for a single row. This context is used to get the state of the list action on a row

class camelot.view.proxy.collection_proxy.SortingRowMapper[source]

Class mapping rows of a collection 1:1 without sorting and filtering, unless a mapping has been defined explicitly

camelot.view.proxy.collection_proxy.strip_data_from_object(obj, columns)[source]

For every column in columns, get the corresponding value from the object. Getting a value from an object is time consuming, so using this function should be minimized. :param obj: the object of which to get data :param columns: a list of columns for which to get data

camelot.view.proxy.collection_proxy.stripped_data_to_unicode(stripped_data, obj, static_field_attributes, dynamic_field_attributes)[source]

Extract for each field in the row data a ‘visible’ form of data