gtk4/auto/tree_store.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, Buildable, TreeDragDest, TreeDragSource, TreeIter, TreeModel, TreeSortable};
7use glib::translate::*;
8
9glib::wrapper! {
10 /// Use [`TreeListModel`][crate::TreeListModel] instead
11 /// A tree-like data structure that can be used with the [`TreeView`][crate::TreeView].
12 ///
13 /// The [`TreeStore`][crate::TreeStore] object is a list model for use with a [`TreeView`][crate::TreeView]
14 /// widget. It implements the [`TreeModel`][crate::TreeModel] interface, and consequently,
15 /// can use all of the methods available there. It also implements the
16 /// [`TreeSortable`][crate::TreeSortable] interface so it can be sorted by the view.
17 /// Finally, it also implements the tree [drag][`TreeDragSource`][crate::TreeDragSource]
18 /// and [drop][`TreeDragDest`][crate::TreeDragDest] interfaces.
19 ///
20 /// [`TreeStore`][crate::TreeStore] is deprecated since GTK 4.10, and should not be used in newly
21 /// written code. You should use [`TreeListModel`][crate::TreeListModel] for a tree-like model
22 /// object.
23 ///
24 /// ## GtkTreeStore as GtkBuildable
25 ///
26 /// The GtkTreeStore implementation of the [`Buildable`][crate::Buildable] interface allows
27 /// to specify the model columns with a `<columns>` element that may contain
28 /// multiple `<column>` elements, each specifying one model column. The “type”
29 /// attribute specifies the data type for the column.
30 ///
31 /// An example of a UI Definition fragment for a tree store:
32 ///
33 /// ```xml
34 /// <object class="GtkTreeStore">
35 /// <columns>
36 /// <column type="gchararray"/>
37 /// <column type="gchararray"/>
38 /// <column type="gint"/>
39 /// </columns>
40 /// </object>
41 /// ```
42 ///
43 /// # Implements
44 ///
45 /// [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`TreeDragDestExt`][trait@crate::prelude::TreeDragDestExt], [`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]
46 #[doc(alias = "GtkTreeStore")]
47 pub struct TreeStore(Object<ffi::GtkTreeStore, ffi::GtkTreeStoreClass>) @implements Buildable, TreeDragDest, TreeDragSource, TreeModel, TreeSortable;
48
49 match fn {
50 type_ => || ffi::gtk_tree_store_get_type(),
51 }
52}
53
54impl TreeStore {
55 /// Appends a new row to @self.
56 ///
57 /// If @parent is non-[`None`], then it will append the new row after the last
58 /// child of @parent, otherwise it will append a row to the top level.
59 ///
60 /// The @iter parameter will be changed to point to this new row. The row will
61 /// be empty after this function is called. To fill in values, you need to call
62 /// gtk_tree_store_set() or gtk_tree_store_set_value().
63 ///
64 /// # Deprecated since 4.10
65 ///
66 /// Use [`TreeListModel`][crate::TreeListModel] instead
67 /// ## `parent`
68 /// A valid [`TreeIter`][crate::TreeIter]
69 ///
70 /// # Returns
71 ///
72 ///
73 /// ## `iter`
74 /// An unset [`TreeIter`][crate::TreeIter] to set to the appended row
75 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
76 #[allow(deprecated)]
77 #[doc(alias = "gtk_tree_store_append")]
78 pub fn append(&self, parent: Option<&TreeIter>) -> TreeIter {
79 unsafe {
80 let mut iter = TreeIter::uninitialized();
81 ffi::gtk_tree_store_append(
82 self.to_glib_none().0,
83 iter.to_glib_none_mut().0,
84 mut_override(parent.to_glib_none().0),
85 );
86 iter
87 }
88 }
89
90 /// Removes all rows from @self
91 ///
92 /// # Deprecated since 4.10
93 ///
94 /// Use [`TreeListModel`][crate::TreeListModel] instead
95 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
96 #[allow(deprecated)]
97 #[doc(alias = "gtk_tree_store_clear")]
98 pub fn clear(&self) {
99 unsafe {
100 ffi::gtk_tree_store_clear(self.to_glib_none().0);
101 }
102 }
103
104 /// Creates a new row at @position.
105 ///
106 /// If parent is non-[`None`], then the row will be made a child of @parent.
107 /// Otherwise, the row will be created at the toplevel.
108 ///
109 /// If @position is `-1` or is larger than the number of rows at that level,
110 /// then the new row will be inserted to the end of the list.
111 ///
112 /// The @iter parameter will be changed to point to this new row. The row
113 /// will be empty after this function is called. To fill in values, you
114 /// need to call gtk_tree_store_set() or gtk_tree_store_set_value().
115 ///
116 /// # Deprecated since 4.10
117 ///
118 /// Use [`TreeListModel`][crate::TreeListModel] instead
119 /// ## `parent`
120 /// A valid [`TreeIter`][crate::TreeIter]
121 /// ## `position`
122 /// position to insert the new row, or -1 for last
123 ///
124 /// # Returns
125 ///
126 ///
127 /// ## `iter`
128 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
129 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
130 #[allow(deprecated)]
131 #[doc(alias = "gtk_tree_store_insert")]
132 pub fn insert(&self, parent: Option<&TreeIter>, position: i32) -> TreeIter {
133 unsafe {
134 let mut iter = TreeIter::uninitialized();
135 ffi::gtk_tree_store_insert(
136 self.to_glib_none().0,
137 iter.to_glib_none_mut().0,
138 mut_override(parent.to_glib_none().0),
139 position,
140 );
141 iter
142 }
143 }
144
145 /// Inserts a new row after @sibling.
146 ///
147 /// If @sibling is [`None`], then the row will be prepended to @parent’s children.
148 ///
149 /// If @parent and @sibling are [`None`], then the row will be prepended to the
150 /// toplevel.
151 ///
152 /// If both @sibling and @parent are set, then @parent must be the parent
153 /// of @sibling. When @sibling is set, @parent is optional.
154 ///
155 /// The @iter parameter will be changed to point to this new row. The row will
156 /// be empty after this function is called. To fill in values, you need to call
157 /// gtk_tree_store_set() or gtk_tree_store_set_value().
158 ///
159 /// # Deprecated since 4.10
160 ///
161 /// Use [`TreeListModel`][crate::TreeListModel] instead
162 /// ## `parent`
163 /// A valid [`TreeIter`][crate::TreeIter]
164 /// ## `sibling`
165 /// A valid [`TreeIter`][crate::TreeIter]
166 ///
167 /// # Returns
168 ///
169 ///
170 /// ## `iter`
171 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
172 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
173 #[allow(deprecated)]
174 #[doc(alias = "gtk_tree_store_insert_after")]
175 pub fn insert_after(&self, parent: Option<&TreeIter>, sibling: Option<&TreeIter>) -> TreeIter {
176 unsafe {
177 let mut iter = TreeIter::uninitialized();
178 ffi::gtk_tree_store_insert_after(
179 self.to_glib_none().0,
180 iter.to_glib_none_mut().0,
181 mut_override(parent.to_glib_none().0),
182 mut_override(sibling.to_glib_none().0),
183 );
184 iter
185 }
186 }
187
188 /// Inserts a new row before @sibling.
189 ///
190 /// If @sibling is [`None`], then the row will be appended to @parent’s children.
191 ///
192 /// If @parent and @sibling are [`None`], then the row will be appended to the
193 /// toplevel.
194 ///
195 /// If both @sibling and @parent are set, then @parent must be the parent
196 /// of @sibling. When @sibling is set, @parent is optional.
197 ///
198 /// The @iter parameter will be changed to point to this new row. The row will
199 /// be empty after this function is called. To fill in values, you need to call
200 /// gtk_tree_store_set() or gtk_tree_store_set_value().
201 ///
202 /// # Deprecated since 4.10
203 ///
204 /// Use [`TreeListModel`][crate::TreeListModel] instead
205 /// ## `parent`
206 /// A valid [`TreeIter`][crate::TreeIter]
207 /// ## `sibling`
208 /// A valid [`TreeIter`][crate::TreeIter]
209 ///
210 /// # Returns
211 ///
212 ///
213 /// ## `iter`
214 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
215 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
216 #[allow(deprecated)]
217 #[doc(alias = "gtk_tree_store_insert_before")]
218 pub fn insert_before(&self, parent: Option<&TreeIter>, sibling: Option<&TreeIter>) -> TreeIter {
219 unsafe {
220 let mut iter = TreeIter::uninitialized();
221 ffi::gtk_tree_store_insert_before(
222 self.to_glib_none().0,
223 iter.to_glib_none_mut().0,
224 mut_override(parent.to_glib_none().0),
225 mut_override(sibling.to_glib_none().0),
226 );
227 iter
228 }
229 }
230
231 /// Checks if @iter is an ancestor of @descendant.
232 ///
233 /// # Deprecated since 4.10
234 ///
235 /// Use [`TreeListModel`][crate::TreeListModel] instead
236 /// ## `iter`
237 /// A valid [`TreeIter`][crate::TreeIter]
238 /// ## `descendant`
239 /// A valid [`TreeIter`][crate::TreeIter]
240 ///
241 /// # Returns
242 ///
243 /// true if @iter is an ancestor of @descendant, and false otherwise
244 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
245 #[allow(deprecated)]
246 #[doc(alias = "gtk_tree_store_is_ancestor")]
247 pub fn is_ancestor(&self, iter: &TreeIter, descendant: &TreeIter) -> bool {
248 unsafe {
249 from_glib(ffi::gtk_tree_store_is_ancestor(
250 self.to_glib_none().0,
251 mut_override(iter.to_glib_none().0),
252 mut_override(descendant.to_glib_none().0),
253 ))
254 }
255 }
256
257 /// Returns the depth of the position pointed by the iterator
258 ///
259 /// The depth will be 0 for anything on the root level, 1 for anything down
260 /// a level, etc.
261 ///
262 /// # Deprecated since 4.10
263 ///
264 /// Use [`TreeListModel`][crate::TreeListModel] instead
265 /// ## `iter`
266 /// A valid [`TreeIter`][crate::TreeIter]
267 ///
268 /// # Returns
269 ///
270 /// The depth of the position pointed by the iterator
271 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
272 #[allow(deprecated)]
273 #[doc(alias = "gtk_tree_store_iter_depth")]
274 pub fn iter_depth(&self, iter: &TreeIter) -> i32 {
275 unsafe {
276 ffi::gtk_tree_store_iter_depth(
277 self.to_glib_none().0,
278 mut_override(iter.to_glib_none().0),
279 )
280 }
281 }
282
283 /// Checks if the given iter is a valid iter for this [`TreeStore`][crate::TreeStore].
284 ///
285 /// This function is slow. Only use it for debugging and/or testing
286 /// purposes.
287 ///
288 /// # Deprecated since 4.10
289 ///
290 /// Use [`TreeListModel`][crate::TreeListModel] instead
291 /// ## `iter`
292 /// the iterator to check
293 ///
294 /// # Returns
295 ///
296 /// true if the iter is valid, and false otherwise
297 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
298 #[allow(deprecated)]
299 #[doc(alias = "gtk_tree_store_iter_is_valid")]
300 pub fn iter_is_valid(&self, iter: &TreeIter) -> bool {
301 unsafe {
302 from_glib(ffi::gtk_tree_store_iter_is_valid(
303 self.to_glib_none().0,
304 mut_override(iter.to_glib_none().0),
305 ))
306 }
307 }
308
309 /// Moves @iter in @self to the position after @position.
310 ///
311 /// @iter and @position should be in the same level.
312 ///
313 /// Note that this function only works with unsorted stores.
314 ///
315 /// If @position is [`None`], @iter will be moved to the start of the level.
316 ///
317 /// # Deprecated since 4.10
318 ///
319 /// Use [`TreeListModel`][crate::TreeListModel] instead
320 /// ## `iter`
321 /// A [`TreeIter`][crate::TreeIter].
322 /// ## `position`
323 /// A [`TreeIter`][crate::TreeIter].
324 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
325 #[allow(deprecated)]
326 #[doc(alias = "gtk_tree_store_move_after")]
327 pub fn move_after(&self, iter: &TreeIter, position: Option<&TreeIter>) {
328 unsafe {
329 ffi::gtk_tree_store_move_after(
330 self.to_glib_none().0,
331 mut_override(iter.to_glib_none().0),
332 mut_override(position.to_glib_none().0),
333 );
334 }
335 }
336
337 /// Moves @iter in @self to the position before @position.
338 ///
339 /// @iter and @position should be in the same level.
340 ///
341 /// Note that this function only works with unsorted stores.
342 ///
343 /// If @position is [`None`], @iter will be moved to the end of the level.
344 ///
345 /// # Deprecated since 4.10
346 ///
347 /// Use [`TreeListModel`][crate::TreeListModel] instead
348 /// ## `iter`
349 /// A [`TreeIter`][crate::TreeIter]
350 /// ## `position`
351 /// A [`TreeIter`][crate::TreeIter]
352 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
353 #[allow(deprecated)]
354 #[doc(alias = "gtk_tree_store_move_before")]
355 pub fn move_before(&self, iter: &TreeIter, position: Option<&TreeIter>) {
356 unsafe {
357 ffi::gtk_tree_store_move_before(
358 self.to_glib_none().0,
359 mut_override(iter.to_glib_none().0),
360 mut_override(position.to_glib_none().0),
361 );
362 }
363 }
364
365 /// Prepends a new row to @self.
366 ///
367 /// If @parent is non-[`None`], then it will prepend the new row before the first
368 /// child of @parent, otherwise it will prepend a row to the top level. The
369 /// `iter` parameter will be changed to point to this new row. The row will
370 /// be empty after this function is called. To fill in values, you need to
371 /// call gtk_tree_store_set() or gtk_tree_store_set_value().
372 ///
373 /// # Deprecated since 4.10
374 ///
375 /// Use [`TreeListModel`][crate::TreeListModel] instead
376 /// ## `parent`
377 /// A valid [`TreeIter`][crate::TreeIter]
378 ///
379 /// # Returns
380 ///
381 ///
382 /// ## `iter`
383 /// An unset [`TreeIter`][crate::TreeIter] to set to the prepended row
384 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
385 #[allow(deprecated)]
386 #[doc(alias = "gtk_tree_store_prepend")]
387 pub fn prepend(&self, parent: Option<&TreeIter>) -> TreeIter {
388 unsafe {
389 let mut iter = TreeIter::uninitialized();
390 ffi::gtk_tree_store_prepend(
391 self.to_glib_none().0,
392 iter.to_glib_none_mut().0,
393 mut_override(parent.to_glib_none().0),
394 );
395 iter
396 }
397 }
398
399 /// Removes @iter from @self.
400 ///
401 /// After being removed, @iter is set to the next valid row at that level, or
402 /// invalidated if it previously pointed to the last one.
403 ///
404 /// # Deprecated since 4.10
405 ///
406 /// Use [`TreeListModel`][crate::TreeListModel] instead
407 /// ## `iter`
408 /// A valid [`TreeIter`][crate::TreeIter]
409 ///
410 /// # Returns
411 ///
412 /// true if @iter is still valid, and false otherwise
413 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
414 #[allow(deprecated)]
415 #[doc(alias = "gtk_tree_store_remove")]
416 pub fn remove(&self, iter: &TreeIter) -> bool {
417 unsafe {
418 from_glib(ffi::gtk_tree_store_remove(
419 self.to_glib_none().0,
420 mut_override(iter.to_glib_none().0),
421 ))
422 }
423 }
424
425 /// Swaps @a and @b in the same level of @self.
426 ///
427 /// Note that this function only works with unsorted stores.
428 ///
429 /// # Deprecated since 4.10
430 ///
431 /// Use [`TreeListModel`][crate::TreeListModel] instead
432 /// ## `a`
433 /// A [`TreeIter`][crate::TreeIter].
434 /// ## `b`
435 /// Another [`TreeIter`][crate::TreeIter].
436 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
437 #[allow(deprecated)]
438 #[doc(alias = "gtk_tree_store_swap")]
439 pub fn swap(&self, a: &TreeIter, b: &TreeIter) {
440 unsafe {
441 ffi::gtk_tree_store_swap(
442 self.to_glib_none().0,
443 mut_override(a.to_glib_none().0),
444 mut_override(b.to_glib_none().0),
445 );
446 }
447 }
448}