GnuCash  5.6-150-g038405b370+
Files | Data Structures | Macros | Enumerations | Functions
GncTreeView

Files

file  gnc-tree-view.c
 Base GncTreeView implementation for gnucash trees.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 
file  tree-view-utils.c
 Simple convenience functions for common tasks on GtkTreeViews.
 

Data Structures

struct  GncTreeViewPrivate
 Private Data Structure. More...
 

Macros

#define STATE_KEY   "state-key"
 
#define STATE_KEY_SORT_COLUMN   "sort_column"
 
#define STATE_KEY_SORT_ORDER   "sort_order"
 
#define STATE_KEY_COLUMN_ORDER   "column_order"
 
#define STATE_KEY_SUFF_VISIBLE   "visible"
 
#define STATE_KEY_SUFF_WIDTH   "width"
 

Enumerations

enum  { PROP_0, PROP_STATE_SECTION, PROP_SHOW_COLUMN_MENU }
 

Functions

void gnc_tree_view_configure_columns (GncTreeView *view)
 Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available. More...
 
GtkTreeViewColumn * gnc_tree_view_add_toggle_column (GncTreeView *view, const gchar *column_title, const gchar *column_short_title, const gchar *pref_name, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn, renderer_toggled toggle_edited_cb)
 This function adds a new toggle column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_text_view_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new text view column to a GncTreeView base view. More...
 
GtkTreeViewColumn * gnc_tree_view_add_pix_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new pixbuf view column to a GncTreeView base view. More...
 
GtkCellRenderer * gnc_tree_view_column_get_renderer (GtkTreeViewColumn *column)
 Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines. More...
 
