Sign up

How to set a row in ListStore with different type of column

I want to add a row in following ListRow

GType[2] columns = [GType.STRING, GType.UINT];
ListStore pageStore = new ListStore(columns);

In C I use gtk_list_store_set and in D?

In other words how can I translate this code in D:

enum
{
  COL_NAME = 0,
  COL_AGE,
  NUM_COLS
} ;


static GtkTreeModel *
create_and_fill_model (void)
{
  GtkListStore  *store;
  GtkTreeIter    iter;
  
  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);

  /* Append a row and fill in some data */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Heinz El-Mann",
                      COL_AGE, 51,
                      -1);
  
  /* append another row and fill in some data */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Jane Doe",
                      COL_AGE, 23,
                      -1);
  
  /* ... and a third row */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Joe Bungop",
                      COL_AGE, 91,
                      -1);
  
  return GTK_TREE_MODEL (store);
}

Thank you

Re: How to set a row in ListStore with different type of column

With gtkD you would use setValue, it has overloads for int and string, so in this case you can call it directly. For other types it needs to be wrapped in a gobject.Value.

enum
{
    COL_NAME = 0,
    COL_AGE,
    NUM_COLS
};
 
static TreeModel createAndFillModel()
{
    ListStore   store;
    GtkTreeIter iter;
   
    store = new ListStore([G_TYPE_STRING, G_TYPE_UINT]);
    iter = store.createIter();

    /* Append a row and fill in some data */
    store.append(iter);
    store.setValue(iter, COL_NAME, "Heinz El-Mann");
    store.setValue(iter, COL_AGE, 51);
   
    /* append another row and fill in some data */
    store.append(iter);
    store.setValue(iter, COL_NAME, "Jane Doe");
    store.setValue(iter, COL_AGE, 23);
   
    /* ... and a third row */
    store.append(iter);
    store.setValue(iter, COL_NAME, "Joe Bungop");
    store.setValue(iter, COL_AGE, 91);

    return store;
}

Re: How to set a row in ListStore with different type of column

Thank you very much...

On Tue, 24 Jun 2014 15:57:53 GMT, Mike Wey wrote:
------------>8------------

For other types it needs to be wrapped in a gobject.Value.

------------>8------------

So, in order to set a LONG column I use:

store = new ListStore([GType.LONG, GType.STRING]);
iter = store.createIter();

Value v = new Value().init(GType.LONG);
v.setLong(to!glong(dut.id));
store.setValue(iter, 0, v);

Does exist a "fast" mode?

Re: How to set a row in ListStore with different type of column

On 06/25/2014 07:01 AM, Orfeo wrote:

So, in order to set a LONG column I use:

store = new ListStore([GType.LONG, GType.STRING]);
iter = store.createIter();

Value v = new Value().init(GType.LONG);
v.setLong(to!glong(dut.id));
store.setValue(iter, 0, v);

Yes,

Does exist a "fast" mode?

No.