1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2020, 2021 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-var-info.h"
21 #include "data/value-labels.h"
22 #include "data/variable.h"
25 #define _(msgid) gettext (msgid)
26 #define N_(msgid) msgid
28 G_DEFINE_TYPE (PsppireVarInfo, psppire_var_info, GTK_TYPE_GRID);
31 psppire_var_info_dispose (GObject *obj)
33 PsppireVarInfo *var_info = PSPPIRE_VAR_INFO (obj);
35 if (var_info->dispose_has_run)
37 var_info->dispose_has_run = TRUE;
39 G_OBJECT_CLASS (psppire_var_info_parent_class)->dispose (obj);
42 static const char *field_labels[n_VAR_INFO] =
47 N_("Measurement Level"),
59 psppire_var_info_init (PsppireVarInfo *var_info)
61 g_object_set (var_info,
67 for (int r = 0; r < n_VAR_INFO; ++r)
69 GtkWidget *label = gtk_label_new (gettext (field_labels[r]));
71 "halign", GTK_ALIGN_START,
74 gtk_grid_attach (GTK_GRID (var_info), label, 0, r, 1, 1);
75 gtk_widget_show (label);
77 if (r >= n_VAR_INFO - 1)
80 var_info->entry[r] = gtk_entry_new ();
82 g_object_set (var_info->entry[r],
84 "double-buffered", FALSE,
89 gtk_grid_attach (GTK_GRID (var_info), var_info->entry[r], 1, r, 1, 1);
92 var_info->combo = gtk_combo_box_text_new_with_entry ();
93 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (var_info->combo));
94 g_object_set (entry, "editable", FALSE, NULL);
95 gtk_widget_show (var_info->combo);
97 gtk_grid_attach (GTK_GRID (var_info), var_info->combo, 1, n_VAR_INFO - 1, 1, 1);
101 psppire_var_info_new (void)
103 return GTK_WIDGET (g_object_new (psppire_var_info_get_type (), NULL));
114 __set_property (GObject *object,
119 PsppireVarInfo *var_info = PSPPIRE_VAR_INFO (object);
125 gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (var_info->combo));
126 gtk_combo_box_set_active (GTK_COMBO_BOX (var_info->combo), 0);
127 GtkWidget *entry = gtk_bin_get_child (GTK_BIN (var_info->combo));
128 gtk_entry_set_text (GTK_ENTRY (entry), "");
130 const struct variable *var = g_value_get_pointer (value);
133 for (int i = 0; i < n_VAR_INFO - 1; ++i)
135 gtk_entry_set_text (GTK_ENTRY (var_info->entry[i]), "");
137 gtk_combo_box_set_active (GTK_COMBO_BOX (var_info->combo), -1);
142 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_NAME]),
145 str = g_strdup_printf ("%ld", var_get_dict_index (var));
146 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_POSITION]),
150 const char *label = var_get_label (var);
151 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_LABEL]),
154 str = g_strdup_printf ("%d", var_get_width (var));
155 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_WIDTH]),
159 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_MEASUREMENT_LEVEL]),
160 measure_to_string (var_get_measure (var)));
162 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_ROLE]),
163 var_role_to_string (var_get_role (var)));
165 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_ALIGNMENT]),
166 alignment_to_string (var_get_alignment (var)));
168 const struct fmt_spec *pf = var_get_print_format (var);
169 char xx[FMT_STRING_LEN_MAX + 1];
170 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_PRINT_FORMAT]),
171 fmt_to_string (pf, xx));
173 const struct fmt_spec *wf = var_get_write_format (var);
174 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_WRITE_FORMAT]),
175 fmt_to_string (wf, xx));
177 const struct missing_values *mv = var_get_missing_values (var);
178 str = mv_to_string (mv, "UTF-8");
179 gtk_entry_set_text (GTK_ENTRY (var_info->entry[VAR_INFO_MISSING_VALUES]),
183 const struct val_labs *vls = var_get_value_labels (var);
186 for (const struct val_lab *vl = val_labs_first (vls);
188 vl = val_labs_next (vls, vl))
191 ds_init_empty (&text);
193 const char *l = val_lab_get_label (vl);
194 const union value *v = val_lab_get_value (vl);
196 var_append_value_name__ (var, v, SETTINGS_VALUE_SHOW_VALUE, &text);
197 ds_put_cstr (&text, ": ");
198 ds_put_cstr (&text, l);
200 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (var_info->combo), ds_cstr (&text));
201 gtk_combo_box_set_active (GTK_COMBO_BOX (var_info->combo), 0);
208 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
214 __get_property (GObject *object,
222 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 psppire_var_info_class_init (PsppireVarInfoClass *class)
232 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
235 gobject_class->set_property = __set_property;
236 gobject_class->get_property = __get_property;
237 gobject_class->dispose = psppire_var_info_dispose;
239 g_object_class_install_property (gobject_class, PROP_VARIABLE,
243 "The variable whose parameters are to be displayed",