GtkTreeViewColumn * gnc_tree_view_add_numeric_column (GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_color_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
 This function adds a new numeric column to a GncTreeView base view. More...
 
gint gnc_tree_view_append_column (GncTreeView *view, GtkTreeViewColumn *column)
 Add a column to a view based upon a GncTreeView. More...
 
gboolean gnc_tree_view_path_is_valid (GncTreeView *view, GtkTreePath *path)
 
void gnc_tree_view_keynav (GncTreeView *view, GtkTreeViewColumn **col, GtkTreePath *path, GdkEventKey *event)
 
void gnc_tree_view_set_editing_started_cb (GncTreeView *view, GFunc editing_started_cb, gpointer editing_cb_data)
 Setup a callback for when the user starts editing so appropriate actions can be taken like disable the actions delete menu option.
 
void gnc_tree_view_set_editing_finished_cb (GncTreeView *view, GFunc editing_finished_cb, gpointer editing_cb_data)
 Setup a callback for when the user finishes editing so appropriate actions can be taken like enable the actions delete menu option.
 
void tree_view_column_set_default_width (GtkTreeView *view, GtkTreeViewColumn *column, const gchar *sizing_text)
 Set default width for a treeview column. More...
 

Gnc Tree View Auxiliary Functions

GtkTreeViewColumn * gnc_tree_view_find_column_by_name (GncTreeView *view, const gchar *wanted)
 Find a tree column given the "pref name" used with saved state. More...
 

Gnc Tree View state Callback / Related Functions

void gnc_tree_view_remove_state_information (GncTreeView *view)
 Completely wipe the treeview's state information (column visibility, width, sorting order,..). More...
 
void gnc_tree_view_set_state_section (GncTreeView *view, const gchar *section)
 Set up or remove an association between a saved state section and the display of a view. More...
 
const gchar * gnc_tree_view_get_state_section (GncTreeView *view)
 Get the name of the state section this tree view is associated with. More...
 
void gnc_tree_view_save_state (GncTreeView *view)
 This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file. More...
 

Gnc Tree View Column Selection Menu Related Functions

void gnc_tree_view_expand_columns (GncTreeView *view, gchar *first_column_name,...)
 This function set the columns that will be allocated the free space in the view. More...
 
void gnc_tree_view_set_control_column_background (GncTreeView *view, gint column, GtkTreeCellDataFunc func)
 This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property. More...
 
void gnc_tree_view_set_sort_user_data (GncTreeView *view, GtkTreeModel *s_model)
 This allows the columns to be setup without the model connected. More...
 
void gnc_tree_view_set_show_column_menu (GncTreeView *view, gboolean visible)
 This function is called to set the "show-column-menu" property on this view. More...
 
gboolean gnc_tree_view_get_show_column_menu (GncTreeView *view)
 This function is called to get the current value of the "show-column-menu" property. More...
 

Detailed Description

Function Documentation

◆ gnc_tree_view_add_numeric_column()

GtkTreeViewColumn* gnc_tree_view_add_numeric_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_color_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new numeric column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered. A numeric column is nothing more then a text column with a few extra attributes.

Parameters are defined in gnc-tree-view.h

Definition at line 2061 of file gnc-tree-view.c.

2069 {
2070  GtkTreeViewColumn *column;
2071  GtkCellRenderer *renderer;
2072  gfloat alignment = 1.0;
2073 
2074  /* Use GncCellRendererLabel so the user can click a cell and select
2075  * its text (e.g. to copy it to the clipboard), without being able
2076  * to modify the underlying data. */
2077  renderer = gnc_cell_renderer_label_new ();
2078  column = add_text_column_variant (view, renderer, column_title, pref_name,
2079  NULL, sizing_text, model_data_column,
2080  model_visibility_column, column_sort_fn);
2081 
2082  /* Right align the column title and data for both ltr and rtl */
2083  if (gtk_widget_get_direction (GTK_WIDGET(view)) == GTK_TEXT_DIR_RTL)
2084  alignment = 0.0;
2085 
2086  g_object_set (G_OBJECT(column), "alignment", alignment, NULL);
2087  g_object_set (G_OBJECT(renderer), "xalign", alignment, NULL);
2088 
2089  /* Change the text color */
2090  if (model_color_column != GNC_TREE_VIEW_COLUMN_COLOR_NONE)
2091  gtk_tree_view_column_add_attribute (column, renderer,
2092  "foreground", model_color_column);
2093 
2094  return column;
2095 }

◆ gnc_tree_view_add_pix_column()

GtkTreeViewColumn* gnc_tree_view_add_pix_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new pixbuf view column to a GncTreeView base view.

This function adds a pixbuf view column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1985 of file gnc-tree-view.c.

1992 {
1993  GtkTreeViewColumn *column;
1994  PangoLayout* layout;
1995  int default_width, title_width;
1996  GtkCellRenderer *renderer;
1997 
1998  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1999 
2000  renderer = gtk_cell_renderer_pixbuf_new ();
2001 
2002  column = gtk_tree_view_column_new ();
2003  gtk_tree_view_column_set_title (column, column_title);
2004 
2005  /* Set up a text renderer and attributes */
2006  gtk_tree_view_column_pack_start (column, renderer, TRUE);
2007 
2008  /* Set renderer attributes controlled by the model */
2009  if (model_data_column != GNC_TREE_VIEW_COLUMN_DATA_NONE)
2010  gtk_tree_view_column_add_attribute (column, renderer,
2011  "icon-name", model_data_column);
2012  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
2013  gtk_tree_view_column_add_attribute (column, renderer,
2014  "visible", model_visibility_column);
2015 
2016  /* Default size is the larger of the column title and the sizing text */
2017  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
2018  pango_layout_get_pixel_size (layout, &title_width, NULL);
2019  g_object_unref (layout);
2020  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
2021  pango_layout_get_pixel_size (layout, &default_width, NULL);
2022  g_object_unref (layout);
2023  default_width = MAX(default_width, title_width);
2024  if (default_width)
2025  default_width += 10; /* padding on either side */
2026  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
2027  default_width, TRUE, column_sort_fn);
2028 
2029  gnc_tree_view_append_column (view, column);
2030  return column;
2031 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_add_text_column()

GtkTreeViewColumn* gnc_tree_view_add_text_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1921 of file gnc-tree-view.c.

1929 {
1930  GtkCellRenderer *renderer;
1931 
1932  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1933 
1934  renderer = gtk_cell_renderer_text_new ();
1935 
1936  return add_text_column_variant (view, renderer,
1937  column_title, pref_name,
1938  icon_name, sizing_text,
1939  model_data_column,
1940  model_visibility_column,
1941  column_sort_fn);
1942 }

◆ gnc_tree_view_add_text_view_column()

GtkTreeViewColumn* gnc_tree_view_add_text_view_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  pref_name,
const gchar *  icon_name,
const gchar *  sizing_text,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn 
)

This function adds a new text view column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1953 of file gnc-tree-view.c.

