Made listStore filterable

This commit is contained in:
Markus Koch 2017-02-02 17:16:49 +01:00
parent 6ee8b284b6
commit cc56768804
3 changed files with 28 additions and 15 deletions

View File

@ -2,18 +2,6 @@
<!-- Generated with glade 3.20.0 --> <!-- Generated with glade 3.20.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="entryListStore">
<columns>
<!-- column-name Title -->
<column type="gchararray"/>
<!-- column-name Date -->
<column type="gchararray"/>
<!-- column-name Tags -->
<column type="gchararray"/>
<!-- column-name Timestamp -->
<column type="guint"/>
</columns>
</object>
<object class="GtkTextBuffer" id="entryTextBuffer"> <object class="GtkTextBuffer" id="entryTextBuffer">
<property name="text" translatable="yes">Test text for debugging.</property> <property name="text" translatable="yes">Test text for debugging.</property>
</object> </object>
@ -132,7 +120,6 @@
<property name="height_request">300</property> <property name="height_request">300</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="model">entryListStore</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection" id="entryListSelection"/> <object class="GtkTreeSelection" id="entryListSelection"/>
</child> </child>

View File

@ -26,11 +26,38 @@ static void mainWindow_list_add_entry(struct mainWindow *mainWindow, struct mdia
g_free(date_text); g_free(date_text);
} }
static gboolean mainWindow_list_entry_visible (GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
{
/* gtk_tree_model_get (model, iter, COLUMN_NAME, &target, -1); */
return 1;
}
static void mainWindow_configure_treeView(struct mainWindow *mainWindow) static void mainWindow_configure_treeView(struct mainWindow *mainWindow)
{ {
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
GtkTreeSortable *sortable; GtkTreeSortable *sortable;
GtkTreeViewColumn *col; GtkTreeViewColumn *col;
GtkTreeModel *model;
GtkTreeModelFilter *filtered;
GtkTreeModelSort *sorted;
mainWindow->entryListStore = gtk_list_store_new(COL_COUNT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_UINT);
filtered = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (
GTK_TREE_MODEL (mainWindow->entryListStore), NULL));
sorted = GTK_TREE_MODEL_SORT (gtk_tree_model_sort_new_with_model (
GTK_TREE_MODEL (filtered)));
gtk_tree_model_filter_set_visible_func (filtered,
(GtkTreeModelFilterVisibleFunc) mainWindow_list_entry_visible,
mainWindow, NULL);
model = GTK_TREE_MODEL (sorted);
gtk_tree_view_set_model(mainWindow->entryListView, model);
/* TODO: Unref mainWindow->entryListStore and filtered, sorted and model? */
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Title", renderer, gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Title", renderer,
@ -113,7 +140,6 @@ struct mainWindow *mainWindow_new()
mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate")); mainWindow->popoverDate = GTK_WIDGET(gtk_builder_get_object(builder, "popoverDate"));
mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange")); mainWindow->calendarRange = GTK_WIDGET(gtk_builder_get_object(builder, "calendarRange"));
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView")); mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
mainWindow->entryListStore = GTK_LIST_STORE(gtk_builder_get_object(builder, "entryListStore"));
gtk_builder_connect_signals(builder, NULL); gtk_builder_connect_signals(builder, NULL);

View File

@ -14,8 +14,8 @@ struct mainWindow {
GtkWidget *popoverDate; GtkWidget *popoverDate;
GtkWidget *calendarRange; GtkWidget *calendarRange;
GtkTreeView *entryListView; GtkTreeView *entryListView;
GtkListStore *entryListStore;
GtkListStore *entryListStore;
GtkWidget *selectedDateEntry; GtkWidget *selectedDateEntry;
}; };