Merge branch 'wip/otte/listmodels' into 'main'

19 listmodels: Add ::item-type and ::n-items

See merge request GNOME/gtk!4807
This commit is contained in:
Matthias Clasen 2022-06-11 15:15:53 +00:00
commit d88e935398
31 changed files with 1173 additions and 152 deletions

View File

@ -158,6 +158,30 @@ struct _GtkAssistantClass
void (* cancel) (GtkAssistant *assistant);
};
#define GTK_TYPE_ASSISTANT_PAGES (gtk_assistant_pages_get_type ())
G_DECLARE_FINAL_TYPE (GtkAssistantPages, gtk_assistant_pages, GTK, ASSISTANT_PAGES, GObject)
struct _GtkAssistantPages
{
GObject parent_instance;
GtkAssistant *assistant;
};
struct _GtkAssistantPagesClass
{
GObjectClass parent_class;
};
enum {
PAGES_PROP_0,
PAGES_PROP_ITEM_TYPE,
PAGES_PROP_N_ITEMS,
PAGES_N_PROPS
};
static GParamSpec *pages_properties[PAGES_N_PROPS] = { NULL, };
static void gtk_assistant_dispose (GObject *object);
static void gtk_assistant_map (GtkWidget *widget);
static void gtk_assistant_unmap (GtkWidget *widget);
@ -1289,8 +1313,11 @@ gtk_assistant_dispose (GObject *object)
{
GtkAssistant *assistant = GTK_ASSISTANT (object);
if (assistant->model)
g_list_model_items_changed (G_LIST_MODEL (assistant->model), 0, g_list_length (assistant->pages), 0);
if (assistant->model && g_list_length (assistant->pages))
{
g_list_model_items_changed (G_LIST_MODEL (assistant->model), 0, g_list_length (assistant->pages), 0);
g_object_notify_by_pspec (G_OBJECT (assistant->model), pages_properties[PAGES_PROP_N_ITEMS]);
}
/* We set current to NULL so that the remove code doesn't try
* to do anything funny
@ -1733,7 +1760,10 @@ gtk_assistant_add_page (GtkAssistant *assistant,
}
if (assistant->model)
g_list_model_items_changed (assistant->model, position, 0, 1);
{
g_list_model_items_changed (assistant->model, position, 0, 1);
g_object_notify_by_pspec (G_OBJECT (assistant->model), pages_properties[PAGES_PROP_N_ITEMS]);
}
return position;
}
@ -1759,7 +1789,10 @@ gtk_assistant_remove_page (GtkAssistant *assistant,
assistant_remove_page (assistant, page);
if (assistant->model)
g_list_model_items_changed (assistant->model, page_num, 1, 0);
{
g_list_model_items_changed (assistant->model, page_num, 1, 0);
g_object_notify_by_pspec (G_OBJECT (assistant->model), pages_properties[PAGES_PROP_N_ITEMS]);
}
}
/**
@ -2184,20 +2217,6 @@ gtk_assistant_page_get_child (GtkAssistantPage *page)
return page->page;
}
#define GTK_TYPE_ASSISTANT_PAGES (gtk_assistant_pages_get_type ())
G_DECLARE_FINAL_TYPE (GtkAssistantPages, gtk_assistant_pages, GTK, ASSISTANT_PAGES, GObject)
struct _GtkAssistantPages
{
GObject parent_instance;
GtkAssistant *assistant;
};
struct _GtkAssistantPagesClass
{
GObjectClass parent_class;
};
static GType
gtk_assistant_pages_get_item_type (GListModel *model)
{
@ -2231,17 +2250,57 @@ gtk_assistant_pages_list_model_init (GListModelInterface *iface)
iface->get_n_items = gtk_assistant_pages_get_n_items;
iface->get_item = gtk_assistant_pages_get_item;
}
G_DEFINE_TYPE_WITH_CODE (GtkAssistantPages, gtk_assistant_pages, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_assistant_pages_list_model_init))
static void
gtk_assistant_pages_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkAssistantPages *self = GTK_ASSISTANT_PAGES (object);
switch (prop_id)
{
case PAGES_PROP_ITEM_TYPE:
g_value_set_gtype (value, GTK_TYPE_ASSISTANT_PAGE);
break;
case PAGES_PROP_N_ITEMS:
g_value_set_uint (value, gtk_assistant_pages_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_assistant_pages_init (GtkAssistantPages *pages)
{
}
static void
gtk_assistant_pages_class_init (GtkAssistantPagesClass *class)
gtk_assistant_pages_class_init (GtkAssistantPagesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gtk_assistant_pages_get_property;
pages_properties[PAGES_PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
GTK_TYPE_ASSISTANT_PAGE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
pages_properties[PAGES_PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PAGES_N_PROPS, pages_properties);
}
static GtkAssistantPages *

View File

@ -43,7 +43,10 @@ enum {
PROP_FILENAME,
PROP_ATTRIBUTES,
PROP_IO_PRIORITY,
PROP_ITEM_TYPE,
PROP_LOADING,
PROP_N_ITEMS,
NUM_PROPERTIES
};
@ -149,10 +152,10 @@ gtk_bookmark_list_set_property (GObject *object,
}
static void
gtk_bookmark_list_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
gtk_bookmark_list_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkBookmarkList *self = GTK_BOOKMARK_LIST (object);
@ -162,18 +165,26 @@ gtk_bookmark_list_get_property (GObject *object,
g_value_set_string (value, self->attributes);
break;
case PROP_IO_PRIORITY:
g_value_set_int (value, self->io_priority);
break;
case PROP_FILENAME:
g_value_set_string (value, self->filename);
break;
case PROP_IO_PRIORITY:
g_value_set_int (value, self->io_priority);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, G_TYPE_FILE_INFO);
break;
case PROP_LOADING:
g_value_set_boolean (value, gtk_bookmark_list_is_loading (self));
break;
case PROP_N_ITEMS:
g_value_set_uint (value, g_sequence_get_length (self->items));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -236,6 +247,18 @@ gtk_bookmark_list_class_init (GtkBookmarkListClass *class)
-G_MAXINT, G_MAXINT, G_PRIORITY_DEFAULT,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkBookmarkList:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_FILE_INFO,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkBookmarkList:loading: (attributes org.gtk.Property.get=gtk_bookmark_list_is_loading)
*
@ -246,6 +269,18 @@ gtk_bookmark_list_class_init (GtkBookmarkListClass *class)
FALSE,
GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkBookmarkList:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -306,6 +341,7 @@ got_file_info (GObject *source,
g_sequence_append (self->items, info);
g_list_model_items_changed (G_LIST_MODEL (self), g_sequence_get_length (self->items) - 1, 0, 1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_free (uri);
}
@ -331,6 +367,7 @@ gtk_bookmark_list_clear_items (GtkBookmarkList *self)
g_sequence_get_end_iter (self->items));
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}

View File

@ -60,8 +60,11 @@ enum {
PROP_ERROR,
PROP_FILE,
PROP_IO_PRIORITY,
PROP_ITEM_TYPE,
PROP_LOADING,
PROP_MONITORED,
PROP_N_ITEMS,
NUM_PROPERTIES
};
@ -204,6 +207,10 @@ gtk_directory_list_get_property (GObject *object,
g_value_set_int (value, self->io_priority);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, G_TYPE_FILE_INFO);
break;
case PROP_LOADING:
g_value_set_boolean (value, gtk_directory_list_is_loading (self));
break;
@ -212,6 +219,10 @@ gtk_directory_list_get_property (GObject *object,
g_value_set_boolean (value, gtk_directory_list_get_monitored (self));
break;
case PROP_N_ITEMS:
g_value_set_uint (value, g_sequence_get_length (self->items));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -312,6 +323,18 @@ gtk_directory_list_class_init (GtkDirectoryListClass *class)
-G_MAXINT, G_MAXINT, G_PRIORITY_DEFAULT,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkDirectoryList:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_FILE_INFO,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkDirectoryList:loading: (attributes org.gtk.Property.get=gtk_directory_list_is_loading)
*
@ -332,6 +355,18 @@ gtk_directory_list_class_init (GtkDirectoryListClass *class)
TRUE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkDirectoryList:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -380,6 +415,7 @@ gtk_directory_list_clear_items (GtkDirectoryList *self)
g_sequence_get_end_iter (self->items));
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
if (self->error)
@ -462,7 +498,10 @@ gtk_directory_list_got_files_cb (GObject *source,
self);
if (n > 0)
g_list_model_items_changed (G_LIST_MODEL (self), g_sequence_get_length (self->items) - n, 0, n);
{
g_list_model_items_changed (G_LIST_MODEL (self), g_sequence_get_length (self->items) - n, 0, n);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
static void
@ -580,6 +619,7 @@ handle_event (QueuedEvent *event)
position = g_sequence_get_length (self->items);
g_sequence_append (self->items, g_object_ref (info));
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
break;
@ -591,6 +631,7 @@ handle_event (QueuedEvent *event)
position = g_sequence_iter_get_position (iter);
g_sequence_remove (iter);
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
break;

View File

@ -43,7 +43,9 @@ enum {
PROP_0,
PROP_FILTER,
PROP_INCREMENTAL,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
PROP_PENDING,
NUM_PROPERTIES
};
@ -206,14 +208,18 @@ gtk_filter_list_model_emit_items_changed_for_changes (GtkFilterListModel *self,
gtk_bitset_difference (changes, old);
if (!gtk_bitset_is_empty (changes))
{
guint min, max;
guint min, max, removed, added;
min = gtk_bitset_get_minimum (changes);
max = gtk_bitset_get_maximum (changes);
removed = gtk_bitset_get_size_in_range (old, min, max);
added = gtk_bitset_get_size_in_range (self->matches, min, max);
g_list_model_items_changed (G_LIST_MODEL (self),
min > 0 ? gtk_bitset_get_size_in_range (self->matches, 0, min - 1) : 0,
gtk_bitset_get_size_in_range (old, min, max),
gtk_bitset_get_size_in_range (self->matches, min, max));
removed,
added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
gtk_bitset_unref (changes);
gtk_bitset_unref (old);
@ -286,6 +292,8 @@ gtk_filter_list_model_items_changed_cb (GListModel *model,
case GTK_FILTER_MATCH_ALL:
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
return;
case GTK_FILTER_MATCH_SOME:
@ -316,6 +324,8 @@ gtk_filter_list_model_items_changed_cb (GListModel *model,
g_list_model_items_changed (G_LIST_MODEL (self),
position > 0 ? gtk_bitset_get_size_in_range (self->matches, 0, position - 1) : 0,
filter_removed, filter_added);
if (filter_removed != filter_added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -364,10 +374,18 @@ gtk_filter_list_model_get_property (GObject *object,
g_value_set_boolean (value, self->incremental);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_filter_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_filter_list_model_get_n_items (G_LIST_MODEL (self)));
break;
case PROP_PENDING:
g_value_set_uint (value, gtk_filter_list_model_get_pending (self));
break;
@ -415,7 +433,10 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
self->strictness = new_strictness;
gtk_filter_list_model_stop_filtering (self);
if (n_before > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_before, 0);
{
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_before, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
break;
@ -423,8 +444,17 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
switch (self->strictness)
{
case GTK_FILTER_MATCH_NONE:
self->strictness = new_strictness;
g_list_model_items_changed (G_LIST_MODEL (self), 0, 0, g_list_model_get_n_items (self->model));
{
guint n_items;
self->strictness = new_strictness;
n_items = g_list_model_get_n_items (self->model);
if (n_items > 0)
{
g_list_model_items_changed (G_LIST_MODEL (self), 0, 0, n_items);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
break;
case GTK_FILTER_MATCH_ALL:
self->strictness = new_strictness;
@ -460,6 +490,7 @@ gtk_filter_list_model_refilter (GtkFilterListModel *self,
g_clear_pointer (&self->matches, gtk_bitset_unref);
g_list_model_items_changed (G_LIST_MODEL (self), start, n_before - end - start, n_after - end - start);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
break;
@ -571,6 +602,18 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class)
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFilterListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkFilterListModel:model: (attributes org.gtk.Property.get=gtk_filter_list_model_get_model org.gtk.Property.set=gtk_filter_list_model_set_model)
*
@ -581,6 +624,18 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFilterListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkFilterListModel:pending: (attributes org.gtk.Property.get=gtk_filter_list_model_get_pending)
*
@ -737,6 +792,8 @@ gtk_filter_list_model_set_model (GtkFilterListModel *self,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -36,7 +36,10 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
NUM_PROPERTIES
};
@ -239,6 +242,8 @@ gtk_flatten_list_model_items_changed_cb (GListModel *model,
}
g_list_model_items_changed (G_LIST_MODEL (self), real_position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -332,10 +337,18 @@ gtk_flatten_list_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_flatten_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_flatten_list_model_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -367,6 +380,8 @@ gtk_flatten_list_model_model_items_changed_cb (GListModel *model,
if (real_removed > 0 || real_added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), real_position, real_removed, real_added);
if (real_removed != real_added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -399,6 +414,18 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class)
gobject_class->get_property = gtk_flatten_list_model_get_property;
gobject_class->dispose = gtk_flatten_list_model_dispose;
/**
* GtkFlattenListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkFlattenListModel:model: (attributes org.gtk.Property.get=gtk_flatten_list_model_get_model org.gtk.Property.set=gtk_flatten_list_model_set_model)
*
@ -409,6 +436,18 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFlattenListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -481,6 +520,8 @@ gtk_flatten_list_model_set_model (GtkFlattenListModel *self,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -48,6 +48,16 @@ struct _GtkListListModelClass
GObjectClass parent_class;
};
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_N_ITEMS,
N_PROPS
};
static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_list_list_model_get_item_type (GListModel *list)
{
@ -109,6 +119,30 @@ G_DEFINE_TYPE_WITH_CODE (GtkListListModel, gtk_list_list_model,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_list_list_model_list_model_init))
static void
gtk_list_list_model_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkListListModel *self = GTK_LIST_LIST_MODEL (object);
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, G_TYPE_OBJECT);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, self->n_items);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_list_list_model_dispose (GObject *object)
{
@ -128,7 +162,20 @@ gtk_list_list_model_class_init (GtkListListModelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gtk_list_list_model_get_property;
object_class->dispose = gtk_list_list_model_dispose;
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
@ -231,6 +278,7 @@ gtk_list_list_model_item_added_at (GtkListListModel *self,
self->n_items += 1;
g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
void
@ -292,6 +340,7 @@ gtk_list_list_model_item_removed_at (GtkListListModel *self,
self->n_items -= 1;
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
void
@ -310,7 +359,10 @@ gtk_list_list_model_clear (GtkListListModel *self)
self->notify = NULL;
if (n_items > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
{
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}

View File

@ -60,7 +60,10 @@
enum {
PROP_0,
PROP_HAS_MAP,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
NUM_PROPERTIES
};
@ -221,6 +224,8 @@ gtk_map_list_model_items_changed_cb (GListModel *model,
if (self->items == NULL)
{
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
return;
}
@ -269,6 +274,8 @@ gtk_map_list_model_items_changed_cb (GListModel *model,
}
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -305,10 +312,18 @@ gtk_map_list_model_get_property (GObject *object,
g_value_set_boolean (value, self->items != NULL);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_map_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_map_list_model_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -360,6 +375,18 @@ gtk_map_list_model_class_init (GtkMapListModelClass *class)
FALSE,
GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkMapListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkMapListModel:model: (attributes org.gtk.Property.get=gtk_map_list_model_get_model org.gtk.Property.set=gtk_map_list_model_set_model)
*
@ -370,6 +397,18 @@ gtk_map_list_model_class_init (GtkMapListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkMapListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -578,6 +617,8 @@ gtk_map_list_model_set_model (GtkMapListModel *self,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -71,6 +71,16 @@ struct _GtkMultiFilterClass
GtkFilterChange removal_change;
};
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_N_ITEMS,
N_PROPS
};
static GParamSpec *properties[N_PROPS] = { NULL, };
static GType
gtk_multi_filter_get_item_type (GListModel *list)
{
@ -139,6 +149,30 @@ gtk_multi_filter_changed_cb (GtkFilter *filter,
gtk_filter_changed (GTK_FILTER (self), change);
}
static void
gtk_multi_filter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkMultiFilter *self = GTK_MULTI_FILTER (object);
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, GTK_TYPE_FILTER);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_filters_get_size (&self->filters));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_multi_filter_dispose (GObject *object)
{
@ -161,7 +195,34 @@ gtk_multi_filter_class_init (GtkMultiFilterClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->get_property = gtk_multi_filter_get_property;
object_class->dispose = gtk_multi_filter_dispose;
/**
* GtkMultiFilter:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
GTK_TYPE_FILTER,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkMultiFilter:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
@ -186,6 +247,8 @@ gtk_multi_filter_append (GtkMultiFilter *self,
g_signal_connect (filter, "changed", G_CALLBACK (gtk_multi_filter_changed_cb), self);
gtk_filters_append (&self->filters, filter);
g_list_model_items_changed (G_LIST_MODEL (self), gtk_filters_get_size (&self->filters) - 1, 0, 1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
gtk_filter_changed (GTK_FILTER (self),
GTK_MULTI_FILTER_GET_CLASS (self)->addition_change);
@ -216,6 +279,8 @@ gtk_multi_filter_remove (GtkMultiFilter *self,
filter = gtk_filters_get (&self->filters, position);
g_signal_handlers_disconnect_by_func (filter, gtk_multi_filter_changed_cb, self);
gtk_filters_splice (&self->filters, position, 1, FALSE, NULL, 0);
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
gtk_filter_changed (GTK_FILTER (self),
GTK_MULTI_FILTER_GET_CLASS (self)->removal_change);

View File

@ -49,7 +49,9 @@ struct _GtkMultiSelectionClass
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
N_PROPS,
};
@ -266,6 +268,8 @@ gtk_multi_selection_items_changed_cb (GListModel *model,
g_clear_pointer (&pending, g_hash_table_unref);
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -311,10 +315,18 @@ gtk_multi_selection_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_multi_selection_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_multi_selection_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -343,6 +355,18 @@ gtk_multi_selection_class_init (GtkMultiSelectionClass *klass)
gobject_class->set_property = gtk_multi_selection_set_property;
gobject_class->dispose = gtk_multi_selection_dispose;
/**
* GtkMultiSelection:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkMultiSelection:model: (attributes org.gtk.Property.get=gtk_multi_selection_get_model org.gtk.Property.set=gtk_multi_selection_set_model)
*
@ -353,6 +377,18 @@ gtk_multi_selection_class_init (GtkMultiSelectionClass *klass)
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkMultiSelection:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -446,6 +482,8 @@ gtk_multi_selection_set_model (GtkMultiSelection *self,
gtk_bitset_remove_all (self->selected);
g_hash_table_remove_all (self->items);
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
if (n_items_before)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);

View File

@ -66,6 +66,16 @@ struct _GtkMultiSortKeys
GtkMultiSortKey keys[];
};
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_N_ITEMS,
N_PROPS
};
static GParamSpec *properties[N_PROPS] = { NULL, };
static void
gtk_multi_sort_keys_free (GtkSortKeys *keys)
{
@ -327,6 +337,30 @@ gtk_multi_sorter_changed_cb (GtkSorter *sorter,
gtk_multi_sort_keys_new (self));
}
static void
gtk_multi_sorter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkMultiSorter *self = GTK_MULTI_SORTER (object);
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, GTK_TYPE_SORTER);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_sorters_get_size (&self->sorters));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_multi_sorter_dispose (GObject *object)
{
@ -352,7 +386,34 @@ gtk_multi_sorter_class_init (GtkMultiSorterClass *class)
sorter_class->compare = gtk_multi_sorter_compare;
sorter_class->get_order = gtk_multi_sorter_get_order;
object_class->get_property = gtk_multi_sorter_get_property;
object_class->dispose = gtk_multi_sorter_dispose;
/**
* GtkMultiSorter:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
GTK_TYPE_SORTER,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkMultiSorter:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
@ -402,6 +463,8 @@ gtk_multi_sorter_append (GtkMultiSorter *self,
g_signal_connect (sorter, "changed", G_CALLBACK (gtk_multi_sorter_changed_cb), self);
gtk_sorters_append (&self->sorters, sorter);
g_list_model_items_changed (G_LIST_MODEL (self), gtk_sorters_get_size (&self->sorters) - 1, 0, 1);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
gtk_sorter_changed_with_keys (GTK_SORTER (self),
GTK_SORTER_CHANGE_MORE_STRICT,
@ -434,6 +497,8 @@ gtk_multi_sorter_remove (GtkMultiSorter *self,
sorter = gtk_sorters_get (&self->sorters, position);
g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self);
gtk_sorters_splice (&self->sorters, position, 1, FALSE, NULL, 0);
g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
gtk_sorter_changed_with_keys (GTK_SORTER (self),
GTK_SORTER_CHANGE_LESS_STRICT,

View File

@ -48,7 +48,9 @@ struct _GtkNoSelectionClass
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
N_PROPS
};
@ -119,6 +121,18 @@ G_DEFINE_TYPE_EXTENDED (GtkNoSelection, gtk_no_selection, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL,
gtk_no_selection_selection_model_init))
static void
gtk_no_selection_items_changed_cb (GListModel *model,
guint position,
guint removed,
guint added,
GtkNoSelection *self)
{
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
gtk_no_selection_clear_model (GtkNoSelection *self)
{
@ -126,7 +140,7 @@ gtk_no_selection_clear_model (GtkNoSelection *self)
return;
g_signal_handlers_disconnect_by_func (self->model,
g_list_model_items_changed,
gtk_no_selection_items_changed_cb,
self);
g_clear_object (&self->model);
}
@ -162,10 +176,19 @@ gtk_no_selection_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_no_selection_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_no_selection_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -191,6 +214,18 @@ gtk_no_selection_class_init (GtkNoSelectionClass *klass)
gobject_class->set_property = gtk_no_selection_set_property;
gobject_class->dispose = gtk_no_selection_dispose;
/**
* GtkNoSelection:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkNoSelection:model: (attributes org.gtk.property.get=gtk_no_selection_get_model org.gtk.Property.set=gtk_no_selection_set_model)
*
@ -201,6 +236,18 @@ gtk_no_selection_class_init (GtkNoSelectionClass *klass)
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* GtkNoSelection:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -263,7 +310,7 @@ void
gtk_no_selection_set_model (GtkNoSelection *self,
GListModel *model)
{
guint n_items_before;
guint n_items_before, n_items_after;
g_return_if_fail (GTK_IS_NO_SELECTION (self));
g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model));
@ -277,14 +324,19 @@ gtk_no_selection_set_model (GtkNoSelection *self,
if (model)
{
self->model = g_object_ref (model);
g_signal_connect_swapped (self->model, "items-changed",
G_CALLBACK (g_list_model_items_changed), self);
g_signal_connect (self->model, "items-changed",
G_CALLBACK (gtk_no_selection_items_changed_cb), self);
n_items_after = g_list_model_get_n_items (self->model);
}
else
n_items_after = 0;
g_list_model_items_changed (G_LIST_MODEL (self),
0,
n_items_before,
model ? g_list_model_get_n_items (self->model) : 0);
n_items_after);
if (n_items_before != n_items_after)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -39,6 +39,7 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_N_ITEMS,
PROP_OBJECT,
PROP_PROPERTY,
NUM_PROPERTIES
@ -184,6 +185,8 @@ gtk_property_lookup_list_model_notify_cb (GObject *object,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static guint
@ -318,6 +321,10 @@ gtk_property_lookup_list_model_get_property (GObject *object,
g_value_set_gtype (value, self->item_type);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_property_lookup_list_model_get_n_items (G_LIST_MODEL (self)));
break;
case PROP_OBJECT:
g_value_set_object (value, gtk_property_lookup_list_model_get_object (self));
break;
@ -366,13 +373,25 @@ gtk_property_lookup_list_model_class_init (GtkPropertyLookupListModelClass *klas
/**
* GtkPropertyLookupListModel:item-type:
*
* The `GType` for elements of this object
* The `GType` for elements of this object. See [method@Gio.ListModel.get_item_type].
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkPropertyLookupListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkPropertyLookupListModel:property:
*
@ -456,6 +475,8 @@ gtk_property_lookup_list_model_set_object (GtkPropertyLookupListModel *self,
g_assert (removed != 0 || added != 0);
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
gpointer

View File

@ -34,7 +34,10 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
NUM_PROPERTIES
};
@ -127,6 +130,8 @@ selection_filter_model_items_changed (GtkSelectionFilterModel *self,
if (sel_removed > 0 || sel_added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), sel_position, sel_removed, sel_added);
if (sel_removed != sel_added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -178,10 +183,18 @@ gtk_selection_filter_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_selection_filter_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_selection_filter_model_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -220,6 +233,18 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
gobject_class->get_property = gtk_selection_filter_model_get_property;
gobject_class->dispose = gtk_selection_filter_model_dispose;
/**
* GtkSelectionFilterModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSelectionFilterModel:model: (attributes org.gtk.Property.get=gtk_selection_filter_model_get_model org.gtk.Property.set=gtk_selection_filter_model_set_model)
*
@ -230,6 +255,18 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
GTK_TYPE_SELECTION_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSelectionFilterModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@ -300,6 +337,8 @@ gtk_selection_filter_model_set_model (GtkSelectionFilterModel *self,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -103,8 +103,10 @@ struct _GtkShortcutControllerClass
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MNEMONICS_MODIFIERS,
PROP_MODEL,
PROP_N_ITEMS,
PROP_SCOPE,
N_PROPS
@ -186,6 +188,18 @@ gtk_shortcut_controller_is_rooted (GtkShortcutController *self)
return gtk_widget_get_root (widget) != NULL;
}
static void
gtk_shortcut_controller_items_changed_cb (GListModel *model,
guint position,
guint removed,
guint added,
GtkShortcutController *self)
{
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
gtk_shortcut_controller_set_property (GObject *object,
guint prop_id,
@ -214,10 +228,10 @@ gtk_shortcut_controller_set_property (GObject *object,
self->custom_shortcuts = FALSE;
}
self->shortcuts_changed_id = g_signal_connect_swapped (self->shortcuts,
"items-changed",
G_CALLBACK (g_list_model_items_changed),
self);
self->shortcuts_changed_id = g_signal_connect (self->shortcuts,
"items-changed",
G_CALLBACK (gtk_shortcut_controller_items_changed_cb),
self);
}
break;
@ -240,10 +254,18 @@ gtk_shortcut_controller_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, G_TYPE_OBJECT);
break;
case PROP_MNEMONICS_MODIFIERS:
g_value_set_flags (value, self->mnemonics_modifiers);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, g_list_model_get_n_items (self->shortcuts));
break;
case PROP_SCOPE:
g_value_set_enum (value, self->scope);
break;
@ -562,6 +584,18 @@ gtk_shortcut_controller_class_init (GtkShortcutControllerClass *klass)
controller_class->set_widget = gtk_shortcut_controller_set_widget;
controller_class->unset_widget = gtk_shortcut_controller_unset_widget;
/**
* GtkShortCutController:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcutController:mnemonic-modifiers: (attributes org.gtk.Property.get=gtk_shortcut_controller_get_mnemonics_modifiers org.gtk.Property.set=gtk_shortcut_controller_set_mnemonics_modifiers)
*
@ -583,6 +617,18 @@ gtk_shortcut_controller_class_init (GtkShortcutControllerClass *klass)
G_TYPE_LIST_MODEL,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcutController:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcutController:scope: (attributes org.gtk.Property.get=gtk_shortcut_controller_get_scope org.gtk.Property.set=gtk_shortcut_controller_set_scope)
*

View File

@ -57,9 +57,11 @@ enum {
PROP_0,
PROP_AUTOSELECT,
PROP_CAN_UNSELECT,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
PROP_SELECTED,
PROP_SELECTED_ITEM,
PROP_MODEL,
N_PROPS
};
@ -271,6 +273,8 @@ gtk_single_selection_items_changed_cb (GListModel *model,
}
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_thaw_notify (G_OBJECT (self));
}
@ -337,10 +341,19 @@ gtk_single_selection_get_property (GObject *object,
case PROP_CAN_UNSELECT:
g_value_set_boolean (value, self->can_unselect);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_single_selection_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_single_selection_get_n_items (G_LIST_MODEL (self)));
break;
case PROP_SELECTED:
g_value_set_uint (value, self->selected);
break;
@ -397,6 +410,40 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkSingleSelection:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSingleSelection:model: (attributes org.gtk.Property.get=gtk_single_selection_get_model org.gtk.Property.set=gtk_single_selection_set_model)
*
* The model being managed.
*/
properties[PROP_MODEL] =
g_param_spec_object ("model", NULL, NULL,
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* GtkSingleSelection:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSingleSelection:selected: (attributes org.gtk.Property.get=gtk_single_selection_get_selected org.gtk.Property.set=gtk_single_selection_set_selected)
*
@ -414,18 +461,8 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass)
*/
properties[PROP_SELECTED_ITEM] =
g_param_spec_object ("selected-item", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSingleSelection:model: (attributes org.gtk.Property.get=gtk_single_selection_get_model org.gtk.Property.set=gtk_single_selection_set_model)
*
* The model being managed.
*/
properties[PROP_MODEL] =
g_param_spec_object ("model", NULL, NULL,
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@ -528,6 +565,8 @@ gtk_single_selection_set_model (GtkSingleSelection *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
}
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
if (n_items_before)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);

View File

@ -38,7 +38,9 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
PROP_OFFSET,
PROP_SIZE,
NUM_PROPERTIES
@ -162,6 +164,8 @@ gtk_slice_list_model_items_changed_cb (GListModel *model,
n_before = CLAMP (n_before, self->offset, self->offset + self->size) - self->offset;
g_list_model_items_changed (G_LIST_MODEL (self), skip, n_before - skip, n_after - skip);
if (n_before != n_after)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
@ -203,10 +207,18 @@ gtk_slice_list_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_slice_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_slice_list_model_get_n_items (G_LIST_MODEL (self)));
break;
case PROP_OFFSET:
g_value_set_uint (value, self->offset);
break;
@ -250,6 +262,18 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
gobject_class->get_property = gtk_slice_list_model_get_property;
gobject_class->dispose = gtk_slice_list_model_dispose;
/**
* GtkSliceListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSliceListModel:model: (attributes org.gtk.Property.get=gtk_slice_list_model_get_model org.gtk.Property.set=gtk_slice_list_model_set_model)
*
@ -260,6 +284,18 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSliceListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSliceListModel:offset: (attributes org.gtk.Property.get=gtk_slice_list_model_get_offset org.gtk.Property.set=gtk_slice_list_model_set_offset)
*
@ -360,6 +396,8 @@ gtk_slice_list_model_set_model (GtkSliceListModel *self,
if (removed > 0 || added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}
@ -409,6 +447,8 @@ gtk_slice_list_model_set_offset (GtkSliceListModel *self,
if (before > 0 || after > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, before, after);
if (before != after)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_OFFSET]);
}
@ -458,9 +498,15 @@ gtk_slice_list_model_set_size (GtkSliceListModel *self,
after = g_list_model_get_n_items (G_LIST_MODEL (self));
if (before > after)
g_list_model_items_changed (G_LIST_MODEL (self), after, before - after, 0);
{
g_list_model_items_changed (G_LIST_MODEL (self), after, before - after, 0);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
else if (before < after)
g_list_model_items_changed (G_LIST_MODEL (self), before, 0, after - before);
{
g_list_model_items_changed (G_LIST_MODEL (self), before, 0, after - before);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
/* else nothing */
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SIZE]);

