gtk4/auto/
flatten_list_model.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6#[cfg(feature = "v4_12")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
8use crate::SectionModel;
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16#[cfg(feature = "v4_12")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18glib::wrapper! {
19    /// [`FlattenListModel`][crate::FlattenListModel] is a list model that concatenates other list models.
20    ///
21    /// [`FlattenListModel`][crate::FlattenListModel] takes a list model containing list models, and flattens
22    /// it into a single model. Each list model becomes a section in the single model.
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `item-type`
28    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
29    ///
30    /// Readable
31    ///
32    ///
33    /// #### `model`
34    ///  The model being flattened.
35    ///
36    /// Readable | Writeable
37    ///
38    ///
39    /// #### `n-items`
40    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
41    ///
42    /// Readable
43    ///
44    /// # Implements
45    ///
46    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`SectionModelExt`][trait@crate::prelude::SectionModelExt]
47    #[doc(alias = "GtkFlattenListModel")]
48    pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel, SectionModel;
49
50    match fn {
51        type_ => || ffi::gtk_flatten_list_model_get_type(),
52    }
53}
54
55#[cfg(not(any(feature = "v4_12")))]
56glib::wrapper! {
57    #[doc(alias = "GtkFlattenListModel")]
58    pub struct FlattenListModel(Object<ffi::GtkFlattenListModel, ffi::GtkFlattenListModelClass>) @implements gio::ListModel;
59
60    match fn {
61        type_ => || ffi::gtk_flatten_list_model_get_type(),
62    }
63}
64
65impl FlattenListModel {
66    /// Creates a new [`FlattenListModel`][crate::FlattenListModel] that flattens @list.
67    /// ## `model`
68    /// the model to be flattened
69    ///
70    /// # Returns
71    ///
72    /// a new [`FlattenListModel`][crate::FlattenListModel]
73    #[doc(alias = "gtk_flatten_list_model_new")]
74    pub fn new(model: Option<impl IsA<gio::ListModel>>) -> FlattenListModel {
75        assert_initialized_main_thread!();
76        unsafe {
77            from_glib_full(ffi::gtk_flatten_list_model_new(
78                model.map(|p| p.upcast()).into_glib_ptr(),
79            ))
80        }
81    }
82
83    /// Gets the model set via gtk_flatten_list_model_set_model().
84    ///
85    /// # Returns
86    ///
87    /// The model flattened by @self
88    #[doc(alias = "gtk_flatten_list_model_get_model")]
89    #[doc(alias = "get_model")]
90    pub fn model(&self) -> Option<gio::ListModel> {
91        unsafe { from_glib_none(ffi::gtk_flatten_list_model_get_model(self.to_glib_none().0)) }
92    }
93
94    /// Returns the model containing the item at the given position.
95    /// ## `position`
96    /// a position
97    ///
98    /// # Returns
99    ///
100    /// the model containing the item at @position
101    #[doc(alias = "gtk_flatten_list_model_get_model_for_item")]
102    #[doc(alias = "get_model_for_item")]
103    pub fn model_for_item(&self, position: u32) -> Option<gio::ListModel> {
104        unsafe {
105            from_glib_none(ffi::gtk_flatten_list_model_get_model_for_item(
106                self.to_glib_none().0,
107                position,
108            ))
109        }
110    }
111
112    /// Sets a new model to be flattened.
113    /// ## `model`
114    /// the new model
115    #[doc(alias = "gtk_flatten_list_model_set_model")]
116    #[doc(alias = "model")]
117    pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
118        unsafe {
119            ffi::gtk_flatten_list_model_set_model(
120                self.to_glib_none().0,
121                model.map(|p| p.as_ref()).to_glib_none().0,
122            );
123        }
124    }
125
126    #[doc(alias = "model")]
127    pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
128        unsafe extern "C" fn notify_model_trampoline<F: Fn(&FlattenListModel) + 'static>(
129            this: *mut ffi::GtkFlattenListModel,
130            _param_spec: glib::ffi::gpointer,
131            f: glib::ffi::gpointer,
132        ) {
133            let f: &F = &*(f as *const F);
134            f(&from_glib_borrow(this))
135        }
136        unsafe {
137            let f: Box_<F> = Box_::new(f);
138            connect_raw(
139                self.as_ptr() as *mut _,
140                b"notify::model\0".as_ptr() as *const _,
141                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142                    notify_model_trampoline::<F> as *const (),
143                )),
144                Box_::into_raw(f),
145            )
146        }
147    }
148}