gi-gtk-hs-0.3.7.0: 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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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 #

A convenience alias for Nothing :: Maybe TreeModel.

type TreeModelRowChangedCallback #

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 () #

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

type TreeModelRowDeletedCallback #

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 () #

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

type TreeModelRowHasChildToggledCallback #

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 () #

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

type TreeModelRowInsertedCallback #

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 () #

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

newtype TreeModel #

Memory-managed wrapper type.

Instances
GObject TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

Methods

gobjectType :: IO GType #

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

Defined in GI.Gtk.Interfaces.TreeModel

Methods

fromLabel :: TreeModel -> p #

HasParentTypes TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

HasAttributeList TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

type ParentTypes TreeModel 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

type ParentTypes TreeModel = Object ': ([] :: [Type])
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, IsDescendantOf TreeModel o) => IsTreeModel o #

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

Instances
(GObject o, IsDescendantOf TreeModel o) => IsTreeModel o 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelForeachMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelGetFlagsMethodInfo #

Instances
(signature ~ m [TreeModelFlags], MonadIO m, IsTreeModel a) => MethodInfo TreeModelGetFlagsMethodInfo a signature 
Instance details

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelGetIterMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelGetPathMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelGetValueMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelIterNextMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelIterParentMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRefNodeMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRowChangedMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRowDeletedMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelRowInsertedMethodInfo #

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

Defined in GI.Gtk.Interfaces.TreeModel

data TreeModelUnrefNodeMethodInfo #

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 #

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

Show (ColumnId row ty) Source # 
Instance details

Defined in Data.GI.Gtk.ModelView.TreeModel

Methods

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

show :: ColumnId row ty -> String #

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

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 #

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

Show (ColumnId row ty) Source # 
Instance details

Methods

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

show :: ColumnId row ty -> String #

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