X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Futil.cpp;h=192a2e06ba1571766bbab637e1135d1980b5904a;hp=029ae079b64fcea1253bc66ed5fead8f7969f757;hb=60d9b99a32e551cffd2b537d3e157d578a761c9b;hpb=ca810a8ce1f0257e78ad00bc8f794c68f7438cad diff --git a/pv/util.cpp b/pv/util.cpp index 029ae07..192a2e0 100644 --- a/pv/util.cpp +++ b/pv/util.cpp @@ -41,7 +41,7 @@ const int FirstSIPrefix = 8; const int FirstSIPrefixPower = -(FirstSIPrefix * 3); const double MinTimeDelta = 1e-15; // Anything below 1 fs can be considered zero -QString format_si_value(double v, QString unit, int prefix, +static QString format_si_value(double v, QString unit, int prefix, unsigned int precision, bool sign) { if (prefix < 0) { @@ -71,12 +71,18 @@ QString format_si_value(double v, QString unit, int prefix, return s; } +QString format_si_value(const Timestamp& v, QString unit, int prefix, + unsigned int precision, bool sign) +{ + return format_si_value(v.convert_to(), unit, prefix, precision, sign); +} + static QString pad_number(unsigned int number, int length) { return QString("%1").arg(number, length, 10, QChar('0')); } -static QString format_time_in_full(double t, signed precision, bool force_sign) +static QString format_time_in_full(double t, signed precision) { const unsigned int whole_seconds = abs((int) t); const unsigned int days = whole_seconds / (60 * 60 * 24); @@ -87,9 +93,9 @@ static QString format_time_in_full(double t, signed precision, bool force_sign) QString s; QTextStream ts(&s); - if (force_sign && (t >= 0)) + if (t >= 0) ts << "+"; - if (t < 0) + else ts << "-"; bool use_padding = false; @@ -142,7 +148,7 @@ static QString format_time_in_full(double t, signed precision, bool force_sign) } static QString format_time_with_si(double t, QString unit, int prefix, - unsigned int precision, bool sign) + unsigned int precision) { // The precision is always given without taking the prefix into account // so we need to deduct the number of decimals the prefix might imply @@ -153,11 +159,10 @@ static QString format_time_with_si(double t, QString unit, int prefix, (prefix >= pv::util::FirstSIPrefix) ? precision : std::max((int)(precision - prefix_order), 0); - return format_si_value(t, unit, prefix, relative_prec, sign); + return format_si_value(t, unit, prefix, relative_prec); } -QString format_time(double t, int prefix, TimeUnit unit, - unsigned int precision, double step_size, bool sign) +static QString format_time(double t, int prefix, TimeUnit unit, unsigned int precision) { // Make 0 appear as 0, not random +0 or -0 if (fabs(t) < MinTimeDelta) @@ -165,26 +170,26 @@ QString format_time(double t, int prefix, TimeUnit unit, // If we have to use samples then we have no alternative formats if (unit == Samples) - return format_time_with_si(t, "sa", prefix, precision, sign); - - // View zoomed way out -> low precision (0), high step size (>=60s) - // -> DD:HH:MM - if ((precision == 0) && (step_size >= 60)) - return format_time_in_full(t, -1, sign); + return format_time_with_si(t, "sa", prefix, precision); // View in "normal" range -> medium precision, medium step size // -> HH:MM:SS.mmm... or xxxx (si unit) if less than 60 seconds // View zoomed way in -> high precision (>3), low step size (<1s) // -> HH:MM:SS.mmm... or xxxx (si unit) if less than 60 seconds if (abs(t) < 60) - return format_time_with_si(t, "s", prefix, precision, sign); + return format_time_with_si(t, "s", prefix, precision); else - return format_time_in_full(t, precision, sign); + return format_time_in_full(t, precision); +} + +QString format_time(const Timestamp& t, int prefix, TimeUnit unit, unsigned int precision) +{ + return format_time(t.convert_to(), prefix, unit, precision); } -QString format_second(double second) +QString format_second(const Timestamp& second) { - return format_si_value(second, "s", -1, 0, false); + return format_si_value(second.convert_to(), "s", -1, 0, false); } } // namespace util