]> saetta.ns0.it Git - libgdaexgrid/commitdiff
Added private function ::_set_gvalue_stringify_from_datamodel.
authorAndrea Zagli <azagli@libero.it>
Sun, 28 Mar 2021 07:48:32 +0000 (09:48 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 28 Mar 2021 07:48:32 +0000 (09:48 +0200)
src/grid.c

index 4f32f93cef7681d0dfd617b9dd456f9c5f44ab15..f5dbd72ec77fa96bd095ac34bd0cca1e687db7f5 100644 (file)
@@ -563,6 +563,52 @@ gdaex_grid_fill_from_sql_with_missing_func_with_sel (GdaExGrid *grid,
        return ret;
 }
 
+static GValue
+*_set_gvalue_stringify_from_datamodel (GdaExGridColumn *col, GValue *gval, GdaDataModel *dm, GdaDataModelIter *dm_iter, const gchar *field_name)
+{
+       GdaColumn *gda_col;
+       GType gda_col_gtype;
+
+       GDateTime *gdatetime;
+
+       gda_col = gda_data_model_describe_column (dm, gda_data_model_get_column_index (dm, field_name));
+       gda_col_gtype = gda_column_get_g_type (gda_col);
+
+       switch (gda_col_gtype)
+               {
+               case G_TYPE_STRING:
+                       g_value_set_string (gval, _gettext (gdaex_data_model_iter_get_field_value_stringify_at (dm_iter, field_name)));
+                       break;
+
+               case G_TYPE_BOOLEAN:
+                       g_value_set_string (gval, gdaex_data_model_iter_get_field_value_boolean_at (dm_iter, field_name) ? "X" : "");
+                       break;
+
+               case G_TYPE_INT:
+               case G_TYPE_FLOAT:
+               case G_TYPE_DOUBLE:
+                       g_value_set_string (gval, gdaex_format_money (gdaex_data_model_iter_get_field_value_double_at (dm_iter, field_name),
+                                                                     gdaex_grid_column_get_decimals (col), FALSE));
+                       break;
+
+               default:
+                       if (gda_col_gtype == G_TYPE_DATE
+                           || gda_col_gtype == G_TYPE_DATE_TIME
+                           || gda_col_gtype == GDA_TYPE_TIMESTAMP)
+                               {
+                                       gdatetime = gdaex_data_model_iter_get_field_value_gdatetime_at (dm_iter, field_name);
+                                       /* TODO find default format from locale */
+                                       g_value_set_string (gval, g_date_time_format (gdatetime, gda_col_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
+                                       g_date_time_unref (gdatetime);
+                               }
+                       else
+                               {
+                                       g_value_set_string (gval, _gettext (gdaex_data_model_iter_get_field_value_stringify_at (dm_iter, field_name)));
+                               }
+                       break;
+               }
+}
+
 /**
  * gdaex_grid_fill_from_datamodel_with_missing_func_with_sel:
  * @grid: a #GdaExGrid object.
@@ -668,43 +714,7 @@ gdaex_grid_fill_from_datamodel_with_missing_func_with_sel (GdaExGrid *grid,
                                                        switch (col_gtype)
                                                                {
                                                                        case G_TYPE_STRING:
-                                                                               gda_col = gda_data_model_describe_column (dm, gda_data_model_get_column_index (dm, field_name));
-                                                                               gda_col_gtype = gda_column_get_g_type (gda_col);
-
-                                                                               switch (gda_col_gtype)
-                                                                                       {
-                                                                                               case G_TYPE_STRING:
-                                                                                                       g_value_set_string (&gval, _gettext (gdaex_data_model_iter_get_field_value_stringify_at (dm_iter, field_name)));
-                                                                                                       break;
-
-                                                                                               case G_TYPE_BOOLEAN:
-                                                                                                       g_value_set_string (&gval, gdaex_data_model_iter_get_field_value_boolean_at (dm_iter, field_name) ? "X" : "");
-                                                                                                       break;
-
-                                                                                               case G_TYPE_INT:
-                                                                                               case G_TYPE_FLOAT:
-                                                                                               case G_TYPE_DOUBLE:
-                                                                                                       dval = gdaex_data_model_iter_get_field_value_double_at (dm_iter, field_name);
-                                                                                                       g_value_set_string (&gval, gdaex_format_money (dval, gdaex_grid_column_get_decimals ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col)), FALSE));
-                                                                                                       break;
-
-                                                                                               default:
-                                                                                                       if (gda_col_gtype == G_TYPE_DATE
-                                                                                                               || gda_col_gtype == G_TYPE_DATE_TIME
-                                                                                                               || gda_col_gtype == GDA_TYPE_TIMESTAMP)
-                                                                                                               {
-                                                                                                                       gdatetime = gdaex_data_model_iter_get_field_value_gdatetime_at (dm_iter, field_name);
-                                                                                                                       /* TODO find default format from locale */
-                                                                                                                       g_value_set_string (&gval, g_date_time_format (gdatetime, gda_col_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
-                                                                                                                       g_date_time_unref (gdatetime);
-                                                                                                               }
-                                                                                                       else
-                                                                                                               {
-                                                                                                                       g_value_set_string (&gval, _gettext (gdaex_data_model_iter_get_field_value_stringify_at (dm_iter, field_name)));
-                                                                                                               }
-                                                                                                       break;
-                                                                                       }
-
+                                                                               _set_gvalue_stringify_from_datamodel((GdaExGridColumn *)g_ptr_array_index (priv->columns, col), &gval, dm, dm_iter, field_name);
                                                                                break;
 
                                                                        case G_TYPE_INT: