Sign up

What is the equivalent of this row_activated method in D

I would like to translate this example to D.

static void
on_row_activated (GtkTreeView *view,
                  GtkTreePath *path,
                  GtkTreeViewColumn *col,
                  Store *store)
{
    GtkTreeIter iter;
    GtkTreePath *filtered_path;
    GtkTreePath *child_path;

    filtered_path = gtk_tree_model_sort_convert_path_to_child_path (GTK_TREE_MODEL_SORT (store->sorted),
                                                                    path);

    child_path = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (store->filtered),
                                                                   filtered_path);

    if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store->articles), &iter, child_path)) {
        gchar *article;
        gdouble price;

        gtk_tree_model_get (GTK_TREE_MODEL (store->articles), &iter,
                            COLUMN_ARTICLE, &article,
                            COLUMN_PRICE, &price,
                            -1);

        g_print ("You want to buy %s for %f?\n", article, price);
        g_free (article);
    }
}

In this example there is a simple struct which keeps data.

enum
{
    COLUMN_ARTICLE = 0,
    COLUMN_PRICE,
    N_COLUMNS
};

typedef struct
{
    GtkListStore       *articles;
    GtkTreeModelSort   *sorted;
    GtkTreeModelFilter *filtered;
    gdouble             max_price;
} Store;

My code looks like this:

class MyWindow: MainWindow
{
    ViewModel view;
    TreeModelFilter filtered;
    TreeModelSort sorted;

    this(ViewModel model)
    {
        super("Treeview example");
        this.view = view;

        view.addOnRowActivated(&onRowActivated);

        /* ... */ 

    }

    void onRowActivated(TreePath path, TreeViewColumn col, TreeView view)
    {
        auto filteredPath = sorted.convertPathToChildPath(path);
        auto childPath = filtered.convertPathToChildPath(filteredPath);

    }

}


class DataModel: ListStore /* model */
{
    /* ... */ 
}

class ViewModel: TreeView /* view */
{
    this (DataModel model)
    {
        /* ... */ 

    }

}

I'd like to undo the path conversion that was introduced by the filter and sort model. What would be the equivalent of the code in if block

if (gtk_tree_model_get_iter .. etc..

Re: What is the equivalent of this row_activated method in D

On 02/11/2017 10:56 AM, Erdem wrote:

I would like to translate this example to D.

I'd like to undo the path conversion that was introduced by the filter and sort model. What would be the equivalent of the code in if block

if (gtk_tree_model_get_iter .. etc..

TreeIter iter = new TreeIter();

if ( model.getIter(iter, childPath) )

where model is your DataModel / Liststore.

Re: What is the equivalent of this row_activated method in D

On Sat, 11 Feb 2017 13:19:24 +0100, Mike Wey wrote:

 TreeIter iter = new TreeIter();
 
 if ( model.getIter(iter, childPath) )

where model is your DataModel / Liststore.

Thanks. I recognized that my code was nearly identical. But I've forgotten to create instance of class.

TreeIter iter;

To retrieve a value I was using getValue function like this.

            model.getValue(iter, 0);

Is it possible to use model.get() instead of getValue(). If so what should I pass to get function.

Re: What is the equivalent of this row_activated method in D

On Sat, 11 Feb 2017 20:44:09 GMT, Erdem wrote:

Is it possible to use model.get() instead of getValue(). If so what should I pass to get function.

Like other gtk functions that use variadics TreeModel.get currently isn't available.