X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Foutput%2Fpivot-table.h;h=99fbdb295df000b4cfb50b05dcd084eb2478efd8;hb=75ac1e869e551495c403cf94a3a24dd0dfee98ef;hp=474b3acde250b916e0a0c559cb04d952cbb2efa2;hpb=5cab4cf3322f29c0ed7134d23740e07382914f20;p=pspp diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 474b3acde2..99fbdb295d 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -60,13 +60,20 @@ union value; Creating a pivot table usually consists of the following steps: 1. Create the table with pivot_table_create(), passing in the title. + It's commonly useful to set up a few options at this point: + + - If empty rows or columns should not be displayed, set ->omit_empty to + true. + + - Set the format to use for "count" values with + pivot_table_set_weight_var() or pivot_table_set_weight_format(). 2. Create each dimension with pivot_dimension_create() and populate it with categories and, possibly, with groups that contain the categories. This call also assigns the dimension to an axis. In simple cases, only a call to pivot_dimension_create() is needed. - Other functions such as pivot__create_group() can be used for + Other functions such as pivot_category_create_group() can be used for hierarchies of categories. Sometimes it's easier to create categories in tandem with inserting data, @@ -100,6 +107,7 @@ enum pivot_area }; const char *pivot_area_to_string (enum pivot_area); +const struct table_area_style *pivot_area_get_default_style (enum pivot_area); /* Table borders for styling purposes. */ enum pivot_border @@ -138,15 +146,14 @@ enum pivot_border }; const char *pivot_border_to_string (enum pivot_border); +void pivot_border_get_default_style (enum pivot_border, + struct table_border_style *); /* Sizing for rows or columns of a rendered table. The comments below talk about columns and their widths but they apply equally to rows and their heights. */ struct pivot_table_sizing { - /* Minimum and maximum column width, in 1/96" units. */ - int range[2]; - /* Specific column widths, in 1/96" units. */ int *widths; size_t n_widths; @@ -211,7 +218,7 @@ struct pivot_axis breaks out of the loop prematurely, it needs to free it with free(). */ #define PIVOT_AXIS_FOR_EACH(INDEXES, AXIS) \ for ((INDEXES) = NULL; \ - ((INDEXES) = pivot_axis_iterator_next (INDEXES, AXIS)) != NULL; ) + ((INDEXES) = pivot_axis_iterator_next (INDEXES, AXIS)) != NULL;) size_t *pivot_axis_iterator_next (size_t *indexes, const struct pivot_axis *); /* Dimensions. @@ -362,28 +369,27 @@ void pivot_category_destroy (struct pivot_category *); bool pivot_result_class_change (const char *, const struct fmt_spec *); -/* A pivot table. See the top of this file for more information. */ -struct pivot_table +/* Styling for a pivot table. + + The division between this and the style information in struct pivot_table + seems fairly arbitrary. The ultimate reason for the division is simply + because that's how SPSS documentation and file formats do it. */ +struct pivot_table_look { - /* Display settings. */ - bool rotate_inner_column_labels; - bool rotate_outer_row_labels; - bool row_labels_in_corner; - bool show_grid_lines; + char *name; /* May be null. */ + + /* General properties. */ bool omit_empty; - size_t *current_layer; /* axis[PIVOT_AXIS_LAYER]->n_dimensions elements. */ - char *table_look; - enum settings_value_show show_values; - enum settings_value_show show_variables; - struct fmt_spec weight_format; + bool row_labels_in_corner; + int width_ranges[TABLE_N_AXES][2]; /* In 1/96" units. */ /* Footnote display settings. */ bool show_numeric_markers; bool footnote_marker_superscripts; - /* Column and row sizing and page breaks. - sizing[TABLE_HORZ] is for columns, sizing[TABLE_VERT] is for rows. */ - struct pivot_table_sizing sizing[TABLE_N_AXES]; + /* Styles. */ + struct table_area_style areas[PIVOT_N_AREAS]; + struct table_border_style borders[PIVOT_N_BORDERS]; /* Print settings. */ bool print_all_layers; @@ -392,6 +398,37 @@ struct pivot_table bool top_continuation, bottom_continuation; char *continuation; size_t n_orphan_lines; + }; + +void pivot_table_look_init (struct pivot_table_look *); +void pivot_table_look_uninit (struct pivot_table_look *); +void pivot_table_look_copy (struct pivot_table_look *, + const struct pivot_table_look *); + +/* A pivot table. See the top of this file for more information. */ +struct pivot_table + { + /* Reference count. A pivot_table may be shared between multiple owners, + indicated by a reference count greater than 1. When this is the case, + the pivot_table must not be modified. */ + int ref_cnt; + + /* Styling. */ + struct pivot_table_look look; + + /* Display settings. */ + bool rotate_inner_column_labels; + bool rotate_outer_row_labels; + bool show_grid_lines; + bool show_caption; + size_t *current_layer; /* axis[PIVOT_AXIS_LAYER].n_dimensions elements. */ + enum settings_value_show show_values; + enum settings_value_show show_variables; + struct fmt_spec weight_format; + + /* Column and row sizing and page breaks. + sizing[TABLE_HORZ] is for columns, sizing[TABLE_VERT] is for rows. */ + struct pivot_table_sizing sizing[TABLE_N_AXES]; /* Format settings. */ int epoch; @@ -417,15 +454,11 @@ struct pivot_table /* Titles. */ struct pivot_value *title; - struct pivot_value *subtype; /* Same as pivot_item's subtype. */ + struct pivot_value *subtype; /* Same as spv_item's subtype. */ struct pivot_value *corner_text; struct pivot_value *caption; char *notes; - /* Styles. */ - struct area_style areas[PIVOT_N_AREAS]; - struct table_border_style borders[PIVOT_N_BORDERS]; - /* Dimensions. */ struct pivot_dimension **dimensions; size_t n_dimensions; @@ -438,10 +471,20 @@ struct pivot_table /* Creating and destroy pivot tables. */ struct pivot_table *pivot_table_create (const char *title); -struct pivot_table *pivot_table_create__ (struct pivot_value *title); +struct pivot_table *pivot_table_create__ (struct pivot_value *title, + const char *subtype); struct pivot_table *pivot_table_create_for_text (struct pivot_value *title, struct pivot_value *content); -void pivot_table_destroy (struct pivot_table *); + +struct pivot_table *pivot_table_ref (const struct pivot_table *); +void pivot_table_unref (struct pivot_table *); +bool pivot_table_is_shared (const struct pivot_table *); + +/* Styling. */ +const struct pivot_table_look *pivot_table_get_look ( + const struct pivot_table *); +void pivot_table_set_look (struct pivot_table *, + const struct pivot_table_look *); /* Format of PIVOT_RC_COUNT cells. */ void pivot_table_set_weight_var (struct pivot_table *, @@ -453,7 +496,7 @@ void pivot_table_set_weight_format (struct pivot_table *, bool pivot_table_is_empty (const struct pivot_table *); /* Output. */ -void pivot_table_submit (const struct pivot_table *); +void pivot_table_submit (struct pivot_table *); /* Data cells. */ void pivot_table_put (struct pivot_table *, const size_t *dindexes, size_t n, @@ -482,6 +525,7 @@ struct pivot_footnote size_t idx; struct pivot_value *content; struct pivot_value *marker; + bool show; }; struct pivot_footnote *pivot_table_create_footnote ( @@ -580,10 +624,13 @@ struct pivot_value { struct font_style *font_style; struct cell_style *cell_style; - char *subscript; + + char **subscripts; + size_t n_subscripts; + char *superscript; - struct pivot_footnote **footnotes; + const struct pivot_footnote **footnotes; size_t n_footnotes; enum pivot_value_type type; @@ -633,7 +680,8 @@ struct pivot_value /* PIVOT_VALUE_TEMPLATE. */ struct { - char *s; + char *local; /* Localized. */ + char *id; /* Identifier. */ struct pivot_argument *args; size_t n_args; } @@ -658,16 +706,20 @@ struct pivot_value *pivot_value_new_variable (const struct variable *); /* Values from text strings. */ struct pivot_value *pivot_value_new_text (const char *); struct pivot_value *pivot_value_new_text_format (const char *, ...) - PRINTF_FORMAT (1, 2); +#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4) + __attribute__((format(gnu_printf, 1, 2))); +#else + __attribute__((format(__printf__, 1, 2))); +#endif struct pivot_value *pivot_value_new_user_text (const char *, size_t length); struct pivot_value *pivot_value_new_user_text_nocopy (char *); /* Footnotes. */ -void pivot_value_add_footnote (struct pivot_value *, struct pivot_footnote *); +void pivot_value_add_footnote (struct pivot_value *, const struct pivot_footnote *); /* Numeric formats. */ -void pivot_value_set_rc (struct pivot_table *, struct pivot_value *, +void pivot_value_set_rc (const struct pivot_table *, struct pivot_value *, const char *rc); /* Converting a pivot_value to a string for display. */ @@ -687,9 +739,11 @@ void pivot_value_destroy (struct pivot_value *); /* Styling. */ void pivot_value_get_style (struct pivot_value *, - const struct area_style *default_style, - struct area_style *); -void pivot_value_set_style (struct pivot_value *, const struct area_style *); + const struct font_style *base_font_style, + const struct cell_style *base_cell_style, + struct table_area_style *); +void pivot_value_set_style (struct pivot_value *, + const struct table_area_style *); /* Template arguments. */ struct pivot_argument @@ -699,5 +753,13 @@ struct pivot_argument }; void pivot_argument_uninit (struct pivot_argument *); + +/* One piece of data within a pivot table. */ +struct pivot_cell + { + struct hmap_node hmap_node; /* In struct pivot_table's 'cells' hmap. */ + struct pivot_value *value; + unsigned int idx[]; /* One index per table dimension. */ + }; #endif /* output/pivot-table.h */