From 9bea4cae33c3345ad7cf8375cf2dd3403586cfd0 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 14 Jul 2014 10:25:57 +0200 Subject: [PATCH] VnColumnSpin: - Eliminadas propiedades ya definidas en su cellrenderer interno. VnConsulter: - Limpieza de codigo obsoleto. --- module/data/consulter.glade | 171 ++++++++++++++----------- module/src/vn-consulter.c | 242 +++++++++++++++++++----------------- vn/column/vn-column-spin.c | 94 +------------- vn/column/vn-column-spin.h | 1 - vn/vn-column.c | 11 +- 5 files changed, 237 insertions(+), 282 deletions(-) diff --git a/module/data/consulter.glade b/module/data/consulter.glade index 7d0935a..9de6610 100644 --- a/module/data/consulter.glade +++ b/module/data/consulter.glade @@ -1,7 +1,7 @@ - + @@ -31,24 +31,17 @@ - - - - - - - 300 True False - 8 + 6 vertical - 8 + 5 - + True False - 8 + 4 True @@ -71,7 +64,7 @@ True True - Set on the code + Type or select a query @@ -83,48 +76,65 @@ - - True - send + True - True - True + False + 4 + start + + + Send + True + send + True + True + True + True + + + False + False + 0 + + + + + Clean + True + clean + True + True + True + True + + + False + False + 1 + + + + + gtk-stop + True + True + True + True + + + + False + False + 2 + + False - True + False 2 - - - True - clean - True - True - True - - - False - False - 3 - - - - - gtk-stop - True - True - True - True - - - - False - False - 4 - - False @@ -133,16 +143,37 @@ - + True True - 120 - True + vertical - + + True + True + in + + + True + True + + + multiple + + + + + + + True + False + + + + + 100 True True - never in @@ -154,35 +185,19 @@ True True - + - - - - - False - True - - - - - True - True - in - - - True - True - - - multiple + + + fixed + Log - True + False True @@ -236,4 +251,10 @@ + + + + + + diff --git a/module/src/vn-consulter.c b/module/src/vn-consulter.c index 52f411a..7afb336 100644 --- a/module/src/vn-consulter.c +++ b/module/src/vn-consulter.c @@ -20,6 +20,31 @@ #define FILE_KW "sql://" +static const gchar * queries[] = +{ + //MySQL (kk schema) + + "/*my*/SELECT id, name, item_id, item_id2, amount, item.price " + "FROM movement JOIN item USING (item_id, item_id2)" + ,"/*my*/SELECT item_id,item_id2, i.name, m.id, m.amount, m.price " + "FROM item i LEFT JOIN movement m USING (item_id, item_id2)" + ,"/*my*/SELECT item_id, item_id2, name, price FROM item" + + //PgSQL (test schema) + + ,"/*pg*/SELECT pg_sleep(120)" + ,"/*pg*/SELECT i.id, i.name, i.color, m.id, m.amount " + "FROM item i LEFT JOIN movement m ON i.id = m.item_id" + ,"/*pg*/SELECT m.id, amount, item_id, name, color " + "FROM movement m JOIN item ON m.item_id = item.id" + ,"sql://example/consulter" + ,"/*pg*/ SELECT id1, id2, name, ok, date, number, floating, image " + "FROM prueben" + ,"/*pg*/ SELECT id1, number, floating FROM prueben LIMIT 1" + + ,"SELECT 1 f_integer, 'A' f_varchar, 1.1 f_double, TRUE f_boolean, NULL f_null" +}; + G_DEFINE_TYPE (VnConsulter, vn_consulter, VN_TYPE_FORM); //+++++++++++++++++++++++++++++++++++++++++++++++++++ Private @@ -49,6 +74,7 @@ static void vn_consulter_set_message (VnConsulter * obj, const gchar * msg) static void vn_consulter_model_status_changed (DbModel * model, DbModelStatus status, VnConsulter * obj) { + gint i; GList * n; GtkTreeView * tv = GTK_TREE_VIEW (obj->grid); GList * cols = gtk_tree_view_get_columns (tv); @@ -61,96 +87,111 @@ static void vn_consulter_model_status_changed (DbModel * model, g_list_free (cols); - switch (status) + if (status == DB_MODEL_STATUS_READY) + for (i = 0; i < db_model_get_ncols (model); i++) { - case DB_MODEL_STATUS_READY: + VnColumn * column; + GType col_type, type = db_model_get_column_type (model, i); + const gchar * colname = db_model_get_column_name (model, i); + + switch (type) { - gint i; + case G_TYPE_BOOLEAN: + col_type = VN_TYPE_COLUMN_CHECK; + break; + case G_TYPE_INT: + case G_TYPE_UINT: + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + col_type = VN_TYPE_COLUMN_SPIN; + break; + default: + if (g_strcmp0 (colname, "image")) + col_type = VN_TYPE_COLUMN_ENTRY; + else + col_type = VN_TYPE_COLUMN_IMAGE; + } - for (i = 0; i < db_model_get_ncols (model); i++) + column = g_object_new (col_type + ,"title", colname + ,"column-index", i + ,"editable", TRUE + ,"expand", FALSE + ,"resizable", TRUE + ,NULL + ); + + // Cofigures the numeric columns + + if (col_type == VN_TYPE_COLUMN_SPIN) + { + guint min_width = 100; + guint digits = 0; + gdouble climb_rate = 0.5; + GtkCellRenderer * cell; + GtkAdjustment * adjustment = NULL; + + switch (type) { - VnColumn * column; - GType col_type, type = db_model_get_column_type (model, i); - gboolean image = FALSE; - gchar * format = NULL; -/*col_type = VN_TYPE_COLUMN_ENTRY; - if (type == G_TYPE_INT) -format = "%d"; - else if (type == G_TYPE_UINT) -format = "%u"; - else*/ - if (type == G_TYPE_FLOAT || type == G_TYPE_DOUBLE - || type == G_TYPE_INT || type == G_TYPE_UINT) - col_type = VN_TYPE_COLUMN_SPIN; -//format = "%.2f"; - else if (type == G_TYPE_BYTES) - col_type = VN_TYPE_COLUMN_IMAGE; - else if (type == G_TYPE_BOOLEAN) - col_type = VN_TYPE_COLUMN_CHECK; -//format = "%b"; - else if (type == G_TYPE_STRING && !g_utf8_collate - (g_utf8_casefold (db_model_get_column_name (model, i), -1) - ,g_utf8_casefold ("image", -1))) - { - image = TRUE; - col_type = VN_TYPE_COLUMN_IMAGE; - } -/*else if (type == G_TYPE_DATE) -format = "%Y-%m-%d"; -else if (type == G_TYPE_DATE_TIME) -format = "%Y-%m-%d %T"; -*/ else - { - col_type = VN_TYPE_COLUMN_ENTRY; -//format = "%s"; - } - - column = g_object_new (col_type - ,"title", db_model_get_column_name (model, i) - ,"column-index", i - ,"editable", TRUE - ,"expand", FALSE - ,NULL - ); - gtk_tree_view_append_column (GTK_TREE_VIEW (obj->grid), - GTK_TREE_VIEW_COLUMN (column)); - -if (format) - g_object_set (column, "format", format, NULL); - - if (type == G_TYPE_INT) - g_object_set (column, - "lower", (gdouble)G_MININT, - "upper", (gdouble)G_MAXINT, - NULL); - else if (type == G_TYPE_UINT) - g_object_set (column, - "upper", (gdouble)G_MAXUINT, - NULL); - else if (type == G_TYPE_FLOAT || type == G_TYPE_DOUBLE) - g_object_set (column, - "digits", 2, - "lower", -1000.0, - "upper", 1000.0, - "step-increment", 0.1, - NULL); - else - if (image) - g_object_set (column, - "host", "www.verdnatura.es", - "path", "image/cache/catalog/icon", - "tooltip-path", "../full", - NULL); + case G_TYPE_INT: + adjustment = gtk_adjustment_new ( + 0, G_MININT, G_MAXINT, 1, 1, 0); + break; + case G_TYPE_UINT: + adjustment = gtk_adjustment_new ( + 0, 0, G_MAXUINT, 1, 1, 0); + break; + case G_TYPE_FLOAT: + adjustment = gtk_adjustment_new ( + 0, G_MINFLOAT, G_MAXFLOAT, 0.1, 1, 0); + break; + case G_TYPE_DOUBLE: + adjustment = gtk_adjustment_new ( + 0, G_MINDOUBLE, G_MAXDOUBLE, 0.1, 1, 0); + break; } - break; + switch (type) + { + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + digits = 2; + climb_rate = 0.1; + min_width = 120; + } + + g_object_set (column + ,"digits", digits + ,"min-width", min_width + ,NULL + ); + + cell = vn_column_get_cell_renderer (column); + g_object_set (cell + ,"adjustment", adjustment + ,"climb_rate", climb_rate + ,"digits", digits + ,NULL + ); } - case DB_MODEL_STATUS_ERROR: - vn_consulter_set_message (obj, "Error"); - break; - default: - break; + + // Cofigures the image columns + + if (col_type == VN_TYPE_COLUMN_IMAGE) + g_object_set (column + ,"host", "www.verdnatura.es" + ,"path", "image/cache/catalog/icon" + ,"tooltip-path", "../full" + ,NULL + ); + + // Appends the column to the grid + + gtk_tree_view_append_column (GTK_TREE_VIEW (obj->grid), + GTK_TREE_VIEW_COLUMN (column)); } + else if (status == DB_MODEL_STATUS_ERROR) + vn_consulter_set_message (obj, "Error"); gtk_widget_set_sensitive (GTK_WIDGET (obj->mode), TRUE); } @@ -202,46 +243,23 @@ void vn_consulter_send (GtkButton * button, VnConsulter * obj) static void vn_consulter_open (VnConsulter * obj) { gint i; + GtkCellRenderer * cell; + GtkTreeViewColumn * column; VnForm * form = VN_FORM (obj); - obj->file = g_strconcat - (FILE_KW, vn_mod_get_name (form->mod), "/consulter", NULL); - - gchar * queries[] = - { -//MySQL (kk schema) - "/*my*/SELECT id, name, item_id, item_id2, amount, item.price " - "FROM movement JOIN item USING (item_id, item_id2)" - ,"/*my*/SELECT item_id,item_id2, i.name, m.id, m.amount, m.price " - "FROM item i LEFT JOIN movement m USING (item_id, item_id2)" - ,"/*my*/SELECT item_id, item_id2, name, price FROM item" -//PgSQL (test schema) - ,"/*pg*/SELECT pg_sleep(120)" - ,"/*pg*/SELECT i.id, i.name, i.color, m.id, m.amount " - "FROM item i LEFT JOIN movement m ON i.id = m.item_id" - ,"/*pg*/SELECT m.id, amount, item_id, name, color " - "FROM movement m JOIN item ON m.item_id = item.id" - ,obj->file - ,"/*pg*/ SELECT id1, id2, name, ok, date, number, floating, image " - "FROM prueben" - ,"/*pg*/ SELECT id1, number, floating FROM prueben LIMIT 1" - ,"SELECT 1, 'A', 1.1, TRUE, NULL" - ,NULL - }; - obj->model = vn_form_get (form, "model"); obj->combo = vn_form_get (form, "query"); obj->tv = vn_form_get (form, "treeview"); obj->mode = vn_form_get (form, "mode"); obj->grid = vn_form_get (form, "consulter"); obj->handler = vn_form_get (form, "handler"); - gtk_entry_set_placeholder_text (vn_form_get (form, "combo-entry"), - _("Type or select a query")); - gtk_tree_view_insert_column_with_attributes (obj->tv, -1, _("Message"), - gtk_cell_renderer_text_new (), "text", 0, NULL); + column = vn_form_get (form, "column-log"); + cell = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, cell, TRUE); + gtk_tree_view_column_add_attribute (column, cell, "text", 0); - for (i = 0; i < g_strv_length (queries); i++) + for (i = 0; i < G_N_ELEMENTS (queries); i++) gtk_combo_box_text_prepend_text (obj->combo, queries[i]); } diff --git a/vn/column/vn-column-spin.c b/vn/column/vn-column-spin.c index 9e097a0..8980f43 100644 --- a/vn/column/vn-column-spin.c +++ b/vn/column/vn-column-spin.c @@ -31,27 +31,11 @@ static void vn_column_spin_on_edited (GtkCellRendererSpin * cell, const gchar * path, gchar * text, VnColumnSpin * obj) { GValue value = G_VALUE_INIT; - DbModelStatus status = db_model_get_status (vn_column_get_model (VN_COLUMN (obj))); - - if (status != DB_MODEL_STATUS_READY) - return; if (g_strcmp0 (text, "")) { - gchar * err; - - if (!err || *err == '\0') - { - gdouble val, min, max; - - g_object_get (obj->adjustment, "lower", &min, "upper", &max, NULL); - val = CLAMP (g_strtod (text, &err), min, max); - g_value_init (&value, G_TYPE_DOUBLE); - g_value_set_double (&value, val); - g_object_set (obj->adjustment, "value", val, NULL); - } - else - return; + g_value_init (&value, G_TYPE_DOUBLE); + g_value_set_double (&value, g_strtod (text, NULL)); } else g_value_init (&value, GVN_TYPE_NULL); @@ -148,11 +132,7 @@ static void vn_column_spin_set_value (VnColumnSpin * obj, GtkTreeModel * model, enum { - PROP_CLIMB_RATE = 1 - ,PROP_DIGITS - ,PROP_LOWER - ,PROP_UPPER - ,PROP_STEP + PROP_DIGITS = 1 }; static void vn_column_spin_set_property (VnColumnSpin * obj, guint id, @@ -160,9 +140,6 @@ static void vn_column_spin_set_property (VnColumnSpin * obj, guint id, { switch (id) { - case PROP_CLIMB_RATE: - g_object_set (VN_COLUMN (obj)->cell, "climb-rate", g_value_get_double (value), NULL); - break; case PROP_DIGITS: { guint digits = g_value_get_uint (value); @@ -171,18 +148,6 @@ static void vn_column_spin_set_property (VnColumnSpin * obj, guint id, obj->format = g_strdup_printf ("%%.%df", digits); break; } - case PROP_LOWER: - g_object_set (obj->adjustment, "lower", g_value_get_double (value), NULL); - break; - case PROP_UPPER: - g_object_set (obj->adjustment, "upper", g_value_get_double (value), NULL); - break; - case PROP_STEP: - g_object_set (obj->adjustment, - "step-increment", g_value_get_double (value), - "page-increment", g_value_get_double (value) * 10, - NULL); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); } @@ -193,21 +158,9 @@ static void vn_column_spin_get_property (VnColumnSpin * obj, guint id, { switch (id) { - case PROP_CLIMB_RATE: - g_object_get_property (G_OBJECT (VN_COLUMN (obj)->cell), "climb-rate", value); - break; case PROP_DIGITS: g_object_get_property (G_OBJECT (VN_COLUMN (obj)->cell), "digits", value); break; - case PROP_LOWER: - g_object_get_property (G_OBJECT (obj->adjustment), "lower", value); - break; - case PROP_UPPER: - g_object_get_property (G_OBJECT (obj->adjustment), "upper", value); - break; - case PROP_STEP: - g_object_get_property (G_OBJECT (obj->adjustment), "step-increment", value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); } @@ -215,19 +168,16 @@ static void vn_column_spin_get_property (VnColumnSpin * obj, guint id, static void vn_column_spin_init (VnColumnSpin * obj) { - GtkCellRenderer * cell = gtk_cell_renderer_spin_new (); + GtkCellRenderer * cell; - obj->adjustment = gtk_adjustment_new (0.0, G_MININT, G_MAXINT, 0.0, 1.0, 0.0); + obj->format = NULL; + cell = gtk_cell_renderer_spin_new (); g_object_set (cell - ,"adjustment", obj->adjustment ,"xalign", 1.0 ,"alignment", PANGO_ALIGN_RIGHT ,NULL ); - - obj->format = NULL; - VN_COLUMN_GET_CLASS (obj)->set_renderer (VN_COLUMN (obj), cell); } @@ -246,14 +196,6 @@ static void vn_column_spin_class_init (VnColumnSpinClass * klass) col_k->set_value = (VnColumnSetValueFunc) vn_column_spin_set_value; col_k->set_editable = (VnColumnSetEditableFunc) vn_column_spin_set_editable; - g_object_class_install_property (k, PROP_CLIMB_RATE, - g_param_spec_double ("climb-rate" - ,_("Climb rate") - ,_("The acceleration rate when you hold down a button.") - ,0.0 ,G_MAXDOUBLE ,0.0 - ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE - )); - g_object_class_install_property (k, PROP_DIGITS, g_param_spec_uint ("digits" ,_("Digits") @@ -261,28 +203,4 @@ static void vn_column_spin_class_init (VnColumnSpinClass * klass) ,0 ,20 ,0 ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE )); - - g_object_class_install_property (k, PROP_LOWER, - g_param_spec_double ("lower" - ,_("Minimum value") - ,_("The minimum value of the internal adjustment.") - ,-G_MAXDOUBLE ,G_MAXDOUBLE ,-G_MAXDOUBLE - ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE - )); - - g_object_class_install_property (k, PROP_UPPER, - g_param_spec_double ("upper" - ,_("Maximum value") - ,_("The maximum value of the internal adjustment.") - ,-G_MAXDOUBLE ,G_MAXDOUBLE ,G_MAXDOUBLE - ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE - )); - - g_object_class_install_property (k, PROP_STEP, - g_param_spec_double ("step-increment" - ,_("Step Increment") - ,_("The step increment of the internal adjustment") - ,0.00000000000000000001 ,10000000000.0 ,1.0 - ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE - )); } diff --git a/vn/column/vn-column-spin.h b/vn/column/vn-column-spin.h index 99801a0..86de37e 100644 --- a/vn/column/vn-column-spin.h +++ b/vn/column/vn-column-spin.h @@ -33,7 +33,6 @@ typedef struct _VnColumnSpinClass VnColumnSpinClass; struct _VnColumnSpin { VnColumn parent; - GtkAdjustment * adjustment; gchar * format; }; diff --git a/vn/vn-column.c b/vn/vn-column.c index 3af0a80..ca05e5e 100644 --- a/vn/vn-column.c +++ b/vn/vn-column.c @@ -55,14 +55,14 @@ static void vn_column_value_changed (VnColumn * obj, const gchar * path, const G static void vn_column_data_func (GtkTreeViewColumn * col, GtkCellRenderer * cell, GtkTreeModel * model, GtkTreeIter * iter, VnColumn * obj) { - GdkRGBA * background; +/* GdkRGBA * background; DbIter dbiter; DbModelRowOp ops; - +*/ GValue value = G_VALUE_INIT; gtk_tree_model_get_value (model, iter, obj->column_index, &value); obj->set_value (obj, model, iter, cell, &value); - +/* vn_gtk_tree_iter_to_db_iter (iter, &dbiter); ops = db_model_get_row_operations ( vn_grid_model_get_model (VN_GRID_MODEL (model)) @@ -76,9 +76,8 @@ static void vn_column_data_func (GtkTreeViewColumn * col, GtkCellRenderer * cell else background = NULL; - if (background) - g_object_set (cell, "cell-background-rgba", background, NULL); - + g_object_set (cell, "cell-background-rgba", background, NULL); +*/ if (obj->style_func) obj->style_func (VN_COLUMN (col), cell, iter, &value);