After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 408291 - Easier way of using Gtk::CellRendererCombo wanted
Easier way of using Gtk::CellRendererCombo wanted
Status: RESOLVED INVALID
Product: gtkmm
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on: 324282
Blocks:
 
 
Reported: 2007-02-15 16:24 UTC by Ole Laursen
Modified: 2009-11-13 18:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ole Laursen 2007-02-15 16:24:36 UTC
I think CellRendererCombo is too hard to use for the simple case of making a list of string choices available inside a treeview row. I found some code in Gobby which does this, otherwise I think I would have given up. The current steps appear to be: make a separate column model and list store, fill it in, make a CellRendererCombo and a TreeViewColumn, make a callback for the cell_data_func and one for the cell edited signal, and finally fill in some glue code that makes plenty use of TreeIter.

The code itself is not terribly long, but takes time to write and is difficult to read because of the many concepts involved. Furthermore, most of it appears to be boiler plate code.

Ideally, the type inference feature used to generate cell renderers for strings and numbers would have a specialisation that makes this possible. I don't quite know how yet, though.
Comment 1 Murray Cumming 2007-02-15 16:56:04 UTC
We have a text-only Gtk::ComboBoxText, so I think it would be fine to create a CellRendererComboText. That might help a bit, for some people.

However, I believe that most people will need multiple columns, instead of just the visible human-readable column.

If you can write an example of the application code you'd like to see, we can discuss whether a) that's nice, and b) whether that's possible.
Comment 2 Ole Laursen 2007-02-16 10:08:20 UTC
About multiple columns: I was thinking the same as you, but it appears that CellRendererCombo gives you the visible string when it is changed and not the combo model row. So if you have multiple columns in the combo model, you have to scan through them manually with the TreeIter interface to find the right row. Hence, I think it's easier to attach a hidden std::map or something like that to the treeview model instead. For the two cases I'm sitting with right now, I just need one global mapping as the list of choices is the same for all rows.  

I'm not sure about the application code. Perhaps something like this:

class MyColumns: public Gtk::TreeModelColumnRecord {
public:
    MyColumns()
	{ add(id); add(type); }
	
    Gtk::TreeModelColumn<Glib::ustring> id;
    Gtk::TreeModelColumn<Gtk::CellComboText> type;
};

// ...

my_treeview.append_column("ID", my_columns.id);
my_treeview.append_column("Type", my_columns.type);

// ...

Gtk::TreeIter i = my_store.append();
(*i)[my_columns.type].append_text("A choice");
(*i)[my_columns.type].append_text("B choice");
(*i)[my_columns.type].append_text("C choice");
(*i)[my_columns.type].set_active_text("B choice");


This is somewhat painful (and wasteful) when the choice list is the same for all rows. Perhaps if the text column model was ripped out of Gtk::ComboBoxText and made generally available, then you could do something like:

Gtk::TextListStore text_store;
text_store.append_text("A choice");
text_store.append_text("B choice");
text_store.append_text("C choice");

// ...

Gtk::TreeIter i = my_store.append();
(*i)[my_columns.type].set_model(text_store);
(*i)[my_columns.type].set_active("B choice");


I hope you get the idea.
Comment 3 Murray Cumming 2007-03-23 16:29:35 UTC
> I was thinking the same as you, but it appears that
> CellRendererCombo gives you the visible string when it is changed and not the
> combo model row. So if you have multiple columns in the combo model, you have
> to scan through them manually with the TreeIter interface to find the right
> row.

Yes, that's annoying. Here is a patch to add this to GTK+:
http://bugzilla.gnome.org/show_bug.cgi?id=324282
I would rather try to get that applied rather than adding logic to gtkmm.
Comment 4 Ole Laursen 2009-11-13 18:24:14 UTC
Hi, this feature request is very old now, and I'm not sure it is still relevant. I've since lost interest in the matter. So I'll just close the request.