Package: gtk
Class gtk-list-store
Superclassesgtk-tree-model, gtk-tree-drag-source, gtk-tree-drag-dest, gtk-tree-sortable, gtk-buildable, g-object, common-lisp:standard-object, common-lisp:t 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 function gtk-tree-model-row-changed to emit the "row-changed" signal. This most commonly affects lists with gdk-pixbuf objects stored. Performance ConsiderationsInternally, 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 OperationsIt is important to note that only the method gtk-list-store-insert-with-values 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 e.g. the functions gtk-list-store-append and then gtk-list-store-set 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 "row-inserted" 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 callback function gtk-tree-model-filter-visible-func. Using any of the non-atomic operations to append rows to the gtk-list-store object will cause the callback function gtk-tree-model-filter-visible-func to be visited with an empty row first. The function must be prepared for that.Example(defun create-and-fill-model () (let ((list-data '("Name1" "Name2" "Name3" "Name4" "Name5")) ;; Create a new list store with three columns (list-store (make-instance 'gtk-list-store :column-types '("gint" "gchararray" "gboolean")))) ;; Fill in some data (loop for data in list-data for i from 0 do ;; Add a new row to the model (gtk-list-store-set list-store (gtk-list-store-append list-store) i data nil)) ;; Modify a particular row (let ((path (gtk-tree-path-new-from-string "2"))) (gtk-list-store-set-value list-store (gtk-tree-model-iter list-store path) 2 t)) ;; Return the new list store list-store)) GtkListStore as GtkBuildableAdditionally, 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> | Inherited Slot Access FunctionsSee also |
*2021-4-21