开发者

In Gtk, how do I search a ListStore for the row containing a particular value?

开发者 https://www.devze.com 2022-12-19 04:04 出处:网络
I have a ListStore mode开发者_Python百科ling a list of Tags. This list may change apart from the ListStore. What I\'d like to do is listen to the TagRemoved event in my TagList class, and remove the T

I have a ListStore mode开发者_Python百科ling a list of Tags. This list may change apart from the ListStore. What I'd like to do is listen to the TagRemoved event in my TagList class, and remove the Tag from the ListStore when the event is triggered. However, I can't seem to find a way to search a ListStore for the row containing a given Tag, so that I can remove it.

Is there any way to do this?


A GtkListStore implements the GtkTreeModel interface, which contains the tree traversal operations you want. As far as I know, there is no convenience API for searching a list/tree store, so you'll have to roll your own.

Since you're simply iterating over a GtkListStore, you can ignore all of the API dealing with child/parent relations, and simply use gtk_tree_model_iter_first() and gtk_tree_model_iter_next() to traverse the list.

Alternatively, if you already know the index of the removed tag in the store (e.g., from your TagRemoved event), you can turn that into a GtkTreePath and use gtk_tree_model_get_iter() to retrieve the row in question directly without searching.


GtkListStore is internally implemented as a linked list so you should scan the model by yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消