2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef PULSEVIEW_UTIL_HPP
22 #define PULSEVIEW_UTIL_HPP
36 extern const int FirstSIPrefixPower;
39 * Formats a given value with the specified SI prefix.
40 * @param v The value to format.
41 * @param unit The unit of quantity.
42 * @param prefix The number of the prefix, from 0 for 'femto' up to
43 * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
44 * @param precision The number of digits after the decimal separator.
45 * @param sign Whether or not to add a sign also for positive numbers.
47 * @return The formated value.
49 QString format_si_value(
50 double v, QString unit, int prefix = -1,
51 unsigned precision = 0, bool sign = true);
54 * Formats a given time with the specified SI prefix.
55 * @param t The time value in seconds to format.
56 * @param prefix The number of the prefix, from 0 for 'femto' up to
57 * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
58 * @param unit The unit of quantity.
59 * @param precision The number of digits after the decimal separator or period (.).
60 * @param step_size The delta between two consecutive time markers (if applicable).
61 * @param sign Whether or not to add a sign also for positive numbers.
63 * @return The formated value.
66 double t, int prefix = -1, TimeUnit unit = Time, unsigned precision = 0,
67 double step_size = 0, bool sign = true);
70 * Formats a given time value with a SI prefix so that the
71 * value is between 1 and 999.
72 * @param second The time value in seconds to format.
74 * @return The formated value.
76 QString format_second(double second);
81 #endif // PULSEVIEW_UTIL_HPP