Re: Two questions



Konstantin L Kouptsov wrote:


In my program I would like to have a ListStore/TreeView list with several columns, to which I will add additional rows. I also want that each time the row is added, the (re)calculation over entire list is performed, say, using on_row_added(). For the last thing, I need to catch some event and connect it to my on_row_added() function.

1. To add a row I have the code as follows:

// these are defined elsewhere

 class StimListRow:public Gtk::TreeModel::ColumnRecord
    { ... } glr,slr;
 Glib::RefPtr<Gtk::ListStore> good_ref= Gtk::ListStore::create(glr);
 Gtk::TreeView *treeview;

// now the code:

 Glib::RefPtr<Gtk::TreeSelection> Selection = treeview->get_selection();
 Gtk::ListStore::iterator iter = Selection->get_selected();

 treeview->remove_all_columns();
 Gtk::ListStore::Row new_row = *(good_ref->append());
 int time = row[slr.time];
 int chan = row[slr.chan];
 new_row[glr.time] = time;
 new_row[glr.chan] = chan;
 treeview->set_model(good_ref);
 treeview->append_column("Stim", glr.time);
 treeview->append_column("Channel", glr.chan);

This works, but I am not sure this is the best way. Is there more elegant way of doing that?

You don't need to remove and add columns every time, the same is about set_model.
Just call append() for your tree model store, and then set row cells.

Also, thinking about events to catch, what are the events that may be suitable for my task (i.e. to call recalculate() once after the row was added)


2. When trying to add event handler to solve the previous task, I get an error when adding the following line

good_ref->signal_row_inserted().connect(SigC::slot(*this,&MyWindow::on_row_added),false);



MyWindow.cc: In member function `int TrigViewWindow::open_trg_file()':
MyWindow.cc:410: error: no matching function for call to `
   Glib::SignalProxy2<void, const Gtk::TreePath&, const Gtk::TreeIter&>::
   connect(SigC::Slot0<void>, bool)'
/usr/include/gtkmm-2.0/glibmm/signalproxy.h:159: error: candidates are:
SigC::Connection Glib::SignalProxy2<R, P1, P2>::connect(const SigC::Slot2<R,
   P1, P2>&, bool) [with R = void, P1 = const Gtk::TreePath&, P2 = const
   Gtk::TreeIter&]

Can someone shed a light on what's going on?

you were trying to connect function declared as "void open_trg_file()" to signal that requires function declaration like that: "void function(const Gtk::TreePath&, const Gtk::TreeIter)". There is 2 ways: 1st - declare function with fake parameters, 2nd - use SigC adaptors (SigC::hide) to "hide" signal arguments.

I also use glade to design interface, and some of the events added by glade generate the same type of error. Perhaps I am missing something.

Sorry, not familiar with glade, but see problem solution above.

PS
May be we both could use russian to understand your needs better? :)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]