gtk4/auto/
tree_model_filter.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#![allow(deprecated)]
5
6use crate::{ffi, TreeDragSource, TreeIter, TreeModel, TreePath};
7use glib::{prelude::*, translate::*};
8use std::boxed::Box as Box_;
9
10glib::wrapper! {
11    /// Use [`FilterListModel`][crate::FilterListModel] instead.
12    /// A [`TreeModel`][crate::TreeModel] which hides parts of an underlying tree model
13    ///
14    /// A [`TreeModelFilter`][crate::TreeModelFilter] is a tree model which wraps another tree model,
15    /// and can do the following things:
16    ///
17    /// - Filter specific rows, based on data from a “visible column”, a column
18    ///   storing booleans indicating whether the row should be filtered or not,
19    ///   or based on the return value of a “visible function”, which gets a
20    ///   model, iter and user_data and returns a boolean indicating whether the
21    ///   row should be filtered or not.
22    ///
23    /// - Modify the “appearance” of the model, using a modify function.
24    ///   This is extremely powerful and allows for just changing some
25    ///   values and also for creating a completely different model based
26    ///   on the given child model.
27    ///
28    /// - Set a different root node, also known as a “virtual root”. You can pass
29    ///   in a [`TreePath`][crate::TreePath] indicating the root node for the filter at construction
30    ///   time.
31    ///
32    /// The basic API is similar to [`TreeModelSort`][crate::TreeModelSort]. For an example on its usage,
33    /// see the section on [`TreeModelSort`][crate::TreeModelSort].
34    ///
35    /// When using [`TreeModelFilter`][crate::TreeModelFilter], it is important to realize that
36    /// [`TreeModelFilter`][crate::TreeModelFilter] maintains an internal cache of all nodes which are
37    /// visible in its clients. The cache is likely to be a subtree of the tree
38    /// exposed by the child model. [`TreeModelFilter`][crate::TreeModelFilter] will not cache the entire
39    /// child model when unnecessary to not compromise the caching mechanism
40    /// that is exposed by the reference counting scheme. If the child model
41    /// implements reference counting, unnecessary signals may not be emitted
42    /// because of reference counting rule 3, see the [`TreeModel`][crate::TreeModel]
43    /// documentation. (Note that e.g. [`TreeStore`][crate::TreeStore] does not implement
44    /// reference counting and will always emit all signals, even when
45    /// the receiving node is not visible).
46    ///
47    /// Because of this, limitations for possible visible functions do apply.
48    /// In general, visible functions should only use data or properties from
49    /// the node for which the visibility state must be determined, its siblings
50    /// or its parents. Usually, having a dependency on the state of any child
51    /// node is not possible, unless references are taken on these explicitly.
52    /// When no such reference exists, no signals may be received for these child
53    /// nodes (see reference counting rule number 3 in the [`TreeModel`][crate::TreeModel] section).
54    ///
55    /// Determining the visibility state of a given node based on the state
56    /// of its child nodes is a frequently occurring use case. Therefore,
57    /// [`TreeModelFilter`][crate::TreeModelFilter] explicitly supports this. For example, when a node
58    /// does not have any children, you might not want the node to be visible.
59    /// As soon as the first row is added to the node’s child level (or the
60    /// last row removed), the node’s visibility should be updated.
61    ///
62    /// This introduces a dependency from the node on its child nodes. In order
63    /// to accommodate this, [`TreeModelFilter`][crate::TreeModelFilter] must make sure the necessary
64    /// signals are received from the child model. This is achieved by building,
65    /// for all nodes which are exposed as visible nodes to [`TreeModelFilter`][crate::TreeModelFilter]'s
66    /// clients, the child level (if any) and take a reference on the first node
67    /// in this level. Furthermore, for every row-inserted, row-changed or
68    /// row-deleted signal (also these which were not handled because the node
69    /// was not cached), [`TreeModelFilter`][crate::TreeModelFilter] will check if the visibility state
70    /// of any parent node has changed.
71    ///
72    /// Beware, however, that this explicit support is limited to these two
73    /// cases. For example, if you want a node to be visible only if two nodes
74    /// in a child’s child level (2 levels deeper) are visible, you are on your
75    /// own. In this case, either rely on [`TreeStore`][crate::TreeStore] to emit all signals
76    /// because it does not implement reference counting, or for models that
77    /// do implement reference counting, obtain references on these child levels
78    /// yourself.
79    ///
80    /// ## Properties
81    ///
82    ///
83    /// #### `child-model`
84    ///  The child model of the tree model filter.
85    ///
86    /// Readable | Writeable | Construct Only
87    ///
88    ///
89    /// #### `virtual-root`
90    ///  The virtual root of the tree model filter.
91    ///
92    /// Readable | Writeable | Construct Only
93    ///
94    /// # Implements
95    ///
96    /// [`TreeModelFilterExt`][trait@crate::prelude::TreeModelFilterExt], [`trait@glib::ObjectExt`], [`TreeDragSourceExt`][trait@crate::prelude::TreeDragSourceExt], [`TreeModelExt`][trait@crate::prelude::TreeModelExt], [`TreeModelFilterExtManual`][trait@crate::prelude::TreeModelFilterExtManual], [`TreeModelExtManual`][trait@crate::prelude::TreeModelExtManual]
97    #[doc(alias = "GtkTreeModelFilter")]
98    pub struct TreeModelFilter(Object<ffi::GtkTreeModelFilter, ffi::GtkTreeModelFilterClass>) @implements TreeDragSource, TreeModel;
99
100    match fn {
101        type_ => || ffi::gtk_tree_model_filter_get_type(),
102    }
103}
104
105impl TreeModelFilter {
106    pub const NONE: Option<&'static TreeModelFilter> = None;
107}
108
109mod sealed {
110    pub trait Sealed {}
111    impl<T: super::IsA<super::TreeModelFilter>> Sealed for T {}
112}
113
114/// Trait containing all [`struct@TreeModelFilter`] methods.
115///
116/// # Implementors
117///
118/// [`TreeModelFilter`][struct@crate::TreeModelFilter]
119pub trait TreeModelFilterExt: IsA<TreeModelFilter> + sealed::Sealed + 'static {
120    /// This function should almost never be called. It clears the @self
121    /// of any cached iterators that haven’t been reffed with
122    /// gtk_tree_model_ref_node(). This might be useful if the child model
123    /// being filtered is static (and doesn’t change often) and there has been
124    /// a lot of unreffed access to nodes. As a side effect of this function,
125    /// all unreffed iters will be invalid.
126    ///
127    /// # Deprecated since 4.10
128    ///
129    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
130    #[allow(deprecated)]
131    #[doc(alias = "gtk_tree_model_filter_clear_cache")]
132    fn clear_cache(&self) {
133        unsafe {
134            ffi::gtk_tree_model_filter_clear_cache(self.as_ref().to_glib_none().0);
135        }
136    }
137
138    /// Sets @filter_iter to point to the row in @self that corresponds to the
139    /// row pointed at by @child_iter.  If @filter_iter was not set, [`false`] is
140    /// returned.
141    ///
142    /// # Deprecated since 4.10
143    ///
144    /// ## `child_iter`
145    /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on the child model.
146    ///
147    /// # Returns
148    ///
149    /// [`true`], if @filter_iter was set, i.e. if @child_iter is a
150    /// valid iterator pointing to a visible row in child model.
151    ///
152    /// ## `filter_iter`
153    /// An uninitialized [`TreeIter`][crate::TreeIter]
154    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
155    #[allow(deprecated)]
156    #[doc(alias = "gtk_tree_model_filter_convert_child_iter_to_iter")]
157    fn convert_child_iter_to_iter(&self, child_iter: &TreeIter) -> Option<TreeIter> {
158        unsafe {
159            let mut filter_iter = TreeIter::uninitialized();
160            let ret = from_glib(ffi::gtk_tree_model_filter_convert_child_iter_to_iter(
161                self.as_ref().to_glib_none().0,
162                filter_iter.to_glib_none_mut().0,
163                mut_override(child_iter.to_glib_none().0),
164            ));
165            if ret {
166                Some(filter_iter)
167            } else {
168                None
169            }
170        }
171    }
172
173    /// Converts @child_path to a path relative to @self. That is, @child_path
174    /// points to a path in the child model. The rerturned path will point to the
175    /// same row in the filtered model. If @child_path isn’t a valid path on the
176    /// child model or points to a row which is not visible in @self, then [`None`]
177    /// is returned.
178    ///
179    /// # Deprecated since 4.10
180    ///
181    /// ## `child_path`
182    /// A [`TreePath`][crate::TreePath] to convert.
183    ///
184    /// # Returns
185    ///
186    /// A newly allocated [`TreePath`][crate::TreePath]
187    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
188    #[allow(deprecated)]
189    #[doc(alias = "gtk_tree_model_filter_convert_child_path_to_path")]
190    fn convert_child_path_to_path(&self, child_path: &TreePath) -> Option<TreePath> {
191        unsafe {
192            from_glib_full(ffi::gtk_tree_model_filter_convert_child_path_to_path(
193                self.as_ref().to_glib_none().0,
194                mut_override(child_path.to_glib_none().0),
195            ))
196        }
197    }
198
199    /// Sets @child_iter to point to the row pointed to by @filter_iter.
200    ///
201    /// # Deprecated since 4.10
202    ///
203    /// ## `filter_iter`
204    /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on @self.
205    ///
206    /// # Returns
207    ///
208    ///
209    /// ## `child_iter`
210    /// An uninitialized [`TreeIter`][crate::TreeIter]
211    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
212    #[allow(deprecated)]
213    #[doc(alias = "gtk_tree_model_filter_convert_iter_to_child_iter")]
214    fn convert_iter_to_child_iter(&self, filter_iter: &TreeIter) -> TreeIter {
215        unsafe {
216            let mut child_iter = TreeIter::uninitialized();
217            ffi::gtk_tree_model_filter_convert_iter_to_child_iter(
218                self.as_ref().to_glib_none().0,
219                child_iter.to_glib_none_mut().0,
220                mut_override(filter_iter.to_glib_none().0),
221            );
222            child_iter
223        }
224    }
225
226    /// Converts @filter_path to a path on the child model of @self. That is,
227    /// @filter_path points to a location in @self. The returned path will
228    /// point to the same location in the model not being filtered. If @filter_path
229    /// does not point to a location in the child model, [`None`] is returned.
230    ///
231    /// # Deprecated since 4.10
232    ///
233    /// ## `filter_path`
234    /// A [`TreePath`][crate::TreePath] to convert.
235    ///
236    /// # Returns
237    ///
238    /// A newly allocated [`TreePath`][crate::TreePath]
239    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
240    #[allow(deprecated)]
241    #[doc(alias = "gtk_tree_model_filter_convert_path_to_child_path")]
242    fn convert_path_to_child_path(&self, filter_path: &TreePath) -> Option<TreePath> {
243        unsafe {
244            from_glib_full(ffi::gtk_tree_model_filter_convert_path_to_child_path(
245                self.as_ref().to_glib_none().0,
246                mut_override(filter_path.to_glib_none().0),
247            ))
248        }
249    }
250
251    /// Returns a pointer to the child model of @self.
252    ///
253    /// # Deprecated since 4.10
254    ///
255    ///
256    /// # Returns
257    ///
258    /// A pointer to a [`TreeModel`][crate::TreeModel]
259    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
260    #[allow(deprecated)]
261    #[doc(alias = "gtk_tree_model_filter_get_model")]
262    #[doc(alias = "get_model")]
263    fn model(&self) -> TreeModel {
264        unsafe {
265            from_glib_none(ffi::gtk_tree_model_filter_get_model(
266                self.as_ref().to_glib_none().0,
267            ))
268        }
269    }
270
271    /// Emits ::row_changed for each row in the child model, which causes
272    /// the filter to re-evaluate whether a row is visible or not.
273    ///
274    /// # Deprecated since 4.10
275    ///
276    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
277    #[allow(deprecated)]
278    #[doc(alias = "gtk_tree_model_filter_refilter")]
279    fn refilter(&self) {
280        unsafe {
281            ffi::gtk_tree_model_filter_refilter(self.as_ref().to_glib_none().0);
282        }
283    }
284
285    /// Sets @column of the child_model to be the column where @self should
286    /// look for visibility information. @columns should be a column of type
287    /// `G_TYPE_BOOLEAN`, where [`true`] means that a row is visible, and [`false`]
288    /// if not.
289    ///
290    /// Note that gtk_tree_model_filter_set_visible_func() or
291    /// gtk_tree_model_filter_set_visible_column() can only be called
292    /// once for a given filter model.
293    ///
294    /// # Deprecated since 4.10
295    ///
296    /// ## `column`
297    /// A `int` which is the column containing the visible information
298    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
299    #[allow(deprecated)]
300    #[doc(alias = "gtk_tree_model_filter_set_visible_column")]
301    fn set_visible_column(&self, column: i32) {
302        unsafe {
303            ffi::gtk_tree_model_filter_set_visible_column(self.as_ref().to_glib_none().0, column);
304        }
305    }
306
307    /// Sets the visible function used when filtering the @self to be @func.
308    /// The function should return [`true`] if the given row should be visible and
309    /// [`false`] otherwise.
310    ///
311    /// If the condition calculated by the function changes over time (e.g.
312    /// because it depends on some global parameters), you must call
313    /// gtk_tree_model_filter_refilter() to keep the visibility information
314    /// of the model up-to-date.
315    ///
316    /// Note that @func is called whenever a row is inserted, when it may still
317    /// be empty. The visible function should therefore take special care of empty
318    /// rows, like in the example below.
319    ///
320    ///
321    ///
322    /// **⚠️ The following code is in C ⚠️**
323    ///
324    /// ```C
325    /// static gboolean
326    /// visible_func (GtkTreeModel *model,
327    ///               GtkTreeIter  *iter,
328    ///               gpointer      data)
329    /// {
330    ///   // Visible if row is non-empty and first column is “HI”
331    ///   char *str;
332    ///   gboolean visible = FALSE;
333    ///
334    ///   gtk_tree_model_get (model, iter, 0, &str, -1);
335    ///   if (str && strcmp (str, "HI") == 0)
336    ///     visible = TRUE;
337    ///   g_free (str);
338    ///
339    ///   return visible;
340    /// }
341    /// ```
342    ///
343    /// Note that gtk_tree_model_filter_set_visible_func() or
344    /// gtk_tree_model_filter_set_visible_column() can only be called
345    /// once for a given filter model.
346    ///
347    /// # Deprecated since 4.10
348    ///
349    /// ## `func`
350    /// A `GtkTreeModelFilterVisibleFunc`, the visible function
351    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
352    #[allow(deprecated)]
353    #[doc(alias = "gtk_tree_model_filter_set_visible_func")]
354    fn set_visible_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(&self, func: P) {
355        let func_data: Box_<P> = Box_::new(func);
356        unsafe extern "C" fn func_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(
357            model: *mut ffi::GtkTreeModel,
358            iter: *mut ffi::GtkTreeIter,
359            data: glib::ffi::gpointer,
360        ) -> glib::ffi::gboolean {
361            let model = from_glib_borrow(model);
362            let iter = from_glib_borrow(iter);
363            let callback = &*(data as *mut P);
364            (*callback)(&model, &iter).into_glib()
365        }
366        let func = Some(func_func::<P> as _);
367        unsafe extern "C" fn destroy_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(
368            data: glib::ffi::gpointer,
369        ) {
370            let _callback = Box_::from_raw(data as *mut P);
371        }
372        let destroy_call3 = Some(destroy_func::<P> as _);
373        let super_callback0: Box_<P> = func_data;
374        unsafe {
375            ffi::gtk_tree_model_filter_set_visible_func(
376                self.as_ref().to_glib_none().0,
377                func,
378                Box_::into_raw(super_callback0) as *mut _,
379                destroy_call3,
380            );
381        }
382    }
383
384    /// The child model of the tree model filter.
385    #[doc(alias = "child-model")]
386    fn child_model(&self) -> Option<TreeModel> {
387        ObjectExt::property(self.as_ref(), "child-model")
388    }
389}
390
391impl<O: IsA<TreeModelFilter>> TreeModelFilterExt for O {}