From: Soeren Apel Date: Sun, 9 Aug 2015 18:32:41 +0000 (+0200) Subject: Introduce time units X-Git-Tag: pulseview-0.3.0~150 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=96b6316ab8ed24551a0affb7a5819d1c97147a5c;p=pulseview.git Introduce time units --- diff --git a/pv/util.cpp b/pv/util.cpp index 83f2ae0b..e3619829 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -67,10 +67,13 @@ QString format_si_value(double v, QString unit, int prefix, 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) diff --git a/pv/util.hpp b/pv/util.hpp index f75c9572..f1351650 100644 --- a/pv/util.hpp +++ b/pv/util.hpp @@ -28,6 +28,11 @@ namespace pv { namespace util { +enum TimeUnit { + Time = 1, + Samples = 2 +}; + extern const int FirstSIPrefixPower; /** @@ -57,7 +62,8 @@ QString format_si_value( * @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 diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp index 512b5fa9..503031a7 100644 --- a/pv/view/cursor.cpp +++ b/pv/view/cursor.cpp @@ -55,7 +55,8 @@ bool Cursor::enabled() const 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 diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp index 46f24556..aec68919 100644 --- a/pv/view/cursorpair.cpp +++ b/pv/view/cursorpair.cpp @@ -164,7 +164,7 @@ QString CursorPair::format_string() 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)); } diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 2f9b140e..f25bcb8f 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -122,7 +122,7 @@ void Ruler::paintEvent(QPaintEvent*) // 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)); }