lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 9b94a39 8/8: Don't pass "hidden" columns into


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9b94a39 8/8: Don't pass "hidden" columns into class wx_table_generator
Date: Mon, 6 Aug 2018 18:36:25 -0400 (EDT)

branch: master
commit 9b94a39c2b1119d440ca5fceffa117629973d0de
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Don't pass "hidden" columns into class wx_table_generator
    
    Passing a "hidden" column and a boolean indicating that it should be
    ignored is less clear than doing nothing.
---
 group_quote_pdf_gen_wx.cpp  | 25 +++++++++++++++++++------
 ledger_pdf_generator_wx.cpp | 45 ++++++++++++++++++++++++++++++++-------------
 wx_table_generator.cpp      | 33 ++++++++++++++++++++++-----------
 wx_table_generator.hpp      | 14 +++++++-------
 4 files changed, 80 insertions(+), 37 deletions(-)

diff --git a/group_quote_pdf_gen_wx.cpp b/group_quote_pdf_gen_wx.cpp
index 9382865..0e937e9 100644
--- a/group_quote_pdf_gen_wx.cpp
+++ b/group_quote_pdf_gen_wx.cpp
@@ -686,7 +686,6 @@ void group_quote_pdf_generator_wx::save(std::string const& 
output_filename)
 
     std::vector<column_parameters> vc;
     std::vector<int> indices;
-    int visible_column_count = 0;
     for(int i = 0; i < e_col_max; ++i)
         {
         column_definition const& cd = column_definitions[i];
@@ -737,17 +736,16 @@ void group_quote_pdf_generator_wx::save(std::string 
const& output_filename)
                 break;
             }
 
-        indices.push_back(visible_column_count);
+        indices.push_back(lmi::ssize(vc));
         cd.visibility_ = visibility;
         if(oe_shown == visibility)
             {
-            ++visible_column_count;
+            vc.push_back({header, cd.widest_text_, alignment, visibility, 
elasticity});
             }
-        vc.push_back({header, cd.widest_text_, alignment, visibility, 
elasticity});
         }
     // Add a one-past-the-end index equal to the last value, because
     // some member functions of class wx_table_generator expect it.
-    indices.push_back(visible_column_count);
+    indices.push_back(lmi::ssize(vc));
 
     wx_table_generator table_gen
         (group_quote_style_tag{}
@@ -792,7 +790,17 @@ void group_quote_pdf_generator_wx::save(std::string const& 
output_filename)
 
     for(auto const& i : rows_)
         {
-        table_gen.output_row(pos_y, i.output_values);
+        LMI_ASSERT(lmi::ssize(i.output_values) == 
lmi::ssize(column_definitions));
+        std::vector<std::string> visible_values;
+        for(int j = 0; j < e_col_max; ++j)
+            {
+            if(oe_shown == column_definitions[j].visibility_)
+                {
+                visible_values.push_back(i.output_values[j]);
+                }
+            }
+
+        table_gen.output_row(pos_y, visible_values);
 
         if(last_row_y <= pos_y)
             {
@@ -1101,6 +1109,11 @@ void 
group_quote_pdf_generator_wx::output_aggregate_values
 
     for(int i = e_first_totalled_column; i < e_col_max; ++i)
         {
+        if(oe_shown != column_definitions[i].visibility_)
+            {
+            continue;
+            }
+
         int const decimals =
             ((e_col_basic_face_amount           == i) ? 0
             :(e_col_basic_premium               == i) ? 2
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 5007cf4..7884394 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -38,6 +38,7 @@
 #include "miscellany.hpp"               // lmi_tolower(), page_count()
 #include "oecumenic_enumerations.hpp"
 #include "pdf_writer_wx.hpp"
+#include "ssize_lmi.hpp"
 #include "wx_table_generator.hpp"
 
 #include <wx/pdfdc.h>
@@ -362,26 +363,24 @@ class using_illustration_table
         std::vector<column_parameters> vc;
         std::vector<int> indices;
         int column = 0;
-        int visible_column_count = 0;
         for(auto const& i : get_table_columns())
             {
-            indices.push_back(visible_column_count);
+            indices.push_back(lmi::ssize(vc));
             if(!should_hide_column(ledger, column))
                 {
-                ++visible_column_count;
+                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
-                 ,should_hide_column(ledger, column) ? oe_hidden : oe_shown
-                 ,oe_inelastic
-                });
             ++column;
             }
         // Add a one-past-the-end index equal to the last value, because
         // some member functions of class wx_table_generator expect it.
-        indices.push_back(visible_column_count);
+        indices.push_back(lmi::ssize(vc));
 
         // Arguably, should_hide_column() should return an enumerator--see:
         //   https://lists.nongnu.org/archive/html/lmi/2018-05/msg00026.html
@@ -1505,7 +1504,17 @@ class numeric_summary_table_cell
                             ;
                         }
 
-                    table_gen.output_row(pos_y, output_values);
+                    std::vector<std::string> visible_values;
+                    // PDF !! Subsume this into foregoing for-loop.
+                    for(int j = 0; j < lmi::ssize(columns); ++j)
+                        {
+                        if(oe_shown == columns[j].visibility)
+                            {
+                            visible_values.push_back(output_values[j]);
+                            }
+                        }
+
+                    table_gen.output_row(pos_y, visible_values);
                     break;
                 }
             }
@@ -1635,7 +1644,17 @@ class page_with_tabular_report
                         ;
                     }
 