1961 {
1962  GtkCellRenderer *renderer;
1963 
1964  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1965 
1966  renderer = gnc_cell_renderer_text_view_new ();
1967 
1968  return add_text_column_variant (view, renderer,
1969  column_title, pref_name,
1970  icon_name, sizing_text,
1971  model_data_column,
1972  model_visibility_column,
1973  column_sort_fn);
1974 }

◆ gnc_tree_view_add_toggle_column()

GtkTreeViewColumn* gnc_tree_view_add_toggle_column ( GncTreeView *  view,
const gchar *  column_title,
const gchar *  column_short_title,
const gchar *  pref_name,
gint  model_data_column,
gint  model_visibility_column,
GtkTreeIterCompareFunc  column_sort_fn,
renderer_toggled  toggle_edited_cb 
)

This function adds a new toggle column to a GncTreeView base view.

It takes all the parameters necessary to hook a GtkTreeModel column to a GtkTreeViewColumn. It handles creating a tooltip to show the full title name, and setting the sort and edit callback functions. If the tree has a state section associated with it, this function also wires up the column so that its visibility and width are remembered.

Parameters are defined in gnc-tree-view.h

Definition at line 1768 of file gnc-tree-view.c.

1776 {
1777  GtkTreeViewColumn *column;
1778  GtkCellRenderer *renderer;
1779 
1780  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1781 
1782  renderer = gtk_cell_renderer_toggle_new ();
1783  if (!toggle_edited_cb)
1784  {
1785  gtk_cell_renderer_toggle_set_activatable (GTK_CELL_RENDERER_TOGGLE(renderer), FALSE);
1786  }
1787  column =
1788  gtk_tree_view_column_new_with_attributes (column_short_title,
1789  renderer,
1790  "active", model_data_column,
1791  NULL);
1792 
1793  /* Add the full title to the object for menu creation */
1794  g_object_set_data_full (G_OBJECT(column), REAL_TITLE,
1795  g_strdup(column_title), g_free);
1796  if (toggle_edited_cb)
1797  g_signal_connect (G_OBJECT(renderer), "toggled",
1798  G_CALLBACK(toggle_edited_cb), view);
1799 
1800  if (model_visibility_column != GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS)
1801  gtk_tree_view_column_add_attribute (column, renderer,
1802  "visible", model_visibility_column);
1803 
1804 
1805  gnc_tree_view_column_properties (view, column, pref_name, model_data_column,
1806  0, FALSE, column_sort_fn);
1807 
1808  gnc_tree_view_append_column (view, column);
1809 
1810  /* Also add the full title to the object as a tooltip */
1811  gtk_widget_set_tooltip_text (gtk_tree_view_column_get_button (column), column_title);
1812 
1813  return column;
1814 }
gint gnc_tree_view_append_column(GncTreeView *view, GtkTreeViewColumn *column)
Add a column to a view based upon a GncTreeView.

◆ gnc_tree_view_append_column()

gint gnc_tree_view_append_column ( GncTreeView *  view,
GtkTreeViewColumn *  column 
)

Add a column to a view based upon a GncTreeView.

This function knows about the two special columns on the right side of this type of view, and adds the new column before these two columns. You could say that it appends to the data columns and ignores the infrastructure columns.

Parameters are defined in gnc-tree-view.h

Definition at line 2106 of file gnc-tree-view.c.

2108 {
2109  int n = gtk_tree_view_get_n_columns (GTK_TREE_VIEW(view));
2110 
2111  /* Ignore the initial column, the selection menu */
2112  if (n >= 1)
2113  n -= 1;
2114  return gtk_tree_view_insert_column (GTK_TREE_VIEW(view), column, n);
2115 }

◆ gnc_tree_view_column_get_renderer()

GtkCellRenderer* gnc_tree_view_column_get_renderer ( GtkTreeViewColumn *  column)

Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the convenience routines.

Parameters
columnThe tree view column that was added to the GncTreeView
Returns
The cell renderer in use in the column.

Definition at line 2034 of file gnc-tree-view.c.

2035 {
2036  GList *renderers;
2037  GtkCellRenderer *cr = NULL;
2038 
2039  g_return_val_if_fail (GTK_TREE_VIEW_COLUMN(column), NULL);
2040 
2041  /* Get the list of one renderer */
2042  renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(column));
2043  if (g_list_length (renderers) > 0)
2044  cr = GTK_CELL_RENDERER(renderers->data);
2045  g_list_free (renderers);
2046 
2047  return cr;
2048 }

