gtk4/tree_model.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{translate::*, value::FromValue};
4
5use crate::{ffi, prelude::*, TreeIter, TreeModel};
6
7// rustdoc-stripper-ignore-next
8/// Trait containing manually implemented methods of
9/// [`TreeModel`](crate::TreeModel).
10#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
11#[allow(deprecated)]
12pub trait TreeModelExtManual: IsA<TreeModel> + 'static {
13 #[doc(alias = "gtk_tree_model_get")]
14 #[doc(alias = "gtk_tree_model_get_value")]
15 #[doc(alias = "gtk_tree_model_get_valist")]
16 fn get_value(&self, iter: &TreeIter, column: i32) -> glib::Value {
17 let total_columns = self.as_ref().n_columns();
18 assert!(
19 column < total_columns,
20 "TreeModel has {total_columns} columns but TreeModelExt::get got {column} passed as a column number",
21 );
22 unsafe {
23 let mut value = glib::Value::uninitialized();
24 ffi::gtk_tree_model_get_value(
25 self.as_ref().to_glib_none().0,
26 mut_override(iter.to_glib_none().0),
27 column,
28 value.to_glib_none_mut().0,
29 );
30 value
31 }
32 }
33
34 #[doc(alias = "gtk_tree_model_get")]
35 #[doc(alias = "gtk_tree_model_get_value")]
36 #[doc(alias = "gtk_tree_model_get_valist")]
37 // rustdoc-stripper-ignore-next
38 /// Similar to [`Self::get_value`] but panics if the value is of a different
39 /// type.
40 // rustdoc-stripper-ignore-next-stop
41 /// Gets the value of one or more cells in the row referenced by @iter.
42 ///
43 /// The variable argument list should contain integer column numbers,
44 /// each column number followed by a place to store the value being
45 /// retrieved. The list is terminated by a -1. For example, to get a
46 /// value from column 0 with type `G_TYPE_STRING`, you would
47 /// write: `gtk_tree_model_get (model, iter, 0, &place_string_here, -1)`,
48 /// where `place_string_here` is a #gchararray
49 /// to be filled with the string.
50 ///
51 /// Returned values with type `G_TYPE_OBJECT` have to be unreferenced,
52 /// values with type `G_TYPE_STRING` or `G_TYPE_BOXED` have to be freed.
53 /// Other values are passed by value.
54 ///
55 /// # Deprecated since 4.10
56 ///
57 /// ## `iter`
58 /// a row in @self
59 fn get<V: for<'b> FromValue<'b> + 'static>(&self, iter: &TreeIter, column: i32) -> V {
60 let value = self.get_value(iter, column);
61 value
62 .get_owned::<V>()
63 .expect("Failed to get TreeModel value")
64 }
65}
66
67impl<O: IsA<TreeModel>> TreeModelExtManual for O {}