Function to add a new column to an account tree to display kvp data.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gnucash-gnome2-dev@9645 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton
2003-10-26 00:01:56 +00:00
parent 7a8788685e
commit 08e7986e24
2 changed files with 70 additions and 0 deletions

View File

@@ -756,3 +756,57 @@ gnc_tree_view_account_set_selected_accounts (GncTreeViewAccount *view,
gtk_tree_path_free(path);
}
}
/************************************************************/
/* Account Tree View Get/Set Functions */
/************************************************************/
static void
account_cell_kvp_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *filter_model,
GtkTreeIter *filter_iter,
gpointer key)
{
GtkTreeModel *model;
GtkTreeIter iter;
Account *account;
kvp_frame * frame;
g_return_if_fail (EGG_IS_TREE_MODEL_FILTER (filter_model));
model =
egg_tree_model_filter_get_model(EGG_TREE_MODEL_FILTER(filter_model));
egg_tree_model_filter_convert_iter_to_child_iter (EGG_TREE_MODEL_FILTER(filter_model),
&iter,
filter_iter);
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), &iter);
frame = xaccAccountGetSlots(account);
g_object_set (G_OBJECT (cell),
"text", kvp_frame_get_string(frame, (gchar *)key),
"xalign", 0.0,
NULL);
}
void
gnc_tree_view_account_add_kvp_column (GncTreeViewAccount *view,
const gchar *column_title,
const gchar *kvp_key)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
renderer = gtk_cell_renderer_text_new ();
g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL);
column = gtk_tree_view_column_new_with_attributes (column_title,
renderer,
NULL);
gtk_tree_view_column_set_cell_data_func (column, renderer,
account_cell_kvp_data_func,
g_strdup(kvp_key), g_free);
gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
}

View File

@@ -114,6 +114,22 @@ const char *gnc_tree_view_account_get_field_name (AccountFieldCode field);
*/
void gnc_tree_view_account_configure_columns (GncTreeViewAccount *account_view,
GSList *column_names);
/** Add a new column to the set of columns in an account tree view.
* This column will display the contents of a specified KVP slot.
*
* @param view A pointer to an account tree view.
*
* @param column_title The title for this new column.
*
* @param kvp_key The lookup key to use for looking up data in the
* account KVP structures. The value associated with this key is what
* will be displayed in the column.
*/
void gnc_tree_view_account_add_kvp_column (GncTreeViewAccount *view,
const gchar *column_title,
const gchar *kvp_key);
/** @} */