listmodels: Clarify documentation for function prototypes

Fixes #1341
This commit is contained in:
Benjamin Otte 2018-09-18 07:27:48 +02:00
parent 0d7c987b1a
commit 29c700d1c7
4 changed files with 33 additions and 4 deletions

View File

@ -36,6 +36,17 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkFilterListModel, gtk_filter_list_model, GTK, FILTER_LIST_MODEL, GObject)
/**
* GtkFilterListModelFilterFunc:
* @item: (type GObject): The item that may be filtered
* @user_data: user data
*
* User function that is called to determine if the @item of the original model should be visible.
* If it should be visible, this function must return %TRUE. If the model should filter out the
* @item, %FALSE must be returned.
*
* Returns: %TRUE to keep the item around
*/
typedef gboolean (* GtkFilterListModelFilterFunc) (gpointer item, gpointer user_data);
GDK_AVAILABLE_IN_ALL

View File

@ -180,6 +180,11 @@ gtk_map_list_model_get_item (GListModel *list,
}
node->item = self->map_func (g_list_model_get_item (self->model, position), self->user_data);
if (!G_TYPE_CHECK_INSTANCE_TYPE (node->item, self->item_type))
{
g_critical ("Map function returned a %s, but it is not a subtype of the model's type %s",
G_OBJECT_TYPE_NAME (node->item), g_type_name (self->item_type));
}
g_object_add_weak_pointer (node->item, &node->item);
return node->item;

View File

@ -38,12 +38,17 @@ G_DECLARE_FINAL_TYPE (GtkMapListModel, gtk_map_list_model, GTK, MAP_LIST_MODEL,
/**
* GtkMapListModelMapFunc:
* @item: (transfer full): The item to map
* @item: (type GObject) (transfer full): The item to map
* @user_data: user data
*
* User function that is called to map an @item of the original model.
* User function that is called to map an @item of the original model to
* an item expected by the map model.
*
* Returns: (transfer full): The item to map to. This function may not return %NULL
* The returned items must conform to the item type of the model they are
* used with.
*
* Returns: (type GObject) (transfer full): The item to map to.
* This function may not return %NULL
*/
typedef gpointer (* GtkMapListModelMapFunc) (gpointer item, gpointer user_data);

View File

@ -41,11 +41,19 @@ G_DECLARE_FINAL_TYPE (GtkTreeListRow, gtk_tree_list_row, GTK, TREE_LIST_ROW, GOb
/**
* GtkTreeListModelCreateModelFunc:
* @item: The item that is expaned
* @item: (type GObject): The item that is being expanded
* @user_data: User data passed when registering the function
*
* Prototype of the function called to create new child models when
* gtk_tree_list_row_set_expanded() is called.
*
* This function can return %NULL to indicate that @item is guaranteed to be
* a leave node and will never have children.
* If it does not have children but may get children later, it should return
* an empty model that is filled once children arrive.
*
* Returns: (nullable): The model tracking the children of @item or %NULL if
* @item can never have children
*/
typedef GListModel * (* GtkTreeListModelCreateModelFunc) (gpointer item, gpointer user_data);