]> sigrok.org Git - pulseview.git/blobdiff - pv/util.hpp
util: Added format_si_value
[pulseview.git] / pv / util.hpp
index 572bed31814e6bba0baa670027e1762f04b261c9..5d65694054ab2c0b2e6a9f652fc736abfc5da8cd 100644 (file)
@@ -31,18 +31,33 @@ namespace util {
 extern const int FirstSIPrefixPower;
 
 /**
- * Formats a given time value with the specified SI prefix.
+ * Formats a given value with the specified SI prefix.
+ * @param v The value to format.
+ * @param unit The unit of quantity.
+ * @param prefix The number of the prefix, from 0 for 'femto' up to
+ *   8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
+ * @param precision The number of digits after the decimal separator.
+ * @param sign Whether or not to add a sign also for positive numbers.
+ *
+ * @return The formated value.
+ */
+QString format_si_value(
+       double v, QString unit, int prefix = -1,
+       unsigned precision = 0, bool sign = true);
+
+/**
+ * Formats a given time with the specified SI prefix.
  * @param t The time value in seconds to format.
  * @param prefix The number of the prefix, from 0 for 'femto' up to
- *               8 for 'giga'.
- * @parma precision The number of digits after the decimal separator.
+ *   8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
+ * @param unit The unit of quantity.
+ * @param precision The number of digits after the decimal separator.
  * @param sign Whether or not to add a sign also for positive numbers.
  *
  * @return The formated value.
  */
 QString format_time(
-       double t, unsigned int prefix,
-       unsigned precision = 0, bool sign = true);
+       double t, int prefix = -1, unsigned precision = 0, bool sign = true);
 
 /**
  * Formats a given time value with a SI prefix so that the