Migrate `Gtk::ListStore::iterator` code

I am trying to migrate some gtk3 → gtk4 code regarding Gtk::ListStore and the new Gio::ListStore.

The task of the class is to fetch memory/allocation data and show it in a TreeView in Inkscpape.

imatge

I’ve started to refactor it into purely gtk4 code (TreeViewListView, TreeView.modelListView.factory, …)
The code has a function update which gets state and updates all rows. Currently this is done using an Gtk::ListStore::iterator, but Gio::ListStore doesn’t have this property (as it’s only data). I have doubts on how to use this class. Do I need a separate model for the UI?

Another problem is that I have included giomm/liststore.h, however I can’t use Gio::ListStore. IDE recommends GListStore, but marks it as an incomplete type afterwards.

Original gtk3 code → src/ui/dialog/memory.cpp · master · Inkscape / inkscape · GitLab
Partial gtk4 code → src/ui/widget/memory.cpp · kaixoo/merge-debug-dialogs · Kaixo Gamorra / inkscape · GitLab

Here are two examples for you:
taozuhong/GtkColumnViewDemo: A GtkColumnView demo app (github.com)

1 Like

What are the changes needed to make? I can’t read your gigantic code. Thanks for the quick response btw!

It’s true that Gio::ListStore doesn’t have an iterator. But it has
Gio::ListModel::get_n_items() and Gio::ListStore<T_item>::get_item(position).
Items in a Gio::ListStore are reference counted. get_item() does not get a copy,
it gets a Glib::RefPtr to the item in the Gio::ListStore.

I have included giomm/liststore.h, however I can’t use Gio::ListStore.

How do you try to use it? Have you noticed that Gio::ListStore is a template class?

well, that explains it. I don’t know why I didn’t see that in the docs. Thank you so much!
Yes, I know it’s a template class.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.