ruby-****@sourc*****
ruby-****@sourc*****
2012年 8月 22日 (水) 03:14:48 JST
------------------------- REMOTE_ADDR = 70.49.49.99 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-trees ------------------------- @@ -161,15 +161,16 @@ One important thing to be notice is the sequential data organization within the tree store. This may be obvious from the way we set-up our array ((*list:*)) list = Array.new - list[0] = GroceryItem.new(P_CATEGORY, true, 0, "Cleaning Supplies") - list[1] = GroceryItem.new(P_CHILD, true, 1, "Paper Towels") - list[2] = GroceryItem.new(P_CHILD, true, 3, "Toilet Paper") - list[3] = GroceryItem.new(P_CATEGORY, true, 0, "Food") - list[4] = GroceryItem.new(P_CHILD, true, 2, "Bread") - list[5] = GroceryItem.new(P_CHILD, false, 1, "Butter") - list[6] = GroceryItem.new(P_CHILD, true, 1, "Milk") - list[7] = GroceryItem.new(P_CHILD, false, 3, "Chips") - list[8] = GroceryItem.new(P_CHILD, true, 4, "Soda") + # Category Buy Qty Product + list[0] = GroceryItem.new(P_CATEGORY, true, 0, "Cleaning Supplies") + list[1] = GroceryItem.new(P_CHILD, true, 1, "Paper Towels") + list[2] = GroceryItem.new(P_CHILD, true, 3, "Toilet Paper") + list[3] = GroceryItem.new(P_CATEGORY, true, 0, "Food") + list[4] = GroceryItem.new(P_CHILD, true, 2, "Bread") + list[5] = GroceryItem.new(P_CHILD, false, 1, "Butter") + list[6] = GroceryItem.new(P_CHILD, true, 1, "Milk") + list[7] = GroceryItem.new(P_CHILD, false, 3, "Chips") + list[8] = GroceryItem.new(P_CHILD, true, 4, "Soda") Parent/child relationship dictates that we bundle together all children of a parent below it. When later on application inserts new rows, particularly children, they have to be inserted into, or better immediately after, the list children of such a group. This makes indices to certain rows ephemeral. For instance if you store (memorize) an index to a certain row that index will became invalid after an insertion or a deletion of a row positioned before the element (row) for which you have stored (memorized) the index. Also the orderly sequential organization of the rows in a tree store allows you to readily process the data, since you can always be sure about locations of rows and the groupings of the children can be determined in a predictable manner. In our example program we exploited this fact in the loop calculating the totals for the parents by iterating through their groups of children: