[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 02c6f2e 12/13: Pass column data to table gene
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 02c6f2e 12/13: Pass column data to table generator as an aggregate parameter |
Date: |
Sat, 12 May 2018 12:00:23 -0400 (EDT) |
branch: master
commit 02c6f2e5bb982a8f1e749e57983aa320a02d08bb
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Pass column data to table generator as an aggregate parameter
All columns are already known when a PDF table generator is constructed.
Made add_column() private because it is only a ctor helper and can be
called only at time of construction.
---
group_quote_pdf_gen_wx.cpp | 16 +++++++++-------
ledger_pdf_generator_wx.cpp | 46 +++++++++++++++++++++++++--------------------
wx_table_generator.cpp | 12 +++++++++---
wx_table_generator.hpp | 22 +++++++++++++++++-----
4 files changed, 61 insertions(+), 35 deletions(-)
diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 491bacb..47e621b 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -664,17 +664,12 @@ void group_quote_pdf_generator_wx::save(std::string
const& output_filename)
output_document_header(pdf_writer, &pos_y);
pos_y += 2 * vert_skip;
- wx_table_generator table_gen
- (pdf_writer.dc()
- ,pdf_writer.get_horz_margin()
- ,pdf_writer.get_page_width()
- );
-
// Some of the table columns don't need to be shown if all the values in
// them are zeroes.
bool const has_suppl_amount =
totals_.total(e_col_supplemental_face_amount) != 0.0;
bool const has_addl_premium = totals_.total(e_col_additional_premium
) != 0.0;
+ std::vector<column_parameters> vc;
for(int col = 0; col < e_col_max; ++col)
{
column_definition const& cd = column_definitions[col];
@@ -726,9 +721,16 @@ void group_quote_pdf_generator_wx::save(std::string const&
output_filename)
break;
}
- table_gen.add_column(header, cd.widest_text_);
+ vc.push_back({header, cd.widest_text_});
}
+ wx_table_generator table_gen
+ (vc
+ ,pdf_writer.dc()
+ ,pdf_writer.get_horz_margin()
+ ,pdf_writer.get_page_width()
+ );
+
output_aggregate_values(pdf_writer, table_gen, &pos_y);
int const y_before_header = pos_y;
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 8ab5292..6e00a13 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -322,12 +322,13 @@ class illustration_table_generator : public
wx_table_generator
public:
static int const rows_per_group = 5;
- explicit illustration_table_generator(pdf_writer_wx& writer)
- :wx_table_generator
- (writer.dc()
- ,writer.get_horz_margin()
- ,writer.get_page_width()
- )
+ illustration_table_generator
+ (std::vector<column_parameters> const& vc
+ ,wxDC& dc
+ ,int left_margin
+ ,int total_width
+ )
+ :wx_table_generator(vc, dc, left_margin, total_width)
{
use_condensed_style();
align_right();
@@ -389,6 +390,19 @@ class using_illustration_table
,pdf_writer_wx& writer
) const
{
+ std::vector<column_parameters> vc;
+ int column = 0;
+ for(auto const& i : get_table_columns())
+ {
+ std::string header;
+ if(should_show_column(ledger, column++))
+ {
+ header = i.header;
+ }
+ //else: Leave the header empty to avoid showing the column.
+ vc.push_back({header, i.widest_text});
+ }
+
// Set the smaller font used for all tables before creating the table
// generator which uses the DC font for its measurements.
auto& pdf_dc = writer.dc();
@@ -396,25 +410,17 @@ class using_illustration_table
font.SetPointSize(9);
pdf_dc.SetFont(font);
- illustration_table_generator table_gen(writer);
+ illustration_table_generator table_gen
+ (vc
+ ,writer.dc()
+ ,writer.get_horz_margin()
+ ,writer.get_page_width()
+ );
// But set the highlight color for drawing separator lines after
// creating it to override its default pen.
pdf_dc.SetPen(rule_color);
- int column = 0;
- for(auto const& i : get_table_columns())
- {
- std::string header;
- if(should_show_column(ledger, column++))
- {
- header = i.header;
- }
- //else: Leave the header empty to avoid showing the column.
-
- table_gen.add_column(header, i.widest_text);
- }
-
return table_gen;
}
};
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index cfcd450..d7a95ce 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -231,9 +231,10 @@ void increase_to_if_smaller(T& first, T second)
} // Unnamed namespace.
wx_table_generator::wx_table_generator
- (wxDC& dc
- ,int left_margin
- ,int total_width
+ (std::vector<column_parameters> const& vc
+ ,wxDC& dc
+ ,int left_margin
+ ,int total_width
)
:dc_(dc)
,left_margin_(left_margin)
@@ -244,6 +245,11 @@ wx_table_generator::wx_table_generator
,column_widths_already_computed_(false)
,max_header_lines_(1)
{
+ for(auto const& i : vc)
+ {
+ add_column(i.header, i.widest_text);
+ }
+
// Set a pen with 0 width to get the thin lines, and round cap style for
the
// different segments drawn in do_output_values() to seamlessly combine
// into a single line.
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index 1cbcb6e..f9f69c4 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -33,6 +33,14 @@
#include <string>
#include <vector>
+/// Aggregate of per-column table-generator ctor arguments.
+
+struct column_parameters
+{
+ std::string header;
+ std::string widest_text;
+};
+
/// Simplifies outputting tabular data on wxDC.
///
/// To create a table, columns must be initialized first by calling
@@ -50,14 +58,17 @@ class wx_table_generator
class column_info;
public:
- wx_table_generator(wxDC& dc, int left_margin, int total_width);
+ wx_table_generator
+ (std::vector<column_parameters> const& vc
+ ,wxDC& dc
+ ,int left_margin
+ ,int total_width
+ );
wx_table_generator(wx_table_generator const&);
~wx_table_generator();
- void add_column(std::string const& header, std::string const& widest_text);
-
void output_header
(int* pos_y
,oenum_render_or_only_measure output_mode = oe_render
@@ -97,6 +108,9 @@ class wx_table_generator
void align_right();
private:
+ void add_column(std::string const& header, std::string const& widest_text);
+ void do_compute_column_widths();
+
wxFont get_header_font() const;
int do_get_cell_x(std::size_t column);
@@ -104,8 +118,6 @@ class wx_table_generator
void do_output_horz_separator(int x1, int x2, int y );
void do_output_vert_separator(int x , int y1, int y2);
- void do_compute_column_widths();
-
void do_output_values
(int& pos_x
,int& pos_y
- [lmi-commits] [lmi] master updated (0c90de6 -> 45b086a), Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 914ea72 02/13: Remove a "helper" lambda, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 990dbe2 01/13: Improve encapsulation, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 0188828 07/13: Improve alignment, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master be2f05a 09/13: Improve a variable's name, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master e00fb75 05/13: Spell 'color' one way only, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master cccd64c 04/13: Remove disused header, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 111f2bd 03/13: Correct a misleading comment, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 02c6f2e 12/13: Pass column data to table generator as an aggregate parameter,
Greg Chicares <=
- [lmi-commits] [lmi] master 45b086a 13/13: Simplify logic, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 5c9a0db 08/13: Improve typography, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 8e0a46c 11/13: Regularize names, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master e7b741f 10/13: Write 'const' after the type it modifies, Greg Chicares, 2018/05/12
- [lmi-commits] [lmi] master 0870adc 06/13: Document function definitions, Greg Chicares, 2018/05/12