DictModel

Methods

qconcurrency.models.DictModel.__init__(columns)
param columns:Defines the available columns for the table/tree this QtGui.QStandardItemModel
qconcurrency.models.DictModel.add_row(key[, …]) Adds a new (toplevel) row to this DictModel, henceforth referred to by the key key.
qconcurrency.models.DictModel.clear() Removes all items from QtGui.QStandardItemModel
qconcurrency.models.DictModel.column_index([…]) Returns the column-index for a specific columnname at a specific level.
qconcurrency.models.DictModel.columns([level]) Returns the columns for a particular level of nested-table within this qconcurrency.models.DictModel.
qconcurrency.models.DictModel.default_columnvals([level]) Returns the default-columnvals for a particular level of nested-table.
qconcurrency.models.DictModel.has_key(k) Wraps self._data.has_key
qconcurrency.models.DictModel.hierarchy() Returns the model’s hierarchy tuple
qconcurrency.models.DictModel.items() Lists a tuple with the key and DictModelRow
qconcurrency.models.DictModel.keys() Lists key value for every row in the
qconcurrency.models.DictModel.removeRow(key)
qconcurrency.models.DictModel.staticMetaObject
qconcurrency.models.DictModel.takeRow(key)
qconcurrency.models.DictModel.values() Lists DictModelRow objects for every row in the

Documentation

class qconcurrency.models.DictModel(columns, hierarchy=None)[source]

Bases: PySide.QtGui.QStandardItemModel

Customized python interface for QtGui.QStandardItemModel so that it’s values, and nested tables can be accessed like a python dictionary.

Example

Simple Example:

| _id | firstname | lastname  | username |
|========================================|
| 101 | luke      | skywalker | lukes    |
| 102 | leia      | skywalker | leias    |
|========================================|
model = DictModel( columns=('firstname','lastname','username') )

model.add_row( 101, columnvals = {
        'firstname':'luke'      ,
        'lastname' :'skywalker' ,
        'username' :'lukes'     ,
    }
)

userId = 101
print( model[userId].column('firstname') )
>>> 'luke'

print( model[userId].columnvals() )
>>> {'_id':101, 'firstname':'luke', 'lastname':'skywalker', 'username':'lukes'}

Nested-Table Example:

|=============|
| _id | class |  # level: 'jedi_class'
|=============|
| 101 | sith  |
|  |===========================================|
|  | _id | firstname  | lastname   | username  | # level: 'user'
|  |===========================================|
|  | 56  | Darth      | Vader      | anakins   |
|  | 57  | Darth      | Maul       | darthm    |
|  |===========================================|
|             |
| 102 | jedi  |
|  |===========================================|
|  | _id | firstname  | lastname   | username  | # level: 'user'
|  |===========================================|
|  | 58  | Mace       | Windu      | macew     |
|  | 59  | Ben        | Kenobi     | benk      |
|  |===========================================|
|             |
|=============|
model = DictModel(
        hierarchy = ('jedi_class','user'),
        columns   = {
            'jedi_class':  ('class'),
            'user':        ('firstname','lastname','username')
        },
    )

sith_row = model.add_row( 101, {'class':'sith'} )
jedi_row = model.add_row( 102, {'class':'jedi'} )
sith_row.add_child( 56, {'firstname':'Darth', 'lastname':'Vader', 'username':'anakins'} )
sith_row.add_child( 57, {'firstname':'Darth', 'lastname':'Maul',  'username':'darthm'} )

jediclassId = 101
userId      =  56
print( model[jediclassId][userId].column('username') )
>>> 'anakins'

print( model[jediclassId].level() )
>>> 'jedi_class'

print( model[jediclassId][userId].level() )
>>> 'user'

qconcurrency.models.DictModel column datatypes

|===============================================|
| _id          | columnA        | columnB       |
|===============================================|
| DictModelRow |  QStandardItem | QStandardItem |
|   |===============================================|
|   | _id          | columnA        | columnB       |
|   |===============================================|
|   | DictModelRow |  QStandardItem | QStandardItem |
|   |===============================================|
|                                               |
|===============================================|
__init__(columns, hierarchy=None)[source]
Parameters:
  • columns (list, dict) –

    Defines the available columns for the table/tree this QtGui.QStandardItemModel (the key, generally referring to the databaseId, is always the first column)

    If hierarchy argument is set, you have two options:

    • This can be a list of column-names, that will be created in all levels of nested table.
    • This can be a dictionary in the form of {'level_name':(column,column,column,...), ...} that indicates specific-columns for each level of table-nesting.

    If hierarchy is not set, this must be a list of column-names, and they will be applicable to any level of table-nesting.

    {
        ‘jedi_class’: (‘class’,),
        ‘user’:       (‘firstname’,’lastname’),
    }
    
  • hierarchy (dict, optional) –

    (ex:  ('department_type','department')  ) A list that labels what type of data is stored at each level of table-nesting in this qconcurrency.models.DictModel. Each item indicates another level of nesting.

    hierarchy = (‘jedi_class’,’user’),
    
add_row(key, columnvals=None)[source]

Adds a new (toplevel) row to this DictModel, henceforth referred to by the key key.

Parameters:
  • key (obj) – Key is the id you will use to refer to this object. Generally it will be a databaseId. This object must be hashable.
  • columnvals (dict, optional) – Optionally, you may provide a dictionary of column-val assignments (appropriate to this item’s table-level). All columns, not assigned in columnvals will be initialized with a value of ”.
Returns:

qconcurrency.models.DictModelRow

clear()[source]

Removes all items from QtGui.QStandardItemModel

column_index(level=None, column=None)[source]

Returns the column-index for a specific columnname at a specific level.

Parameters:level (obj) –

( ex:  'jedi_class', 0 ) If a hierarchy was assigned to this qconcurrency.models.DictModel, this can be a label from it, or an integer indicating the level-of-nesting.

Otherwise, this will be an integer indicating the level-of-nesting (and it will be ignored).

Returns:
3   # a column-index
columns(level=None)[source]

Returns the columns for a particular level of nested-table within this qconcurrency.models.DictModel.

Parameters:level (obj) –

( ex:  'jedi_class', 0 ) If a hierarchy was assigned to this qconcurrency.models.DictModel, this can be a label from it, or an integer indicating the level-of-nesting.

Otherwise, this will be an integer indicating the level-of-nesting (and it will be ignored).

Returns:
(‘id’,’firstname’,’lastname’,’username’, …)
default_columnvals(level=None)[source]

Returns the default-columnvals for a particular level of nested-table. See qconcurrency.models.DictModelRow.level()

Parameters:level (obj) – If a hierarchy was assigned to this qconcurrency.models.DictModel, this will be a label from it. Otherwise, this will be an integer indicating the level-of-nesting (and it will be ignored).
Returns:
{
    ‘firstname’: None,
    ‘lastname’:  None,
    …
}
has_key(k)[source]

Wraps self._data.has_key

hierarchy()[source]

Returns the model’s hierarchy tuple (if one has been assigned in qconcurrency.models.DictModel.__init__)

Returns:
(‘jedi_class’, ‘user’) # if assigned a hierarchy
None                   # if no hierarchy is assigned
items()[source]

Lists a tuple with the key and DictModelRow objects for every row in the QtWidgets.QStandardItemModel

keys()[source]

Lists key value for every row in the QtWidgets.QStandardItemModel

removeRow(key)[source]
staticMetaObject = <PySide.QtCore.QMetaObject object>
takeRow(key)[source]
values()[source]

Lists DictModelRow objects for every row in the QtWidgets.QStandardItemModel