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