View File

@ -79,7 +79,9 @@
enum {
PROP_0,
PROP_INCREMENTAL,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
PROP_PENDING,
PROP_SORTER,
NUM_PROPERTIES
@ -580,6 +582,8 @@ gtk_sort_list_model_items_changed_cb (GListModel *model,
{
self->n_items = self->n_items - removed + added;
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
return;
}
@ -620,6 +624,8 @@ gtk_sort_list_model_items_changed_cb (GListModel *model,
n_items = self->n_items - start - end;
g_list_model_items_changed (G_LIST_MODEL (self), start, n_items - added + removed, n_items);
if (removed != added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@ -664,10 +670,18 @@ gtk_sort_list_model_get_property (GObject *object,
g_value_set_boolean (value, self->incremental);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_sort_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, gtk_sort_list_model_get_n_items (G_LIST_MODEL (self)));
break;
case PROP_PENDING:
g_value_set_uint (value, gtk_sort_list_model_get_pending (self));
break;
@ -788,6 +802,18 @@ gtk_sort_list_model_class_init (GtkSortListModelClass *class)
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSortListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSortListModel:model: (attributes org.gtk.Property.get=gtk_sort_list_model_get_model org.gtk.Property.set=gtk_sort_list_model_set_model)
*
@ -798,6 +824,18 @@ gtk_sort_list_model_class_init (GtkSortListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSortListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSortListModel:pending: (attributes org.gtk.Property.get=gtk_sort_list_model_get_pending)
*
@ -898,6 +936,8 @@ gtk_sort_list_model_set_model (GtkSortListModel *self,
if (removed > 0 || self->n_items > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, self->n_items);
if (removed != self->n_items)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}

View File

@ -498,6 +498,16 @@ struct _GtkStackPagesClass
GObjectClass parent_class;
};
enum {
PAGES_PROP_0,
PAGES_PROP_ITEM_TYPE,
PAGES_PROP_N_ITEMS,
PAGES_N_PROPS
};
static GParamSpec *pages_properties[PAGES_N_PROPS] = { NULL, };
static GType
gtk_stack_pages_get_item_type (GListModel *model)
{
@ -582,14 +592,53 @@ G_DEFINE_TYPE_WITH_CODE (GtkStackPages, gtk_stack_pages, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_stack_pages_list_model_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SELECTION_MODEL, gtk_stack_pages_selection_model_init))
static void
gtk_stack_pages_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkStackPages *self = GTK_STACK_PAGES (object);
switch (prop_id)
{
case PAGES_PROP_ITEM_TYPE:
g_value_set_gtype (value, GTK_TYPE_STACK_PAGE);
break;
case PAGES_PROP_N_ITEMS:
g_value_set_uint (value, gtk_stack_pages_get_n_items (G_LIST_MODEL (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_stack_pages_init (GtkStackPages *pages)
{
}
static void
gtk_stack_pages_class_init (GtkStackPagesClass *class)
gtk_stack_pages_class_init (GtkStackPagesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gtk_stack_pages_get_property;
pages_properties[PAGES_PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
GTK_TYPE_STACK_PAGE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
pages_properties[PAGES_PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PAGES_N_PROPS, pages_properties);
}
static GtkStackPages *
@ -680,8 +729,11 @@ gtk_stack_dispose (GObject *obj)
while ((child = gtk_widget_get_first_child (GTK_WIDGET (stack))))
stack_remove (stack, child, TRUE);
if (priv->pages)
g_list_model_items_changed (G_LIST_MODEL (priv->pages), 0, n_pages, 0);
if (priv->pages && n_pages > 0)
{
g_list_model_items_changed (G_LIST_MODEL (priv->pages), 0, n_pages, 0);
g_object_notify_by_pspec (G_OBJECT (priv->pages), pages_properties[PAGES_PROP_N_ITEMS]);
}
G_OBJECT_CLASS (gtk_stack_parent_class)->dispose (obj);
}
@ -1535,7 +1587,10 @@ gtk_stack_add_page (GtkStack *stack,
gtk_widget_set_parent (child_info->widget, GTK_WIDGET (stack));
if (priv->pages)
g_list_model_items_changed (G_LIST_MODEL (priv->pages), g_list_length (priv->children) - 1, 0, 1);
{
g_list_model_items_changed (G_LIST_MODEL (priv->pages), g_list_length (priv->children) - 1, 0, 1);
g_object_notify_by_pspec (G_OBJECT (priv->pages), pages_properties[PAGES_PROP_N_ITEMS]);
}
g_signal_connect (child_info->widget, "notify::visible",
G_CALLBACK (stack_child_visibility_notify_cb), stack);
@ -1616,7 +1671,10 @@ gtk_stack_remove (GtkStack *stack,
stack_remove (stack, child, FALSE);
if (priv->pages)
g_list_model_items_changed (G_LIST_MODEL (priv->pages), position, 1, 0);
{
g_list_model_items_changed (G_LIST_MODEL (priv->pages), position, 1, 0);
g_object_notify_by_pspec (G_OBJECT (priv->pages), pages_properties[PAGES_PROP_N_ITEMS]);
}
}
/**

View File

@ -34,7 +34,9 @@
enum {
PROP_0,
PROP_AUTOEXPAND,
PROP_ITEM_TYPE,
PROP_MODEL,
PROP_N_ITEMS,
PROP_PASSTHROUGH,
NUM_PROPERTIES
};
@ -432,6 +434,8 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
tree_position,
tree_removed,
tree_added);
if (tree_removed != tree_added)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void gtk_tree_list_row_destroy (GtkTreeListRow *row);
@ -645,10 +649,18 @@ gtk_tree_list_model_get_property (GObject *object,
g_value_set_boolean (value, self->autoexpand);
break;
case PROP_ITEM_TYPE:
g_value_set_gtype (value, gtk_tree_list_model_get_item_type (G_LIST_MODEL (self)));
break;
case PROP_MODEL:
g_value_set_object (value, self->root_node.model);
break;
case PROP_N_ITEMS:
g_value_set_uint (value, tree_node_get_n_children (&self->root_node));
break;
case PROP_PASSTHROUGH:
g_value_set_boolean (value, self->passthrough);
break;
@ -690,6 +702,18 @@ gtk_tree_list_model_class_init (GtkTreeListModelClass *class)
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkTreeListModel:item-type:
*
* The type of items. See [method@Gio.ListModel.get_item_type].
*
* Since: 4.8
**/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", NULL, NULL,
G_TYPE_OBJECT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkTreeListModel:model: (attributes org.gtk.Property.get=gtk_tree_list_model_get_model)
*
@ -700,6 +724,18 @@ gtk_tree_list_model_class_init (GtkTreeListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkTreeListModel:n-items:
*
* The number of items. See [method@Gio.ListModel.get_n_items].
*
* Since: 4.8
**/
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkTreeListModel:passthrough: (attributes org.gtk.Property.get=gtk_tree_list_model_get_passthrough)
*
@ -1192,13 +1228,19 @@ gtk_tree_list_row_set_expanded (GtkTreeListRow *self,
{
n_items = gtk_tree_list_model_expand_node (list, self->node);
if (n_items > 0)
g_list_model_items_changed (G_LIST_MODEL (list), tree_node_get_position (self->node) + 1, 0, n_items);
{
g_list_model_items_changed (G_LIST_MODEL (list), tree_node_get_position (self->node) + 1, 0, n_items);
g_object_notify_by_pspec (G_OBJECT (list), properties[PROP_N_ITEMS]);
}
}
else
{
n_items = gtk_tree_list_model_collapse_node (list, self->node);
if (n_items > 0)
g_list_model_items_changed (G_LIST_MODEL (list), tree_node_get_position (self->node) + 1, n_items, 0);
{
g_list_model_items_changed (G_LIST_MODEL (list), tree_node_get_position (self->node) + 1, n_items, 0);
g_object_notify_by_pspec (G_OBJECT (list), properties[PROP_N_ITEMS]);
}
}
g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDED]);

View File

@ -298,6 +298,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
strcmp (pspec->name, "model") == 0)
check = FALSE;
if (g_type_is_a (type, GTK_TYPE_TREE_LIST_MODEL) &&
(strcmp (pspec->name, "item-type") == 0)) /* might be a treelistrow */
check = FALSE;
/* This is set in init() */
if (g_type_is_a (type, GTK_TYPE_FONT_CHOOSER_WIDGET) &&
strcmp (pspec->name, "tweak-action") == 0)

View File

@ -75,6 +75,9 @@ assert_items_changed_correctly (GListModel *model,
{
guint i, n_items;
//sanity check that we got all notifies
g_assert_cmpuint (g_list_model_get_n_items (compare), ==, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items")));
//g_print ("%s => %u -%u +%u => %s\n", model_to_string (compare), position, removed, added, model_to_string (model));
g_assert_cmpint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added);
@ -127,6 +130,21 @@ assert_items_changed_correctly (GListModel *model,
}
}
static void
assert_n_items_notified_properly (GListModel *model,
GParamSpec *pspec,
GListModel *compare)
{
g_assert_cmpuint (g_list_model_get_n_items (model), !=, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items")));
/* These should hve been updated in items-changed, which should have been emitted first */
g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare));
g_object_set_data (G_OBJECT (compare),
"last-notified-n-items",
GUINT_TO_POINTER (g_list_model_get_n_items (model)));
}
static GtkFilterListModel *
filter_list_model_new (GListModel *source,
GtkFilter *filter)
@ -154,6 +172,16 @@ filter_list_model_new (GListModel *source,
(GClosureNotify) g_object_unref,
0);
g_object_set_data (G_OBJECT (check),
"last-notified-n-items",
GUINT_TO_POINTER (g_list_model_get_n_items (G_LIST_MODEL (check))));
g_signal_connect_data (model,
"notify::n-items",
G_CALLBACK (assert_n_items_notified_properly),
g_object_ref (check),
(GClosureNotify) g_object_unref,
0);
return model;
}

View File

@ -143,6 +143,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -171,6 +179,7 @@ new_model (guint size,
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -248,7 +257,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "1 2 3 4 5 6");
assert_changes (filter, "6-4");
assert_changes (filter, "6-4*");
g_object_unref (filter);
filter = new_model (10, NULL, NULL);
@ -256,7 +265,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "");
assert_changes (filter, "0-10");
assert_changes (filter, "0-10*");
g_object_unref (filter);
filter = new_model (10, NULL, NULL);
@ -272,7 +281,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "4 5 6 7 8 9 10");
assert_changes (filter, "0-3");
assert_changes (filter, "0-3*");
g_object_unref (filter);
filter = new_model (10, NULL, NULL);
@ -280,7 +289,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "");
assert_changes (filter, "0-10");
assert_changes (filter, "0-10*");
g_object_unref (filter);
filter = new_model (10, NULL, NULL);
@ -288,7 +297,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "3 4 5 6 7");
assert_changes (filter, "0-10+5");
assert_changes (filter, "0-10+5*");
g_object_unref (filter);
filter = new_model (10, NULL, NULL);
@ -296,7 +305,7 @@ test_empty_set_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "1 2 8 9 10");
assert_changes (filter, "2-5");
assert_changes (filter, "2-5*");
g_object_unref (filter);
}
@ -320,19 +329,19 @@ test_change_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "1 2 3 4 5 6");
assert_changes (filter, "3-2+3");
assert_changes (filter, "3-2+3*");
custom = GTK_FILTER (gtk_custom_filter_new (is_smaller_than, GUINT_TO_POINTER (6), NULL));
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "1 2 3 4 5");
assert_changes (filter, "-5");
assert_changes (filter, "-5*");
custom = GTK_FILTER (gtk_custom_filter_new (is_larger_than, GUINT_TO_POINTER (4), NULL));
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "5 6 7 8 9 10");
assert_changes (filter, "0-5+6");
assert_changes (filter, "0-5+6*");
custom = GTK_FILTER (gtk_custom_filter_new (is_not_near, GUINT_TO_POINTER (2), NULL));
gtk_filter_list_model_set_filter (filter, custom);
@ -344,7 +353,7 @@ test_change_filter (void)
gtk_filter_list_model_set_filter (filter, custom);
g_object_unref (custom);
assert_model (filter, "1 7 8 9 10");
assert_changes (filter, "0-2+1");
assert_changes (filter, "0-2+1*");
g_object_unref (filter);
}

View File

@ -193,6 +193,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -216,6 +224,7 @@ new_model (GListStore *store)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -271,7 +280,7 @@ test_model_add (void)
add_store (model, 8, 10, 1);
assert_model (flat, "1 2 3 4 5 6 7 8 9 10");
assert_changes (flat, "0+3, +3, 4+3, 7+3");
assert_changes (flat, "0+3*, +3*, 4+3*, 7+3*");
g_object_unref (model);
g_object_unref (flat);
@ -293,13 +302,13 @@ test_submodel_add (void)
store[2] = add_store (model, 5, 4, 1);
store[3] = add_store (model, 8, 8, 1);
assert_model (flat, "2 3 4 8");
assert_changes (flat, "0+2, +2, +3");
assert_changes (flat, "0+2*, +2*, +3*");
insert (store[0], 0, 1);
splice (store[2], 0, 0, (guint[3]) { 5, 6, 7 }, 3);
splice (store[3], 1, 0, (guint[2]) { 9, 10 }, 2);
assert_model (flat, "1 2 3 4 5 6 7 8 9 10");
assert_changes (flat, "+0, 4+3, 8+2");
assert_changes (flat, "+0*, 4+3*, 8+2*");
g_object_unref (model);
g_object_unref (flat);
@ -325,19 +334,19 @@ test_submodel_add2 (void)
add (store[0], 1);
assert_model (flat, "1");
assert_changes (flat, "+0");
assert_changes (flat, "+0*");
add (store[1], 3);
assert_model (flat, "1 3");
assert_changes (flat, "+1");
assert_changes (flat, "+1*");
add (store[0], 2);
assert_model (flat, "1 2 3");
assert_changes (flat, "+1");
assert_changes (flat, "+1*");
add (store[1], 4);
assert_model (flat, "1 2 3 4");
assert_changes (flat, "+3");
assert_changes (flat, "+3*");
g_object_unref (model);
g_object_unref (flat);
@ -363,7 +372,7 @@ test_model_remove (void)
g_list_store_remove (model, 0);
g_object_unref (model);
assert_model (flat, "");
assert_changes (flat, "3-4, 3-3, 0-3");
assert_changes (flat, "3-4*, 3-3*, 0-3*");
g_object_unref (flat);
}
@ -389,7 +398,7 @@ test_submodel_remove (void)
g_object_unref (model);
assert_model (flat, "2 3 4 8");
assert_changes (flat, "-0, 3-3, 4-2");
assert_changes (flat, "-0*, 3-3*, 4-2*");
g_object_unref (flat);
}

