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 | Writeable | 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 /// ## `child_model`
136 /// A [`TreeModel`][crate::TreeModel]
137 ///
138 /// # Returns
139 ///
140 /// A new [`TreeModelSort`][crate::TreeModelSort].
141 #[doc(alias = "gtk_tree_model_sort_new_with_model")]
142 #[doc(alias = "new_with_model")]
143 pub fn with_model(child_model: &impl IsA<TreeModel>) -> TreeModelSort {
144 skip_assert_initialized!();
145 unsafe {
146 from_glib_full(ffi::gtk_tree_model_sort_new_with_model(
147 child_model.as_ref().to_glib_none().0,
148 ))
149 }
150 }
151}
152
153/// Trait containing all [`struct@TreeModelSort`] methods.
154///
155/// # Implementors
156///
157/// [`TreeModelSort`][struct@crate::TreeModelSort]
158pub trait TreeModelSortExt: IsA<TreeModelSort> + 'static {
159 /// This function should almost never be called. It clears the @self
160 /// of any cached iterators that haven’t been reffed with
161 /// gtk_tree_model_ref_node(). This might be useful if the child model being
162 /// sorted is static (and doesn’t change often) and there has been a lot of
163 /// unreffed access to nodes. As a side effect of this function, all unreffed
164 /// iters will be invalid.
165 ///
166 /// # Deprecated since 4.10
167 ///
168 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
169 #[allow(deprecated)]
170 #[doc(alias = "gtk_tree_model_sort_clear_cache")]
171 fn clear_cache(&self) {
172 unsafe {
173 ffi::gtk_tree_model_sort_clear_cache(self.as_ref().to_glib_none().0);
174 }
175 }
176
177 /// Sets @sort_iter to point to the row in @self that corresponds to
178 /// the row pointed at by @child_iter. If @sort_iter was not set, [`false`]
179 /// is returned. Note: a boolean is only returned since 2.14.
180 ///
181 /// # Deprecated since 4.10
182 ///
183 /// ## `child_iter`
184 /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on the child model
185 ///
186 /// # Returns
187 ///
188 /// [`true`], if @sort_iter was set, i.e. if @sort_iter is a
189 /// valid iterator pointer to a visible row in the child model.
190 ///
191 /// ## `sort_iter`
192 /// An uninitialized [`TreeIter`][crate::TreeIter]
193 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
194 #[allow(deprecated)]
195 #[doc(alias = "gtk_tree_model_sort_convert_child_iter_to_iter")]
196 fn convert_child_iter_to_iter(&self, child_iter: &TreeIter) -> Option<TreeIter> {
197 unsafe {
198 let mut sort_iter = TreeIter::uninitialized();
199 let ret = from_glib(ffi::gtk_tree_model_sort_convert_child_iter_to_iter(
200 self.as_ref().to_glib_none().0,
201 sort_iter.to_glib_none_mut().0,
202 mut_override(child_iter.to_glib_none().0),
203 ));
204 if ret { Some(sort_iter) } else { None }
205 }
206 }
207
208 /// Converts @child_path to a path relative to @self. That is,
209 /// @child_path points to a path in the child model. The returned path will
210 /// point to the same row in the sorted model. If @child_path isn’t a valid
211 /// path on the child model, then [`None`] is returned.
212 ///
213 /// # Deprecated since 4.10
214 ///
215 /// ## `child_path`
216 /// A [`TreePath`][crate::TreePath] to convert
217 ///
218 /// # Returns
219 ///
220 /// A newly allocated [`TreePath`][crate::TreePath]
221 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
222 #[allow(deprecated)]
223 #[doc(alias = "gtk_tree_model_sort_convert_child_path_to_path")]
224 fn convert_child_path_to_path(&self, child_path: &TreePath) -> Option<TreePath> {
225 unsafe {
226 from_glib_full(ffi::gtk_tree_model_sort_convert_child_path_to_path(
227 self.as_ref().to_glib_none().0,
228 mut_override(child_path.to_glib_none().0),
229 ))
230 }
231 }
232
233 /// Sets @child_iter to point to the row pointed to by @sorted_iter.
234 ///
235 /// # Deprecated since 4.10
236 ///
237 /// ## `sorted_iter`
238 /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on @self.
239 ///
240 /// # Returns
241 ///
242 ///
243 /// ## `child_iter`
244 /// An uninitialized [`TreeIter`][crate::TreeIter]
245 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
246 #[allow(deprecated)]
247 #[doc(alias = "gtk_tree_model_sort_convert_iter_to_child_iter")]
248 fn convert_iter_to_child_iter(&self, sorted_iter: &TreeIter) -> TreeIter {
249 unsafe {
250 let mut child_iter = TreeIter::uninitialized();
251 ffi::gtk_tree_model_sort_convert_iter_to_child_iter(
252 self.as_ref().to_glib_none().0,
253 child_iter.to_glib_none_mut().0,
254 mut_override(sorted_iter.to_glib_none().0),
255 );
256 child_iter
257 }
258 }
259
260 /// Converts @sorted_path to a path on the child model of @self.
261 /// That is, @sorted_path points to a location in @self. The
262 /// returned path will point to the same location in the model not being
263 /// sorted. If @sorted_path does not point to a location in the child model,
264 /// [`None`] is returned.
265 ///
266 /// # Deprecated since 4.10
267 ///
268 /// ## `sorted_path`
269 /// A [`TreePath`][crate::TreePath] to convert
270 ///
271 /// # Returns
272 ///
273 /// A newly allocated [`TreePath`][crate::TreePath]
274 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
275 #[allow(deprecated)]
276 #[doc(alias = "gtk_tree_model_sort_convert_path_to_child_path")]
277 fn convert_path_to_child_path(&self, sorted_path: &TreePath) -> Option<TreePath> {
278 unsafe {
279 from_glib_full(ffi::gtk_tree_model_sort_convert_path_to_child_path(
280 self.as_ref().to_glib_none().0,
281 mut_override(sorted_path.to_glib_none().0),
282 ))
283 }
284 }
285
286 /// Returns the model the [`TreeModelSort`][crate::TreeModelSort] is sorting.
287 ///
288 /// # Returns
289 ///
290 /// the "child model" being sorted
291 #[doc(alias = "gtk_tree_model_sort_get_model")]
292 #[doc(alias = "get_model")]
293 fn model(&self) -> TreeModel {
294 unsafe {
295 from_glib_none(ffi::gtk_tree_model_sort_get_model(
296 self.as_ref().to_glib_none().0,
297 ))
298 }
299 }
300
301 /// > This function is slow. Only use it for debugging and/or testing
302 /// > purposes.
303 ///
304 /// Checks if the given iter is a valid iter for this [`TreeModelSort`][crate::TreeModelSort].
305 ///
306 /// # Deprecated since 4.10
307 ///
308 /// ## `iter`
309 /// A [`TreeIter`][crate::TreeIter]
310 ///
311 /// # Returns
312 ///
313 /// [`true`] if the iter is valid, [`false`] if the iter is invalid.
314 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
315 #[allow(deprecated)]
316 #[doc(alias = "gtk_tree_model_sort_iter_is_valid")]
317 fn iter_is_valid(&self, iter: &TreeIter) -> bool {
318 unsafe {
319 from_glib(ffi::gtk_tree_model_sort_iter_is_valid(
320 self.as_ref().to_glib_none().0,
321 mut_override(iter.to_glib_none().0),
322 ))
323 }
324 }
325
326 /// This resets the default sort function to be in the “unsorted” state. That
327 /// is, it is in the same order as the child model. It will re-sort the model
328 /// to be in the same order as the child model only if the [`TreeModelSort`][crate::TreeModelSort]
329 /// is in “unsorted” state.
330 ///
331 /// # Deprecated since 4.10
332 ///
333 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
334 #[allow(deprecated)]
335 #[doc(alias = "gtk_tree_model_sort_reset_default_sort_func")]
336 fn reset_default_sort_func(&self) {
337 unsafe {
338 ffi::gtk_tree_model_sort_reset_default_sort_func(self.as_ref().to_glib_none().0);
339 }
340 }
341}
342
343impl<O: IsA<TreeModelSort>> TreeModelSortExt for O {}