]> sigrok.org Git - pulseview.git/commitdiff
SamplingBar: Use nicer time format in the tooltip.
authorJens Steinhauser <redacted>
Thu, 22 May 2014 20:03:23 +0000 (22:03 +0200)
committerJoel Holdsworth <redacted>
Fri, 23 May 2014 20:07:36 +0000 (21:07 +0100)
pv/toolbars/samplingbar.cpp
pv/util.cpp
pv/util.h

index 05c730bf528fe35efdab94acea14be9183838fd6..085e0430582e08b5ff488b7b1d2a708ef35bca35 100644 (file)
@@ -35,6 +35,7 @@
 #include <pv/device/devinst.h>
 #include <pv/popups/deviceoptions.h>
 #include <pv/popups/probes.h>
+#include <pv/util.h>
 
 using boost::shared_ptr;
 using std::map;
@@ -456,16 +457,9 @@ bool SamplingBar::eventFilter(QObject *watched, QEvent *event)
        if ((watched == &_sample_count || watched == &_sample_rate) &&
                (event->type() == QEvent::ToolTip)) {
                double sec = (double)_sample_count.value() / _sample_rate.value();
-
-               QString str;
-               QTextStream(&str)
-                       << tr("Total sampling time: ")
-                       << fixed
-                       << qSetRealNumberPrecision(1)
-                       << sec
-                       << "s";
-
                QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
+
+               QString str = tr("Total sampling time: %1").arg(pv::util::format_second(sec));
                QToolTip::showText(help_event->globalPos(), str);
 
                return true;
index 28e0dfde50d2fb9230219c5bce3b18e58a70b2bc..a54bdcaf8f957e8df5b462b5594ef2842afae3e5 100644 (file)
@@ -55,5 +55,18 @@ QString format_time(double t, unsigned int prefix,
        return s;
 }
 
+QString format_second(double second)
+{
+       unsigned int i = 0;
+       int exp = - FirstSIPrefixPower;
+
+       while ((second * pow(10.0, exp)) > 999.0 && i < countof(SIPrefixes) - 1) {
+               i++;
+               exp -= 3;
+       }
+
+       return format_time(second, i, 0, false);
+}
+
 } // namespace util
 } // namespace pv
index 1af3ce93ac5f7179e346dde7310b03f4d2249007..572bed31814e6bba0baa670027e1762f04b261c9 100644 (file)
--- a/pv/util.h
+++ b/pv/util.h
@@ -44,6 +44,15 @@ QString format_time(
        double t, unsigned int prefix,
        unsigned precision = 0, bool sign = true);
 
+/**
+ * Formats a given time value with a SI prefix so that the
+ * value is between 1 and 999.
+ * @param second The time value in seconds to format.
+ *
+ * @return The formated value.
+ */
+QString format_second(double second);
+
 } // namespace util
 } // namespace pv