◆ gnc_tree_view_configure_columns()

void gnc_tree_view_configure_columns ( GncTreeView *  view)

Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.

Parameters
viewA pointer to an gnc tree view.

Definition at line 1598 of file gnc-tree-view.c.

1599 {
1600  GncTreeViewPrivate *priv;
1601  GtkTreeViewColumn *column;
1602  GList *columns;
1603  gboolean hide_menu_column;
1604 
1605  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1606 
1607  ENTER(" ");
1608 
1609  /* Update the view and saved state */
1610  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1611  g_list_foreach (columns, (GFunc)gnc_tree_view_update_visibility, view);
1612  g_list_free (columns);
1613 
1614  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1615  if (priv->state_section)
1616  priv->seen_state_visibility = TRUE;
1617 
1618  /* If only the first column is visible, hide the spacer and make that
1619  * column expand. */
1620  hide_menu_column = (gnc_tree_view_count_visible_columns (view) == 1);
1621  column = gtk_tree_view_get_column (GTK_TREE_VIEW(view), 0);
1622  gtk_tree_view_column_set_expand (column, hide_menu_column);
1623  gtk_tree_view_column_set_visible (priv->column_menu_column, !hide_menu_column);
1624 
1625  LEAVE(" ");
1626 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_expand_columns()

void gnc_tree_view_expand_columns ( GncTreeView *  view,
gchar *  first_column_name,
  ... 
)

This function set the columns that will be allocated the free space in the view.

Parameters
viewThe tree view.
listof column names.

Definition at line 1433 of file gnc-tree-view.c.

1436 {
1437  GtkTreeViewColumn *column;
1438  GList *columns, *tmp;
1439  gchar *name, *pref_name;
1440  va_list args;
1441 
1442  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1443  ENTER(" ");
1444  va_start (args, first_column_name);
1445  name = first_column_name;
1446 
1447  /* First disable the expand property on all (non-infrastructure) columns. */
1448  columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1449  for (tmp = columns; tmp; tmp = g_list_next (tmp))
1450  {
1451  column = tmp->data;
1452  pref_name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1453  if (pref_name != NULL)
1454  gtk_tree_view_column_set_expand (column, FALSE);
1455  }
1456  g_list_free(columns);
1457 
1458  /* Now enable it on the requested columns. */
1459  while (name != NULL)
1460  {
1461  column = gnc_tree_view_find_column_by_name (view, name);
1462  if (column != NULL)
1463  {
1464  gtk_tree_view_column_set_expand (column, TRUE);
1465  }
1466  name = va_arg (args, gchar*);
1467  }
1468  va_end (args);
1469 
1470  LEAVE(" ");
1471 }
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_tree_view_find_column_by_name()

GtkTreeViewColumn* gnc_tree_view_find_column_by_name ( GncTreeView *  view,
const gchar *  wanted 
)

Find a tree column given the "pref name" used with saved state.

Find a tree column given the "pref name".

This function simply runs the list of all (visible and invisible) columns looking for a match. Column names were attached to each column at the time the column was created.

Parameters
viewThe visible tree widget.
wantedThe "pref name" to find.

Definition at line 538 of file gnc-tree-view.c.

540 {
541  GtkTreeViewColumn *column, *found = NULL;
542  GList *column_list, *tmp;
543  const gchar *name;
544 
545  // ENTER("view %p, wanted %s", view, wanted);
546  column_list = gtk_tree_view_get_columns(GTK_TREE_VIEW(view));
547  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
548  {
549  column = tmp->data;
550  name = g_object_get_data (G_OBJECT(column), PREF_NAME);
551  if (!name || (strcmp(name, wanted) != 0))
552  continue;
553  found = column;
554  break;
555  }
556  g_list_free (column_list);
557 
558  // LEAVE("column %p", found);
559  return found;
560 }

◆ gnc_tree_view_get_show_column_menu()

gboolean gnc_tree_view_get_show_column_menu ( GncTreeView *  view)

This function is called to get the current value of the "show-column-menu" property.

It returns the same value passed to gnc_tree_view_set_show_menu_column().

Parameters are defined in gnc-tree-view.h

Definition at line 1562 of file gnc-tree-view.c.

1563 {
1564  GncTreeViewPrivate *priv;
1565 
1566  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), FALSE);
1567 
1568  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1569  return (priv->show_column_menu);
1570 }
Private Data Structure.

