Document GListModel requiring unique instance pointers from GListModelInterface.get_item
There are some real-world cases where you can have duplicate entries in a GListModel
, and GtkListItemManager
sort of falls over here.
For example, in Sysprof, I have stack traces which may contain a SysprofSymbol
, and that symbol can show up multiple times in a single stack-trace. g_task_return_now()
is one such common example.
To work around this, you have to create a copy of your data objects or an additional indirect object.
Presumably this is where developers will hit this issue.
110 static void
111 gtk_list_item_change_release (GtkListItemChange *change,
112 GtkListItemBase *widget)
113 {
114 if (change->deleted_items == NULL)
115 change->deleted_items = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gtk_widget_unparent);
116
117 if (!g_hash_table_replace (change->deleted_items, gtk_list_item_base_get_item (GTK_LIST_ITEM_BASE (widget)), widget))
118 {
119 g_warning ("Duplicate item detected in list. Picking one randomly.");
120 gtk_list_item_change_recycle (change, widget);
121 }
122 }
Edit
Since it appears to be expected by the interface creators that we should expect unique instances coming from GListModel
, we need to document that behavior.
It might be useful to warn from GListStore
if we detect that behavior, but I suspect the overhead of a GHashTable
for pointer unique'ness checks may be a bit annoying. (Although we could do that only in debug builds).