|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Custom cell_data_func for treeviewcolumn warnings.Hello. I'm having problems with this code. The problem is that I get a
lot of warnings when I try to insert rows in my TreeModel from the main function. My TreeColumnRecord has a pointer type, but it's not derived from Glib::Object. Is this the problem? And if it is, is there any workaround to not require my class to inherit from Glib::Object without splitting MisCols class into separate fields. Thanks in advance. struct MiClase { std::string a; public: MiClase() {} MiClase(std::string aa) : a(aa) {} }; struct MisCols : TreeModelColumnRecord { Gtk::TreeModelColumn<MiClase *> entero_; public: MisCols() { add(entero_); } }; void funcCol(CellRenderer * r, const Gtk::TreeModel::iterator& iter) { CellRendererText * re = (CellRendererText *)r; Gtk::TreeModelColumn<MiClase *> col; re->property_text() = (iter->get_value(col)->a); // re->property_text() = iter->get_value(col)->a; } int main(int argc, char * argv[]) { Main m(argc, argv); TreeView tv; Window w; MisCols cols; vector<MiClase> mc = {MiClase("hola"), MiClase("adios") }; auto l = ListStore::create(cols); tv.set_model(l); auto row = *l->append(); row[cols.entero_] = &mc[0]; //row = *l->append(); //row[cols.entero_] = &mc[1]; TreeViewColumn viewcol("MiClase", cols.entero_); viewcol.set_cell_data_func(*viewcol.get_first_cell_renderer(), &funcCol); tv.append_column(viewcol); w.add(tv); w.show_all(); Main::run(w); } _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
Re: Custom cell_data_func for treeviewcolumn warnings.Am Sonntag, den 21.06.2009, 23:44 +0200 schrieb Germán Diago:
> Hello. I'm having problems with this code. The problem is that I get a > lot of warnings > when I try to insert rows in my TreeModel from the main function. > My TreeColumnRecord has a pointer type, but it's not derived from > Glib::Object. Is this the problem? No. > Gtk::TreeModelColumn<MiClase *> col; > re->property_text() = (iter->get_value(col)->a); This is the problem. That TreeModelColumn is not assigned to any tree model column. You need to use a direct reference to the TreeModelColumn instance you added to the TreeModelColumnRecord. For background, a TreeModelColumn stores two things: The C GType that corresponds to the C++ template argument, and the model column index. The model column index is assigned by the add() method, starting from zero and incremented by one with each add() call. The idea behind the TreeModelColumn and TreeModelColumnRecord classes is to tie the dynamic type information of the C API and the static type information of the C++ API together. This makes it possible to have all the flexibility offered by the GtkTreeModel API without sacrificing compile-time type-safety. > // re->property_text() = iter->get_value(col)->a; Hm, get_value() is sort of half-internal API. It is preferable to write MiClase* value = (*iter)[columns.entero]; re->property_text() = value->a; instead. --Daniel _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
| Free embeddable forum powered by Nabble | Forum Help |