return s;
}
-QString format_time(double t, int prefix,
+QString format_time(double t, int prefix, TimeUnit unit,
unsigned int precision, bool sign)
{
- return format_si_value(t, "s", prefix, precision, sign);
+ if (unit == TimeUnit::Time)
+ return format_si_value(t, "s", prefix, precision, sign);
+ else
+ return format_si_value(t, "sa", prefix, precision, sign);
}
QString format_second(double second)
namespace pv {
namespace util {
+enum TimeUnit {
+ Time = 1,
+ Samples = 2
+};
+
extern const int FirstSIPrefixPower;
/**
* @return The formated value.
*/
QString format_time(
- double t, int prefix = -1, unsigned precision = 0, bool sign = true);
+ double t, int prefix = -1, TimeUnit unit = Time, unsigned precision = 0,
+ bool sign = true);
/**
* Formats a given time value with a SI prefix so that the
QString Cursor::get_text() const
{
- return pv::util::format_time(time_, view_.tick_prefix(), 2);
+ return util::format_time(time_, view_.tick_prefix(),
+ util::TimeUnit::Time, 2);
}
QRectF Cursor::label_rect(const QRectF &rect) const
const unsigned int prefix = view_.tick_prefix();
const double delta = second_->time() - first_->time();
return QString("%1 / %2").
- arg(util::format_time(delta, prefix, 2)).
+ arg(util::format_time(delta, prefix, util::TimeUnit::Time, 2)).
arg(util::format_si_value(1.0 / fabs(delta), "Hz", -1, 4));
}
// Draw a major tick
p.drawText(x, ValueMargin, 0, text_height,
AlignCenter | AlignTop | TextDontClip,
- pv::util::format_time(t, prefix));
+ util::format_time(t, prefix));
p.drawLine(QPointF(x, major_tick_y1),
QPointF(x, ruler_height));
}