View File

@ -164,6 +164,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -202,6 +210,7 @@ new_model (GListStore *store)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -249,11 +258,11 @@ test_set_model (void)
store = new_store (1, 5, 1);
gtk_map_list_model_set_model (map, G_LIST_MODEL (store));
assert_model (map, "2 4 6 8 10");
assert_changes (map, "0+5");
assert_changes (map, "0+5*");
gtk_map_list_model_set_model (map, NULL);
assert_model (map, "");
assert_changes (map, "0-5");
assert_changes (map, "0-5*");
g_object_unref (store);
g_object_unref (map);

View File

@ -224,6 +224,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
selection_changed (GListModel *model,
guint position,
@ -258,6 +266,7 @@ new_model (GListStore *store)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes);
@ -277,6 +286,7 @@ new_filter_model (GtkSelectionModel *model)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -331,19 +341,19 @@ test_changes (void)
g_list_store_remove (store, 3);
assert_model (selection, "1 2 3 5");
assert_changes (selection, "-3");
assert_changes (selection, "-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
insert (store, 3, 99);
assert_model (selection, "1 2 3 99 5");
assert_changes (selection, "+3");
assert_changes (selection, "+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
splice (store, 3, 2, (guint[]) { 97 }, 1);
assert_model (selection, "1 2 3 97");
assert_changes (selection, "3-2+1");
assert_changes (selection, "3-2+1*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
@ -354,7 +364,7 @@ test_changes (void)
insert (store, 2, 22);
assert_model (selection, "1 2 22 3 97");
assert_changes (selection, "+2");
assert_changes (selection, "+2*");
assert_selection (selection, "2 3");
assert_selection_changes (selection, "");
@ -543,74 +553,74 @@ test_selection_filter (void)
assert_selection (selection, "4");
assert_selection_changes (selection, "3:1");
assert_model (filter, "4");
assert_changes (filter, "+0");
assert_changes (filter, "+0*");
ret = gtk_selection_model_unselect_item (selection, 3);
g_assert_true (ret);
assert_selection (selection, "");
assert_selection_changes (selection, "3:1");
assert_model (filter, "");
assert_changes (filter, "-0");
assert_changes (filter, "-0*");
ret = gtk_selection_model_select_item (selection, 1, FALSE);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "1:1");
assert_model (filter, "2");
assert_changes (filter, "+0");
assert_changes (filter, "+0*");
ret = gtk_selection_model_select_item (selection, 0, FALSE);
g_assert_true (ret);
assert_selection (selection, "1 2");
assert_selection_changes (selection, "0:1");
assert_model (filter, "1 2");
assert_changes (filter, "+0");
assert_changes (filter, "+0*");
ret = gtk_selection_model_unselect_item (selection, 0);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "0:1");
assert_model (filter, "2");
assert_changes (filter, "-0");
assert_changes (filter, "-0*");
ret = gtk_selection_model_select_range (selection, 3, 2, FALSE);
g_assert_true (ret);
assert_selection (selection, "2 4 5");
assert_selection_changes (selection, "3:2");
assert_model (filter, "2 4 5");
assert_changes (filter, "1+2");
assert_changes (filter, "1+2*");
ret = gtk_selection_model_unselect_range (selection, 3, 2);
g_assert_true (ret);
assert_selection (selection, "2");
assert_selection_changes (selection, "3:2");
assert_model (filter, "2");
assert_changes (filter, "1-2");
assert_changes (filter, "1-2*");
ret = gtk_selection_model_select_all (selection);
g_assert_true (ret);
assert_selection (selection, "1 2 3 4 5");
assert_selection_changes (selection, "0:5");
assert_model (filter, "1 2 3 4 5");
assert_changes (filter, "0-1+5");
assert_changes (filter, "0-1+5*");
ret = gtk_selection_model_unselect_all (selection);
g_assert_true (ret);
assert_selection (selection, "");
assert_selection_changes (selection, "0:5");
assert_model (filter, "");
assert_changes (filter, "0-5");
assert_changes (filter, "0-5*");
ret = gtk_selection_model_select_range (selection, 1, 3, FALSE);
g_assert_true (ret);
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "1:3");
assert_model (filter, "2 3 4");
assert_changes (filter, "0+3");
assert_changes (filter, "0+3*");
insert (store, 2, 22);
assert_model (selection, "1 2 22 3 4 5");
assert_changes (selection, "+2");
assert_changes (selection, "+2*");
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "");
assert_model (filter, "2 3 4");
@ -618,7 +628,7 @@ test_selection_filter (void)
g_list_store_remove (store, 2);
assert_model (selection, "1 2 3 4 5");
assert_changes (selection, "-2");
assert_changes (selection, "-2*");
assert_selection (selection, "2 3 4");
assert_selection_changes (selection, "");
assert_model (filter, "2 3 4");
@ -651,17 +661,17 @@ test_set_model (void)
/* we retain the selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_changes (selection, "0-5+3*");
assert_selection (selection, "2 3");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), NULL);
assert_changes (selection, "0-3");
assert_changes (selection, "0-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m2);
assert_changes (selection, "0+3");
assert_changes (selection, "0+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
@ -672,7 +682,7 @@ test_set_model (void)
/* we retain no selected item across model changes */
gtk_multi_selection_set_model (GTK_MULTI_SELECTION (selection), m1);
assert_changes (selection, "0-3+5");
assert_changes (selection, "0-3+5*");
assert_selection (selection, "1 2 3");
assert_selection_changes (selection, "");

