diff options
author | John Wiegley <johnw@newartisans.com> | 2009-02-17 19:48:42 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-02-17 19:48:42 -0400 |
commit | 93d195f1d97c376c26e5a7e88d6b0fc6e3b8e2d0 (patch) | |
tree | f72c2d5adb24d446eaa763f56b2db47342df0045 /src | |
parent | 07f4aefdfde719c57aa4574a53e1f33b6e295a58 (diff) | |
download | fork-ledger-93d195f1d97c376c26e5a7e88d6b0fc6e3b8e2d0.tar.gz fork-ledger-93d195f1d97c376c26e5a7e88d6b0fc6e3b8e2d0.tar.bz2 fork-ledger-93d195f1d97c376c26e5a7e88d6b0fc6e3b8e2d0.zip |
Only display a final balance total if necessary
In the case where only one top-level account is being reported, there is
no reason to duplicate the total balance shown.
Diffstat (limited to 'src')
-rw-r--r-- | src/account.h | 12 | ||||
-rw-r--r-- | src/output.cc | 42 | ||||
-rw-r--r-- | src/output.h | 15 |
3 files changed, 38 insertions, 31 deletions
diff --git a/src/account.h b/src/account.h index bd0210db..d97df2e0 100644 --- a/src/account.h +++ b/src/account.h @@ -118,12 +118,12 @@ class account_t : public scope_t struct xdata_t : public supports_flags<> { -#define ACCOUNT_EXT_DISPLAYED 0x01 -#define ACCOUNT_EXT_SORT_CALC 0x02 -#define ACCOUNT_EXT_HAS_NON_VIRTUALS 0x04 -#define ACCOUNT_EXT_HAS_UNB_VIRTUALS 0x08 -#define ACCOUNT_EXT_VISITED 0x10 -#define ACCOUNT_EXT_MATCHING 0x20 +#define ACCOUNT_EXT_SORT_CALC 0x01 +#define ACCOUNT_EXT_HAS_NON_VIRTUALS 0x02 +#define ACCOUNT_EXT_HAS_UNB_VIRTUALS 0x04 +#define ACCOUNT_EXT_VISITED 0x08 +#define ACCOUNT_EXT_MATCHING 0x10 +#define ACCOUNT_EXT_DISPLAYED 0x20 value_t value; value_t total; diff --git a/src/output.cc b/src/output.cc index 35633889..2e068631 100644 --- a/src/output.cc +++ b/src/output.cc @@ -210,8 +210,10 @@ void format_entries::operator()(xact_t& xact) last_entry = xact.entry; } -void format_accounts::post_accounts(account_t& account) +std::size_t format_accounts::post_accounts(account_t& account) { + std::size_t displayed = 0; + // Don't ever print the top-most account if (account.parent) { bind_scope_t bound_scope(report, account); @@ -242,30 +244,36 @@ void format_accounts::post_accounts(account_t& account) " No, neither it nor its children were eligible for display"); } - if (format_account) + if (format_account) { + account.xdata().add_flags(ACCOUNT_EXT_DISPLAYED); + displayed++; + format.format(report.output_stream, bound_scope); + } } - foreach (accounts_map::value_type pair, account.accounts) - post_accounts(*pair.second); + foreach (accounts_map::value_type pair, account.accounts) { + if (post_accounts(*pair.second) > 0) + displayed++; + } + + return displayed; } void format_accounts::flush() { std::ostream& out(report.output_stream); - post_accounts(*report.session.master.get()); + std::size_t top_displayed = post_accounts(*report.session.master.get()); - if (print_final_total) { - assert(report.session.master->has_xdata()); - account_t::xdata_t& xdata(report.session.master->xdata()); + assert(report.session.master->has_xdata()); + account_t::xdata_t& xdata(report.session.master->xdata()); - if (! report.HANDLED(collapse) && xdata.total) { - out << "--------------------\n"; - xdata.value = xdata.total; - bind_scope_t bound_scope(report, *report.session.master); - format.format(out, bound_scope); - } + if (top_displayed > 1 && ! report.HANDLED(collapse) && xdata.total) { + out << "--------------------\n"; + xdata.value = xdata.total; + bind_scope_t bound_scope(report, *report.session.master); + format.format(out, bound_scope); } out.flush(); @@ -341,12 +349,12 @@ void format_equity::flush() out.flush(); } -void format_equity::post_accounts(account_t& account) +std::size_t format_equity::post_accounts(account_t& account) { std::ostream& out(report.output_stream); if (! account.has_flags(ACCOUNT_EXT_MATCHING)) - return; + return 0; value_t val = account.xdata().value; @@ -368,6 +376,8 @@ void format_equity::post_accounts(account_t& account) next_lines_format.format(out, bound_scope); } total += val; + + return 1; } } // namespace ledger diff --git a/src/output.h b/src/output.h index 6952a4a5..bb1b907b 100644 --- a/src/output.h +++ b/src/output.h @@ -163,14 +163,11 @@ protected: report_t& report; format_t format; item_predicate disp_pred; - bool print_final_total; public: format_accounts(report_t& _report, - const string& _format = "", - const bool _print_final_total = true) - : report(_report), format(_format), disp_pred(), - print_final_total(_print_final_total) + const string& _format = "") + : report(_report), format(_format), disp_pred() { TRACE_CTOR(format_accounts, "report&, const string&, const bool"); @@ -184,8 +181,8 @@ public: TRACE_DTOR(format_accounts); } - virtual void post_accounts(account_t& account); - virtual void flush(); + virtual std::size_t post_accounts(account_t& account); + virtual void flush(); virtual void operator()(account_t& account); }; @@ -209,8 +206,8 @@ class format_equity : public format_accounts TRACE_DTOR(format_equity); } - virtual void flush(); - virtual void post_accounts(account_t& account); + virtual std::size_t post_accounts(account_t& account); + virtual void flush(); }; } // namespace ledger |