FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TreeStore.getValueInt returns weird values

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
elkano



Joined: 19 Jun 2009
Posts: 24

PostPosted: Fri Aug 07, 2009 9:53 am    Post subject: TreeStore.getValueInt returns weird values Reply with quote

Hello again,
After expanding a bit my previous code, I am having a weird issue.
My interface includes a TreeView (defined in XML), linked to a TreeStore (defined in code).
I am having no problems populating the tree with some data from a database.
There's a callback called 'OnRowActivated', which needs to retrieve some code from the TreeStore: an int (not showed in the TreeView) and a string (which is). The string comes along nicely, not so the int. Instead of values 0, 1, ... it returns values -1210499296, -1210515264, ...

Here is the code:

Code:

class XMLApp {

   Generic db;
   Builder app;

   this(char[][] args, Generic db) {
      this.db = db;
      Main.init(args);

      app = new Builder();
      auto err = app.addFromFile("Interface.xml");
      if(err == 0 ) {
         Stderr("Error opening glade file.").newline;
      }

      app.connectSignals(null);

      this.initTree();

      auto obj = app.getObject("window");
      obj.setData("GObject", null);
      auto w = new Window(cast(GtkWindow*)obj.getObjectGStruct());

      if(w !is null) {
         w.show();
         w.addOnHide( delegate void(Widget aux){ Main.exit(0); } );
         Main.run();
      }
      else { Stderr("Error launching application.").newline; }

   }

   void initTree() {
      auto obj = app.getObject("sideTreeView");
      obj.setData("GObject", null);
      auto treeview = new TreeView(cast(GtkTreeView*)obj.getObjectGStruct());

      GType[2] columns = [GType.INT, GType.STRING];
      auto tree = new TreeStore(columns);

      TreeIter[char[]] parent;
      auto tables = db.get_tables();

      foreach(table; tables) {
         //Add the table as a root node
         parent[table.get_name()] = tree.append(null);
         auto iter = parent[table.get_name()];
         insert_value(tree, iter, table);       

         //Add contents of the table too
         auto values = db.get_names(table);
         foreach(value; values) {
            auto subiter = tree.append(iter);
            insert_value(tree, subiter, value);
         }
      }
     
      treeview.addOnRowActivated(&tree_selected);

      treeview.setModel(tree);
   }

   void tree_selected(TreePath path, TreeViewColumn col, TreeView treeview) {
      TreeIter iter = new TreeIter();;
      auto tree = treeview.getModel();
      tree.getIter(iter, path);
      auto parent = iter.getParent();

      auto parent_name = tree.getValueString(parent, 1);

      switch(parent_name) {
         case "notes":
            auto id = tree.getValueInt(iter, 0);
            auto content = db.get_note(new Element(id, "", null));

            Stdout(id)(content).newline;
            break;

         case "sheet":
            auto id = tree.getValueInt(iter, 0);
            auto name = tree.getValueString(iter, 1);
            Stdout("You clicked on:")(id)(name).newline;
            break;

         default: break;
      }

      return true;
   }

   void insert_value(TreeStore tree, TreeIter iter, Element elt) {
      auto id = elt.get_id();
      auto name = elt.get_name();
      tree.setValue(iter, 0, id);
      tree.setValue(iter, 1, name);
   }
}
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Aug 08, 2009 7:22 am    Post subject: Reply with quote

It looks like it should be working. I'll see if i can find out whats messing things up this weekend.

I'm assuming elt.get_id does indeed return the 0, 1, ... you are trying to retrieve.
Back to top
View user's profile Send private message
elkano



Joined: 19 Jun 2009
Posts: 24

PostPosted: Sat Aug 08, 2009 1:43 pm    Post subject: Reply with quote

Yes, sorry. I should have mentioned: get_id() returns the id key of the element in a database, starting at 0 and incrementing. It's double checked working.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Aug 09, 2009 8:54 am    Post subject: Reply with quote

Fixed in svn r697
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group