[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b341a2a 061/156: Factor out using_illustratio
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b341a2a 061/156: Factor out using_illustration_table helper class |
Date: |
Tue, 30 Jan 2018 17:22:11 -0500 (EST) |
branch: master
commit b341a2a3f90b770154d35785882377000f3638a2
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>
Factor out using_illustration_table helper class
This will allow reusing the code dealing with tables outside of
page_with_tabular_report and derived classes code.
---
ledger_pdf_generator_wx.cpp | 80 +++++++++++++++++++++++++--------------------
1 file changed, 44 insertions(+), 36 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 732b29a..ddb5c10 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -243,14 +243,6 @@ class html_interpolator
std::map<std::string, text> vars_;
};
-// Description of a single table column.
-struct illustration_table_column
-{
- char const* variable_name;
- char const* label;
- char const* widest_text;
-};
-
// A slightly specialized table generator for the tables used in the
// illustrations.
class illustration_table_generator : public wx_table_generator
@@ -282,6 +274,42 @@ class illustration_table_generator : public
wx_table_generator
}
};
+// A helper mix-in class for pages using tables.
+class using_illustration_table
+{
+ protected:
+ // Description of a single table column.
+ struct illustration_table_column
+ {
+ char const* variable_name;
+ char const* label;
+ char const* widest_text;
+ };
+
+ using illustration_table_columns = std::vector<illustration_table_column>;
+
+ // Must be overridden to return the description of the table columns.
+ virtual illustration_table_columns const& get_table_columns() const = 0;
+
+ // Useful helper for creating the table generator using the columns defined
+ // by the separate (and simpler to implement) get_table_columns() pure
+ // virtual method.
+ illustration_table_generator create_table_generator
+ (pdf_writer_wx& writer
+ ,wxDC& dc
+ ) const
+ {
+ illustration_table_generator table(writer, dc);
+
+ for(auto const& i : get_table_columns())
+ {
+ table.add_column(i.label, i.widest_text);
+ }
+
+ return table;
+ }
+};
+
class page
{
public:
@@ -1710,7 +1738,9 @@ class numeric_summary_or_attachment_page
// Helper base class for pages showing a table displaying values for all
// contract years after some fixed content.
-class page_with_tabular_report : public numbered_page
+class page_with_tabular_report
+ :public numbered_page
+ ,protected using_illustration_table
{
public:
void render
@@ -1724,7 +1754,7 @@ class page_with_tabular_report : public numbered_page
illustration_table_generator table{create_table_generator(writer, dc)};
- auto const& columns = get_report_columns();
+ auto const& columns = get_table_columns();
// Just some cached values used inside the loop below.
auto const row_height = table.row_height();
@@ -1781,11 +1811,6 @@ class page_with_tabular_report : public numbered_page
}
protected:
- using columns = std::vector<illustration_table_column>;
-
- // Must be overridden to return the description of the table columns.
- virtual columns const& get_report_columns() const = 0;
-
// Must be overridden to render (only if output_mode is e_output_normal)
// the fixed page part and (in any case) return the vertical coordinate of
// its bottom, where the tabular report starts.
@@ -1798,23 +1823,6 @@ class page_with_tabular_report : public numbered_page
) const = 0;
private:
- // Common part of render() and get_extra_pages_needed(): create the table
- // generator to use.
- illustration_table_generator create_table_generator
- (pdf_writer_wx& writer
- ,wxDC& dc
- ) const
- {
- illustration_table_generator table(writer, dc, get_footer_top());
-
- for(auto const& i : get_report_columns())
- {
- table.add_column(i.label, i.widest_text);
- }
-
- return table;
- }
-
// Override the base class method as the table may overflow onto the next
// page(s).
int get_extra_pages_needed
@@ -1945,9 +1953,9 @@ class tabular_detail_page : public
page_with_tabular_report
return pos_y;
}
- columns const& get_report_columns() const override
+ illustration_table_columns const& get_table_columns() const override
{
- static columns const columns =
+ static illustration_table_columns const columns =
{{ "PolicyYear" , "Policy\nYear" , "999" }
,{ "AttainedAge" , "End of\nYear Age" , "999" }
,{ "GrossPmt" , "Premium\nOutlay" , "999,999" }
@@ -1975,9 +1983,9 @@ class tabular_detail2_page : public
page_with_tabular_report
,column_max
};
- columns const& get_report_columns() const override
+ illustration_table_columns const& get_table_columns() const override
{
- static columns const columns =
+ static illustration_table_columns const columns =
{{ "PolicyYear" , "Policy\nYear" ,
"999" }
,{ "AttainedAge" , "End of\nYear Age" ,
"999" }
,{ "AnnGAIntRate_Current", "Illustrated\nCrediting Rate",
"99.99%" }
- [lmi-commits] [lmi] master f484622 044/156: Only show numeric summary if not in force, (continued)
- [lmi-commits] [lmi] master f484622 044/156: Only show numeric summary if not in force, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 67db94b 042/156: Implement more of numeric summary page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master dbaf3c4 048/156: Render PDF illustrations in two passes, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master de9567e 152/156: Fix misplaced commas in ledger PDF generator code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 783befa 006/156: Add separate class for representing HTML contents, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 8c5be11 128/156: Use proper types for get_two_column_header() parameters, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 257ff4b 065/156: Add numeric summary table to PDF illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master ef38c9d 141/156: Revert the title map related changes, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b1ab0fa 126/156: Leave a gap between upper footer part and main page contents, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 940198c 059/156: Add numeric summary attachment page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b341a2a 061/156: Factor out using_illustration_table helper class,
Greg Chicares <=
- [lmi-commits] [lmi] master 1b46585 076/156: Use MarketingNameFootnote & StateMarketingImprimatur on cover page, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 234cd39 012/156: Use custom font sizes to be closer to the existing illustrations, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 956fcca 071/156: Change the second narrative summary page to use a template too, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master dbe5955 015/156: Factor out html_interpolator from pdf_illustration, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 9665573 070/156: Change narrative summary page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master a629602 083/156: Use custom <scaled_image> HTML tag for the embedded images, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master b425030 082/156: Factor out html_cell_for_pdf_output from numeric_summary_table_cell, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d99576a 069/156: Change cover page to use an external template, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master 416ab02 030/156: Add support for vector variables to PDF generating code, Greg Chicares, 2018/01/30
- [lmi-commits] [lmi] master d4dfaa9 075/156: Also use data directory for image files referenced from HTML, Greg Chicares, 2018/01/30