Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
ListModel
is an interface that represents a mutable list of
GObjects
. Its main intention is as a model for various widgets in
user interfaces, such as list views, but it can also be used as a
convenient method of returning lists of data, with support for
updates.
Each object in the list may also report changes in itself via some
mechanism (normally the Object
::notify
signal). Taken together
with the ListModel
::items-changed
signal, this provides for a list
that can change its membership, and in which the members can change
their individual properties.
A good example would be the list of visible wireless network access points, where each access point can report dynamic properties such as signal strength.
It is important to note that the ListModel
itself does not report
changes to the individual items. It only reports changes to the list
membership. If you want to observe changes to the objects themselves
then you need to connect signals to the objects that you are
interested in.
All items in a ListModel
are of (or derived from) the same type.
listModelGetItemType
returns that type. The type may be an
interface, in which case all objects in the list must implement it.
The semantics are close to that of an array:
listModelGetNItems
returns the number of items in the list and
g_list_model_get_item()
returns an item at a (0-based) position. In
order to allow implementations to calculate the list length lazily,
you can also iterate over items: starting from 0, repeatedly call
g_list_model_get_item()
until it returns Nothing
.
An implementation may create objects lazily, but must take care to return the same object for a given position until all references to it are gone.
On the other side, a consumer is expected only to hold references on objects that are currently "user visible", in order to faciliate the maximum level of laziness in the implementation of the list and to reduce the required number of signal connections at a given time.
This interface is intended only to be used from a single thread. The thread in which it is appropriate to use it depends on the particular implementation, but typically it will be from the thread that owns the [thread-default main context][g-main-context-push-thread-default] in effect at the time that the model was created.
Synopsis
- newtype ListModel = ListModel (ManagedPtr ListModel)
- noListModel :: Maybe ListModel
- class GObject o => IsListModel o
- toListModel :: (MonadIO m, IsListModel o) => o -> m ListModel
- listModelGetItem :: (HasCallStack, MonadIO m, IsListModel a) => a -> Word32 -> m (Maybe Object)
- listModelGetItemType :: (HasCallStack, MonadIO m, IsListModel a) => a -> m GType
- listModelGetNItems :: (HasCallStack, MonadIO m, IsListModel a) => a -> m Word32
- listModelItemsChanged :: (HasCallStack, MonadIO m, IsListModel a) => a -> Word32 -> Word32 -> Word32 -> m ()
- type C_ListModelItemsChangedCallback = Ptr () -> Word32 -> Word32 -> Word32 -> Ptr () -> IO ()
- type ListModelItemsChangedCallback = Word32 -> Word32 -> Word32 -> IO ()
- afterListModelItemsChanged :: (IsListModel a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId
- genClosure_ListModelItemsChanged :: ListModelItemsChangedCallback -> IO Closure
- mk_ListModelItemsChangedCallback :: C_ListModelItemsChangedCallback -> IO (FunPtr C_ListModelItemsChangedCallback)
- noListModelItemsChangedCallback :: Maybe ListModelItemsChangedCallback
- onListModelItemsChanged :: (IsListModel a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId
- wrap_ListModelItemsChangedCallback :: ListModelItemsChangedCallback -> C_ListModelItemsChangedCallback
Exported types
Memory-managed wrapper type.
Instances
GObject ListModel Source # | |
Defined in GI.Gio.Interfaces.ListModel gobjectType :: ListModel -> IO GType # | |
IsObject ListModel Source # | |
Defined in GI.Gio.Interfaces.ListModel | |
IsListModel ListModel Source # | |
Defined in GI.Gio.Interfaces.ListModel |
class GObject o => IsListModel o Source #
Type class for types which can be safely cast to ListModel
, for instance with toListModel
.
Instances
(GObject a, (UnknownAncestorError ListModel a :: Constraint)) => IsListModel a Source # | |
Defined in GI.Gio.Interfaces.ListModel | |
IsListModel ListModel Source # | |
Defined in GI.Gio.Interfaces.ListModel | |
IsListModel ListStore Source # | |
Defined in GI.Gio.Objects.ListStore |
toListModel :: (MonadIO m, IsListModel o) => o -> m ListModel Source #
Methods
getItem
:: (HasCallStack, MonadIO m, IsListModel a) | |
=> a |
|
-> Word32 |
|
-> m (Maybe Object) | Returns: the object at |
Get the item at position
. If position
is greater than the number of
items in list
, Nothing
is returned.
Nothing
is never returned for an index that is smaller than the length
of the list. See listModelGetNItems
.
Since: 2.44
getItemType
:: (HasCallStack, MonadIO m, IsListModel a) | |
=> a |
|
-> m GType | Returns: the |
Gets the type of the items in list
. All items returned from
g_list_model_get_type()
are of that type or a subtype, or are an
implementation of that interface.
The item type of a ListModel
can not change during the life of the
model.
Since: 2.44
getNItems
:: (HasCallStack, MonadIO m, IsListModel a) | |
=> a |
|
-> m Word32 | Returns: the number of items in |
Gets the number of items in list
.
Depending on the model implementation, calling this function may be
less efficient than iterating the list with increasing values for
position
until g_list_model_get_item()
returns Nothing
.
Since: 2.44
itemsChanged
listModelItemsChanged Source #
:: (HasCallStack, MonadIO m, IsListModel a) | |
=> a |
|
-> Word32 |
|
-> Word32 |
|
-> Word32 |
|
-> m () |
Emits the ListModel
::items-changed
signal on list
.
This function should only be called by classes implementing
ListModel
. It has to be called after the internal representation
of list
has been updated, because handlers connected to this signal
might query the new state of the list.
Implementations must only make changes to the model (as visible to
its consumer) in places that will not cause problems for that
consumer. For models that are driven directly by a write API (such
as ListStore
), changes can be reported in response to uses of that
API. For models that represent remote data, changes should only be
made from a fresh mainloop dispatch. It is particularly not
permitted to make changes in response to a call to the ListModel
consumer API.
Stated another way: in general, it is assumed that code making a series of accesses to the model via the API, without returning to the mainloop, and without calling other code, will continue to view the same contents of the model.
Since: 2.44
Signals
itemsChanged
type C_ListModelItemsChangedCallback = Ptr () -> Word32 -> Word32 -> Word32 -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type ListModelItemsChangedCallback Source #
= Word32 |
|
-> Word32 |
|
-> Word32 |
|
-> IO () |
This signal is emitted whenever items were added or removed to
list
. At position
, removed
items were removed and added
items
were added in their place.
Since: 2.44
afterListModelItemsChanged :: (IsListModel a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId Source #
Connect a signal handler for the “items-changed
” signal, to be run after the default handler.
When overloading is enabled, this is equivalent to
after
listModel #itemsChanged callback
genClosure_ListModelItemsChanged :: ListModelItemsChangedCallback -> IO Closure Source #
Wrap the callback into a Closure
.
mk_ListModelItemsChangedCallback :: C_ListModelItemsChangedCallback -> IO (FunPtr C_ListModelItemsChangedCallback) Source #
Generate a function pointer callable from C code, from a C_ListModelItemsChangedCallback
.
noListModelItemsChangedCallback :: Maybe ListModelItemsChangedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
ListModelItemsChangedCallback
onListModelItemsChanged :: (IsListModel a, MonadIO m) => a -> ListModelItemsChangedCallback -> m SignalHandlerId Source #
Connect a signal handler for the “items-changed
” signal, to be run before the default handler.
When overloading is enabled, this is equivalent to
on
listModel #itemsChanged callback