From: Andrea Zagli Date: Fri, 2 Dec 2011 08:51:55 +0000 (+0100) Subject: Added functions GdaEx::fill_liststore_from_sql_with_missing_func and GdaEx::fill_list... X-Git-Tag: 0.5.0~12 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=79a9046ccb962ffb520d0087b6a7c3d77ca86000;p=libgdaex Added functions GdaEx::fill_liststore_from_sql_with_missing_func and GdaEx::fill_liststore_from_datamodel_with_missing_func. --- diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..cbe5da2 --- /dev/null +++ b/.cproject @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..97b97f7 --- /dev/null +++ b/.project @@ -0,0 +1,315 @@ + + + libgdaex + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/libgdaex/Default} + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + 1322811819863 + + 30 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-autom4te.cache + + + + 1322811819866 + + 30 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-m4 + + + + 1322811819870 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.h + + + + 1322811819875 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-aclocal.m4 + + + + 1322811819878 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-Makefile + + + + 1322811819881 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-Makefile.in + + + + 1322811819885 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.la + + + + 1322811819888 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.exe + + + + 1322811819891 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.guess + + + + 1322811819895 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.h.in* + + + + 1322811819898 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.log + + + + 1322811819902 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.status + + + + 1322811819905 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-config.sub + + + + 1322811819908 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-depcomp + + + + 1322811819912 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-gtk-doc.make + + + + 1322811819915 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-intltool* + + + + 1322811819918 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-install-sh + + + + 1322811819921 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.anjuta + + + + 1322811819924 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.pc + + + + 1322811819928 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-libtool + + + + 1322811819931 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-missing + + + + 1322811819934 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-mkinstalldirs + + + + 1322811819938 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-stamp-h1 + + + + 1322811819942 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-ltmain.sh + + + + 1322811820098 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-configure + + + + 1322811820101 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.o + + + + 1322811820117 + + 22 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.lo + + + + diff --git a/src/gdaex.c b/src/gdaex.c index cd9de2e..b7ee9d0 100644 --- a/src/gdaex.c +++ b/src/gdaex.c @@ -2761,11 +2761,12 @@ GtkBuilder } void -gdaex_fill_liststore_from_sql (GdaEx *gdaex, - GtkListStore *lstore, - const gchar *sql, - guint *cols_formatted, - gchar *(*cols_format_func) (GdaDataModelIter *, guint)) +gdaex_fill_liststore_from_sql_with_missing_func (GdaEx *gdaex, + GtkListStore *lstore, + const gchar *sql, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint), + GdaExFillListStoreMissingFunc missing_func, gpointer user_data) { GdaDataModel *dm; @@ -2779,15 +2780,16 @@ gdaex_fill_liststore_from_sql (GdaEx *gdaex, g_return_if_fail (g_strcmp0 (_sql, "") != 0); dm = gdaex_query (gdaex, _sql); - gdaex_fill_liststore_from_datamodel (gdaex, lstore, dm, cols_formatted, cols_format_func); + gdaex_fill_liststore_from_datamodel_with_missing_func (gdaex, lstore, dm, cols_formatted, cols_format_func, missing_func, user_data); } void -gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, - GtkListStore *lstore, - GdaDataModel *dm, - guint *cols_formatted, - gchar *(*cols_format_func) (GdaDataModelIter *, guint)) +gdaex_fill_liststore_from_datamodel_with_missing_func (GdaEx *gdaex, + GtkListStore *lstore, + GdaDataModel *dm, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint), + GdaExFillListStoreMissingFunc missing_func, gpointer user_data) { GtkTreeIter iter; @@ -2796,9 +2798,12 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, guint cols; guint col; - GType *col_gtypes; + GdaColumn *gdacolumn; + GType *col_gtypes; GType *gcol_gtypes; + gboolean *col_missings; + gboolean call_missing_func; gint *columns; GValue *values; @@ -2829,14 +2834,26 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, values = (GValue *)g_new0 (GValue, cols); col_gtypes = (GType *)g_new0 (GType, cols); gcol_gtypes = (GType *)g_new0 (GType, cols); + col_missings = (gboolean *)g_new0 (gboolean, cols); + + call_missing_func = FALSE; /* caching of columns types */ for (col = 0; col < cols; col++) { col_gtypes[col] = gtk_tree_model_get_column_type (GTK_TREE_MODEL (lstore), col); - if (col_gtypes[col] == G_TYPE_STRING) + + gdacolumn = gda_data_model_describe_column (dm, col); + if (gdacolumn == NULL) { - gcol_gtypes[col] = gda_column_get_g_type (gda_data_model_describe_column (dm, col)); + col_missings[col] = TRUE; + gcol_gtypes[col] = 0; + call_missing_func = TRUE; + } + else + { + col_missings[col] = FALSE; + gcol_gtypes[col] = gda_column_get_g_type (gdacolumn); } } @@ -2853,67 +2870,102 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, switch (col_gtypes[col]) { case G_TYPE_STRING: - switch (gcol_gtypes[col]) + if (col_missings[col]) { - case G_TYPE_STRING: - g_value_set_string (&gval, gdaex_data_model_iter_get_value_stringify_at (gda_iter, col)); - break; - - case G_TYPE_BOOLEAN: - g_value_set_string (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col) ? "X" : ""); - break; - - case G_TYPE_INT: - ival = gdaex_data_model_iter_get_value_integer_at (gda_iter, col); - g_value_set_string (&gval, gdaex_format_money ((gdouble)ival, 0, FALSE)); - break; - - case G_TYPE_FLOAT: - case G_TYPE_DOUBLE: - dval = gdaex_data_model_iter_get_value_double_at (gda_iter, col); - g_value_set_string (&gval, gdaex_format_money (dval, -1, FALSE)); - break; - - default: - if (cols_format_func != NULL) - { - g_value_set_string (&gval, (*cols_format_func) (gda_iter, col)); - } - else if (gcol_gtypes[col] == G_TYPE_DATE - || gcol_gtypes[col] == GDA_TYPE_TIMESTAMP - || gcol_gtypes[col] == G_TYPE_DATE_TIME) - { - gdatetime = gdaex_data_model_iter_get_value_gdatetime_at (gda_iter, col); - /* TODO find default format from locale */ - g_value_set_string (&gval, g_date_time_format (gdatetime, gcol_gtypes[col] == 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 (gda_iter, col))); - } - break; + g_value_set_string (&gval, ""); + } + else + { + switch (gcol_gtypes[col]) + { + case G_TYPE_STRING: + g_value_set_string (&gval, gdaex_data_model_iter_get_value_stringify_at (gda_iter, col)); + break; + + case G_TYPE_BOOLEAN: + g_value_set_string (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col) ? "X" : ""); + break; + + case G_TYPE_INT: + ival = gdaex_data_model_iter_get_value_integer_at (gda_iter, col); + g_value_set_string (&gval, gdaex_format_money ((gdouble)ival, 0, FALSE)); + break; + + case G_TYPE_FLOAT: + case G_TYPE_DOUBLE: + dval = gdaex_data_model_iter_get_value_double_at (gda_iter, col); + g_value_set_string (&gval, gdaex_format_money (dval, -1, FALSE)); + break; + + default: + if (cols_format_func != NULL) + { + g_value_set_string (&gval, (*cols_format_func) (gda_iter, col)); + } + else if (gcol_gtypes[col] == G_TYPE_DATE + || gcol_gtypes[col] == GDA_TYPE_TIMESTAMP + || gcol_gtypes[col] == G_TYPE_DATE_TIME) + { + gdatetime = gdaex_data_model_iter_get_value_gdatetime_at (gda_iter, col); + /* TODO find default format from locale */ + g_value_set_string (&gval, g_date_time_format (gdatetime, gcol_gtypes[col] == 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 (gda_iter, col))); + } + break; + } } values[col] = gval; break; case G_TYPE_INT: - g_value_set_int (&gval, gdaex_data_model_iter_get_value_integer_at (gda_iter, col)); + if (col_missings[col]) + { + g_value_set_int (&gval, 0); + } + else + { + g_value_set_int (&gval, gdaex_data_model_iter_get_value_integer_at (gda_iter, col)); + } values[col] = gval; break; case G_TYPE_FLOAT: - g_value_set_float (&gval, gdaex_data_model_iter_get_value_float_at (gda_iter, col)); + if (col_missings[col]) + { + g_value_set_float (&gval, 0.0); + } + else + { + g_value_set_float (&gval, gdaex_data_model_iter_get_value_float_at (gda_iter, col)); + } values[col] = gval; break; case G_TYPE_DOUBLE: - g_value_set_double (&gval, gdaex_data_model_iter_get_value_double_at (gda_iter, col)); + if (col_missings[col]) + { + g_value_set_double (&gval, 0.0); + } + else + { + g_value_set_double (&gval, gdaex_data_model_iter_get_value_double_at (gda_iter, col)); + } values[col] = gval; break; case G_TYPE_BOOLEAN: - g_value_set_boolean (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col)); + if (col_missings[col]) + { + g_value_set_boolean (&gval, FALSE); + } + else + { + g_value_set_boolean (&gval, gdaex_data_model_iter_get_value_boolean_at (gda_iter, col)); + } values[col] = gval; break; @@ -2924,9 +2976,34 @@ gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, } gtk_list_store_set_valuesv (lstore, &iter, columns, values, cols); + if (call_missing_func + && missing_func != NULL) + { + missing_func (lstore, &iter, user_data); + } } } +void +gdaex_fill_liststore_from_sql (GdaEx *gdaex, + GtkListStore *lstore, + const gchar *sql, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint)) +{ + gdaex_fill_liststore_from_sql_with_missing_func (gdaex, lstore, sql, cols_formatted, cols_format_func, NULL, NULL); +} + +void +gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, + GtkListStore *lstore, + GdaDataModel *dm, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint)) +{ + gdaex_fill_liststore_from_datamodel_with_missing_func (gdaex, lstore, dm, cols_formatted, cols_format_func, NULL, NULL); +} + gchar *gdaex_format_money (gdouble number, gint decimals, diff --git a/src/gdaex.h b/src/gdaex.h index 39a8b39..8740a05 100644 --- a/src/gdaex.h +++ b/src/gdaex.h @@ -200,12 +200,30 @@ const gchar *gdaex_get_guifile (GdaEx *gdaex); GtkBuilder *gdaex_get_gtkbuilder (GdaEx *gdaex); -void gdaex_fill_liststore_from_sql (GdaEx *gdaex, GtkListStore *lstore, const gchar *sql, - guint *cols_formatted, - gchar *(*cols_format_func) (GdaDataModelIter *, guint)); -void gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, GtkListStore *lstore, GdaDataModel *dm, - guint *cols_formatted, - gchar *(*cols_format_func) (GdaDataModelIter *, guint)); +typedef void (*GdaExFillListStoreMissingFunc) (GtkListStore *lstore, GtkTreeIter *iter, gpointer user_data); + +void gdaex_fill_liststore_from_sql_with_missing_func (GdaEx *gdaex, + GtkListStore *lstore, + const gchar *sql, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint), + GdaExFillListStoreMissingFunc missing_func, gpointer user_data); +void gdaex_fill_liststore_from_datamodel_with_missing_func (GdaEx *gdaex, + GtkListStore *lstore, + GdaDataModel *dm, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint), + GdaExFillListStoreMissingFunc missing_func, gpointer user_data); +void gdaex_fill_liststore_from_sql (GdaEx *gdaex, + GtkListStore *lstore, + const gchar *sql, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint)); +void gdaex_fill_liststore_from_datamodel (GdaEx *gdaex, + GtkListStore *lstore, + GdaDataModel *dm, + guint *cols_formatted, + gchar *(*cols_format_func) (GdaDataModelIter *, guint)); gchar *gdaex_format_money (gdouble number, gint decimals,