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..