From 01e61a79fd84c7c7f16c60d4f1171a9128a1b545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 28 Sep 2019 21:59:24 +0200 Subject: [PATCH] Integrate cell selector to main gui class --- cell-selector/tree-store.c | 182 ------------------ gds-render-gui.c | 12 +- include/gds-render/cell-selector/tree-store.h | 50 ----- 3 files changed, 8 insertions(+), 236 deletions(-) delete mode 100644 cell-selector/tree-store.c delete mode 100644 include/gds-render/cell-selector/tree-store.h diff --git a/cell-selector/tree-store.c b/cell-selector/tree-store.c deleted file mode 100644 index 9c6e6b4..0000000 --- a/cell-selector/tree-store.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * GDSII-Converter - * Copyright (C) 2018 Mario Hüttel - * - * This file is part of GDSII-Converter. - * - * GDSII-Converter is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * GDSII-Converter is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GDSII-Converter. If not, see . - */ - -/** - * @file tree-store.h - * @brief Tree store implementation - * @author Mario Hüttel - */ - -/** - * @addtogroup GUI - * @{ - */ - -#include -#include -#include - -struct filter_visible_params { - GtkSearchEntry *search_entry; - GtkTreeView *tree_view; -}; - -/** - * @brief this function olny allows cells to be selected - * @param selection - * @param model - * @param path - * @param path_currently_selected - * @param data - * @return TRUE if element is selectable, FALSE if not - */ -static gboolean tree_sel_func(GtkTreeSelection *selection, - GtkTreeModel *model, - GtkTreePath *path, - gboolean path_currently_selected, - gpointer data) -{ - GtkTreeIter iter; - struct gds_cell *cell; - unsigned int error_level; - gboolean ret = FALSE; - (void)selection; - (void)path_currently_selected; - (void)data; - - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, CELL_SEL_CELL, &cell, CELL_SEL_CELL_ERROR_STATE, &error_level, -1); - - /* Allow only rows with _valid_ cell to be selected */ - if (cell) { - /* Cell available. Check if it passed the critical checks */ - if (!(error_level & LIB_CELL_RENDERER_ERROR_ERR)) - ret = TRUE; - } - - return ret; -} - -/** - * @brief cell_store_filter_visible_func Decides whether an element of the tree model @p model is visible. - * @param model Tree model - * @param iter Current element / iter in Model to check - * @param data Data. Set to static stores variable - * @return TRUE if visible, else FALSE - * @note TODO: Maybe implement Damerau-Levenshtein distance matching - */ -static gboolean cell_store_filter_visible_func(GtkTreeModel *model, GtkTreeIter *iter, gpointer data) -{ - struct filter_visible_params *params = (struct filter_visible_params *)data; - struct gds_cell *cell; - struct gds_library *lib; - gboolean result = FALSE; - const char *search_string; - - if (!model || !iter || !params) - goto exit_filter; - - gtk_tree_model_get(model, iter, CELL_SEL_CELL, &cell, CELL_SEL_LIBRARY, &lib, -1); - - if (lib) { - result = TRUE; - goto exit_filter; - } - - if (!cell) - goto exit_filter; - - search_string = gtk_entry_get_text(GTK_ENTRY(params->search_entry)); - - /* Show all, if field is empty */ - if (!strlen(search_string)) - result = TRUE; - - if (strstr(cell->name, search_string)) - result = TRUE; - - gtk_tree_view_expand_all(params->tree_view); - -exit_filter: - return result; -} - -static void change_filter(GtkWidget *entry, gpointer data) -{ - struct tree_stores *stores = (struct tree_stores *)data; - (void)entry; - - gtk_tree_model_filter_refilter(stores->filter); -} - -/** - * @brief Setup a GtkTreeView with the necessary columns - * @param view Tree view to set up - * @param search_entry Entry field for search - * @return Tree stores for storing data inside the GtkTreeView - */ -int setup_cell_selector(GtkTreeView *view, GtkEntry *search_entry, GtkTreeStore **base_store, - GtkTreeModelFilter **filter) -{ - static struct tree_stores stores; - GtkTreeStore *base_store; - GtkCellRenderer *render_dates; - GtkCellRenderer *render_cell; - GtkCellRenderer *render_lib; - GtkTreeViewColumn *column; - - - - *base_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, - G_TYPE_POINTER, G_TYPE_UINT, - G_TYPE_STRING, G_TYPE_STRING); - - /* Searching */ - *filter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(*base_store), NULL)); - gtk_tree_model_filter_set_visible_func(*filter, - (GtkTreeModelFilterVisibleFunc)cell_store_filter_visible_func, - &stores, NULL); - g_signal_connect(GTK_SEARCH_ENTRY(search_entry), "search-changed", G_CALLBACK(change_filter), &stores); - - gtk_tree_view_set_model(view, GTK_TREE_MODEL(*filter)); - - render_dates = gtk_cell_renderer_text_new(); - render_cell = lib_cell_renderer_new(); - render_lib = lib_cell_renderer_new(); - - column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL); - gtk_tree_view_append_column(view, column); - - column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, - "error-level", CELL_SEL_CELL_ERROR_STATE, NULL); - gtk_tree_view_append_column(view, column); - - column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL); - gtk_tree_view_append_column(view, column); - - column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", CELL_SEL_ACCESSDATE, NULL); - gtk_tree_view_append_column(view, column); - - /* Callback for selection - * This prevents selecting a library */ - gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(view), tree_sel_func, NULL, NULL); - - return &stores; -} -/** @} */ diff --git a/gds-render-gui.c b/gds-render-gui.c index 78e36fe..f18b3c3 100644 --- a/gds-render-gui.c +++ b/gds-render-gui.c @@ -135,7 +135,7 @@ static GString *generate_string_from_date(struct gds_time_field *date) } /** - * @brief this function olny allows cells to be selected + * @brief This function only allows valid cells to be selected * @param selection * @param model * @param path @@ -170,6 +170,11 @@ static gboolean tree_sel_func(GtkTreeSelection *selection, return ret; } +/** + * @brief Trigger refiltering of cell filter + * @param entry Unused widget, that emitted the signal + * @param data GdsrenderGui self instance + */ static void cell_tree_view_change_filter(GtkWidget *entry, gpointer data) { GdsRenderGui *self = RENDERER_GUI(data); @@ -210,7 +215,7 @@ static gboolean cell_store_filter_visible_func(GtkTreeModel *model, GtkTreeIter if (!cell) goto exit_filter; - search_string = gtk_entry_get_text(GTK_ENTRY(self->cell_search_entry)); + search_string = gtk_entry_get_text(GTK_ENTRY(self->cell_search_entry )); /* Show all, if field is empty */ if (!strlen(search_string)) @@ -231,7 +236,6 @@ exit_filter: */ int gds_render_gui_setup_cell_selector(GdsRenderGui *self) { - GtkTreeStore *base_store; GtkCellRenderer *render_dates; GtkCellRenderer *render_cell; GtkCellRenderer *render_lib; @@ -242,7 +246,7 @@ int gds_render_gui_setup_cell_selector(GdsRenderGui *self) G_TYPE_STRING, G_TYPE_STRING); /* Searching */ - self->cell_filter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(base_store), NULL)); + self->cell_filter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(GTK_TREE_MODEL(self->cell_tree_store), NULL)); gtk_tree_model_filter_set_visible_func(self->cell_filter, (GtkTreeModelFilterVisibleFunc)cell_store_filter_visible_func, self, NULL); diff --git a/include/gds-render/cell-selector/tree-store.h b/include/gds-render/cell-selector/tree-store.h deleted file mode 100644 index b6378ab..0000000 --- a/include/gds-render/cell-selector/tree-store.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * GDSII-Converter - * Copyright (C) 2018 Mario Hüttel - * - * This file is part of GDSII-Converter. - * - * GDSII-Converter is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * GDSII-Converter is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GDSII-Converter. If not, see . - */ - -/** - * @file tree-store.h - * @brief Header file for Tree store implementation - * @author Mario Hüttel - */ - -/** - * @addtogroup GUI - * @{ - */ - -#ifndef __TREE_STORE_H__ -#define __TREE_STORE_H__ - -#include - -/** @brief Columns of selection tree view */ -enum cell_store_columns { - CELL_SEL_LIBRARY = 0, - CELL_SEL_CELL, - CELL_SEL_CELL_ERROR_STATE, /**< Used for cell color and selectability */ - CELL_SEL_MODDATE, - CELL_SEL_ACCESSDATE, - CELL_SEL_COLUMN_COUNT /**< @brief Not a column. Used to determine count of columns */ -}; - -int setup_cell_selector(GtkTreeView* view, GtkEntry *search_entry); - -#endif /* __TREE_STORE_H__ */ - -/** @} */