-                table_gen.output_row(pos_y, output_values);
+                std::vector<std::string> visible_values;
+                // PDF !! Subsume this into foregoing for-loop.
+                for(int j = 0; j < lmi::ssize(columns); ++j)
+                    {
+                    if(oe_shown == columns[j].visibility)
+                        {
+                        visible_values.push_back(output_values[j]);
+                        }
+                    }
+
+                table_gen.output_row(pos_y, visible_values);
 
                 ++year;
                 if(year == year_max)
diff --git a/wx_table_generator.cpp b/wx_table_generator.cpp
index c1d18bc..7021dc4 100644
--- a/wx_table_generator.cpp
+++ b/wx_table_generator.cpp
@@ -188,12 +188,15 @@ void wx_table_generator::output_headers
 
 void wx_table_generator::output_super_header
         (std::string const&           header
-        ,std::size_t                  begin_column
-        ,std::size_t                  end_column
+        ,std::size_t                  a_begin_column
+        ,std::size_t                  a_end_column
         ,int&                         pos_y
         ,oenum_render_or_only_measure output_mode
         )
 {
+    int begin_column = indices_[a_begin_column];
+    int end_column   = indices_[a_end_column];
+
     std::vector<std::string> const lines(split_into_lines(header));
     int const anticipated_pos_y = pos_y + row_height() * lines.size();
 
@@ -226,12 +229,14 @@ void wx_table_generator::output_super_header
 /// Shade the background of a single cell; center the given contents.
 
 void wx_table_generator::output_highlighted_cell
-    (std::size_t        column
+    (std::size_t        a_column
     ,int                y
     ,std::string const& value
     )
 {
-    LMI_ASSERT(column < all_columns().size());
+    int column = indices_[a_column];
+
+    LMI_ASSERT(column < lmi::ssize(all_columns()));
     if(all_columns().at(column).is_hidden())
         {
         return;
@@ -275,11 +280,13 @@ void wx_table_generator::output_row
 /// separator after the last column.
 
 void wx_table_generator::output_vert_separator
-    (std::size_t before_column
+    (std::size_t a_before_column
     ,int         y
     )
 {
-    LMI_ASSERT(before_column <= all_columns().size());
+    int before_column = indices_[a_before_column];
+
+    LMI_ASSERT(before_column <= lmi::ssize(all_columns()));
 
     do_output_vert_separator(cell_pos_x(before_column), y, y + row_height_);
 }
@@ -289,12 +296,15 @@ void wx_table_generator::output_vert_separator
 /// The column range is specified as [begin, end), as is usual in C++.
 
 void wx_table_generator::output_horz_separator
-    (std::size_t                  begin_column
-    ,std::size_t                  end_column
+    (std::size_t                  a_begin_column
+    ,std::size_t                  a_end_column
     ,int                          y
     ,oenum_render_or_only_measure output_mode
     )
 {
+    int begin_column = indices_[a_begin_column];
+    int end_column   = indices_[a_end_column];
+
     switch(output_mode)
         {
         case oe_render:
@@ -304,12 +314,12 @@ void wx_table_generator::output_horz_separator
         }
 
     LMI_ASSERT(begin_column < end_column);
-    LMI_ASSERT(end_column <= all_columns().size());
+    LMI_ASSERT(end_column <= lmi::ssize(all_columns()));
 
     int const x1 = cell_pos_x(begin_column);
 
     int x2 = x1;
-    for(std::size_t i = begin_column; i < end_column; ++i)
+    for(int i = begin_column; i < end_column; ++i)
         {
         x2 += all_columns().at(i).col_width();
         }
@@ -333,8 +343,9 @@ int wx_table_generator::separator_line_height() const
     return row_height() / 2;
 }
 
-wxRect wx_table_generator::external_text_rect(std::size_t column, int y) const
+wxRect wx_table_generator::external_text_rect(std::size_t a_column, int y) 
const
 {
+    int column = indices_[a_column];
     return text_rect(column, y);
 }
 
diff --git a/wx_table_generator.hpp b/wx_table_generator.hpp
index de5c687..044933e 100644
--- a/wx_table_generator.hpp
+++ b/wx_table_generator.hpp
@@ -100,24 +100,24 @@ class wx_table_generator
 
     void output_super_header
         (std::string const&           header
-        ,std::size_t                  begin_column
-        ,std::size_t                  end_column
+        ,std::size_t                  a_begin_column
+        ,std::size_t                  a_end_column
         ,int&                         pos_y
         ,oenum_render_or_only_measure output_mode = oe_render
         );
 
     void output_highlighted_cell
-        (std::size_t        column
+        (std::size_t        a_column
         ,int                y
         ,std::string const& value
         );
 
     void output_row(int& pos_y, std::vector<std::string> const values);
 
-    void output_vert_separator(std::size_t before_column, int y);
+    void output_vert_separator(std::size_t a_before_column, int y);
     void output_horz_separator
-        (std::size_t                  begin_column
-        ,std::size_t                  end_column
+        (std::size_t                  a_begin_column
+        ,std::size_t                  a_end_column
         ,int                          y
         ,oenum_render_or_only_measure output_mode = oe_render
         );
@@ -128,7 +128,7 @@ class wx_table_generator
     // Used only by group_quote_pdf_generator_wx::output_aggregate_values(),
     // in a context where something like output_highlighted_cell() should
     // probably be used instead. PDF !! revisit this later
-    wxRect external_text_rect(std::size_t column, int y) const;
+    wxRect external_text_rect(std::size_t a_column, int y) const;
 
   private:
     void enroll_column(column_parameters const&);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]