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::{ffi, TreeDragSource, TreeIter, TreeModel, TreePath, TreeSortable};
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 {
205 Some(sort_iter)
206 } else {
207 None
208 }
209 }
210 }
211
212 /// Converts @child_path to a path relative to @self. That is,
213 /// @child_path points to a path in the child model. The returned path will
214 /// point to the same row in the sorted model. If @child_path isn’t a valid
215 /// path on the child model, then [`None`] is returned.
216 ///
217 /// # Deprecated since 4.10
218 ///
219 /// ## `child_path`
220 /// A [`TreePath`][crate::TreePath] to convert
221 ///
222 /// # Returns
223 ///
224 /// A newly allocated [`TreePath`][crate::TreePath]
225 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
226 #[allow(deprecated)]
227 #[doc(alias = "gtk_tree_model_sort_convert_child_path_to_path")]
228 fn convert_child_path_to_path(&self, child_path: &TreePath) -> Option<TreePath> {
229 unsafe {
230 from_glib_full(ffi::gtk_tree_model_sort_convert_child_path_to_path(
231 self.as_ref().to_glib_none().0,
232 mut_override(child_path.to_glib_none().0),
233 ))
234 }
235 }
236
237 /// Sets @child_iter to point to the row pointed to by @sorted_iter.
238 ///
239 /// # Deprecated since 4.10
240 ///
241 /// ## `sorted_iter`
242 /// A valid [`TreeIter`][crate::TreeIter] pointing to a row on @self.
243 ///
244 /// # Returns
245 ///
246 ///
247 /// ## `child_iter`
248 /// An uninitialized [`TreeIter`][crate::TreeIter]
249 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
250 #[allow(deprecated)]
251 #[doc(alias = "gtk_tree_model_sort_convert_iter_to_child_iter")]
252 fn convert_iter_to_child_iter(&self, sorted_iter: &TreeIter) -> TreeIter {
253 unsafe {
254 let mut child_iter = TreeIter::uninitialized();
255 ffi::gtk_tree_model_sort_convert_iter_to_child_iter(
256 self.as_ref().to_glib_none().0,
257 child_iter.to_glib_none_mut().0,
258 mut_override(sorted_iter.to_glib_none().0),
259 );
260 child_iter
261 }
262 }
263
264 /// Converts @sorted_path to a path on the child model of @self.
265 /// That is, @sorted_path points to a location in @self. The
266 /// returned path will point to the same location in the model not being
267 /// sorted. If @sorted_path does not point to a location in the child model,
268 /// [`None`] is returned.
269 ///
270 /// # Deprecated since 4.10
271 ///
272 /// ## `sorted_path`
273 /// A [`TreePath`][crate::TreePath] to convert
274 ///
275 /// # Returns
276 ///
277 /// A newly allocated [`TreePath`][crate::TreePath]
278 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
279 #[allow(deprecated)]
280 #[doc(alias = "gtk_tree_model_sort_convert_path_to_child_path")]
281 fn convert_path_to_child_path(&self, sorted_path: &TreePath) -> Option<TreePath> {
282 unsafe {
283 from_glib_full(ffi::gtk_tree_model_sort_convert_path_to_child_path(
284 self.as_ref().to_glib_none().0,
285 mut_override(sorted_path.to_glib_none().0),
286 ))
287 }
288 }
289
290 /// Returns the model the [`TreeModelSort`][crate::TreeModelSort] is sorting.
291 ///
292 /// # Returns
293 ///
294 /// the "child model" being sorted
295 #[doc(alias = "gtk_tree_model_sort_get_model")]
296 #[doc(alias = "get_model")]
297 fn model(&self) -> TreeModel {
298 unsafe {
299 from_glib_none(ffi::gtk_tree_model_sort_get_model(
300 self.as_ref().to_glib_none().0,
301 ))
302 }
303 }
304
305 /// > This function is slow. Only use it for debugging and/or testing
306 /// > purposes.
307 ///
308 /// Checks if the given iter is a valid iter for this [`TreeModelSort`][crate::TreeModelSort].
309 ///
310 /// # Deprecated since 4.10
311 ///
312 /// ## `iter`
313 /// A [`TreeIter`][crate::TreeIter]
314 ///
315 /// # Returns
316 ///
317 /// [`true`] if the iter is valid, [`false`] if the iter is invalid.
318 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
319 #[allow(deprecated)]
320 #[doc(alias = "gtk_tree_model_sort_iter_is_valid")]
321 fn iter_is_valid(&self, iter: &TreeIter) -> bool {
322 unsafe {
323 from_glib(ffi::gtk_tree_model_sort_iter_is_valid(
324 self.as_ref().to_glib_none().0,
325 mut_override(iter.to_glib_none().0),
326 ))
327 }
328 }
329
330 /// This resets the default sort function to be in the “unsorted” state. That
331 /// is, it is in the same order as the child model. It will re-sort the model
332 /// to be in the same order as the child model only if the [`TreeModelSort`][crate::TreeModelSort]
333 /// is in “unsorted” state.
334 ///
335 /// # Deprecated since 4.10
336 ///
337 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
338 #[allow(deprecated)]
339 #[doc(alias = "gtk_tree_model_sort_reset_default_sort_func")]
340 fn reset_default_sort_func(&self) {
341 unsafe {
342 ffi::gtk_tree_model_sort_reset_default_sort_func(self.as_ref().to_glib_none().0);
343 }
344 }
345}
346
347impl<O: IsA<TreeModelSort>> TreeModelSortExt for O {}