mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-12 05:20:17 +00:00
gtk3-demo: Make the filter model example more interesting
Allow editing values in the first treeview, to see the derived models update in real time.
This commit is contained in:
parent
8a2812217b
commit
e01f35ef5f
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
WIDTH_COLUMN,
|
WIDTH_COLUMN,
|
||||||
@ -83,6 +84,28 @@ visible_func (GtkTreeModel *model,
|
|||||||
return width < 10;
|
return width < 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cell_edited (GtkCellRendererSpin *cell,
|
||||||
|
const char *path_string,
|
||||||
|
const char *new_text,
|
||||||
|
GtkListStore *store)
|
||||||
|
{
|
||||||
|
int val;
|
||||||
|
GtkTreePath *path;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
int column;
|
||||||
|
|
||||||
|
path = gtk_tree_path_new_from_string (path_string);
|
||||||
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
|
||||||
|
gtk_tree_path_free (path);
|
||||||
|
|
||||||
|
column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column"));
|
||||||
|
|
||||||
|
val = atoi (new_text);
|
||||||
|
|
||||||
|
gtk_list_store_set (store, &iter, column, val, -1);
|
||||||
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
do_filtermodel (GtkWidget *do_widget)
|
do_filtermodel (GtkWidget *do_widget)
|
||||||
{
|
{
|
||||||
@ -106,15 +129,21 @@ do_filtermodel (GtkWidget *do_widget)
|
|||||||
g_signal_connect (window, "destroy",
|
g_signal_connect (window, "destroy",
|
||||||
G_CALLBACK (gtk_widget_destroyed), &window);
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
||||||
|
|
||||||
|
store = (GtkListStore*)gtk_builder_get_object (builder, "liststore1");
|
||||||
|
|
||||||
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn1");
|
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn1");
|
||||||
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext1");
|
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext1");
|
||||||
gtk_tree_view_column_set_cell_data_func (column, cell,
|
gtk_tree_view_column_set_cell_data_func (column, cell,
|
||||||
format_number, GINT_TO_POINTER (WIDTH_COLUMN), NULL);
|
format_number, GINT_TO_POINTER (WIDTH_COLUMN), NULL);
|
||||||
|
g_object_set_data (G_OBJECT (cell), "column", GINT_TO_POINTER (WIDTH_COLUMN));
|
||||||
|
g_signal_connect (cell, "edited", G_CALLBACK (cell_edited), store);
|
||||||
|
|
||||||
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn2");
|
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn2");
|
||||||
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext2");
|
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext2");
|
||||||
gtk_tree_view_column_set_cell_data_func (column, cell,
|
gtk_tree_view_column_set_cell_data_func (column, cell,
|
||||||
format_number, GINT_TO_POINTER (HEIGHT_COLUMN), NULL);
|
format_number, GINT_TO_POINTER (HEIGHT_COLUMN), NULL);
|
||||||
|
g_object_set_data (G_OBJECT (cell), "column", GINT_TO_POINTER (HEIGHT_COLUMN));
|
||||||
|
g_signal_connect (cell, "edited", G_CALLBACK (cell_edited), store);
|
||||||
|
|
||||||
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn3");
|
column = (GtkTreeViewColumn*)gtk_builder_get_object (builder, "treeviewcolumn3");
|
||||||
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext3");
|
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrenderertext3");
|
||||||
@ -135,7 +164,6 @@ do_filtermodel (GtkWidget *do_widget)
|
|||||||
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrendererpixbuf1");
|
cell = (GtkCellRenderer*)gtk_builder_get_object (builder, "cellrendererpixbuf1");
|
||||||
gtk_tree_view_column_add_attribute (column, cell, "visible", SQUARE_COLUMN);
|
gtk_tree_view_column_add_attribute (column, cell, "visible", SQUARE_COLUMN);
|
||||||
|
|
||||||
store = (GtkListStore*)gtk_builder_get_object (builder, "liststore1");
|
|
||||||
tree = (GtkWidget*)gtk_builder_get_object (builder, "treeview2");
|
tree = (GtkWidget*)gtk_builder_get_object (builder, "treeview2");
|
||||||
|
|
||||||
types[WIDTH_COLUMN] = G_TYPE_INT;
|
types[WIDTH_COLUMN] = G_TYPE_INT;
|
||||||
|
@ -24,6 +24,12 @@
|
|||||||
</row>
|
</row>
|
||||||
</data>
|
</data>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkAdjustment" id="adj">
|
||||||
|
<property name="lower">5</property>
|
||||||
|
<property name="upper">50</property>
|
||||||
|
<property name="step-increment">1</property>
|
||||||
|
<property name="page-increment">5</property>
|
||||||
|
</object>
|
||||||
<object class="GtkWindow" id="window1">
|
<object class="GtkWindow" id="window1">
|
||||||
<property name="title" translatable="yes">Filter Model</property>
|
<property name="title" translatable="yes">Filter Model</property>
|
||||||
<child>
|
<child>
|
||||||
@ -63,7 +69,10 @@
|
|||||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||||
<property name="title" translatable="yes">Width</property>
|
<property name="title" translatable="yes">Width</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCellRendererText" id="cellrenderertext1"/>
|
<object class="GtkCellRendererSpin" id="cellrenderertext1">
|
||||||
|
<property name="editable">1</property>
|
||||||
|
<property name="adjustment">adj</property>
|
||||||
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
@ -71,7 +80,10 @@
|
|||||||
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
|
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
|
||||||
<property name="title" translatable="yes">Height</property>
|
<property name="title" translatable="yes">Height</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCellRendererText" id="cellrenderertext2"/>
|
<object class="GtkCellRendererSpin" id="cellrenderertext2">
|
||||||
|
<property name="editable">1</property>
|
||||||
|
<property name="adjustment">adj</property>
|
||||||
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
Loading…
Reference in New Issue
Block a user