ListStore#
Superclasses: Object
Implemented Interfaces: ListModel
GListStore
is a simple implementation of ListModel
that stores
all items in memory.
It provides insertions, deletions, and lookups in logarithmic time with a fast path for the common case of iterating the list linearly.
Constructors#
Methods#
- class ListStore
- append(item: Object) None #
Appends
item
tostore
.item
must be of typeListStore
:item-type.This function takes a ref on
item
.Use
splice()
to append multiple items at the same time efficiently.Added in version 2.44.
- Parameters:
item – the new item
- find(item: Object) Tuple[bool, int] #
Looks up the given
item
in the list store by looping over the items until the first occurrence ofitem
. Ifitem
was not found, thenposition
will not be set, and this method will returnFalse
.If you need to compare the two items with a custom comparison function, use
find_with_equal_func()
with a customEqualFunc
instead.Added in version 2.64.
- Parameters:
item – an item
- find_with_equal_func(item, equal_func, *user_data)#
Looks up the given
item
in the list store by looping over the items and comparing them withequal_func
until the first occurrence ofitem
which matches. Ifitem
was not found, thenposition
will not be set, and this method will returnFalse
.item
is always passed as second parameter toequal_func
.Since GLib 2.76 it is possible to pass
NULL
foritem
.Added in version 2.64.
- Parameters:
item – an item
equal_func – A custom equality check function
user_data
- find_with_equal_func_full(item: Object | None, equal_func: Callable[[Any, Any, Any], bool], user_data: Any = None) Tuple[bool, int] #
Like
find_with_equal_func()
but with an additionaluser_data
that is passed toequal_func
.item
is always passed as second parameter toequal_func
.Since GLib 2.76 it is possible to pass
NULL
foritem
.Added in version 2.74.
- Parameters:
item – an item
equal_func – A custom equality check function
user_data – user data for
equal_func
- insert(position: int, item: Object) None #
Inserts
item
intostore
atposition
.item
must be of typeListStore
:item-type or derived from it.position
must be smaller than the length of the list, or equal to it to append.This function takes a ref on
item
.Use
splice()
to insert multiple items at the same time efficiently.Added in version 2.44.
- Parameters:
position – the position at which to insert the new item
item – the new item
- insert_sorted(item, compare_func, *user_data)#
Inserts
item
intostore
at a position to be determined by thecompare_func
.The list must already be sorted before calling this function or the result is undefined. Usually you would approach this by only ever inserting items by way of this function.
This function takes a ref on
item
.Added in version 2.44.
- Parameters:
item – the new item
compare_func – pairwise comparison function for sorting
user_data – user data for
compare_func
- remove(position: int) None #
Removes the item from
store
that is atposition
.position
must be smaller than the current length of the list.Use
splice()
to remove multiple items at the same time efficiently.Added in version 2.44.
- Parameters:
position – the position of the item that is to be removed
- sort(compare_func, *user_data)#
Sort the items in
store
according tocompare_func
.Added in version 2.46.
- Parameters:
compare_func – pairwise comparison function for sorting
user_data – user data for
compare_func
- splice(position: int, n_removals: int, additions: list[Object]) None #
Changes
store
by removingn_removals
items and addingn_additions
items to it.additions
must containn_additions
items of typeListStore
:item-type.None
is not permitted.This function is more efficient than
insert()
andremove()
, because it only emitsListModel
::items-changed once for the change.This function takes a ref on each item in
additions
.The parameters
position
andn_removals
must be correct (ie:position
+n_removals
must be less than or equal to the length of the list at the time this function is called).Added in version 2.44.
- Parameters:
position – the position at which to make the change
n_removals – the number of items to remove
additions – the items to add