work toward making pivot tables the primary representation
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 29 Dec 2020 19:17:34 +0000 (11:17 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 31 Dec 2020 03:58:11 +0000 (19:58 -0800)
src/output/pivot-table.c
src/output/pivot-table.h
src/output/text-item.c

index 50bed0a7115f626918d27c7be8057c8e712d3c9c..afa306e30ff9607ffca429ade31a88c29a353b73 100644 (file)
@@ -817,11 +817,11 @@ pivot_table_create (const char *title)
   return pivot_table_create__ (pivot_value_new_text (title), title);
 }
 
-/* Creates and returns a new pivot table with the given TITLE, and takes
-   ownership of TITLE.  The new pivot table's subtype is SUBTYPE, which
-   should be an untranslated English string that describes the contents of
-   the table at a high level without being specific about the variables or
-   other context involved.
+/* Creates and returns a new pivot table with the given TITLE (which may be
+   null), and takes ownership of TITLE.  The new pivot table's subtype is
+   SUBTYPE, which should be an untranslated English string that describes the
+   contents of the table at a high level without being specific about the
+   variables or other context involved.
 
    Operations commonly performed on the new pivot_table:
 
@@ -2122,16 +2122,29 @@ pivot_value_get_style (struct pivot_value *value,
 void
 pivot_value_set_style (struct pivot_value *value,
                        const struct table_area_style *area)
+{
+  pivot_value_set_font_style (value, &area->font_style);
+  pivot_value_set_cell_style (value, &area->cell_style);
+}
+
+void
+pivot_value_set_font_style (struct pivot_value *value,
+                            const struct font_style *font_style)
 {
   if (value->font_style)
     font_style_uninit (value->font_style);
   else
     value->font_style = xmalloc (sizeof *value->font_style);
-  font_style_copy (NULL, value->font_style, &area->font_style);
+  font_style_copy (NULL, value->font_style, font_style);
+}
 
+void
+pivot_value_set_cell_style (struct pivot_value *value,
+                            const struct cell_style *cell_style)
+{
   if (!value->cell_style)
     value->cell_style = xmalloc (sizeof *value->cell_style);
-  *value->cell_style = area->cell_style;
+  *value->cell_style = *cell_style;
 }
 
 /* Frees the data owned by ARG (but not ARG itself). */
index be82d0685ee1b6d4d80b06e00862967d8e2726b6..091984a0daecd896bc585ad7cdc5938e99e88fcc 100644 (file)
@@ -753,6 +753,10 @@ void pivot_value_get_style (struct pivot_value *,
                             struct table_area_style *);
 void pivot_value_set_style (struct pivot_value *,
                             const struct table_area_style *);
+void pivot_value_set_font_style (struct pivot_value *,
+                                 const struct font_style *);
+void pivot_value_set_cell_style (struct pivot_value *,
+                                 const struct cell_style *);
 
 /* Template arguments. */
 struct pivot_argument
index 9dad57dee8ca6a45c9b3d2b8ecaf71670e843e3f..ced77d2f64acd8598a3fa30813cfd234db685fa7 100644 (file)
@@ -25,6 +25,7 @@
 #include "libpspp/pool.h"
 #include "output/driver.h"
 #include "output/output-item-provider.h"
+#include "output/pivot-table.h"
 #include "output/table.h"
 #include "output/table-item.h"
 #include "output/table-provider.h"
@@ -70,6 +71,13 @@ text_item_create_nocopy (enum text_item_type type, char *text, char *label)
     .type = type,
     .style = FONT_STYLE_INITIALIZER,
   };
+
+  if (type == TEXT_ITEM_SYNTAX || type == TEXT_ITEM_LOG)
+    {
+      free (item->style.typeface);
+      item->style.typeface = xstrdup ("Monospaced");
+    }
+
   return item;
 }
 
@@ -154,25 +162,20 @@ text_item_append (struct text_item *dst, const struct text_item *src)
 struct table_item *
 text_item_to_table_item (struct text_item *text_item)
 {
-  struct table *tab = table_create (1, 1, 0, 0, 0, 0);
+  struct pivot_table *table = pivot_table_create__ (NULL, "Text");
+  pivot_table_set_look (table, pivot_table_look_builtin_default ());
 
-  struct table_area_style *style = pool_alloc (tab->container, sizeof *style);
-  *style = (struct table_area_style) {
-    .cell_style = CELL_STYLE_INITIALIZER,
-    .cell_style.halign = TABLE_HALIGN_LEFT,
-  };
-  font_style_copy (tab->container, &style->font_style, &text_item->style);
-  tab->styles[0] = style;
-
-  int opts = 0;
-  if (text_item->style.markup)
-    opts |= TAB_MARKUP;
-  if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
-    opts |= TAB_FIX;
-  table_text (tab, 0, 0, opts, text_item_get_text (text_item));
-  struct table_item *table_item = table_item_create (tab);
-  text_item_unref (text_item);
-  return table_item;
+  struct pivot_dimension *d = pivot_dimension_create (
+    table, PIVOT_AXIS_ROW, N_("Text"));
+  d->hide_all_labels = true;
+  pivot_category_create_leaf (d->root, pivot_value_new_text ("null"));
+
+  struct pivot_value *content = pivot_value_new_user_text (
+    text_item->text, SIZE_MAX);
+  pivot_value_set_font_style (content, &text_item->style);
+  pivot_table_put1 (table, 0, content);
+
+  return table;
 }
 \f
 static const char *