View File

@ -90,6 +90,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -145,6 +153,7 @@ new_model (gboolean fill)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -185,14 +194,14 @@ test_set_object (void)
model = new_model (FALSE);
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
assert_changes (model, "+0");
assert_changes (model, "+0*");
g_object_unref (model);
model = new_model (FALSE);
assert_model (model, "");
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
assert_changes (model, "0+4");
assert_changes (model, "0+4*");
g_object_unref (model);
destroy_widgets ();
@ -212,15 +221,15 @@ test_change_property (void)
assert_model (model, ""); /* make sure the model has a definite size */
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
assert_changes (model, "0+4");
assert_changes (model, "0+4*");
gtk_grid_remove (GTK_GRID (parent), widget);
assert_model (model, "GtkLabel");
assert_changes (model, "1-3");
assert_changes (model, "1-3*");
gtk_box_append (GTK_BOX (grandparent), widget);
assert_model (model, "GtkLabel GtkBox GtkWindow");
assert_changes (model, "1+2");
assert_changes (model, "1+2*");
g_object_unref (model);
destroy_widgets ();

View File

@ -220,6 +220,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
selection_changed (GListModel *model,
guint position,
@ -265,6 +273,7 @@ new_model (GListStore *store, gboolean autoselect, gboolean can_unselect)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes);
@ -336,19 +345,19 @@ test_changes (void)
g_list_store_remove (store, 3);
assert_model (selection, "1 2 3 5");
assert_changes (selection, "-3");
assert_changes (selection, "-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
insert (store, 3, 99);
assert_model (selection, "1 2 3 99 5");
assert_changes (selection, "+3");
assert_changes (selection, "+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
splice (store, 3, 2, (guint[]) { 97 }, 1);
assert_model (selection, "1 2 3 97");
assert_changes (selection, "3-2+1");
assert_changes (selection, "3-2+1*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
@ -434,31 +443,31 @@ test_autoselect (void)
add (store, 1);
assert_model (selection, "1");
assert_changes (selection, "+0");
assert_changes (selection, "+0*");
assert_selection (selection, "1");
assert_selection_changes (selection, "");
splice (store, 0, 1, (guint[]) { 7, 8, 9 }, 3);
assert_model (selection, "7 8 9");
assert_changes (selection, "0-1+3");
assert_changes (selection, "0-1+3*");
assert_selection (selection, "7");
assert_selection_changes (selection, "");
splice (store, 0, 0, (guint[]) { 5, 6 }, 2);
assert_model (selection, "5 6 7 8 9");
assert_changes (selection, "0+2");
assert_changes (selection, "0+2*");
assert_selection (selection, "7");
assert_selection_changes (selection, "");
g_list_store_remove (store, 2);
assert_model (selection, "5 6 8 9");
assert_changes (selection, "2-2+1");
assert_changes (selection, "2-2+1*");
assert_selection (selection, "8");
assert_selection_changes (selection, "");
splice (store, 2, 2, NULL, 0);
assert_model (selection, "5 6");
assert_changes (selection, "1-3+1");
assert_changes (selection, "1-3+1*");
assert_selection (selection, "6");
assert_selection_changes (selection, "");
@ -470,13 +479,13 @@ test_autoselect (void)
g_list_store_remove (store, 0);
assert_model (selection, "2");
assert_changes (selection, "-0");
assert_changes (selection, "-0*");
assert_selection (selection, "2");
assert_selection_changes (selection, "");
g_list_store_remove (store, 0);
assert_model (selection, "");
assert_changes (selection, "-0");
assert_changes (selection, "-0*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
@ -671,24 +680,24 @@ test_set_model (void)
/* we retain the selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_changes (selection, "0-5+3*");
assert_selection (selection, "1");
assert_selection_changes (selection, "");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), NULL);
assert_changes (selection, "0-3");
assert_changes (selection, "0-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0+3");
assert_changes (selection, "0+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
/* we retain no selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m1);
assert_changes (selection, "0-3+5");
assert_changes (selection, "0-3+5*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
@ -697,7 +706,7 @@ test_set_model (void)
assert_selection_changes (selection, "4:1");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
assert_changes (selection, "0-5+3");
assert_changes (selection, "0-5+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");

View File

@ -174,6 +174,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -198,6 +206,7 @@ new_model (GListStore *store, guint offset, guint size)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -245,11 +254,11 @@ test_set_model (void)
store = new_store (1, 7, 2);
gtk_slice_list_model_set_model (slice, G_LIST_MODEL (store));
assert_model (slice, "1 3");
assert_changes (slice, "0+2");
assert_changes (slice, "0+2*");
gtk_slice_list_model_set_model (slice, NULL);
assert_model (slice, "");
assert_changes (slice, "0-2");
assert_changes (slice, "0-2*");
g_object_unref (store);
g_object_unref (slice);
@ -272,11 +281,11 @@ test_set_slice (void)
gtk_slice_list_model_set_size (slice, 2);
assert_model (slice, "3 5");
assert_changes (slice, "-2");
assert_changes (slice, "-2*");
gtk_slice_list_model_set_size (slice, 10);
assert_model (slice, "3 5 7");
assert_changes (slice, "+2");
assert_changes (slice, "+2*");
g_object_unref (store);
g_object_unref (slice);
@ -306,15 +315,15 @@ test_changes (void)
splice (store, 13, 6, (guint[]) { 97 }, 1);
assert_model (slice, "12 13 99 97");
assert_changes (slice, "3-2+1");
assert_changes (slice, "3-2+1*");
splice (store, 13, 1, (guint[]) { 36, 37, 38 }, 3);
assert_model (slice, "12 13 99 36 37");
assert_changes (slice, "3-1+2");
assert_changes (slice, "3-1+2*");
g_list_store_remove_all (store);
assert_model (slice, "");
assert_changes (slice, "0-5");
assert_changes (slice, "0-5*");
g_object_unref (store);
g_object_unref (slice);

View File

@ -84,9 +84,12 @@ assert_items_changed_correctly (GListModel *model,
{
guint i, n_items;
//sanity check that we got all notifies
g_assert_cmpuint (g_list_model_get_n_items (compare), ==, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items")));
//g_print ("%s => %u -%u +%u => %s\n", model_to_string (compare), position, removed, added, model_to_string (model));
g_assert_cmpint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added);
g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare) - removed + added);
n_items = g_list_model_get_n_items (model);
if (position != 0 || removed != n_items)
@ -139,6 +142,21 @@ assert_items_changed_correctly (GListModel *model,
}
}
static void
assert_n_items_notified_properly (GListModel *model,
GParamSpec *pspec,
GListModel *compare)
{
g_assert_cmpuint (g_list_model_get_n_items (model), !=, GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (compare), "last-notified-n-items")));
/* These should hve been updated in items-changed, which should have been emitted first */
g_assert_cmpuint (g_list_model_get_n_items (model), ==, g_list_model_get_n_items (compare));
g_object_set_data (G_OBJECT (compare),
"last-notified-n-items",
GUINT_TO_POINTER (g_list_model_get_n_items (model)));
}
static GtkSortListModel *
sort_list_model_new (GListModel *source,
GtkSorter *sorter)
@ -162,6 +180,16 @@ sort_list_model_new (GListModel *source,
(GClosureNotify) g_object_unref,
0);
g_object_set_data (G_OBJECT (check),
"last-notified-n-items",
GUINT_TO_POINTER (g_list_model_get_n_items (G_LIST_MODEL (check))));
g_signal_connect_data (model,
"notify::n-items",
G_CALLBACK (assert_n_items_notified_properly),
g_object_ref (check),
(GClosureNotify) g_object_unref,
0);
return model;
}

View File

@ -176,6 +176,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -228,6 +236,7 @@ new_model (gpointer model)
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
@ -275,11 +284,11 @@ test_set_model (void)
store = new_store ((guint[]) { 4, 8, 2, 6, 10, 0 });
gtk_sort_list_model_set_model (sort, G_LIST_MODEL (store));
assert_model (sort, "4 8 2 6 10");
assert_changes (sort, "0+5");
assert_changes (sort, "0+5*");
gtk_sort_list_model_set_model (sort, NULL);
assert_model (sort, "");
assert_changes (sort, "0-5");
assert_changes (sort, "0-5*");
g_object_unref (sort);
@ -290,11 +299,11 @@ test_set_model (void)
gtk_sort_list_model_set_model (sort, NULL);
assert_model (sort, "");
assert_changes (sort, "0-5");
assert_changes (sort, "0-5*");
gtk_sort_list_model_set_model (sort, G_LIST_MODEL (store));
assert_model (sort, "2 4 6 8 10");
assert_changes (sort, "0+5");
assert_changes (sort, "0+5*");
g_object_unref (store);
g_object_unref (sort);
@ -345,7 +354,7 @@ test_add_items (void)
assert_changes (sort, "");
splice (store, 4, 0, (guint[]) { 1, 2 }, 2);
assert_model (sort, "1 2 49 50 51 99 100");
assert_changes (sort, "0+2");
assert_changes (sort, "0+2*");
g_object_unref (store);
g_object_unref (sort);
@ -356,7 +365,7 @@ test_add_items (void)
assert_changes (sort, "");
splice (store, 2, 0, (guint[]) { 49, 50, 51 }, 3);
assert_model (sort, "1 2 49 50 51 99 100");
assert_changes (sort, "2+3");
assert_changes (sort, "2+3*");
g_object_unref (store);
g_object_unref (sort);
@ -367,7 +376,7 @@ test_add_items (void)
assert_changes (sort, "");
splice (store, 1, 0, (guint[]) { 99, 100 }, 2);
assert_model (sort, "1 2 49 50 51 99 100");
assert_changes (sort, "5+2");
assert_changes (sort, "5+2*");
g_object_unref (store);
g_object_unref (sort);
}
@ -385,7 +394,7 @@ test_remove_items (void)
assert_changes (sort, "");
splice (store, 4, 2, NULL, 0);
assert_model (sort, "49 50 51 99 100");
assert_changes (sort, "0-2");
assert_changes (sort, "0-2*");
g_object_unref (store);
g_object_unref (sort);
@ -396,7 +405,7 @@ test_remove_items (void)
assert_changes (sort, "");
splice (store, 2, 3, NULL, 0);
assert_model (sort, "1 2 99 100");
assert_changes (sort, "2-3");
assert_changes (sort, "2-3*");
g_object_unref (store);
g_object_unref (sort);
@ -407,7 +416,7 @@ test_remove_items (void)
assert_changes (sort, "");
splice (store, 1, 2, NULL, 0);
assert_model (sort, "1 2 49 50 51");
assert_changes (sort, "5-2");
assert_changes (sort, "5-2*");
g_object_unref (store);
g_object_unref (sort);
}

