From 40ab81308025e9655074da37671c444b4257f867 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 26 Feb 2012 02:17:45 -0600 Subject: Don't print amounts when not necessary in 'print' --- src/print.cc | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/print.cc') diff --git a/src/print.cc b/src/print.cc index b7f72bf0..215ab30b 100644 --- a/src/print.cc +++ b/src/print.cc @@ -119,7 +119,12 @@ namespace { } } + std::size_t count = xact.posts.size(); + std::size_t index = 0; + foreach (post_t * post, xact.posts) { + index++; + if (! report.HANDLED(generated) && (post->has_flags(ITEM_TEMP | ITEM_GENERATED) && ! post->has_flags(POST_ANONYMIZED))) @@ -163,17 +168,15 @@ namespace { std::string::size_type slip = (static_cast(account_width) - static_cast(name.length())); - if (slip > 0) { - out.width(static_cast(slip)); - out << ' '; - } - - std::ostringstream amtbuf; string amt; if (post->amount_expr) { amt = post->amount_expr->text(); - } else { + } + else if (! (count == 2 && index == 2 && + (*xact.posts.begin())->amount.commodity() == + post->amount.commodity() && + ! (*xact.posts.begin())->cost && ! post->cost)) { int amount_width = (report.HANDLER(amount_width_).specified ? report.HANDLER(amount_width_).value.to_int() : 12); @@ -191,6 +194,7 @@ namespace { (static_cast(amt.length()) - static_cast(trimmed_amt.length())); + std::ostringstream amtbuf; if (slip + amt_slip < 2) amtbuf << string(2 - (slip + amt_slip), ' '); amtbuf << amt; @@ -208,9 +212,15 @@ namespace { amtbuf << " = " << *post->assigned_amount; string trailer = amtbuf.str(); - out << trailer; - - account_width += unistring(trailer).length(); + if (! trailer.empty()) { + if (slip > 0) { + out.width(static_cast(slip)); + out << ' '; + } + out << trailer; + + account_width += unistring(trailer).length(); + } } else { out << pbuf.str(); } -- cgit v1.2.3