◆ gnc_tree_view_get_state_section()

const gchar* gnc_tree_view_get_state_section ( GncTreeView *  view)

Get the name of the state section this tree view is associated with.

This function is called to get the current association between a saved state section and the display of a view.

It returns the same value passed to gnc_tree_view_set_state_section(); i.e. a string like "dialogs/edit_prices".

Parameters are defined in gnc-tree-view.h

Definition at line 1124 of file gnc-tree-view.c.

1125 {
1126  GncTreeViewPrivate *priv;
1127 
1128  g_return_val_if_fail (GNC_IS_TREE_VIEW(view), NULL);
1129 
1130  priv = GNC_TREE_VIEW_GET_PRIVATE (view);
1131  return priv->state_section;
1132 }
Private Data Structure.

◆ gnc_tree_view_remove_state_information()

void gnc_tree_view_remove_state_information ( GncTreeView *  view)

Completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function is called to completely wipe the treeview's state information (column visibility, width, sorting order,..).

This function may be called at any time; either when the user wants to disconnect or when the view object is being destroyed.

Parameters
viewThe tree view.

Definition at line 982 of file gnc-tree-view.c.

983 {
984  GncTreeViewPrivate *priv;
985  GKeyFile *state_file = gnc_state_get_current ();
986 
987  ENTER(" ");
988  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
989  if (!priv->state_section)
990  {
991  LEAVE("no state section");
992  return;
993  }
994 
995  g_key_file_remove_group (state_file, priv->state_section, NULL);
996  g_free (priv->state_section);
997  priv->state_section = NULL;
998  LEAVE(" ");
999 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_save_state()

void gnc_tree_view_save_state ( GncTreeView *  view)

This function is called to write the treeview's state information (column visibility, width, sorting order,..) to the state file.

Parameters
viewThe tree view.

Definition at line 1134 of file gnc-tree-view.c.

1135 {
1136  GncTreeViewPrivate *priv;
1137 
1138  ENTER("view %p", view);
1139  g_return_if_fail (view != NULL);
1140  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1141 
1142  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1143 
1144  if (priv->state_section)
1145  {
1146  /* Save state. Only store non-default values when possible. */
1147  GList *column_list, *tmp;
1148  GKeyFile *state_file = gnc_state_get_current();
1149  gsize num_cols = 0;
1150  gchar *sort_column = gnc_tree_view_get_sort_column (view);
1151  gchar *sort_order = gnc_tree_view_get_sort_order (view);
1152  gchar **col_order = gnc_tree_view_get_column_order (view, &num_cols);
1153 
1154  /* Default sort column is the name column */
1155  if (sort_column && (g_strcmp0 (sort_column, "name") != 0))
1156  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, sort_column);
1157  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL))
1158  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_COLUMN, NULL);
1159  g_free (sort_column);
1160 
1161 
1162  /* Default sort order is "ascending" */
1163  if (g_strcmp0 (sort_order, "descending") == 0)
1164  g_key_file_set_string (state_file, priv->state_section, STATE_KEY_SORT_ORDER, sort_order);
1165  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL))
1166  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_SORT_ORDER, NULL);
1167  g_free (sort_order);
1168 
1169  if (col_order && (num_cols > 0))
1170  g_key_file_set_string_list (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER,
1171  (const gchar**) col_order, num_cols);
1172  else if (g_key_file_has_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL))
1173  g_key_file_remove_key (state_file, priv->state_section, STATE_KEY_COLUMN_ORDER, NULL);
1174 
1175  g_strfreev (col_order);
1176 
1177 
1178  // ENTER("view %p, wanted %s", view, wanted);
1179  column_list = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
1180  for (tmp = column_list; tmp; tmp = g_list_next (tmp))
1181  {
1182  GtkTreeViewColumn *column = tmp->data;
1183  gchar *key=NULL;
1184  const gchar *name = g_object_get_data (G_OBJECT(column), PREF_NAME);
1185  if (!name)
1186  continue;
1187 
1188  if (!g_object_get_data (G_OBJECT(column), ALWAYS_VISIBLE))
1189  {
1190  key = g_strjoin ("_", name, STATE_KEY_SUFF_VISIBLE, NULL);
1191  g_key_file_set_boolean (state_file, priv->state_section, key,
1192  gtk_tree_view_column_get_visible (column));
1193  g_free (key);
1194  }
1195 
1196  key = g_strjoin ("_", name, STATE_KEY_SUFF_WIDTH, NULL);
1197  if (g_object_get_data (G_OBJECT(column), "default-width") &&
1198  (GPOINTER_TO_INT((g_object_get_data (G_OBJECT(column), "default-width")))
1199  != gtk_tree_view_column_get_width (column)))
1200  {
1201  g_key_file_set_integer (state_file, priv->state_section, key,
1202  gtk_tree_view_column_get_width (column));
1203  }
1204  else if (g_key_file_has_key (state_file, priv->state_section, key, NULL))
1205  g_key_file_remove_key (state_file, priv->state_section, key, NULL);
1206  g_free (key);
1207  }
1208  g_list_free (column_list);
1209  }
1210 
1211  LEAVE(" ");
1212 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_control_column_background()