View File

@ -142,6 +142,14 @@ items_changed (GListModel *model,
}
}
static void
notify_n_items (GObject *object,
GParamSpec *pspec,
GString *changes)
{
g_string_append_c (changes, '*');
}
static void
free_changes (gpointer data)
{
@ -174,6 +182,7 @@ new_model (guint size,
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes);
g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes);
g_signal_connect (tree, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return tree;
}
@ -193,7 +202,7 @@ test_expand (void)
g_object_unref (row);
}
assert_model (tree, "100 100 90 80 70 60 50 40 30 20 10");
assert_changes (tree, "1+10");
assert_changes (tree, "1+10*");
for (i = g_list_model_get_n_items (G_LIST_MODEL (tree)); i > 0; i--)
{
@ -202,7 +211,7 @@ test_expand (void)
g_object_unref (row);
}
assert_model (tree, "100 100 100 99 98 97 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
assert_changes (tree, "11+10, 10+10, 9+10, 8+10, 7+10, 6+10, 5+10, 4+10, 3+10, 2+10");
assert_changes (tree, "11+10*, 10+10*, 9+10*, 8+10*, 7+10*, 6+10*, 5+10*, 4+10*, 3+10*, 2+10*");
for (i = g_list_model_get_n_items (G_LIST_MODEL (tree)); i > 0; i--)
{
@ -229,25 +238,25 @@ test_remove_some (void)
g_assert_true (G_IS_LIST_MODEL (item));
g_list_store_remove (item, 3);
assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
assert_changes (tree, "-5");
assert_changes (tree, "-5*");
item = g_list_model_get_item (G_LIST_MODEL (tree), 0);
g_assert_true (G_IS_LIST_MODEL (item));
g_list_store_remove (item, 3);
assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
assert_changes (tree, "33-11");
assert_changes (tree, "33-11*");
item = g_list_model_get_item (G_LIST_MODEL (tree), 88);
g_assert_true (G_IS_LIST_MODEL (item));
g_list_store_remove (item, 9);
assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2");
assert_changes (tree, "-98");
assert_changes (tree, "-98*");
item = g_list_model_get_item (G_LIST_MODEL (tree), 0);
g_assert_true (G_IS_LIST_MODEL (item));
g_list_store_remove (item, 8);
assert_model (tree, "100 100 100 99 98 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11");
assert_changes (tree, "88-10");
assert_changes (tree, "88-10*");
g_object_unref (tree);
}