X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Futil.hpp;h=ba6702f79f175f345ddfd814ae6fc1ae2ceeda78;hb=ac98198803da204ae26da8592c6e81a912b4a1af;hp=572bed31814e6bba0baa670027e1762f04b261c9;hpb=2acdb232d6bb452cfdfaea3ef5218fb4da592329;p=pulseview.git diff --git a/pv/util.hpp b/pv/util.hpp index 572bed3..ba6702f 100644 --- a/pv/util.hpp +++ b/pv/util.hpp @@ -18,31 +18,53 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef PULSEVIEW_UTIL_H -#define PULSEVIEW_UTIL_H +#ifndef PULSEVIEW_UTIL_HPP +#define PULSEVIEW_UTIL_HPP -#include +#include #include namespace pv { namespace util { +enum TimeUnit { + Time = 1, + Samples = 2 +}; + 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 or period (.). + * @param step_size The delta between two consecutive time markers (if applicable). * @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, TimeUnit unit = Time, unsigned precision = 0, + double step_size = 0, bool sign = true); /** * Formats a given time value with a SI prefix so that the @@ -56,4 +78,4 @@ QString format_second(double second); } // namespace util } // namespace pv -#endif // PULSEVIEW_UTIL_H +#endif // PULSEVIEW_UTIL_HPP