From: Ben Pfaff Date: Tue, 29 Dec 2020 19:17:34 +0000 (-0800) Subject: work toward making pivot tables the primary representation X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8528d21dc66976c98cc14874a11c8b55e24422c1;p=pspp work toward making pivot tables the primary representation --- diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 50bed0a711..afa306e30f 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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). */ diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index be82d0685e..091984a0da 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -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 diff --git a/src/output/text-item.c b/src/output/text-item.c index 9dad57dee8..ced77d2f64 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -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; } static const char *