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
109/// Trait containing all [`struct@TreeModelFilter`] methods.
110///
111/// # Implementors
112///
113/// [`TreeModelFilter`][struct@crate::TreeModelFilter]
114pub trait TreeModelFilterExt: IsA<TreeModelFilter> + 'static {
115    /// This function should almost never be called. It clears the @self
116    /// of any cached iterators that haven’t been reffed with
117    /// gtk_tree_model_ref_node(). This might be useful if the child model
118    /// being filtered is static (and doesn’t change often) and there has been
119    /// a lot of unreffed access to nodes. As a side effect of this function,
120    /// all unreffed iters will be invalid.
121    ///
122    /// # Deprecated since 4.10
123    ///
124    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
125    #[allow(deprecated)]
126    #[doc(alias = "gtk_tree_model_filter_clear_cache")]
127    fn clear_cache(&self) {
128        unsafe {
129            ffi::gtk_tree_model_filter_clear_cache(self.as_ref().to_glib_none().0);
130        }
131    }
132
133    /// Sets @filter_iter to point to the row in @self that corresponds to the
134    /// row pointed at by @child_iter.  If @filter_iter was not set, [`false`] is
135    /// returned.
136    ///
137    /// # Deprecated since 4.10
138    ///
139    /// ## `child_iter`
140    /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on the child model.
141    ///
142    /// # Returns
143    ///
144    /// [`true`], if @filter_iter was set, i.e. if @child_iter is a
145    /// valid iterator pointing to a visible row in child model.
146    ///
147    /// ## `filter_iter`
148    /// An uninitialized [`TreeIter`][crate::TreeIter]
149    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
150    #[allow(deprecated)]
151    #[doc(alias = "gtk_tree_model_filter_convert_child_iter_to_iter")]
152    fn convert_child_iter_to_iter(&self, child_iter: &TreeIter) -> Option<TreeIter> {
153        unsafe {
154            let mut filter_iter = TreeIter::uninitialized();
155            let ret = from_glib(ffi::gtk_tree_model_filter_convert_child_iter_to_iter(
156                self.as_ref().to_glib_none().0,
157                filter_iter.to_glib_none_mut().0,
158                mut_override(child_iter.to_glib_none().0),
159            ));
160            if ret {
161                Some(filter_iter)
162            } else {
163                None
164            }
165        }
166    }
167
168    /// Converts @child_path to a path relative to @self. That is, @child_path
169    /// points to a path in the child model. The rerturned path will point to the
170    /// same row in the filtered model. If @child_path isn’t a valid path on the
171    /// child model or points to a row which is not visible in @self, then [`None`]
172    /// is returned.
173    ///
174    /// # Deprecated since 4.10
175    ///
176    /// ## `child_path`
177    /// A [`TreePath`][crate::TreePath] to convert.
178    ///
179    /// # Returns
180    ///
181    /// A newly allocated [`TreePath`][crate::TreePath]
182    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
183    #[allow(deprecated)]
184    #[doc(alias = "gtk_tree_model_filter_convert_child_path_to_path")]
185    fn convert_child_path_to_path(&self, child_path: &TreePath) -> Option<TreePath> {
186        unsafe {
187            from_glib_full(ffi::gtk_tree_model_filter_convert_child_path_to_path(
188                self.as_ref().to_glib_none().0,
189                mut_override(child_path.to_glib_none().0),
190            ))
191        }
192    }
193
194    /// Sets @child_iter to point to the row pointed to by @filter_iter.
195    ///
196    /// # Deprecated since 4.10
197    ///
198    /// ## `filter_iter`
199    /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on @self.
200    ///
201    /// # Returns
202    ///
203    ///
204    /// ## `child_iter`
205    /// An uninitialized [`TreeIter`][crate::TreeIter]
206    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
207    #[allow(deprecated)]
208    #[doc(alias = "gtk_tree_model_filter_convert_iter_to_child_iter")]
209    fn convert_iter_to_child_iter(&self, filter_iter: &TreeIter) -> TreeIter {
210        unsafe {
211            let mut child_iter = TreeIter::uninitialized();
212            ffi::gtk_tree_model_filter_convert_iter_to_child_iter(
213                self.as_ref().to_glib_none().0,
214                child_iter.to_glib_none_mut().0,
215                mut_override(filter_iter.to_glib_none().0),
216            );
217            child_iter
218        }
219    }
220
221    /// Converts @filter_path to a path on the child model of @self. That is,
222    /// @filter_path points to a location in @self. The returned path will
223    /// point to the same location in the model not being filtered. If @filter_path
224    /// does not point to a location in the child model, [`None`] is returned.
225    ///
226    /// # Deprecated since 4.10
227    ///
228    /// ## `filter_path`
229    /// A [`TreePath`][crate::TreePath] to convert.
230    ///
231    /// # Returns
232    ///
233    /// A newly allocated [`TreePath`][crate::TreePath]
234    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
235    #[allow(deprecated)]
236    #[doc(alias = "gtk_tree_model_filter_convert_path_to_child_path")]
237    fn convert_path_to_child_path(&self, filter_path: &TreePath) -> Option<TreePath> {
238        unsafe {
239            from_glib_full(ffi::gtk_tree_model_filter_convert_path_to_child_path(
240                self.as_ref().to_glib_none().0,
241                mut_override(filter_path.to_glib_none().0),
242            ))
243        }
244    }
245
246    /// Returns a pointer to the child model of @self.
247    ///
248    /// # Deprecated since 4.10
249    ///
250    ///
251    /// # Returns
252    ///
253    /// A pointer to a [`TreeModel`][crate::TreeModel]
254    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
255    #[allow(deprecated)]
256    #[doc(alias = "gtk_tree_model_filter_get_model")]
257    #[doc(alias = "get_model")]
258    fn model(&self) -> TreeModel {
259        unsafe {
260            from_glib_none(ffi::gtk_tree_model_filter_get_model(
261                self.as_ref().to_glib_none().0,
262            ))
263        }
264    }
265
266    /// Emits ::row_changed for each row in the child model, which causes
267    /// the filter to re-evaluate whether a row is visible or not.
268    ///
269    /// # Deprecated since 4.10
270    ///
271    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
272    #[allow(deprecated)]
273    #[doc(alias = "gtk_tree_model_filter_refilter")]
274    fn refilter(&self) {
275        unsafe {
276            ffi::gtk_tree_model_filter_refilter(self.as_ref().to_glib_none().0);
277        }
278    }
279
280    /// Sets @column of the child_model to be the column where @self should
281    /// look for visibility information. @columns should be a column of type
282    /// `G_TYPE_BOOLEAN`, where [`true`] means that a row is visible, and [`false`]
283    /// if not.
284    ///
285    /// Note that gtk_tree_model_filter_set_visible_func() or
286    /// gtk_tree_model_filter_set_visible_column() can only be called
287    /// once for a given filter model.
288    ///
289    /// # Deprecated since 4.10
290    ///
291    /// ## `column`
292    /// A `int` which is the column containing the visible information
293    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
294    #[allow(deprecated)]
295    #[doc(alias = "gtk_tree_model_filter_set_visible_column")]
296    fn set_visible_column(&self, column: i32) {
297        unsafe {
298            ffi::gtk_tree_model_filter_set_visible_column(self.as_ref().to_glib_none().0, column);
299        }
300    }
301
302    /// Sets the visible function used when filtering the @self to be @func.
303    /// The function should return [`true`] if the given row should be visible and
304    /// [`false`] otherwise.
305    ///
306    /// If the condition calculated by the function changes over time (e.g.
307    /// because it depends on some global parameters), you must call
308    /// gtk_tree_model_filter_refilter() to keep the visibility information
309    /// of the model up-to-date.
310    ///
311    /// Note that @func is called whenever a row is inserted, when it may still
312    /// be empty. The visible function should therefore take special care of empty
313    /// rows, like in the example below.
314    ///
315    /// **⚠️ The following code is in c ⚠️**
316    ///
317    /// ```c
318    /// static gboolean
319    /// visible_func (GtkTreeModel *model,
320    ///               GtkTreeIter  *iter,
321    ///               gpointer      data)
322    /// {
323    ///   // Visible if row is non-empty and first column is “HI”
324    ///   char *str;
325    ///   gboolean visible = FALSE;
326    ///
327    ///   gtk_tree_model_get (model, iter, 0, &str, -1);
328    ///   if (str && strcmp (str, "HI") == 0)
329    ///     visible = TRUE;
330    ///   g_free (str);
331    ///
332    ///   return visible;
333    /// }
334    /// ```
335    ///
336    /// Note that gtk_tree_model_filter_set_visible_func() or
337    /// gtk_tree_model_filter_set_visible_column() can only be called
338    /// once for a given filter model.
339    ///
340    /// # Deprecated since 4.10
341    ///
342    /// ## `func`
343    /// A `GtkTreeModelFilterVisibleFunc`, the visible function
344    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
345    #[allow(deprecated)]
346    #[doc(alias = "gtk_tree_model_filter_set_visible_func")]
347    fn set_visible_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(&self, func: P) {
348        let func_data: Box_<P> = Box_::new(func);
349        unsafe extern "C" fn func_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(
350            model: *mut ffi::GtkTreeModel,
351            iter: *mut ffi::GtkTreeIter,
352            data: glib::ffi::gpointer,
353        ) -> glib::ffi::gboolean {
354            let model = from_glib_borrow(model);
355            let iter = from_glib_borrow(iter);
356            let callback = &*(data as *mut P);
357            (*callback)(&model, &iter).into_glib()
358        }
359        let func = Some(func_func::<P> as _);
360        unsafe extern "C" fn destroy_func<P: Fn(&TreeModel, &TreeIter) -> bool + 'static>(
361            data: glib::ffi::gpointer,
362        ) {
363            let _callback = Box_::from_raw(data as *mut P);
364        }
365        let destroy_call3 = Some(destroy_func::<P> as _);
366        let super_callback0: Box_<P> = func_data;
367        unsafe {
368            ffi::gtk_tree_model_filter_set_visible_func(
369                self.as_ref().to_glib_none().0,
370                func,
371                Box_::into_raw(super_callback0) as *mut _,
372                destroy_call3,
373            );
374        }
375    }
376
377    /// The child model of the tree model filter.
378    #[doc(alias = "child-model")]
379    fn child_model(&self) -> Option<TreeModel> {
380        ObjectExt::property(self.as_ref(), "child-model")
381    }
382}
383
384impl<O: IsA<TreeModelFilter>> TreeModelFilterExt for O {}