lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6586] Suppress columns with only zeroes in group quote su


From: gchicares
Subject: [lmi-commits] [6586] Suppress columns with only zeroes in group quote summary (VZ)
Date: Fri, 13 May 2016 13:56:15 +0000 (UTC)

Revision: 6586
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6586
Author:   chicares
Date:     2016-05-13 13:56:15 +0000 (Fri, 13 May 2016)
Log Message:
-----------
Suppress columns with only zeroes in group quote summary (VZ)

Modified Paths:
--------------
    lmi/trunk/group_quote_pdf_gen_wx.cpp
    lmi/trunk/wx_table_generator.cpp
    lmi/trunk/wx_table_generator.hpp

Modified: lmi/trunk/group_quote_pdf_gen_wx.cpp
===================================================================
--- lmi/trunk/group_quote_pdf_gen_wx.cpp        2016-05-13 13:52:34 UTC (rev 
6585)
+++ lmi/trunk/group_quote_pdf_gen_wx.cpp        2016-05-13 13:56:15 UTC (rev 
6586)
@@ -56,6 +56,7 @@
 #include <wx/image.h>
 #include <wx/pdfdc.h>
 
+#include <cstring>                      // std::strstr()
 #include <limits>
 #include <stdexcept>
 #include <utility>                      // std::pair
@@ -954,34 +955,52 @@
         ,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;
