Package: gio

VTable gio:list-model-vtable

Declaration

(gobject:define-vtable ("GListModel" list-model)
  (:skip parent-instance (:struct gobject:type-interface))
  ;; Methods of the GListModel interface
  (get-item-type                               ; virtual function
     (gobject:type-t                           ; return type
       (model (gobject:object list-model))))   ; argument
  (get-n-items (:uint
                (model (gobject:object list-model))))
  (get-item (gobject:object
             (model (gobject:object list-model))
             (pos :uint))))  

Values

get-item-type
Virtual function called by the g:list-model-item-type function. You must implement the g:list-model-get-item-type-impl method, when subclassing from the g:list-model interface.
get-n-items
Virtual function called by the g:list-model-n-items function. You must implement the g:list-model-get-n-items-impl method, when subclassing from the g:list-model interface.
get-item
Virtual function called by the g:list-model-item function. You must implement the g:list-model-get-item-impl method, when subclassing from the g:list-model interface.

Details

The virtual function table for the g:list-model interface.

Examples

Simple example of subclassing the g:list-model interface. The model is internally represented as a Lisp list.
;; Simple implementation which uses a Lisp list
(gobject:define-gobject-subclass "CLListStore" cl-list-store
  (:superclass g:object
   :export t
   :interfaces ("GListModel"))
  ((:cl list
        :initform '()
        :accessor cl-list-store-list)))

(defmethod gio:list-model-get-item-type-impl ((store cl-list-store)) (g:gtype "GAction"))

(defmethod gio:list-model-get-n-items-impl ((store cl-list-store)) (length (cl-list-store-list store)))

(defmethod gio:list-model-get-item-impl ((store cl-list-store) pos) (let ((item (nth pos (cl-list-store-list store)))) (when item ;; We must add a reference to the returned item (g:object-ref item))))
 

See also

2025-3-24