Libksysguard

Formatter.h
1 /*
2  Copyright (C) 2019 Vlad Zahorodnii <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #pragma once
21 
22 // Own
23 #include "formatter_export.h"
24 #include "Unit.h"
25 
26 // Qt
27 #include <QString>
28 #include <QVariant>
29 
30 class KLocalizedString;
31 
32 namespace KSysGuard
33 {
34 
35 /**
36  * This enum type is used to specify format options.
37  */
38 enum FormatOption {
39  FormatOptionNone = 0,
40  FormatOptionAgo = 1 << 0,
41  FormatOptionShowNull = 1 << 1,
42 };
43 Q_DECLARE_FLAGS(FormatOptions, FormatOption)
44 
45 /**
46  * A class for formatting sensor values
47  * @see FormatterWrapper, for using it from Qml
48  */
49 class FORMATTER_EXPORT Formatter
50 {
51 public:
52  /**
53  * Returns the scale factor suitable for display.
54  *
55  * @param value The maximum output value.
56  * @param unit The unit of the value.
57  * @param targetPrefix Preferred metric prefix.
58  */
59  static qreal scaleDownFactor(const QVariant &value, Unit unit,
60  MetricPrefix targetPrefix = MetricPrefixAutoAdjust);
61 
62  /**
63  * Returns localized string that is suitable for display.
64  *
65  * @param value The maximum output value.
66  * @param unit The unit of the value.
67  * @param targetPrefix Preferred metric prefix.
68  */
69  static KLocalizedString localizedString(const QVariant &value, Unit unit,
70  MetricPrefix targetPrefix = MetricPrefixAutoAdjust);
71 
72  /**
73  * Converts @p value to the appropriate displayable string.
74  *
75  * The returned string is localized.
76  *
77  * @param value The value to be converted.
78  * @param unit The unit of the value.
79  * @param targetPrefix Preferred metric prefix.
80  * @param options
81  */
82  static QString formatValue(const QVariant &value, Unit unit,
83  MetricPrefix targetPrefix = MetricPrefixAutoAdjust,
84  FormatOptions options = FormatOptionNone);
85 
86  /**
87  * Returns a symbol that corresponds to the given @p unit.
88  *
89  * The returned unit symbol is localized.
90  */
91  static QString symbol(Unit unit);
92 };
93 
94 } // namespace KSysGuard
95 
96 Q_DECLARE_OPERATORS_FOR_FLAGS(KSysGuard::FormatOptions)
FormatOption
A class for formatting sensor values.
Definition: Formatter.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Mar 2 2021 02:46:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.