Package: gtk

Class gtk:list-store

Superclasses

Documented Subclasses

None

Direct Slots

None

Details

The gtk:list-store object is a list model for use with a gtk:tree-view widget. It implements the gtk:tree-model interface, and consequentialy, can use all of the methods available there. It also implements the gtk:tree-sortable interface so it can be sorted by the tree view. Finally, it also implements the tree drag and drop interfaces.

The gtk:list-store object can accept most GObject types as a column type, though it cannot accept all custom types. Internally, it will keep a copy of data passed in, such as a string or a boxed pointer. Columns that accept GObjects are handled a little differently. The gtk:list-store object will keep a reference to the object instead of copying the value. As a result, if the object is modified, it is up to the application writer to call the gtk:tree-model-row-changed function to emit the "row-changed" signal. This most commonly affects lists with gdk:texture objects stored.

Performance Considerations
Internally, the gtk:list-store object was implemented with a linked list with a tail pointer prior to GTK 2.6. As a result, it was fast at data insertion and deletion, and not fast at random data access. The gtk:list-store object sets the :iters-persist flag of the gtk:tree-model-flags flags, which means that gtk:tree-iter iterators can be cached while the row exists. Thus, if access to a particular row is needed often and your code is expected to run on older versions of GTK, it is worth keeping the iterator around.

Atomic Operations
It is important to note that only the gtk:list-store-insert-with-values method is atomic, in the sense that the row is being appended to the store and the values filled in in a single operation with regard to the gtk:tree-model interface signaling. In contrast, using, for example, the gtk:list-store-append function and then the gtk:list-store-set function will first create a row, which triggers the "row-inserted" signal on the gtk:list-store object. The row, however, is still empty, and any signal handler connecting to the "row-inserted" signal on this particular store should be prepared for the situation that the row might be empty. This is especially important if you are wrapping the gtk:list-store object inside a gtk:tree-model-filter object and are using a gtk:tree-model-filter-visible-func callback function. Using any of the non-atomic operations to append rows to the gtk:list-store object will cause the gtk:tree-model-filter-visible-func callback function to be visited with an empty row first. The function must be prepared for that.

Examples

Creating a simple list store.
(defun create-and-fill-model ()
  (let ((listdata '("Name1" "Name2" "Name3" "Name4" "Name5"))
        ;; Create new list store with three columns
        (store (make-instance 'gtk:list-store
                              :column-types
                              '("gint" "gchararray" "gboolean"))))
    ;; Fill in some data
    (iter (for data in listdata)
          (for i from 0)
          ;; Add a new row to the model
          (gtk:list-store-set store
                              (gtk:list-store-append store)
                              i
                              data
                              nil))
    ;; Modify particular row
    (let ((path (gtk:tree-path-new-from-string "2")))
      (gtk:list-store-set-value store
                                (gtk:tree-model-iter store path)
                                2
                                t))
    ;; Return new list store
    store))    

GtkListStore as GtkBuildable

The gtk:list-store implementation of the gtk:buildable interface allows to specify the model columns with a <columns> element that may contain multiple <column> elements, each specifying one model column. The type attribute specifies the data type for the column.

Additionally, it is possible to specify content for the list store in the UI definition, with the <data> element. It can contain multiple <row> elements, each specifying to content for one row of the list model. Inside a <row>, the <col> elements specify the content for individual cells.

Note that it is probably more common to define your models in the code, and one might consider it a layering violation to specify the content of a list store in a UI definition, data, not presentation, and common wisdom is to separate the two, as far as possible.

Example: A UI Definition fragment for a list store
   <object class="GtkListStore">
     <columns>
       <column type="gchararray"/>
       <column type="gchararray"/>
       <column type="gint"/>
     </columns>
     <data>
       <row>
         <col id="0">John</col>
         <col id="1">Doe</col>
         <col id="2">25</col>
       </row>
       <row>
         <col id="0">Johan</col>
         <col id="1">Dahlin</col>
         <col id="2">50</col>
       </row>
     </data>
   </object>    

Warning

The gtk:list-store implementation is deprecated since 4.10. Use the g:list-store object instead.
 

Returned by

Inherited Slot Access Functions

See also

2024-4-7