gi-gtk-hs-0.3.6.3: A wrapper for gi-gtk, adding a few more idiomatic API parts on top

Stabilityprovisional
Portabilityportable (depends on GHC)
Safe HaskellNone
LanguageHaskell2010

Data.GI.Gtk.ModelView.TreeModel

Contents

Description

The tree interface used by TreeView.

Synopsis

Detail

The TreeModel interface defines a generic storage object for use by the TreeView and similar widgets. Specifically, the functions in defined here are used by Gtk's widgets to access the stored data. Thus, rather than calling these functions, an application programmer has to implement them. While the module Data.GI.Gtk.ModelView.CustomStore provides the necessary functions to implement the TreeMode interface, it is often sufficient to use the wo implementations that come with gi-gtk-hs, namely are ListStore and TreeStore.

The model is represented as a hierarchical tree of values. It is important to note that this interface only provides a way of examining a model and observing changes. The implementation of each individual model decides how and if changes are made.

Two generic models are provided that implement the TreeModel interface: the TreeStore and the ListStore. To use these, the developer simply inserts data into these models as necessary. These models provide the data structure as well as the TreeModel interface. In fact, they implement other interfaces, making drag and drop and storing data trivial.

A TreeModel stores records of the same type. Each record is referred to as row, just like in a relational database. Defining how the information of a row is displayed can be done in two ways: If the widget displays data using CellRenderer or one of its derivatives, it is possible to state how a row is mapped to the attributes of a renderer using the cellLayoutSetAttributes function. Some widgets do not use CellRenderers to display their data. In this case an extraction function can be defined that maps a row to one of a few basic types (like Strings or Ints). This extraction function is associated with a ColumnId using treeModelSetColumn. The latter can be set in the widget for the property that should be set. The widget then uses the function treeModelGetValue and the ColumnId to extract the value from the model. As the name suggests, using ColumnIds creates a view of the data as if each row were divided into a well-defined set of columns, again, like a relational database.

Models are accessed on a node level of granularity. There are two index types used to reference a particular node in a model. They are the TreePath and the TreeIter. Most of the interface consists of operations on a TreeIter.

A path is essentially a potential node. It is a location on a model that may or may not actually correspond to a node on a specific model. A TreePath is in fact a synonym for a list of Ints and hence are easy to manipulate. Each number refers to the offset at that level. Thus, the path [0] refers to the root node and the path [2,4] refers to the fifth child of the third node.