+
     for(int col = 0; col < e_col_max; ++col)
         {
         column_definition const& cd = column_definitions[col];
-        std::string header(cd.header_);
+        std::string header;
 
         // The cast is only used to ensure that if any new elements are added
         // to the enum, the compiler would warn about their values not being
         // present in this switch.
         switch(static_cast<enum_group_quote_columns>(col))
             {
+            case e_col_supplemental_face_amount:
+            case e_col_total_face_amount:
+                if(!has_suppl_amount)
+                    {
+                    // Leave the header empty to hide this column.
+                    break;
+                    }
+                // Fall through
             case e_col_number:
             case e_col_name:
             case e_col_age:
             case e_col_dob:
             case e_col_basic_face_amount:
-            case e_col_supplemental_face_amount:
-            case e_col_total_face_amount:
-                // Nothing to do for these columns: their labels are literal.
+                // Labels of these columns are simple literals.
+                header = cd.header_;
                 break;
-            case e_col_basic_premium:
             case e_col_additional_premium:
             case e_col_total_premium:
+                if(!has_addl_premium)
+                    {
+                    // Leave the header empty to hide this column.
+                    break;
+                    }
+                // Fall through
+            case e_col_basic_premium:
                 {
                 // Labels of these columns are format strings as they need to
                 // be constructed dynamically.
-                LMI_ASSERT(header.find("%s") != std::string::npos);
+                LMI_ASSERT(std::strstr(cd.header_, "%s"));
                 header = wxString::Format
-                    (wxString(header), report_data_.premium_mode_
+                    (cd.header_, report_data_.premium_mode_
                     ).ToStdString();
                 }
                 break;

Modified: lmi/trunk/wx_table_generator.cpp
===================================================================
--- lmi/trunk/wx_table_generator.cpp    2016-05-13 13:52:34 UTC (rev 6585)
+++ lmi/trunk/wx_table_generator.cpp    2016-05-13 13:56:15 UTC (rev 6586)
@@ -74,25 +74,34 @@
     ,std::string const& widest_text
     )
 {
-    wxDCFontChanger set_header_font(dc_, get_header_font());
+    // There is no need to care about the column width for hidden columns.
+    int width;
+    if(header.empty())
+        {
+        width = 0;
+        }
+    else
+        {
+        wxDCFontChanger set_header_font(dc_, get_header_font());
 
-    // Set width to the special value of 0 for the variable width columns.
-    int width = widest_text.empty() ? 0 : dc_.GetTextExtent(widest_text).x;
+        // Set width to the special value of 0 for the variable width columns.
+        width = widest_text.empty() ? 0 : dc_.GetTextExtent(widest_text).x;
 
-    // Keep track of the maximal number of lines in a header as this determines
-    // the number of lines used for all of them. This is one plus the number of
-    // newlines in the anticipated case where there is no newline character at
-    // the beginning or end of the header's string representation.
-    increase_to_if_smaller(max_header_lines_, 1u + count_newlines(header));
+        // Keep track of the maximal number of lines in a header as this 
determines
+        // the number of lines used for all of them. This is one plus the 
number of
+        // newlines in the anticipated case where there is no newline 
character at
+        // the beginning or end of the header's string representation.
+        increase_to_if_smaller(max_header_lines_, 1u + count_newlines(header));
 
-    // Also increase the column width to be sufficiently wide to fit
-    // this header line if it has fixed width.
-    if(0 != width)
-        {
-        increase_to_if_smaller(width, dc_.GetMultiLineTextExtent(header).x);
+        // Also increase the column width to be sufficiently wide to fit
+        // this header line if it has fixed width.
+        if(0 != width)
+            {
+            increase_to_if_smaller(width, 
dc_.GetMultiLineTextExtent(header).x);
 
-        // Add roughly 1 em margins on both sides.
-        width += dc_.GetTextExtent("MM").x;
+            // Add roughly 1 em margins on both sides.
+            width += dc_.GetTextExtent("MM").x;
+            }
         }
 
     columns_.push_back(column_info(header, width));
@@ -152,6 +161,11 @@
     typedef std::vector<column_info>::const_iterator cici;
     for(cici i = columns_.begin(); i != columns_.end(); ++i)
         {
+        if(i->is_hidden())
+            {
+            continue;
+            }
+
         if(0 == i->width_)
             {
             num_expand++;
@@ -176,6 +190,11 @@
         typedef std::vector<column_info>::iterator cii;
         for(cii i = columns_.begin(); i != columns_.end(); ++i)
             {
+            if(i->is_hidden())
+                {
+                continue;
+                }
+
             if(0 == i->width_)
                 {
                 i->width_ = per_expand;
@@ -202,13 +221,19 @@
     std::size_t const num_columns = columns_.size();
     for(std::size_t col = 0; col < num_columns; ++col)
         {
-        int const width = columns_.at(col).width_;
+        column_info const& ci = columns_.at(col);
+        if(ci.is_hidden())
+            {
+            continue;
+            }
 
+        int const width = ci.width_;
+
         std::string const& s = values[col];
         if(!s.empty())
             {
             int x_text = x;
-            if(columns_.at(col).is_centered_)
+            if(ci.is_centered_)
                 {
                 // Centre the text for the columns configured to do it.
                 x_text += (width - dc_.GetTextExtent(s).x) / 2;
@@ -326,6 +351,11 @@
     ,std::string const& rhs
     )
 {
+    if(columns_.at(column).is_hidden())
+        {
+        return;
+        }
+
     wxRect const total_rect = cell_rect(column, y);
     {
     wxDCPenChanger set_transparent_pen(dc_, *wxTRANSPARENT_PEN);

Modified: lmi/trunk/wx_table_generator.hpp
===================================================================
--- lmi/trunk/wx_table_generator.hpp    2016-05-13 13:52:34 UTC (rev 6585)
+++ lmi/trunk/wx_table_generator.hpp    2016-05-13 13:56:15 UTC (rev 6586)
@@ -51,6 +51,13 @@
     // The table has the given total width and starts at the left margin.
     wx_table_generator(wxDC& dc, int left_margin, int total_width);
 
+    // Adds a column to the table. The total number of added columns determines
+    // the number of the expected value in output_row() calls.
+    //
+    // Providing an empty header suppresses the table display, while still
+    // taking into account in output_row(), providing a convenient way to hide
+    // a single column without changing the data representation.
+    //
     // Each column must either have a fixed width, specified as the width of
     // the longest text that may appear in this column, or be expandable
     // meaning that the rest of the page width is allocated to it which will be
@@ -134,6 +141,10 @@
             {
             }
 
+        // A column with empty header is considered to be suppressed and
+        // doesn't appear in the output at all.
+        bool is_hidden() const { return header_.empty(); }
+
         std::string header_;
         int width_;
         bool is_centered_;




reply via email to

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