gtk4/auto/tree_model_sort.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::{TreeDragSource, TreeIter, TreeModel, TreePath, TreeSortable, ffi};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// Use [`SortListModel`][crate::SortListModel] instead
11 /// A GtkTreeModel which makes an underlying tree model sortable
12 ///
13 /// The [`TreeModelSort`][crate::TreeModelSort] is a model which implements the [`TreeSortable`][crate::TreeSortable]
14 /// interface. It does not hold any data itself, but rather is created with
15 /// a child model and proxies its data. It has identical column types to
16 /// this child model, and the changes in the child are propagated. The
17 /// primary purpose of this model is to provide a way to sort a different
18 /// model without modifying it. Note that the sort function used by
19 /// [`TreeModelSort`][crate::TreeModelSort] is not guaranteed to be stable.
20 ///
21 /// The use of this is best demonstrated through an example. In the
22 /// following sample code we create two [`TreeView`][crate::TreeView] widgets each with a
23 /// view of the same data. As the model is wrapped here by a
24 /// [`TreeModelSort`][crate::TreeModelSort], the two [`TreeView`][crate::TreeView]s can each sort their
25 /// view of the data without affecting the other. By contrast, if we
26 /// simply put the same model in each widget, then sorting the first would
27 /// sort the second.
28 ///
29 /// ## Using a [`TreeModelSort`][crate::TreeModelSort]
30 ///
31 /// **⚠️ The following code is in c ⚠️**
32 ///
33 /// ```c
34 /// {
35 /// GtkTreeView *tree_view1;
36 /// GtkTreeView *tree_view2;
37 /// GtkTreeModel *sort_model1;
38 /// GtkTreeModel *sort_model2;
39 /// GtkTreeModel *child_model;
40 ///
41 /// // get the child model
42 /// child_model = get_my_model ();
43 ///
44 /// // Create the first tree
45 /// sort_model1 = gtk_tree_model_sort_new_with_model (child_model);
46 /// tree_view1 = gtk_tree_view_new_with_model (sort_model1);
47 ///
48 /// // Create the second tree
49 /// sort_model2 = gtk_tree_model_sort_new_with_model (child_model);
50 /// tree_view2 = gtk_tree_view_new_with_model (sort_model2);
51 ///
52 /// // Now we can sort the two models independently
53 /// gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model1),
54 /// COLUMN_1, GTK_SORT_ASCENDING);
55 /// gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model2),
56 /// COLUMN_1, GTK_SORT_DESCENDING);
57 /// }
58 /// ```
59 ///
60 /// To demonstrate how to access the underlying child model from the sort
61 /// model, the next example will be a callback for the [`TreeSelection`][crate::TreeSelection]
62 /// `GtkTreeSelection::changed` signal. In this callback, we get a string
63 /// from COLUMN_1 of the model. We then modify the string, find the same
64 /// selected row on the child model, and change the row there.
65 ///
66 /// ## Accessing the child model of in a selection changed callback
67 ///
68 /// **⚠️ The following code is in c ⚠️**
69 ///
70 /// ```c
71 /// void
72 /// selection_changed (GtkTreeSelection *selection, gpointer data)
73 /// {
74 /// GtkTreeModel *sort_model = NULL;
75 /// GtkTreeModel *child_model;
76 /// GtkTreeIter sort_iter;
77 /// GtkTreeIter child_iter;
78 /// char *some_data = NULL;
79 /// char *modified_data;
80 ///
81 /// // Get the current selected row and the model.
82 /// if (! gtk_tree_selection_get_selected (selection,
83 /// &sort_model,
84 /// &sort_iter))
85 /// return;
86 ///
87 /// // Look up the current value on the selected row and get
88 /// // a new value to change it to.
89 /// gtk_tree_model_get (GTK_TREE_MODEL (sort_model), &sort_iter,
90 /// COLUMN_1, &some_data,
91 /// -1);
92 ///
93 /// modified_data = change_the_data (some_data);
94 /// g_free (some_data);
95 ///
96 /// // Get an iterator on the child model, instead of the sort model.
97 /// gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model),
98 /// &child_iter,
99 /// &sort_iter);
100 ///
101 /// // Get the child model and change the value of the row. In this
102 /// // example, the child model is a GtkListStore. It could be any other
103 /// // type of model, though.
104 /// child_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model));
105 /// gtk_list_store_set (GTK_LIST_STORE (child_model), &child_iter,
106 /// COLUMN_1, &modified_data,
107 /// -1);
108 /// g_free (modified_data);
109 /// }
110 /// ```
111 ///
112 /// ## Properties
113 ///
114 ///
115 /// #### `model`
116 /// The model of the tree model sort.
117 ///
118 /// Readable | Writable | Construct Only
119 ///
120 /// # Implements
121 ///
122 /// [`TreeModelSortExt`][trait@crate::prelude::TreeModelSortExt], [`trait@glib::ObjectExt`], [`TreeDragSourceExt`][trait@crate::prelude::TreeDragSourceExt], [`TreeModelExt`][trait@crate::prelude::TreeModelExt], [`TreeSortableExt`][trait@crate::prelude::TreeSortableExt], [`TreeModelExtManual`][trait@crate::prelude::TreeModelExtManual], [`TreeSortableExtManual`][trait@crate::prelude::TreeSortableExtManual]
123 #[doc(alias = "GtkTreeModelSort")]
124 pub struct TreeModelSort(Object<ffi::GtkTreeModelSort, ffi::GtkTreeModelSortClass>) @implements TreeDragSource, TreeModel, TreeSortable;
125
126 match fn {
127 type_ => || ffi::gtk_tree_model_sort_get_type(),
128 }
129}
130
131impl TreeModelSort {
132 pub const NONE: Option<&'static TreeModelSort> = None;
133
134 /// Creates a new [`TreeModelSort`][crate::TreeModelSort], with @child_model as the child model.
135 ///
136 /// # Deprecated since 4.10
137 ///
138 /// ## `child_model`
139 /// A [`TreeModel`][crate::TreeModel]
140 ///
141 /// # Returns
142 ///
143 /// A new [`TreeModelSort`][crate::TreeModelSort].
144 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
145 #[allow(deprecated)]
146 #[doc(alias = "gtk_tree_model_sort_new_with_model")]
147 #[doc(alias = "new_with_model")]
148 pub fn with_model(child_model: &impl IsA<TreeModel>) -> TreeModelSort {
149 skip_assert_initialized!();
150 unsafe {
151 from_glib_full(ffi::gtk_tree_model_sort_new_with_model(
152 child_model.as_ref().to_glib_none().0,
153 ))
154 }
155 }
156}
157
158/// Trait containing all [`struct@TreeModelSort`] methods.
159///
160/// # Implementors
161///
162/// [`TreeModelSort`][struct@crate::TreeModelSort]
163pub trait TreeModelSortExt: IsA<TreeModelSort> + 'static {
164 /// This function should almost never be called. It clears the @self
165 /// of any cached iterators that haven’t been reffed with
166 /// gtk_tree_model_ref_node(). This might be useful if the child model being
167 /// sorted is static (and doesn’t change often) and there has been a lot of
168 /// unreffed access to nodes. As a side effect of this function, all unreffed
169 /// iters will be invalid.
170 ///
171 /// # Deprecated since 4.10
172 ///
173 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
174 #[allow(deprecated)]
175 #[doc(alias = "gtk_tree_model_sort_clear_cache")]
176 fn clear_cache(&self) {
177 unsafe {
178 ffi::gtk_tree_model_sort_clear_cache(self.as_ref().to_glib_none().0);
179 }
180 }
181
182 /// Sets @sort_iter to point to the row in @self that corresponds to
183 /// the row pointed at by @child_iter. If @sort_iter was not set, [`false`]
184 /// is returned. Note: a boolean is only returned since 2.14.
185 ///
186 /// # Deprecated since 4.10
187 ///
188 /// ## `child_iter`
189 /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on the child model
190 ///
191 /// # Returns
192 ///
193 /// [`true`], if @sort_iter was set, i.e. if @sort_iter is a
194 /// valid iterator pointer to a visible row in the child model.
195 ///
196 /// ## `sort_iter`
197 /// An uninitialized [`TreeIter`][crate::TreeIter]
198 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
199 #[allow(deprecated)]
200 #[doc(alias = "gtk_tree_model_sort_convert_child_iter_to_iter")]
201 fn convert_child_iter_to_iter(&self, child_iter: &TreeIter) -> Option<TreeIter> {
202 unsafe {
203 let mut sort_iter = TreeIter::uninitialized();
204 let ret = from_glib(ffi::gtk_tree_model_sort_convert_child_iter_to_iter(
205 self.as_ref().to_glib_none().0,
206 sort_iter.to_glib_none_mut().0,
207 mut_override(child_iter.to_glib_none().0),
208 ));
209 if ret { Some(sort_iter) } else { None }
210 }
211 }
212
213 /// Converts @child_path to a path relative to @self. That is,
214 /// @child_path points to a path in the child model. The returned path will
215 /// point to the same row in the sorted model. If @child_path isn’t a valid
216 /// path on the child model, then [`None`] is returned.
217 ///
218 /// # Deprecated since 4.10
219 ///
220 /// ## `child_path`
221 /// A [`TreePath`][crate::TreePath] to convert
222 ///
223 /// # Returns
224 ///
225 /// A newly allocated [`TreePath`][crate::TreePath]
226 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
227 #[allow(deprecated)]
228 #[doc(alias = "gtk_tree_model_sort_convert_child_path_to_path")]
229 fn convert_child_path_to_path(&self, child_path: &TreePath) -> Option<TreePath> {
230 unsafe {
231 from_glib_full(ffi::gtk_tree_model_sort_convert_child_path_to_path(
232 self.as_ref().to_glib_none().0,
233 mut_override(child_path.to_glib_none().0),
234 ))
235 }
236 }
237
238 /// Sets @child_iter to point to the row pointed to by @sorted_iter.
239 ///
240 /// # Deprecated since 4.10
241 ///
242 /// ## `sorted_iter`
243 /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on @self.
244 ///
245 /// # Returns
246 ///
247 ///
248 /// ## `child_iter`
249 /// An uninitialized [`TreeIter`][crate::TreeIter]
250 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
251 #[allow(deprecated)]
252 #[doc(alias = "gtk_tree_model_sort_convert_iter_to_child_iter")]
253 fn convert_iter_to_child_iter(&self, sorted_iter: &TreeIter) -> TreeIter {
254 unsafe {
255 let mut child_iter = TreeIter::uninitialized();
256 ffi::gtk_tree_model_sort_convert_iter_to_child_iter(
257 self.as_ref().to_glib_none().0,
258 child_iter.to_glib_none_mut().0,
259 mut_override(sorted_iter.to_glib_none().0),
260 );
261 child_iter
262 }
263 }
264
265 /// Converts @sorted_path to a path on the child model of @self.
266 /// That is, @sorted_path points to a location in @self. The
267 /// returned path will point to the same location in the model not being
268 /// sorted. If @sorted_path does not point to a location in the child model,
269 /// [`None`] is returned.
270 ///
271 /// # Deprecated since 4.10
272 ///
273 /// ## `sorted_path`
274 /// A [`TreePath`][crate::TreePath] to convert
275 ///
276 /// # Returns
277 ///
278 /// A newly allocated [`TreePath`][crate::TreePath]
279 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
280 #[allow(deprecated)]
281 #[doc(alias = "gtk_tree_model_sort_convert_path_to_child_path")]
282 fn convert_path_to_child_path(&self, sorted_path: &TreePath) -> Option<TreePath> {
283 unsafe {
284 from_glib_full(ffi::gtk_tree_model_sort_convert_path_to_child_path(
285 self.as_ref().to_glib_none().0,
286 mut_override(sorted_path.to_glib_none().0),
287 ))
288 }
289 }
290
291 /// Returns the model the [`TreeModelSort`][crate::TreeModelSort] is sorting.
292 ///
293 /// # Deprecated since 4.10
294 ///
295 ///
296 /// # Returns
297 ///
298 /// the "child model" being sorted
299 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
300 #[allow(deprecated)]
301 #[doc(alias = "gtk_tree_model_sort_get_model")]
302 #[doc(alias = "get_model")]
303 fn model(&self) -> TreeModel {
304 unsafe {
305 from_glib_none(ffi::gtk_tree_model_sort_get_model(
306 self.as_ref().to_glib_none().0,
307 ))
308 }
309 }
310
311 /// > This function is slow. Only use it for debugging and/or testing
312 /// > purposes.
313 ///
314 /// Checks if the given iter is a valid iter for this [`TreeModelSort`][crate::TreeModelSort].
315 ///
316 /// # Deprecated since 4.10
317 ///
318 /// ## `iter`
319 /// A [`TreeIter`][crate::TreeIter]
320 ///
321 /// # Returns
322 ///
323 /// [`true`] if the iter is valid, [`false`] if the iter is invalid.
324 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
325 #[allow(deprecated)]
326 #[doc(alias = "gtk_tree_model_sort_iter_is_valid")]
327 fn iter_is_valid(&self, iter: &TreeIter) -> bool {
328 unsafe {
329 from_glib(ffi::gtk_tree_model_sort_iter_is_valid(
330 self.as_ref().to_glib_none().0,
331 mut_override(iter.to_glib_none().0),
332 ))
333 }
334 }
335
336 /// This resets the default sort function to be in the “unsorted” state. That
337 /// is, it is in the same order as the child model. It will re-sort the model
338 /// to be in the same order as the child model only if the [`TreeModelSort`][crate::TreeModelSort]
339 /// is in “unsorted” state.
340 ///
341 /// # Deprecated since 4.10
342 ///
343 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
344 #[allow(deprecated)]
345 #[doc(alias = "gtk_tree_model_sort_reset_default_sort_func")]
346 fn reset_default_sort_func(&self) {
347 unsafe {
348 ffi::gtk_tree_model_sort_reset_default_sort_func(self.as_ref().to_glib_none().0);
349 }
350 }
351}
352
353impl<O: IsA<TreeModelSort>> TreeModelSortExt for O {}