Change how checking for missing values works.
[pspp] / src / ui / gui / psppire-data-store.c
index c0fc42a2f285a87ff32a5da5a9e3d1595990a621..2a3efe639522ea320a515914eeb3a734df4db6f6 100644 (file)
@@ -46,9 +46,6 @@
 
 #include "value-variant.h"
 
-static void psppire_data_store_init            (PsppireDataStore      *data_store);
-static void psppire_data_store_class_init      (PsppireDataStoreClass *class);
-
 static void psppire_data_store_finalize        (GObject           *object);
 static void psppire_data_store_dispose        (GObject           *object);
 
@@ -101,7 +98,7 @@ __tree_model_get_n_columns (GtkTreeModel *tree_model)
 {
   PsppireDataStore *store  = PSPPIRE_DATA_STORE (tree_model);
 
-  return psppire_dict_get_var_cnt (store->dict);
+  return psppire_dict_get_n_vars (store->dict);
 }
 
 
@@ -137,11 +134,11 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
 {
   PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
 
-  while (col >= psppire_dict_get_var_cnt (store->dict))
+  while (col >= psppire_dict_get_n_vars (store->dict))
     {
       const struct variable *var =
        psppire_dict_insert_variable (store->dict,
-                                     psppire_dict_get_var_cnt (store->dict),
+                                     psppire_dict_get_n_vars (store->dict),
                                      NULL);
       g_return_val_if_fail (var, FALSE);
     }
@@ -167,7 +164,8 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
   if (vp == NULL)
     {
       xx = data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
-                   fmt->type, &val, width, "UTF-8");
+                   fmt->type, settings_get_fmt_settings (),
+                    &val, width, "UTF-8");
     }
 
   GVariant *vrnt = value_variant_new (&val, width);
@@ -183,7 +181,7 @@ static char *
 unlabeled_value (PsppireDataStore *store, const struct variable *variable, const union value *val)
 {
   if (var_is_numeric (variable) &&
-      var_is_value_missing (variable, val, MV_SYSTEM))
+      var_is_value_missing (variable, val) == MV_SYSTEM)
     return g_strdup ("");
 
   const struct fmt_spec *fmt = var_get_print_format (variable);
@@ -283,44 +281,9 @@ __tree_model_init (GtkTreeModelIface *iface)
   iface->iter_parent     = NULL;
 }
 
-
-GType
-psppire_data_store_get_type (void)
-{
-  static GType data_store_type = 0;
-
-  if (!data_store_type)
-    {
-      static const GTypeInfo data_store_info =
-      {
-       sizeof (PsppireDataStoreClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-        (GClassInitFunc) psppire_data_store_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-        sizeof (PsppireDataStore),
-       0,
-        (GInstanceInitFunc) psppire_data_store_init,
-      };
-
-      static const GInterfaceInfo tree_model_info = {
-       (GInterfaceInitFunc) __tree_model_init,
-       NULL,
-       NULL
-      };
-
-      data_store_type = g_type_register_static (G_TYPE_OBJECT,
-                                               "PsppireDataStore",
-                                               &data_store_info, 0);
-
-      g_type_add_interface_static (data_store_type, GTK_TYPE_TREE_MODEL,
-                                  &tree_model_info);
-    }
-
-  return data_store_type;
-}
-
+G_DEFINE_TYPE_WITH_CODE (PsppireDataStore, psppire_data_store, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
+                                               __tree_model_init))
 
 static void
 psppire_data_store_class_init (PsppireDataStoreClass *class)
@@ -328,7 +291,7 @@ psppire_data_store_class_init (PsppireDataStoreClass *class)
   GObjectClass *object_class;
 
   parent_class = g_type_class_peek_parent (class);
-  object_class = (GObjectClass*) class;
+  object_class = G_OBJECT_CLASS (class);
 
   object_class->finalize = psppire_data_store_finalize;
   object_class->dispose = psppire_data_store_dispose;
@@ -369,7 +332,7 @@ psppire_data_store_get_case_count (const PsppireDataStore *store)
 size_t
 psppire_data_store_get_value_count (const PsppireDataStore *store)
 {
-  return psppire_dict_get_value_cnt (store->dict);
+  return psppire_dict_get_n_values (store->dict);
 }
 
 const struct caseproto *
@@ -426,11 +389,13 @@ resize_datum (const union value *old, union value *new, const void *aux_)
   int new_width = var_get_width (aux->new_variable);
   const char *enc = dict_get_encoding (aux->dict);
   const struct fmt_spec *newfmt = var_get_print_format (aux->new_variable);
-  char *s = data_out (old, enc, var_get_print_format (aux->old_variable));
+  char *s = data_out (old, enc, var_get_print_format (aux->old_variable),
+                      settings_get_fmt_settings ());
   enum fmt_type type = (fmt_usable_for_input (newfmt->type)
                         ? newfmt->type
                         : FMT_DOLLAR);
-  free (data_in (ss_cstr (s), enc, type, new, new_width, enc));
+  free (data_in (ss_cstr (s), enc, type, settings_get_fmt_settings (),
+                 new, new_width, enc));
   free (s);
 }
 
@@ -742,11 +707,10 @@ psppire_data_store_clear (PsppireDataStore *ds)
 struct casereader *
 psppire_data_store_get_reader (PsppireDataStore *ds)
 {
-  int i;
   struct casereader *reader ;
 
   if (ds->dict)
-    for (i = 0 ; i < n_dict_signals; ++i)
+    for (int i = 0 ; i < n_dict_signals; ++i)
       {
        g_signal_handler_block (ds->dict,
                                ds->dict_handler_id[i]);
@@ -876,8 +840,8 @@ psppire_data_store_data_in (PsppireDataStore *ds, casenumber casenum, gint idx,
                         FALSE);
   value_init (&value, width);
   ok = (datasheet_get_value (ds->datasheet, casenum, idx, &value)
-        && data_in_msg (input, UTF8, fmt->type, &value, width,
-                        dict_get_encoding (dict->dict))
+        && data_in_msg (input, UTF8, fmt->type, settings_get_fmt_settings (),
+                        &value, width, dict_get_encoding (dict->dict))
         && datasheet_put_value (ds->datasheet, casenum, idx, &value));
   value_destroy (&value, width);