lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master de5d0b8 060/156: Inline output_and_check_for_


From: Greg Chicares
Subject: [lmi-commits] [lmi] master de5d0b8 060/156: Inline output_and_check_for_page_break() function
Date: Tue, 30 Jan 2018 17:22:11 -0500 (EST)

branch: master
commit de5d0b80fbcdb92e4f1f09d1aa0838948fa87151
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Inline output_and_check_for_page_break() function
    
    This function is used only once, and it doesn't make much sense to have
    it in illustration_table_generator class as it doesn't really fit its
    role as just a simple wrapper of wx_table_generator defining the
    appearance used by the illustration tables.
    
    Doing this also allows to get rid of "page_bottom" argument to this
    class ctor, which will make it possible to reuse it when we don't care
    about the page bottom and pagination at all.
---
 ledger_pdf_generator_wx.cpp | 57 +++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 38 deletions(-)

diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 7ffb222..732b29a 100644
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -261,48 +261,17 @@ class illustration_table_generator : public 
wx_table_generator
     illustration_table_generator
         (pdf_writer_wx& writer
         ,wxDC& dc
-        ,int page_bottom
         )
         :wx_table_generator
             (dc
             ,writer.get_horz_margin()
             ,writer.get_page_width()
             )
-        ,page_bottom_(page_bottom)
     {
         use_condensed_style();
         align_right();
     }
 
-    // This is a wrapper around the base class output_row() which also adds
-    // breaks between row groups for readability and returns true if we need to
-    // start a new page.
-    bool output_and_check_for_page_break
-        (int year
-        ,int* pos_y
-        ,std::string const* values
-        )
-    {
-        wx_table_generator::output_row(pos_y, values);
-
-        if((year + 1) % rows_per_group == 0)
-            {
-            // We need a group break.
-            *pos_y += row_height();
-
-            // And possibly a page break, which will be necessary if we don't
-            // have enough space for another full group because we don't want
-            // to have page breaks in the middle of a group.
-            if(*pos_y >= page_bottom_ - rows_per_group*row_height())
-                {
-                return true;
-                }
-            }
-
-        // No need for a page break yet.
-        return false;
-    }
-
     // Return the amount of vertical space taken by separator lines in the
     // table headers.
     int get_separator_line_height() const
@@ -311,9 +280,6 @@ class illustration_table_generator : public 
wx_table_generator
         // look well.
         return row_height() / 2;
     }
-
-  private:
-    int page_bottom_ = 0;
 };
 
 class page
@@ -1760,6 +1726,10 @@ class page_with_tabular_report : public numbered_page
 
         auto const& columns = get_report_columns();
 
+        // Just some cached values used inside the loop below.
+        auto const row_height = table.row_height();
+        auto const page_bottom = get_footer_top();
+        auto const rows_per_group = 
illustration_table_generator::rows_per_group;
         std::vector<std::string> values(columns.size());
 
         // The table may need several pages, loop over them.
@@ -1789,11 +1759,22 @@ class page_with_tabular_report : public numbered_page
                         ;
                     }
 
-                if(table.output_and_check_for_page_break(year, &pos_y, 
values.data()))
+                table.output_row(&pos_y, values.data());
+
+                if((year + 1) % rows_per_group == 0)
                     {
-                    next_page(dc);
-                    numbered_page::render(ledger, writer, dc, 
interpolate_html);
-                    break;
+                    // We need a group break.
+                    pos_y += row_height;
+
+                    // And possibly a page break, which will be necessary if 
we don't
+                    // have enough space for another full group because we 
don't want
+                    // to have page breaks in the middle of a group.
+                    if(pos_y >= page_bottom - rows_per_group*row_height)
+                        {
+                        next_page(dc);
+                        numbered_page::render(ledger, writer, dc, 
interpolate_html);
+                        break;
+                        }
                     }
                 }
             }



reply via email to

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