By contrast, a TreeIter is a reference to a specific node on a specific model. It is an abstract data type filled in by the model. One can convert a path to an iterator by calling treeModelGetIter. These iterators are the primary way of accessing a model and are similar to the iterators used by TextBuffer. The model interface defines a set of operations using them for navigating the model. Iterators are expected to always be valid for as long as the model is unchanged (and doesn't emit a signal).

Class Hierarchy

|  GInterface
|   +----TreeModel
|   +--------TypedTreeModel

treeModelUnrefNode Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct

-> m () 

Lets the tree unref the node.

This is an optional method for models to implement. To be more specific, models may ignore this call as it exists primarily for performance reasons. For more information on what this means, see treeModelRefNode.

Please note that nodes that are deleted are not unreffed.

treeModelSortNewWithModel Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

childModel: A TreeModel

-> m TreeModel

Returns: A new TreeModel.

Creates a new TreeModel, with childModel as the child model.

treeModelRowsReordered Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreePath

path: a TreePath-struct pointing to the tree node whose children have been reordered

-> Maybe TreeIter

iter: a valid TreeIter-struct pointing to the node whose children have been reordered, or Nothing if the depth of path is 0

-> [Int32]

newOrder: an array of integers mapping the current position of each child to its old position before the re-ordering, i.e. newOrder[newpos] = oldpos

-> m () 

Emits the TreeModel::rows-reordered signal on treeModel.

This should be called by models when their rows have been reordered.

Since: 3.10

treeModelRowInserted Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreePath

path: a TreePath-struct pointing to the inserted row

-> TreeIter

iter: a valid TreeIter-struct pointing to the inserted row

-> m () 

Emits the TreeModel::row-inserted signal on treeModel.

treeModelRowHasChildToggled Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreePath

path: a TreePath-struct pointing to the changed row

-> TreeIter

iter: a valid TreeIter-struct pointing to the changed row

-> m () 

Emits the TreeModel::row-has-child-toggled signal on treeModel. This should be called by models after the child state of a node changes.

treeModelRowDeleted Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreePath

path: a TreePath-struct pointing to the previous location of the deleted row

-> m () 

Emits the TreeModel::row-deleted signal on treeModel.

This should be called by models after a row has been removed. The location pointed to by path should be the location that the row previously was at. It may not be a valid location anymore.

Nodes that are deleted are not unreffed, this means that any outstanding references on the deleted node should not be released.

treeModelRowChanged Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreePath

path: a TreePath-struct pointing to the changed row

-> TreeIter

iter: a valid TreeIter-struct pointing to the changed row

-> m () 

Emits the TreeModel::row-changed signal on treeModel.

treeModelRefNode Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct

-> m () 

Lets the tree ref the node.

This is an optional method for models to implement. To be more specific, models may ignore this call as it exists primarily for performance reasons.

This function is primarily meant as a way for views to let caching models know when nodes are being displayed (and hence, whether or not to cache that node). Being displayed means a node is in an expanded branch, regardless of whether the node is currently visible in the viewport. For example, a file-system based model would not want to keep the entire file-hierarchy in memory, just the sections that are currently being displayed by every current view.

A model should be expected to be able to get an iter independent of its reffed state.

treeModelIterPrevious Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct

-> m Bool

Returns: True if iter has been changed to the previous node

Sets iter to point to the previous node at the current level.

If there is no previous iter, False is returned and iter is set to be invalid.

Since: 3.0

treeModelIterParent Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

child: the TreeIter-struct

-> m (Bool, TreeIter)

Returns: True, if iter is set to the parent of child

Sets iter to be the parent of child.

If child is at the toplevel, and doesn’t have a parent, then iter is set to an invalid iterator and False is returned. child will remain a valid node after this function has been called.

iter will be initialized before the lookup is performed, so child and iter cannot point to the same memory location.

treeModelIterNthChild Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> Maybe TreeIter

parent: the TreeIter-struct to get the child from, or Nothing.

-> Int32

n: the index of the desired child

-> m (Bool, TreeIter)

Returns: True, if parent has an n-th child

Sets iter to be the child of parent, using the given index.

The first index is 0. If n is too big, or parent has no children, iter is set to an invalid iterator and False is returned. parent will remain a valid node after this function has been called. As a special case, if parent is Nothing, then the n-th root node is set.

treeModelIterNext Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct

-> m Bool

Returns: True if iter has been changed to the next node

Sets iter to point to the node following it at the current level.

If there is no next iter, False is returned and iter is set to be invalid.

treeModelIterNChildren Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> Maybe TreeIter

iter: the TreeIter-struct, or Nothing

-> m Int32

Returns: the number of children of iter

Returns the number of children that iter has.

As a special case, if iter is Nothing, then the number of toplevel nodes is returned.

treeModelIterHasChild Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct to test for children

-> m Bool

Returns: True if iter has children

Returns True if iter has children, False otherwise.

treeModelIterChildren Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> Maybe TreeIter

parent: the TreeIter-struct, or Nothing

-> m (Bool, TreeIter)

Returns: True, if iter has been set to the first child

Sets iter to point to the first child of parent.

If parent has no children, False is returned and iter is set to be invalid. parent will remain a valid node after this function has been called.

If parent is Nothing returns the first node, equivalent to gtk_tree_model_get_iter_first (tree_model, iter);

treeModelGetStringFromIter Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: a TreeIter-struct

-> m Text

Returns: a newly-allocated string. Must be freed with free.

Generates a string representation of the iter.

This string is a “:” separated list of numbers. For example, “4:10:0:3” would be an acceptable return value for this string.

Since: 2.2

treeModelGetPath Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> TreeIter

iter: the TreeIter-struct

-> m TreePath

Returns: a newly-created TreePath-struct

Returns a newly-created TreePath-struct referenced by iter.

This path should be freed with treePathFree.

treeModelGetNColumns Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> m Int32

Returns: the number of columns

Returns the number of columns supported by treeModel.

treeModelGetIterFromString Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> Text

pathString: a string representation of a TreePath-struct

-> m (Bool, TreeIter)

Returns: True, if iter was set

Sets iter to a valid iterator pointing to pathString, if it exists. Otherwise, iter is left invalid and False is returned.

treeModelGetIterFirst Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> m (Bool, TreeIter)

Returns: True, if iter was set

Initializes iter with the first iterator in the tree (the one at the path "0") and returns True. Returns False if the tree is empty.

treeModelGetFlags Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> m [TreeModelFlags]

Returns: the flags supported by this interface

Returns a set of flags supported by this interface.

The flags are a bitwise combination of TreeModelFlags. The flags supported should not change during the lifetime of the treeModel.

treeModelGetColumnType Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

treeModel: a TreeModel

-> Int32

index_: the column index

-> m GType

Returns: the type of the column

Returns the type of the column.

treeModelForeach Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

model: a TreeModel

-> TreeModelForeachFunc

func: a function to be called on each row

-> m () 

Calls func on each node in model in a depth-first fashion.

If func returns True, then the tree ceases to be walked, and treeModelForeach returns.

treeModelFilterNew Source #

Arguments

:: (HasCallStack, MonadIO m, IsTreeModel a) 
=> a

childModel: A TreeModel.

-> Maybe TreePath

root: A TreePath or Nothing.

-> m TreeModel

Returns: A new TreeModel.

Creates a new TreeModel, with childModel as the child_model and root as the virtual root.

Since: 2.4

toTreeModel :: (MonadIO m, IsTreeModel o) => o -> m TreeModel Source #

Cast to TreeModel, for types for which this is known to be safe. For general casts, use castTo.

afterTreeModelRowInserted :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowInsertedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-inserted” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after treeModel #rowInserted callback

onTreeModelRowInserted :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowInsertedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-inserted” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on treeModel #rowInserted callback

afterTreeModelRowHasChildToggled :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowHasChildToggledCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-has-child-toggled” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after treeModel #rowHasChildToggled callback

onTreeModelRowHasChildToggled :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowHasChildToggledCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-has-child-toggled” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on treeModel #rowHasChildToggled callback

afterTreeModelRowDeleted :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowDeletedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-deleted” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after treeModel #rowDeleted callback

onTreeModelRowDeleted :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowDeletedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-deleted” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on treeModel #rowDeleted callback

afterTreeModelRowChanged :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowChangedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-changed” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after treeModel #rowChanged callback

onTreeModelRowChanged :: (IsTreeModel a, MonadIO m) => a -> TreeModelRowChangedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “row-changed” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on treeModel #rowChanged callback

noTreeModel :: Maybe TreeModel Source #

A convenience alias for Nothing :: Maybe TreeModel.

type TreeModelRowChangedCallback Source #

Arguments

 = TreePath

path: a TreePath-struct identifying the changed row

-> TreeIter

iter: a valid TreeIter-struct pointing to the changed row

-> IO () 

This signal is emitted when a row in the model has changed.

type C_TreeModelRowChangedCallback = Ptr () -> Ptr TreePath -> Ptr TreeIter -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type TreeModelRowDeletedCallback Source #

Arguments

 = TreePath

path: a TreePath-struct identifying the row

-> IO () 

This signal is emitted when a row has been deleted.

Note that no iterator is passed to the signal handler, since the row is already deleted.

This should be called by models after a row has been removed. The location pointed to by path should be the location that the row previously was at. It may not be a valid location anymore.

type C_TreeModelRowDeletedCallback = Ptr () -> Ptr TreePath -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type TreeModelRowHasChildToggledCallback Source #

Arguments

 = TreePath

path: a TreePath-struct identifying the row

-> TreeIter

iter: a valid TreeIter-struct pointing to the row

-> IO () 

This signal is emitted when a row has gotten the first child row or lost its last child row.

type C_TreeModelRowHasChildToggledCallback = Ptr () -> Ptr TreePath -> Ptr TreeIter -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type TreeModelRowInsertedCallback Source #

Arguments

 = TreePath

path: a TreePath-struct identifying the new row

-> TreeIter

iter: a valid TreeIter-struct pointing to the new row

-> IO () 

This signal is emitted when a new row has been inserted in the model.

Note that the row may still be empty at this point, since it is a common pattern to first insert an empty row, and then fill it with the desired values.

type C_TreeModelRowInsertedCallback = Ptr () -> Ptr TreePath -> Ptr TreeIter -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

newtype TreeModel Source #

Memory-managed wrapper type.

Instances
GObject TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

IsObject TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

IsTreeModel TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

(info ~ ResolveTreeModelMethod t TreeModel, MethodInfo info TreeModel p) => IsLabel t (TreeModel -> p) 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

Methods

fromLabel :: TreeModel -> p Source #

(info ~ ResolveTreeModelMethod t TreeModel, MethodInfo info TreeModel p) => IsLabelProxy t (TreeModel -> p) 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

Methods

fromLabelProxy :: Proxy t -> TreeModel -> p Source #

HasAttributeList TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

type AttributeList TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

type AttributeList TreeModel = TreeModelAttributeList
type SignalList TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

type SignalList TreeModel = TreeModelSignalList

class GObject o => IsTreeModel o Source #

Type class for types which can be safely cast to TreeModel, for instance with toTreeModel.

data TreeModelGetIterMethodInfo Source #

Instances
(signature ~ (TreePath -> m (Bool, TreeIter)), MonadIO m, IsTreeModel a) => MethodInfo TreeModelGetIterMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelIterNextMethodInfo Source #

Instances
(signature ~ (TreeIter -> m Bool), MonadIO m, IsTreeModel a) => MethodInfo TreeModelIterNextMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRefNodeMethodInfo Source #

Instances
(signature ~ (TreeIter -> m ()), MonadIO m, IsTreeModel a) => MethodInfo TreeModelRefNodeMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRowDeletedMethodInfo Source #

Instances
(signature ~ (TreePath -> m ()), MonadIO m, IsTreeModel a) => MethodInfo TreeModelRowDeletedMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelUnrefNodeMethodInfo Source #

Instances
(signature ~ (TreeIter -> m ()), MonadIO m, IsTreeModel a) => MethodInfo TreeModelUnrefNodeMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data ColumnId row ty Source #

The type of a tree column.

Instances
Eq (ColumnId row ty) Source # 
Instance details

Defined in Data.GI.Gtk.ModelView.TreeModel

Methods

(==) :: ColumnId row ty -> ColumnId row ty -> Bool Source #

(/=) :: ColumnId row ty -> ColumnId row ty -> Bool Source #

Show (ColumnId row ty) Source # 
Instance details

Defined in Data.GI.Gtk.ModelView.TreeModel

Methods

showsPrec :: Int -> ColumnId row ty -> ShowS Source #

show :: ColumnId row ty -> String Source #

showList :: [ColumnId row ty] -> ShowS Source #

Constructors

makeColumnIdInt :: Int32 -> ColumnId row Int32 Source #

Create a ColumnId to extract an integer.

makeColumnIdBool :: Int32 -> ColumnId row Bool Source #

Create a ColumnId to extract an Boolean.

makeColumnIdString :: Int32 -> ColumnId row Text Source #

Create a ColumnId to extract an string.

makeColumnIdPixbuf :: Int32 -> ColumnId row Pixbuf Source #

Create a ColumnId to extract an Pixbuf.

invalidColumnId :: ColumnId row ty Source #

The invalid ColumnId. Widgets use this value if no column id has been set.

Methods

columnIdToNumber :: ColumnId row ty -> Int32 Source #

Convert a ColumnId to a bare number.

stringToTreePath :: Text -> [Int32] Source #

Convert a comma or colon separated string into a TreePath. Any non-digit characters are assumed to separate indices, thus, the function always is always successful.

treeModelGetValue Source #

Arguments

:: IsTreeModel self 
=> self 
-> TreeIter 
-> ColumnId row ty

column - The column to lookup the value at.

-> IO ty 

Read the value of at a specific column and TreeIter.

treeModelGetIter :: (MonadIO m, IsTreeModel model) => model -> TreePath -> m (Maybe TreeIter) Source #

Gets the a TreeIter or Nothing if the path is invalid or empty

Orphan instances

Eq (ColumnId row ty) Source # 
Instance details

Methods

(==) :: ColumnId row ty -> ColumnId row ty -> Bool Source #

(/=) :: ColumnId row ty -> ColumnId row ty -> Bool Source #

Show (ColumnId row ty) Source # 
Instance details

Methods

showsPrec :: Int -> ColumnId row ty -> ShowS Source #

show :: ColumnId row ty -> String Source #

showList :: [ColumnId row ty] -> ShowS Source #