ruby-****@sourc*****
ruby-****@sourc*****
2012年 8月 26日 (日) 09:12:00 JST
------------------------- REMOTE_ADDR = 70.49.49.99 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-addrnhs ------------------------- @@ -562,7 +562,7 @@ model = treeview.model iter = model.iter_first #<-- same as: iter = model.get_iter("0") -In the first line above we conveniently tuck away the model separating data store from the view (MVC). We use model to get to the starting iterator, by supplying the top-level root path "0". Then comes a tricky while loop, where we want to process the first iteration with the iter we have just obtained, while at the same time use Gtk::TreeIter#next! as the condition in the while loop. The API for Gtk::TreeIter#next! tells us that this command returns true if the iterator was successfully advanced and false otherwise. In this case (if false is returned the iterator will point again to the first item in the tree store). Of course, the most important part of this loop is the break statement, which abandons the loop leaving the iterator to point to the product category we were looking for. +In the first line above we conveniently tuck away the model separating data store from the view (MVC). We use model to get to the starting iterator, either by Gtk::TreeStore#iter_first, or by Gtk::TreeStore#get_iter by supplying the top-level root path "0". Then comes a tricky while loop, where we want to process the first iteration with the iter we have just obtained, while at the same time use Gtk::TreeIter#next! as the condition in the while loop. The API for Gtk::TreeIter#next! tells us that this command returns true if the iterator was successfully advanced and false otherwise. In this case (if false is returned the iterator will point again to the first item in the tree store). Of course, the most important part of this loop is the break statement, which abandons the loop leaving the iterator to point to the product category we were looking for. We save the "path" of the iterator that points to the parent (our product category), and create a new row for our new product. Adding the data to the new empty row is accomplished by: