Skip to content

Commit

Permalink
Modify GncItemList by adding a couple of functions.
Browse files Browse the repository at this point in the history
It is more efficient to disconnect the list store from the tree store
and then reconnect it before doing large number additions to the list
store so add a couple of functions to do this.
  • Loading branch information
Bob-IT committed May 29, 2023
1 parent 7fb03b1 commit f46a958
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gnucash/register/register-gnome/combocell-gnome.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ gnc_combo_cell_set_sort_enabled (ComboCell* cell, gboolean enabled)
return;

block_list_signals (cell);
gnc_item_list_set_sort_enabled (box->item_list, enabled);
gnc_item_list_set_sort_column (box->item_list, 0);
unblock_list_signals (cell);
}

Expand Down
48 changes: 32 additions & 16 deletions gnucash/register/register-gnome/gnucash-item-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,14 @@ gnc_item_list_append (GncItemList* item_list, const char* string)


void
gnc_item_list_set_sort_enabled (GncItemList* item_list, gboolean enabled)
gnc_item_list_set_sort_column (GncItemList* item_list, gint column_id)
{
if (enabled)
{
gtk_tree_sortable_set_sort_column_id
(GTK_TREE_SORTABLE (item_list->list_store),
0,
GTK_SORT_ASCENDING);
}
else
{
gtk_tree_sortable_set_sort_column_id
g_return_if_fail (IS_GNC_ITEM_LIST (item_list));

gtk_tree_sortable_set_sort_column_id
(GTK_TREE_SORTABLE (item_list->list_store),
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
column_id,
GTK_SORT_ASCENDING);
}
}


Expand Down Expand Up @@ -203,6 +195,7 @@ gnc_item_list_select (GncItemList* item_list, const char* string)
g_free (to_find_data);
}


char*
gnc_item_list_get_selection (GncItemList *item_list)
{
Expand Down Expand Up @@ -277,6 +270,29 @@ gnc_item_list_using_temp (GncItemList *item_list)
return item_list && item_list->temp_store;
}

GtkListStore *
gnc_item_list_disconnect_store (GncItemList *item_list)
{
GtkListStore *store;

g_return_val_if_fail (item_list != NULL, NULL);

store = GTK_LIST_STORE(gtk_tree_view_get_model (item_list->tree_view));

gtk_tree_view_set_model (item_list->tree_view, NULL);

return store;
}

void
gnc_item_list_connect_store (GncItemList *item_list, GtkListStore *list_store)
{
g_return_if_fail (item_list != 0);

gtk_tree_view_set_model (item_list->tree_view,
GTK_TREE_MODEL (list_store));
}

static void
gnc_item_list_init (GncItemList* item_list)
{
Expand Down Expand Up @@ -493,9 +509,9 @@ gnc_item_list_new (GtkListStore* list_store)
g_object_unref (list_store);

gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (
tree_view)),
GTK_SELECTION_BROWSE);
gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_BROWSE);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
0, GTK_SORT_ASCENDING);

Expand Down
6 changes: 5 additions & 1 deletion gnucash/register/register-gnome/gnucash-item-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void gnc_item_list_clear (GncItemList *item_list);

void gnc_item_list_append (GncItemList *item_list, const char *string);

void gnc_item_list_set_sort_enabled(GncItemList *item_list, gboolean enabled);
void gnc_item_list_set_sort_column (GncItemList *item_list, gint column_id);

gboolean gnc_item_in_list (GncItemList *item_list, const char *string);

Expand All @@ -98,5 +98,9 @@ void gnc_item_list_set_temp_store (GncItemList *item_list, GtkListStore *store);

gboolean gnc_item_list_using_temp (GncItemList *item_list);

GtkListStore * gnc_item_list_disconnect_store (GncItemList *item_list);

void gnc_item_list_connect_store (GncItemList *item_list, GtkListStore *store);

/** @} */
#endif /* GNUCASH_ITEM_LIST_H */

0 comments on commit f46a958

Please sign in to comment.