]> sigrok.org Git - pulseview.git/blame - pv/util.hpp
MainWindow: Moved static constants to top of class definitions
[pulseview.git] / pv / util.hpp
CommitLineData
f0c9f81c
JS
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef PULSEVIEW_UTIL_H
22#define PULSEVIEW_UTIL_H
23
d9e71737 24#include <cmath>
f0c9f81c
JS
25
26#include <QString>
27
28namespace pv {
29namespace util {
30
31extern const int FirstSIPrefixPower;
32
33/**
4bc10a91
JH
34 * Formats a given value with the specified SI prefix.
35 * @param v The value to format.
36 * @param unit The unit of quantity.
37 * @param prefix The number of the prefix, from 0 for 'femto' up to
38 * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
39 * @param precision The number of digits after the decimal separator.
40 * @param sign Whether or not to add a sign also for positive numbers.
41 *
42 * @return The formated value.
43 */
44QString format_si_value(
45 double v, QString unit, int prefix = -1,
46 unsigned precision = 0, bool sign = true);
47
48/**
49 * Formats a given time with the specified SI prefix.
f0c9f81c
JS
50 * @param t The time value in seconds to format.
51 * @param prefix The number of the prefix, from 0 for 'femto' up to
4bc10a91
JH
52 * 8 for 'giga'. If prefix is set to -1, the prefix will be calculated.
53 * @param unit The unit of quantity.
54 * @param precision The number of digits after the decimal separator.
f0c9f81c
JS
55 * @param sign Whether or not to add a sign also for positive numbers.
56 *
57 * @return The formated value.
58 */
59QString format_time(
4bc10a91 60 double t, int prefix = -1, unsigned precision = 0, bool sign = true);
f0c9f81c 61
62974f45
JS
62/**
63 * Formats a given time value with a SI prefix so that the
64 * value is between 1 and 999.
65 * @param second The time value in seconds to format.
66 *
67 * @return The formated value.
68 */
69QString format_second(double second);
70
f0c9f81c
JS
71} // namespace util
72} // namespace pv
73
74#endif // PULSEVIEW_UTIL_H