else if (gda_value_isa (v, G_TYPE_DATE))
{
gdate = gdaex_data_model_get_value_gdate_at (data_model, row, col);
- ret = g_date_time_new_local ((gint)gdate->year,
- (gint)gdate->month,
- (gint)gdate->day,
+ ret = g_date_time_new_local ((gint)g_date_get_year (gdate),
+ (gint)g_date_get_month (gdate),
+ (gint)g_date_get_day (gdate),
0,
0,
0.0);
else if (gda_value_isa (v, G_TYPE_DATE))
{
gdate = gdaex_data_model_iter_get_value_gdate_at (iter, col);
- ret = g_date_time_new_local ((gint)gdate->year,
- (gint)gdate->month,
- (gint)gdate->day,
+ ret = g_date_time_new_local ((gint)g_date_get_year (gdate),
+ (gint)g_date_get_month (gdate),
+ (gint)g_date_get_day (gdate),
0,
0,
0.0);
static GtkTreeModel *gdaex_grid_get_model (GdaExGrid *grid);
static GtkTreeView *gdaex_grid_get_view (GdaExGrid *grid);
+static gchar *grid_format_money (gdouble number,
+ gint decimals,
+ gboolean with_currency_symbol);
+
#define GDAEX_GRID_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDAEX_TYPE_GRID, GdaExGridPrivate))
typedef struct _GdaExGridPrivate GdaExGridPrivate;
gint *columns;
GValue *values;
+ GDateTime *gdatetime;
+ gdouble dval;
+
g_return_val_if_fail (GDAEX_IS_GRID (grid), FALSE);
g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), FALSE);
g_value_set_string (&gval, gdaex_data_model_iter_get_value_boolean_at (dm_iter, col) ? "X" : "");
break;
+ case G_TYPE_INT:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE:
+ dval = gdaex_data_model_iter_get_value_double_at (dm_iter, col);
+ g_value_set_string (&gval, grid_format_money (dval, gdaex_grid_column_get_decimals ((GdaExGridColumn *)g_ptr_array_index (priv->columns, col)), FALSE));
+ break;
+
default:
- g_value_set_string (&gval, gda_value_stringify (gda_data_model_iter_get_value_at (dm_iter, col)));
+ if (gcol_gtype == G_TYPE_DATE
+ || gcol_gtype == G_TYPE_DATE_TIME
+ || gcol_gtype == GDA_TYPE_TIMESTAMP)
+ {
+ gdatetime = gdaex_data_model_iter_get_value_gdatetime_at (dm_iter, col);
+ g_value_set_string (&gval, g_date_time_format (gdatetime, gcol_gtype == G_TYPE_DATE ? "%d/%m/%Y" : "%d/%m/%Y %H.%M.%S"));
+ }
+ else
+ {
+ g_value_set_string (&gval, gda_value_stringify (gda_data_model_iter_get_value_at (dm_iter, col)));
+ }
break;
}
model = gdaex_grid_get_model (grid);
view = gtk_tree_view_new_with_model (model);
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
+
for (col = 0; col < priv->columns->len; col++)
{
gcolumn = (GdaExGridColumn *)g_ptr_array_index (priv->columns, col);
return GTK_TREE_VIEW (view);
}
+
+static gchar
+*grid_format_money (gdouble number,
+ gint decimals,
+ gboolean with_currency_symbol)
+{
+ gchar *ret;
+
+ GRegex *regex;
+ GError *error;
+
+ gchar *str_format;
+ gchar *str;
+ gssize str_len;
+
+ /* TODO
+ * - get number of decimals from locale
+ * - get grouping char from locale
+ * - get currency symbol from locale
+ */
+
+ ret = g_strdup ("");
+
+ error = NULL;
+ regex = g_regex_new ("(^[-\\d]?\\d+)(\\d\\d\\d)", 0, 0, &error);
+ if (error != NULL)
+ {
+ g_warning ("Error on creating regex: %s.",
+ error->message != NULL ? error->message : "no details");
+ return "";
+ }
+
+ str_format = g_strdup_printf ("%%0%sf", decimals == 0 ? ".0" : (decimals < 0 ? ".2" : g_strdup_printf (".%d", decimals)));
+ ret = g_strdup_printf (str_format, number);
+
+ while (TRUE)
+ {
+ error = NULL;
+ str_len = g_utf8_strlen (ret, -1);
+ str = g_regex_replace ((const GRegex *)regex,
+ ret, str_len, 0,
+ "\\1.\\2", 0,
+ &error);
+ if (error != NULL)
+ {
+ g_warning ("Error on regex replacing: %s.",
+ error->message != NULL ? error->message : "no details");
+ g_regex_unref (regex);
+ return "";
+ }
+ if (g_strcmp0 (ret, str) != 0)
+ {
+ ret = g_strdup (str);
+ g_free (str);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (with_currency_symbol)
+ {
+ ret = g_strconcat ("€ ", ret, NULL);
+ }
+
+ g_regex_unref (regex);
+
+ return ret;
+}
+
gboolean resizable,
gboolean sortable,
gboolean reorderable,
- guint decimals);
+ gint decimals);
void gdaex_grid_column_set_title (GdaExGridColumn *column, const gchar *title);
const gchar *gdaex_grid_column_get_title (GdaExGridColumn *column);
void gdaex_grid_column_set_reorderable (GdaExGridColumn *column, gboolean reorderable);
gboolean gdaex_grid_column_get_reorderable (GdaExGridColumn *column);
-void gdaex_grid_column_set_decimals (GdaExGridColumn *column, guint decimals);
-guint gdaex_grid_column_get_decimals (GdaExGridColumn *column);
+void gdaex_grid_column_set_decimals (GdaExGridColumn *column, gint decimals);
+gint gdaex_grid_column_get_decimals (GdaExGridColumn *column);
GtkTreeViewColumn *gdaex_grid_column_get_column (GdaExGridColumn *column);