Fixes to the way annotated prices are displayed
This commit is contained in:
parent
eb364f4183
commit
79c7478278
4 changed files with 28 additions and 35 deletions
|
|
@ -1014,19 +1014,13 @@ void amount_t::print(std::ostream& _out) const
|
|||
comm.print(out);
|
||||
}
|
||||
|
||||
// If there are any annotations associated with this commodity,
|
||||
// output them now.
|
||||
|
||||
if (comm.annotated) {
|
||||
annotated_commodity_t& ann(static_cast<annotated_commodity_t&>(comm));
|
||||
assert(! ann.details.price || &*ann.details.price != this);
|
||||
ann.write_annotations(out);
|
||||
}
|
||||
|
||||
// Things are output to a string first, so that if anyone has
|
||||
// specified a width or fill for _out, it will be applied to the
|
||||
// entire amount string, and not just the first part.
|
||||
// If there are any annotations associated with this commodity, output them
|
||||
// now.
|
||||
comm.write_annotations(out);
|
||||
|
||||
// Things are output to a string first, so that if anyone has specified a
|
||||
// width or fill for _out, it will be applied to the entire amount string,
|
||||
// and not just the first part.
|
||||
_out << out.str();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -737,17 +737,21 @@ annotated_commodity_t::strip_annotations(const keep_details_t& what_to_keep)
|
|||
return *new_comm;
|
||||
}
|
||||
|
||||
void annotated_commodity_t::write_annotations(std::ostream& out,
|
||||
const annotation_t& info)
|
||||
void annotated_commodity_t::write_annotations(std::ostream& out) const
|
||||
{
|
||||
if (info.price)
|
||||
out << " {" << *info.price << '}';
|
||||
details.print(out, parent().keep_base);
|
||||
}
|
||||
|
||||
if (info.date)
|
||||
out << " [" << format_date(*info.date, string("%Y/%m/%d")) << ']';
|
||||
void annotation_t::print(std::ostream& out, bool keep_base) const
|
||||
{
|
||||
if (price)
|
||||
out << " {" << (keep_base ? *price : price->unreduced()).rounded() << '}';
|
||||
|
||||
if (info.tag)
|
||||
out << " (" << *info.tag << ')';
|
||||
if (date)
|
||||
out << " [" << format_date(*date, string("%Y/%m/%d")) << ']';
|
||||
|
||||
if (tag)
|
||||
out << " (" << *tag << ')';
|
||||
}
|
||||
|
||||
bool compare_amount_commodities::operator()(const amount_t * left,
|
||||
|
|
@ -817,7 +821,8 @@ bool compare_amount_commodities::operator()(const amount_t * left,
|
|||
}
|
||||
}
|
||||
|
||||
commodity_pool_t::commodity_pool_t() : default_commodity(NULL)
|
||||
commodity_pool_t::commodity_pool_t()
|
||||
: default_commodity(NULL), keep_base(false)
|
||||
{
|
||||
TRACE_CTOR(commodity_pool_t, "");
|
||||
null_commodity = create("");
|
||||
|
|
@ -894,7 +899,7 @@ namespace {
|
|||
|
||||
std::ostringstream name;
|
||||
comm.print(name);
|
||||
annotated_commodity_t::write_annotations(name, details);
|
||||
details.print(name, comm.parent().keep_base);
|
||||
|
||||
DEBUG("amounts.commodities", "make_qualified_name for "
|
||||
<< comm.qualified_symbol << std::endl << details);
|
||||
|
|
|
|||
|
|
@ -391,11 +391,8 @@ struct annotation_t : public equality_comparable<annotation_t>
|
|||
}
|
||||
|
||||
void parse(std::istream& in);
|
||||
void print(std::ostream& out) const {
|
||||
out << "price " << (price ? price->to_string() : "NONE") << " "
|
||||
<< "date " << (date ? *date : date_t()) << " "
|
||||
<< "tag " << (tag ? *tag : "NONE");
|
||||
}
|
||||
|
||||
void print(std::ostream& out, bool keep_base = false) const;
|
||||
|
||||
bool valid() const {
|
||||
assert(*this);
|
||||
|
|
@ -486,13 +483,7 @@ public:
|
|||
}
|
||||
|
||||
virtual commodity_t& strip_annotations(const keep_details_t& what_to_keep);
|
||||
|
||||
virtual void write_annotations(std::ostream& out) const {
|
||||
annotated_commodity_t::write_annotations(out, details);
|
||||
}
|
||||
|
||||
static void write_annotations(std::ostream& out,
|
||||
const annotation_t& info);
|
||||
virtual void write_annotations(std::ostream& out) const;
|
||||
};
|
||||
|
||||
inline annotated_commodity_t&
|
||||
|
|
@ -535,6 +526,8 @@ public:
|
|||
commodity_t * null_commodity;
|
||||
commodity_t * default_commodity;
|
||||
|
||||
bool keep_base;
|
||||
|
||||
public:
|
||||
boost::function<optional<amount_t>
|
||||
(commodity_t& commodity,
|
||||
|
|
|
|||
|
|
@ -373,7 +373,8 @@ void global_scope_t::normalize_report_options(const string& verb)
|
|||
report_t& rep(report());
|
||||
|
||||
// jww (2009-02-09): These global are a hack, but hard to avoid.
|
||||
item_t::use_effective_date = rep.HANDLED(effective);
|
||||
item_t::use_effective_date = rep.HANDLED(effective);
|
||||
rep.session.commodity_pool->keep_base = rep.HANDLED(base);
|
||||
|
||||
if (rep.HANDLED(date_format_)) {
|
||||
output_datetime_format = rep.HANDLER(date_format_).str() + " %H:%M:%S";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue