[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master cce8f6b 2/4: Banish "hidden" columns from cla
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master cce8f6b 2/4: Banish "hidden" columns from class wx_table_generator |
Date: |
Wed, 8 Aug 2018 12:20:10 -0400 (EDT) |
branch: master
commit cce8f6b3a113d105e18cf0a2601b68f0fd30835c
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Banish "hidden" columns from class wx_table_generator
---
group_quote_pdf_gen_wx.cpp | 2 +-
ledger_pdf_generator_wx.cpp | 8 +----
report_table.cpp | 24 +++----------
report_table.hpp | 8 -----
report_table_test.cpp | 84 +++++++++++++++++++++----------------------
wx_table_generator.cpp | 87 ++++++++++++++-------------------------------
wx_table_generator.hpp | 1 -
7 files changed, 74 insertions(+), 140 deletions(-)
diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 0e937e9..2c4d1a9 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -740,7 +740,7 @@ void group_quote_pdf_generator_wx::save(std::string const&
output_filename)
cd.visibility_ = visibility;
if(oe_shown == visibility)
{
- vc.push_back({header, cd.widest_text_, alignment, visibility,
elasticity});
+ vc.push_back({header, cd.widest_text_, alignment, elasticity});
}
}
// Add a one-past-the-end index equal to the last value, because
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 8fcfe4c..d4069ba 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -368,13 +368,7 @@ class using_illustration_table
indices.push_back(lmi::ssize(vc));
if(!should_hide_column(ledger, column))
{
- vc.push_back
- ({i.header
- ,i.widest_text
- ,oe_right
- ,should_hide_column(ledger, column) ? oe_hidden : oe_shown
- ,oe_inelastic
- });
+ vc.push_back({i.header, i.widest_text, oe_right,
oe_inelastic});
}
++column;
}
diff --git a/report_table.cpp b/report_table.cpp
index f251536..ae2b68f 100644
--- a/report_table.cpp
+++ b/report_table.cpp
@@ -57,28 +57,23 @@ void set_column_widths
// comment about it above the implementation.
for(auto& i : all_columns)
{
- if(!i.is_hidden() && !i.is_elastic())
+ if(!i.is_elastic())
{
i.col_width_ += 2 * column_margin;
}
}
- // Number of non-hidden columns.
+ // Number of columns.
int number_of_columns = 0;
- // Number of non-hidden elastic columns.
+ // Number of elastic columns.
int number_of_elastic_columns = 0;
- // Total width of all non-hidden inelastic columns.
+ // Total width of all inelastic columns.
int total_inelastic_width = 0;
for(auto const& i : all_columns)
{
- if(i.is_hidden())
- {
- continue;
- }
-
++number_of_columns;
if(i.is_elastic())
@@ -148,13 +143,7 @@ void set_column_widths
for(auto& i : all_columns)
{
- if(i.is_hidden())
- {
- continue;
- }
-
i.col_width_ -= overflow_per_column;
-
if(0 < underflow)
{
++i.col_width_;
@@ -218,11 +207,6 @@ void set_column_widths
for(auto& i : all_columns)
{
- if(i.is_hidden())
- {
- continue;
- }
-
if(i.is_elastic())
{
i.col_width_ = width_of_each_elastic_column;
diff --git a/report_table.hpp b/report_table.hpp
index de3b773..d11cab9 100644
--- a/report_table.hpp
+++ b/report_table.hpp
@@ -55,10 +55,6 @@
/// arguments, but clipping depends on the elasticity argument. It is
/// distinguished only because clipping is a distinct layout operation.
///
-/// - is_hidden(): Data for every row of all potential columns are
-/// passed into this class; hidden columns are suppressed so that
-/// they don't appear in the output at all.
-///
/// - is_elastic(): An elastic column has no innate fixed or preferred
/// width. After all inelastic columns have claimed their required
/// widths, any remaining width available is prorated among elastic
@@ -76,13 +72,11 @@ class LMI_SO table_column_info
(std::string const& header
,int width
,oenum_h_align const alignment
- ,oenum_visibility const visibility
,oenum_elasticity const elasticity
)
:col_header_ (header)
,col_width_ (width)
,alignment_ (alignment)
- ,is_hidden_ (oe_hidden == visibility)
,is_elastic_ (oe_elastic == elasticity)
{
}
@@ -90,7 +84,6 @@ class LMI_SO table_column_info
std::string const& col_header() const {return col_header_;}
int col_width() const {return col_width_;}
oenum_h_align alignment() const {return alignment_;}
- bool is_hidden() const {return is_hidden_;}
bool is_elastic() const {return is_elastic_;}
bool is_clipped() const {return is_elastic();}
@@ -107,7 +100,6 @@ class LMI_SO table_column_info
private:
oenum_h_align const alignment_;
- bool const is_hidden_;
bool const is_elastic_;
};
diff --git a/report_table_test.cpp b/report_table_test.cpp
index 186d6fc..ebe4485 100644
--- a/report_table_test.cpp
+++ b/report_table_test.cpp
@@ -62,16 +62,16 @@ void report_table_test::test_group_quote()
static int const default_margin = 7;
std::vector<table_column_info> v =
- {{"", 22, oe_center, oe_shown, oe_inelastic}
- ,{"", 0, oe_left , oe_shown, oe_elastic }
- ,{"", 38, oe_center, oe_shown, oe_inelastic}
- ,{"", 48, oe_center, oe_shown, oe_inelastic}
- ,{"", 64, oe_center, oe_shown, oe_inelastic}
- ,{"", 67, oe_center, oe_shown, oe_inelastic}
- ,{"", 64, oe_center, oe_shown, oe_inelastic}
- ,{"", 67, oe_center, oe_shown, oe_inelastic}
- ,{"", 64, oe_center, oe_shown, oe_inelastic}
- ,{"", 67, oe_center, oe_shown, oe_inelastic}
+ {{"", 22, oe_center, oe_inelastic}
+ ,{"", 0, oe_left , oe_elastic }
+ ,{"", 38, oe_center, oe_inelastic}
+ ,{"", 48, oe_center, oe_inelastic}
+ ,{"", 64, oe_center, oe_inelastic}
+ ,{"", 67, oe_center, oe_inelastic}
+ ,{"", 64, oe_center, oe_inelastic}
+ ,{"", 67, oe_center, oe_inelastic}
+ ,{"", 64, oe_center, oe_inelastic}
+ ,{"", 67, oe_center, oe_inelastic}
};
set_column_widths(total_width, default_margin, v);
@@ -91,14 +91,14 @@ void report_table_test::test_illustration()
{
std::vector<table_column_info> v =
- {{"", 24, oe_right, oe_shown, oe_inelastic}
- ,{"", 38, oe_right, oe_shown, oe_inelastic}
- ,{"", 53, oe_right, oe_shown, oe_inelastic}
- ,{"", 52, oe_right, oe_shown, oe_inelastic}
- ,{"", 31, oe_right, oe_shown, oe_inelastic}
- ,{"", 48, oe_right, oe_shown, oe_inelastic}
- ,{"", 48, oe_right, oe_shown, oe_inelastic}
- ,{"", 53, oe_right, oe_shown, oe_inelastic}
+ {{"", 24, oe_right, oe_inelastic}
+ ,{"", 38, oe_right, oe_inelastic}
+ ,{"", 53, oe_right, oe_inelastic}
+ ,{"", 52, oe_right, oe_inelastic}
+ ,{"", 31, oe_right, oe_inelastic}
+ ,{"", 48, oe_right, oe_inelastic}
+ ,{"", 48, oe_right, oe_inelastic}
+ ,{"", 53, oe_right, oe_inelastic}
};
set_column_widths(total_width, default_margin, v);
@@ -113,18 +113,18 @@ void report_table_test::test_illustration()
{
std::vector<table_column_info> v =
- {{"", 26, oe_right, oe_shown, oe_inelastic}
- ,{"", 24, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 32, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
+ {{"", 26, oe_right, oe_inelastic}
+ ,{"", 24, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 32, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
};
set_column_widths(total_width, default_margin, v);
@@ -139,18 +139,18 @@ void report_table_test::test_illustration()
{
std::vector<table_column_info> v =
- {{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
- ,{"", 50, oe_right, oe_shown, oe_inelastic}
+ {{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
+ ,{"", 50, oe_right, oe_inelastic}
};
std::cout << "[Expect a multiline..." << std::endl;
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index e4a880e..f7c4315 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -138,16 +138,10 @@ void wx_table_generator::output_headers
std::vector<std::string> headers_by_line(max_header_lines_ *
number_of_columns);
for(std::size_t i = 0; i < number_of_columns; ++i)
{
- table_column_info const& ci = all_columns().at(i);
- if(ci.is_hidden())
- {
- continue;
- }
-
- std::vector<std::string> const
lines(split_into_lines(ci.col_header()));
-
// Fill the elements from the bottom line to the top one, so that a
// single line header is shown on the last line.
+ table_column_info const& ci = all_columns().at(i);
+ std::vector<std::string> const
lines(split_into_lines(ci.col_header()));
std::size_t const first_line = max_header_lines_ - lines.size();
for(std::size_t j = 0; j < lines.size(); ++j)
{
@@ -235,12 +229,7 @@ void wx_table_generator::output_highlighted_cell
)
{
int column = indices_[a_column];
-
LMI_ASSERT(column < lmi::ssize(all_columns()));
- if(all_columns().at(column).is_hidden())
- {
- return;
- }
{
wxDCPenChanger set_transparent_pen(dc_, *wxTRANSPARENT_PEN);
@@ -371,26 +360,10 @@ wxRect wx_table_generator::text_rect(int column, int y)
const
///
/// Column headers may be multiline strings.
///
-/// All data for every row and every potential column are passed into
-/// this class, even for "hidden" columns that are to be suppressed so
-/// that they don't appear in the output at all. This approach trades
-/// extra complexity here for a uniform data representation elsewhere.
-/// PDF !! Instead of retaining hidden columns, and explicitly skipping
-/// them here and repeatedly later (and also in set_column_widths()),
-/// consider removing them from the vector.
-///
/// Postconditions:
/// - An elastic column's width is initialized to zero. (If there's
/// enough room to display it, set_column_widths() resets its width
/// appropriately.)
-/// - A hidden column's width is initialized to zero--necessarily,
-/// because other member functions, e.g.:
-/// output_horz_separator()
-/// cell_pos_x()
-/// calculate total width by accumulating the widths of all columns,
-/// whether hidden or not. PDF !! In those instances, hidden columns
-/// are skipped implicitly rather than explicitly; this is a further
-/// argument against trafficking in hidden columns.
///
/// Design alternative: this could be written as a nonmember function,
/// by passing the DC and the header font as arguments.
@@ -398,46 +371,43 @@ wxRect wx_table_generator::text_rect(int column, int y)
const
void wx_table_generator::enroll_column(column_parameters const& z)
{
int width = 0;
- LMI_ASSERT(oe_shown == z.visibility);
- if(oe_shown == z.visibility)
+
+ wxDCFontChanger header_font_setter(dc_);
+ if(use_bold_headers_)
{
- wxDCFontChanger header_font_setter(dc_);
- if(use_bold_headers_)
- {
- header_font_setter.Set(header_font());
- }
+ header_font_setter.Set(header_font());
+ }
- wxCoord w, h, lh;
- dc().GetMultiLineTextExtent(z.header, &w, &h, &lh, &dc().GetFont());
- LMI_ASSERT(0 != lh);
- LMI_ASSERT(0 == h % lh);
+ wxCoord w, h, lh;
+ dc().GetMultiLineTextExtent(z.header, &w, &h, &lh, &dc().GetFont());
+ LMI_ASSERT(0 != lh);
+ LMI_ASSERT(0 == h % lh);
// Temporarily assert that this does the same as the code it replaced:
LMI_ASSERT(h / lh == int(1u + count_newlines(z.header)));
// Check it again because of the unfortunate mixed-mode arithmetic:
LMI_ASSERT(std::size_t(h / lh) == 1u + count_newlines(z.header));
- // Store number of lines used by tallest unhidden header:
- // output_headers() uses it to write all headers as a block.
- max_header_lines_ = std::max(max_header_lines_, std::size_t(h / lh));
+ // Store number of lines used by tallest header:
+ // output_headers() uses it to write all headers as a block.
+ max_header_lines_ = std::max(max_header_lines_, std::size_t(h / lh));
- switch(z.elasticity)
+ switch(z.elasticity)
+ {
+ case oe_inelastic:
{
- case oe_inelastic:
- {
- // Greater of header width and 'widest_text' width.
- width = std::max(w, dc().GetTextExtent(z.widest_text).x);
- }
- break;
- case oe_elastic:
- {
- ; // Do nothing: 'width' already initialized to zero.
- }
- break;
+ // Greater of header width and 'widest_text' width.
+ width = std::max(w, dc().GetTextExtent(z.widest_text).x);
}
+ break;
+ case oe_elastic:
+ {
+ ; // Do nothing: 'width' already initialized to zero.
+ }
+ break;
}
all_columns_.push_back
(table_column_info
- (z.header, width, z.alignment, z.visibility, z.elasticity)
+ (z.header, width, z.alignment, z.elasticity)
);
}
@@ -461,11 +431,6 @@ void wx_table_generator::do_output_single_row
for(std::size_t i = 0; i < number_of_columns; ++i)
{
table_column_info const& ci = all_columns().at(i);
- if(ci.is_hidden())
- {
- continue;
- }
-
std::string const& s = values[i];
if(!s.empty())
{
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index 044933e..a43a47e 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -41,7 +41,6 @@ struct column_parameters
std::string const header;
std::string const widest_text;
oenum_h_align const alignment;
- oenum_visibility const visibility;
oenum_elasticity const elasticity;
};