[gtk/wip/otte/listview: 1/46] singleselection: Fix model property
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 1/46] singleselection: Fix model property
- Date: Mon, 7 Oct 2019 05:20:27 +0000 (UTC)
commit 8eeaa2bf4edd723473e99a43d1b552c5c43697c5
Author: Benjamin Otte <otte redhat com>
Date: Mon Oct 7 06:36:25 2019 +0200
singleselection: Fix model property
1. Make the model property construct-only. Allowing to change the
model has invalid side effects.
2. Add a getter for the model property.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtksingleselection.c | 23 +++++++++++++++++++----
gtk/gtksingleselection.h | 4 +++-
testsuite/gtk/defaultvalue.c | 3 ++-
testsuite/gtk/notify.c | 3 ++-
testsuite/gtk/objects-finalize.c | 3 ++-
6 files changed, 29 insertions(+), 8 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 71bb48caf5..65693b1587 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -471,6 +471,7 @@ gtk_selection_model_get_type
GtkSingleSelection
GTK_INVALID_LIST_POSITION
gtk_single_selection_new
+gtk_single_selection_get_model
gtk_single_selection_get_selected
gtk_single_selection_set_selected
gtk_single_selection_get_selected_item
diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c
index 5f9517fbed..f2d0d47f1c 100644
--- a/gtk/gtksingleselection.c
+++ b/gtk/gtksingleselection.c
@@ -329,9 +329,8 @@ gtk_single_selection_set_property (GObject *object,
case PROP_MODEL:
gtk_single_selection_clear_model (self);
self->model = g_value_dup_object (value);
- if (self->model)
- g_signal_connect (self->model, "items-changed",
- G_CALLBACK (gtk_single_selection_items_changed_cb), self);
+ g_signal_connect (self->model, "items-changed",
+ G_CALLBACK (gtk_single_selection_items_changed_cb), self);
if (self->autoselect)
gtk_single_selection_set_selected (self, 0);
break;
@@ -461,7 +460,7 @@ gtk_single_selection_class_init (GtkSingleSelectionClass *klass)
P_("The model"),
P_("The model being managed"),
G_TYPE_LIST_MODEL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@@ -491,6 +490,22 @@ gtk_single_selection_new (GListModel *model)
NULL);
}
+/**
+ * gtk_single_selection_get_model:
+ * @self: a #GtkSingleSelection
+ *
+ * Gets the model that @self is wrapping.
+ *
+ * Returns: (transfer none): The model being wrapped
+ **/
+GListModel *
+gtk_single_selection_get_model (GtkSingleSelection *self)
+{
+ g_return_val_if_fail (GTK_IS_SINGLE_SELECTION (self), NULL);
+
+ return self->model;
+}
+
/**
* gtk_single_selection_get_selected:
* @self: a #GtkSingleSelection
diff --git a/gtk/gtksingleselection.h b/gtk/gtksingleselection.h
index ca96a4e052..74107fcc06 100644
--- a/gtk/gtksingleselection.h
+++ b/gtk/gtksingleselection.h
@@ -42,8 +42,10 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkSingleSelection, gtk_single_selection, GTK, SINGLE_SELECTION, GObject)
GDK_AVAILABLE_IN_ALL
-GtkSingleSelection * gtk_single_selection_new (GListModel *model);
+GtkSingleSelection * gtk_single_selection_new (GListModel *model);
+GDK_AVAILABLE_IN_ALL
+GListModel * gtk_single_selection_get_model (GtkSingleSelection *self);
GDK_AVAILABLE_IN_ALL
guint gtk_single_selection_get_selected (GtkSingleSelection *self);
GDK_AVAILABLE_IN_ALL
diff --git a/testsuite/gtk/defaultvalue.c b/testsuite/gtk/defaultvalue.c
index 1ac3bdfe97..0f86e903b3 100644
--- a/testsuite/gtk/defaultvalue.c
+++ b/testsuite/gtk/defaultvalue.c
@@ -109,7 +109,8 @@ test_type (gconstpointer data)
instance = G_OBJECT (g_object_ref (gdk_surface_new_temp (display,
&(GdkRectangle) { 0, 0, 100, 100 })));
}
- else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL))
+ else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
+ g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION))
{
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
instance = g_object_new (type,
diff --git a/testsuite/gtk/notify.c b/testsuite/gtk/notify.c
index 99b8f82ae8..83a04b0776 100644
--- a/testsuite/gtk/notify.c
+++ b/testsuite/gtk/notify.c
@@ -431,7 +431,8 @@ test_type (gconstpointer data)
NULL);
gdk_content_formats_unref (formats);
}
- else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL))
+ else if (g_type_is_a (type, GTK_TYPE_FILTER_LIST_MODEL) ||
+ g_type_is_a (type, GTK_TYPE_SINGLE_SELECTION))
{
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
instance = g_object_new (type,
diff --git a/testsuite/gtk/objects-finalize.c b/testsuite/gtk/objects-finalize.c
index bb7e51371d..722067c118 100644
--- a/testsuite/gtk/objects-finalize.c
+++ b/testsuite/gtk/objects-finalize.c
@@ -64,7 +64,8 @@ test_finalize_object (gconstpointer data)
NULL);
gdk_content_formats_unref (formats);
}
- else if (g_type_is_a (test_type, GTK_TYPE_FILTER_LIST_MODEL))
+ else if (g_type_is_a (test_type, GTK_TYPE_FILTER_LIST_MODEL) ||
+ g_type_is_a (test_type, GTK_TYPE_SINGLE_SELECTION))
{
GListStore *list_store = g_list_store_new (G_TYPE_OBJECT);
object = g_object_new (test_type,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]