pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sheet prep 6/6] gui: Move some formatting functions into PSPP core.


From: Ben Pfaff
Subject: [sheet prep 6/6] gui: Move some formatting functions into PSPP core.
Date: Wed, 22 Jun 2011 20:33:15 -0700

---
 src/data/format.c                 |   50 ++++++++++++++++++++++++++
 src/data/format.h                 |    1 +
 src/data/variable.c               |   40 +++++++++++++++++++++
 src/data/variable.h               |    7 +++-
 src/ui/gui/psppire-var-store.c    |   71 ++-----------------------------------
 src/ui/gui/var-display.c          |   10 -----
 src/ui/gui/var-display.h          |    1 -
 src/ui/gui/variable-info-dialog.c |    2 +-
 8 files changed, 100 insertions(+), 82 deletions(-)

diff --git a/src/data/format.c b/src/data/format.c
index 95e87a0..e15931a 100644
--- a/src/data/format.c
+++ b/src/data/format.c
@@ -912,6 +912,56 @@ fmt_date_template (enum fmt_type type)
     }
 }
 
+/* Returns a string representing the format TYPE for use in a GUI dialog. */
+const char *
+fmt_gui_name (enum fmt_type type)
+{
+  switch (type)
+    {
+    case FMT_F:
+      return _("Numeric");
+
+    case FMT_COMMA:
+      return _("Comma");
+
+    case FMT_DOT:
+      return _("Dot");
+
+    case FMT_E:
+      return _("Scientific");
+
+    case FMT_DATE:
+    case FMT_EDATE:
+    case FMT_SDATE:
+    case FMT_ADATE:
+    case FMT_JDATE:
+    case FMT_QYR:
+    case FMT_MOYR:
+    case FMT_WKYR:
+    case FMT_DATETIME:
+    case FMT_TIME:
+    case FMT_DTIME:
+    case FMT_WKDAY:
+    case FMT_MONTH:
+      return _("Date");
+
+    case FMT_DOLLAR:
+      return _("Dollar");
+
+    case FMT_CCA:
+    case FMT_CCB:
+    case FMT_CCC:
+    case FMT_CCD:
+    case FMT_CCE:
+      return _("Custom");
+
+    case FMT_A:
+      return _("String");
+
+    default:
+      return fmt_name (type);
+    }
+}
 
 /* Returns true if TYPE is a valid format type,
    false otherwise. */
diff --git a/src/data/format.h b/src/data/format.h
index 481ac87..88a82ee 100644
--- a/src/data/format.h
+++ b/src/data/format.h
@@ -125,6 +125,7 @@ int fmt_to_io (enum fmt_type) PURE_FUNCTION;
 bool fmt_from_io (int io, enum fmt_type *);
 
 const char *fmt_date_template (enum fmt_type) PURE_FUNCTION;
+const char *fmt_gui_name (enum fmt_type);
 
 /* Format settings.
 
diff --git a/src/data/variable.c b/src/data/variable.c
index 35fdab2..41f9221 100644
--- a/src/data/variable.c
+++ b/src/data/variable.c
@@ -636,6 +636,26 @@ measure_is_valid (enum measure m)
   return m == MEASURE_NOMINAL || m == MEASURE_ORDINAL || m == MEASURE_SCALE;
 }
 
+/* Returns a string version of measurement level M, for display to a user. */
+const char *
+measure_to_string (enum measure m)
+{
+  switch (m)
+    {
+    case MEASURE_NOMINAL:
+      return _("Nominal");
+
+    case MEASURE_ORDINAL:
+      return _("Ordinal");
+
+    case MEASURE_SCALE:
+      return _("Scale");
+
+    default:
+      return "Invalid";
+    }
+}
+
 /* Returns V's measurement level. */
 enum measure
 var_get_measure (const struct variable *v)
@@ -700,6 +720,26 @@ alignment_is_valid (enum alignment a)
   return a == ALIGN_LEFT || a == ALIGN_RIGHT || a == ALIGN_CENTRE;
 }
 
+/* Returns a string version of alignment A, for display to a user. */
+const char *
+alignment_to_string (enum alignment a)
+{
+  switch (a)
+    {
+    case ALIGN_LEFT:
+      return _("Left");
+
+    case ALIGN_RIGHT:
+      return _("Right");
+
+    case ALIGN_CENTRE:
+      return _("Center");
+
+    default:
+      return "Invalid";
+    }
+}
+
 /* Returns V's display alignment, which applies only to GUIs. */
 enum alignment
 var_get_alignment (const struct variable *v)
diff --git a/src/data/variable.h b/src/data/variable.h
index 456d2ac..aeed5a5 100644
--- a/src/data/variable.h
+++ b/src/data/variable.h
@@ -112,6 +112,8 @@ enum measure
   };
 
 bool measure_is_valid (enum measure);
+const char *measure_to_string (enum measure);
+
 enum measure var_get_measure (const struct variable *);
 void var_set_measure (struct variable *, enum measure);
 
@@ -128,11 +130,12 @@ enum alignment
   {
     ALIGN_LEFT = 0,
     ALIGN_RIGHT = 1,
-    ALIGN_CENTRE = 2,
-    n_ALIGN
+    ALIGN_CENTRE = 2
   };
 
 bool alignment_is_valid (enum alignment);
+const char *alignment_to_string (enum alignment);
+
 enum alignment var_get_alignment (const struct variable *);
 void var_set_alignment (struct variable *, enum alignment);
 
diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c
index 0ef1939..f924c17 100644
--- a/src/ui/gui/psppire-var-store.c
+++ b/src/ui/gui/psppire-var-store.c
@@ -616,20 +616,6 @@ text_for_column (PsppireVarStore *vs,
                 const struct variable *pv, gint c, GError **err)
 {
   PsppireDict *dict = vs->dictionary;
-  static const gchar *const type_label[] =
-    {
-      N_("Numeric"),
-      N_("Comma"),
-      N_("Dot"),
-      N_("Scientific"),
-      N_("Date"),
-      N_("Dollar"),
-      N_("Custom"),
-      N_("String")
-    };
-
-  enum {VT_NUMERIC, VT_COMMA, VT_DOT, VT_SCIENTIFIC, VT_DATE, VT_DOLLAR,
-       VT_CUSTOM, VT_STRING};
 
   const struct fmt_spec *format = var_get_print_format (pv);
 
@@ -639,58 +625,7 @@ text_for_column (PsppireVarStore *vs,
       return xstrdup (var_get_name (pv));
       break;
     case PSPPIRE_VAR_STORE_COL_TYPE:
-      {
-       switch ( format->type )
-         {
-         case FMT_F:
-           return xstrdup (gettext (type_label[VT_NUMERIC]));
-           break;
-         case FMT_COMMA:
-           return xstrdup (gettext (type_label[VT_COMMA]));
-           break;
-         case FMT_DOT:
-           return xstrdup (gettext (type_label[VT_DOT]));
-           break;
-         case FMT_E:
-           return xstrdup (gettext (type_label[VT_SCIENTIFIC]));
-           break;
-         case FMT_DATE:
-         case FMT_EDATE:
-         case FMT_SDATE:
-         case FMT_ADATE:
-         case FMT_JDATE:
-         case FMT_QYR:
-         case FMT_MOYR:
-         case FMT_WKYR:
-         case FMT_DATETIME:
-         case FMT_TIME:
-         case FMT_DTIME:
-         case FMT_WKDAY:
-         case FMT_MONTH:
-           return xstrdup (gettext (type_label[VT_DATE]));
-           break;
-         case FMT_DOLLAR:
-           return xstrdup (gettext (type_label[VT_DOLLAR]));
-           break;
-         case FMT_CCA:
-         case FMT_CCB:
-         case FMT_CCC:
-         case FMT_CCD:
-         case FMT_CCE:
-           return xstrdup (gettext (type_label[VT_CUSTOM]));
-           break;
-         case FMT_A:
-           return xstrdup (gettext (type_label[VT_STRING]));
-           break;
-         default:
-            {
-              char str[FMT_STRING_LEN_MAX + 1];
-              g_warning ("Unknown format: `%s'\n",
-                        fmt_to_string (format, str));
-            }
-           break;
-         }
-      }
+      return xstrdup (fmt_gui_name (format->type));
       break;
     case PSPPIRE_VAR_STORE_COL_WIDTH:
       {
@@ -763,12 +698,12 @@ text_for_column (PsppireVarStore *vs,
        const gint align = var_get_alignment (pv);
 
        g_assert (align < n_ALIGNMENTS);
-       return xstrdup (gettext (alignments[align]));
+       return xstrdup (alignment_to_string (align));
       }
       break;
     case PSPPIRE_VAR_STORE_COL_MEASURE:
       {
-       return xstrdup (measure_to_string (pv, err));
+       return xstrdup (measure_to_string (var_get_measure (pv)));
       }
       break;
     }
diff --git a/src/ui/gui/var-display.c b/src/ui/gui/var-display.c
index 72b5731..db0020f 100644
--- a/src/ui/gui/var-display.c
+++ b/src/ui/gui/var-display.c
@@ -16,16 +16,6 @@
 static const gchar none[] = N_("None");
 
 
-const gchar *
-measure_to_string (const struct variable *var, GError **err)
-{
-  const gint measure = var_get_measure (var);
-
-  g_assert (measure < n_MEASURES);
-  return gettext (measures[measure]);
-}
-
-
 gchar *
 missing_values_to_string (const PsppireDict *dict, const struct variable *pv, 
GError **err)
 {
diff --git a/src/ui/gui/var-display.h b/src/ui/gui/var-display.h
index 62212c8..3590d7c 100644
--- a/src/ui/gui/var-display.h
+++ b/src/ui/gui/var-display.h
@@ -30,6 +30,5 @@ extern const gchar *const alignments[n_ALIGNMENTS + 1];
 extern const gchar *const measures[n_MEASURES + 1];
 
 gchar *missing_values_to_string (const PsppireDict *dict, const struct 
variable *pv, GError **err);
-const gchar *measure_to_string (const struct variable *var, GError **err);
 
 #endif
diff --git a/src/ui/gui/variable-info-dialog.c 
b/src/ui/gui/variable-info-dialog.c
index 59206a8..d5b41a9 100644
--- a/src/ui/gui/variable-info-dialog.c
+++ b/src/ui/gui/variable-info-dialog.c
@@ -90,7 +90,7 @@ populate_text (PsppireDictView *treeview, gpointer data)
   g_free (text);
 
   g_string_append_printf (gstring, _("Measurement Level: %s\n"),
-                         measure_to_string (var, NULL));
+                         measure_to_string (var_get_measure (var)));
 
 
   /* Value Labels */
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]