void gnc_tree_view_set_control_column_background ( GncTreeView *  view,
gint  column,
GtkTreeCellDataFunc  func 
)

This function links the cell backgrounds of the two control columns to a column in the model that has color strings or a cell data function that sets the "cell-background" property.

Parameters
viewThe tree view.
columnThe column in the model containing color strings.
funcThis is a cell data function that sets the "cell-background".

Definition at line 1502 of file gnc-tree-view.c.

1503 {
1504  GncTreeViewPrivate *priv;
1505 
1506  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1507 
1508  ENTER("view %p, column %d, func %p", view, column, func);
1509  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1510 
1511  update_control_cell_renderers_background (view, priv->column_menu_column, column, func);
1512 
1513  LEAVE(" ");
1514 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_show_column_menu()

void gnc_tree_view_set_show_column_menu ( GncTreeView *  view,
gboolean  visible 
)

This function is called to set the "show-column-menu" property on this view.

This function has no visible effect if the "state-section" property has not been set.

Parameters are defined in gnc-tree-view.h

Definition at line 1541 of file gnc-tree-view.c.

1543 {
1544  GncTreeViewPrivate *priv;
1545 
1546  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1547 
1548  ENTER("view %p, show menu %d", view, visible);
1549  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1550  priv->show_column_menu = visible;
1551  gnc_tree_view_build_column_menu (view);
1552  LEAVE(" ");
1553 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_sort_user_data()

void gnc_tree_view_set_sort_user_data ( GncTreeView *  view,
GtkTreeModel *  s_model 
)

This allows the columns to be setup without the model connected.

Parameters
viewThe tree view.
sortmodel.

Definition at line 1520 of file gnc-tree-view.c.

1521 {
1522  GncTreeViewPrivate *priv;
1523 
1524  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1525 
1526  ENTER("view %p, sort_model %p", view, s_model);
1527  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1528 
1529  priv->sort_model = s_model;
1530  LEAVE(" ");
1531 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ gnc_tree_view_set_state_section()

void gnc_tree_view_set_state_section ( GncTreeView *  view,
const gchar *  section 
)

Set up or remove an association between a saved state section and the display of a view.

This function is called to set up or remove an association between a saved state section and the display of a view.

It will first remove any existing association, and then install the new one. If the new section has state information, update the view with this information.

Parameters are defined in gnc-tree-view.h

Definition at line 1009 of file gnc-tree-view.c.

1011 {
1012  GncTreeViewPrivate *priv;
1013  GKeyFile *state_file;
1014 
1015  g_return_if_fail (GNC_IS_TREE_VIEW(view));
1016 
1017  ENTER("view %p, section %s", view, section);
1018 
1019  priv = GNC_TREE_VIEW_GET_PRIVATE(view);
1020 
1021  /* Drop any previous state section */
1022  if (priv->state_section)
1024 
1025  if (!section)
1026  {
1027  LEAVE("cleared state section");
1028  return;
1029  }
1030 
1031  /* Catch changes in state. Propagate to view. */
1032  priv->state_section = g_strdup (section);
1033 
1034  state_file = gnc_state_get_current ();
1035  if (g_key_file_has_group (state_file, priv->state_section))
1036  {
1037  gsize num_keys, idx;
1038  gchar **keys = g_key_file_get_keys (state_file, priv->state_section, &num_keys, NULL);
1039  for (idx = 0; idx < num_keys; idx++)
1040  {
1041  gchar *key = keys[idx];
1042  if (g_strcmp0 (key, STATE_KEY_SORT_COLUMN) == 0)
1043  {
1044  gchar *name = g_key_file_get_string (state_file, priv->state_section,
1045  key, NULL);
1046  gnc_tree_view_set_sort_column (view, name);
1047  g_free (name);
1048  }
1049  else if (g_strcmp0 (key, STATE_KEY_SORT_ORDER) == 0)
1050  {
1051  gchar *name = g_key_file_get_string (state_file, priv->state_section,
1052  key, NULL);
1053  gnc_tree_view_set_sort_order (view, name);
1054  g_free (name);
1055  }
1056  else if (g_strcmp0 (key, STATE_KEY_COLUMN_ORDER) == 0)
1057  {
1058  gsize length;
1059  gchar **columns = g_key_file_get_string_list (state_file, priv->state_section,
1060  key, &length, NULL);
1061  gnc_tree_view_set_column_order (view, columns, length);
1062  g_strfreev (columns);
1063  }
1064  else
1065  {
1066  /* Make a copy of the local part of the key so it can be split
1067  * into column name and key type */
1068  gboolean known = FALSE;
1069  gchar *column_name = g_strdup (key);
1070  gchar *type_name = g_strrstr (column_name, "_");
1071 
1072  if (type_name != NULL) //guard against not finding '_'
1073  {
1074  *type_name++ = '\0';
1075 
1076  if (g_strcmp0 (type_name, STATE_KEY_SUFF_VISIBLE) == 0)
1077  {
1078  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1079  if (column)
1080  {
1081  known = TRUE;
1082  if (!g_object_get_data (G_OBJECT (column), ALWAYS_VISIBLE))
1083  {
1084  gtk_tree_view_column_set_visible (column,
1085  g_key_file_get_boolean (state_file, priv->state_section, key, NULL));
1086  }
1087  }
1088  }
1089  else if (g_strcmp0 (type_name, STATE_KEY_SUFF_WIDTH) == 0)
1090  {
1091  gint width = g_key_file_get_integer (state_file, priv->state_section, key, NULL);
1092  GtkTreeViewColumn *column = gnc_tree_view_find_column_by_name (view, column_name);
1093  if (column)
1094  {
1095  known = TRUE;
1096  if (width && (width != gtk_tree_view_column_get_width (column)))
1097  {
1098  gtk_tree_view_column_set_fixed_width (column, width);
1099  }
1100  }
1101  }
1102  if (!known)
1103  DEBUG ("Ignored key %s", key);
1104 
1105  g_free (column_name);
1106  }
1107  }
1108  }
1109  g_strfreev (keys);
1110  }
1111 
1112  /* Rebuild the column visibility menu */
1113  gnc_tree_view_build_column_menu (view);
1114  LEAVE ("set state section");
1115 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_tree_view_remove_state_information(GncTreeView *view)
Completely wipe the treeview&#39;s state information (column visibility, width, sorting order...
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition: gnc-state.c:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
Private Data Structure.

◆ tree_view_column_set_default_width()

void tree_view_column_set_default_width ( GtkTreeView *  view,
GtkTreeViewColumn *  column,
const gchar *  sizing_text 
)

Set default width for a treeview column.

This base width is the largest of the column title and some arbitrary text passed in via sizing_text. This base width is then increased with some padding.

Definition at line 43 of file tree-view-utils.c.

46 {
47  PangoLayout* layout;
48  int default_width, title_width;
49  const gchar *column_title;
50 
51  /* Default size is the larger of the column title and the sizing text */
52  column_title = gtk_tree_view_column_get_title (column);
53  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
54  pango_layout_get_pixel_size(layout, &title_width, NULL);
55  g_object_unref(layout);
56  layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
57  pango_layout_get_pixel_size(layout, &default_width, NULL);
58  g_object_unref(layout);
59  default_width = MAX(default_width, title_width);
60  if (default_width)
61  {
62  default_width += 10; /* add some padding */
63  g_object_set(G_OBJECT(column),
64  "sizing", GTK_TREE_VIEW_COLUMN_FIXED,
65  "fixed-width", default_width,
66  NULL);
67  }
68 }