From f186d633d16a1c0ec18542f2ddc8f5a1474f89f0 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 1 Feb 2014 16:16:10 +0100 Subject: [PATCH] RptReport::new_from_gtktreeview: now works custom order. It's impossibile to read column attribute where it is the col source. So it searches for custom gobject data named "rpt_text_col_idx" (closes #802). --- src/rptreport.c | 14 ++++++++++++-- tests/gtktreeview.c | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rptreport.c b/src/rptreport.c index fa363bc..978d509 100644 --- a/src/rptreport.c +++ b/src/rptreport.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2013 Andrea Zagli + * Copyright (C) 2007-2014 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -599,6 +599,8 @@ RptReport gchar *field_name; guint idx; + gint col_idx; + gpointer ptr_col_idx; gint iheight; gdouble height; @@ -718,7 +720,15 @@ RptReport g_free (point); g_free (size); - g_hash_table_insert (columns_names, field_name, g_strdup_printf ("%d", idx)); + /* it's not possible to read column attribute that represents the source from liststore */ + col_idx = idx; + ptr_col_idx = g_object_get_data (G_OBJECT (col), "rpt_text_col_idx"); + if (ptr_col_idx != NULL) + { + col_idx = strtol ((gchar *)ptr_col_idx, NULL, 10); + } + + g_hash_table_insert (columns_names, field_name, g_strdup_printf ("%d", col_idx)); x += col_width; } diff --git a/tests/gtktreeview.c b/tests/gtktreeview.c index efc5e48..b44443c 100644 --- a/tests/gtktreeview.c +++ b/tests/gtktreeview.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013 Andrea Zagli + * Copyright (C) 2011-2014 Andrea Zagli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -131,11 +131,11 @@ main (int argc, char **argv) GtkTreeViewColumn *column; renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Book's title", renderer, "text", TITLE_COLUMN, NULL); + g_object_set_data (G_OBJECT (column), "rpt_text_col_idx", g_strdup_printf ("%d", TITLE_COLUMN)); gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_column_set_clickable (column, TRUE); gtk_tree_view_column_set_sort_column_id (column, TITLE_COLUMN); @@ -147,6 +147,7 @@ main (int argc, char **argv) renderer, "text", AUTHOR_COLUMN, NULL); + g_object_set_data (G_OBJECT (column), "rpt_text_col_idx", g_strdup_printf ("%d", AUTHOR_COLUMN)); gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_column_set_clickable (column, TRUE); gtk_tree_view_column_set_sort_column_id (column, AUTHOR_COLUMN); @@ -158,6 +159,7 @@ main (int argc, char **argv) renderer, "active", CHECKED_COLUMN, NULL); + g_object_set_data (G_OBJECT (column), "rpt_text_col_idx", g_strdup_printf ("%d", CHECKED_COLUMN)); gtk_tree_view_column_set_resizable (column, TRUE); gtk_tree_view_column_set_clickable (column, TRUE); gtk_tree_view_column_set_sort_column_id (column, CHECKED_COLUMN); -- 2.49.0