Libksysguard

Formatter.h
1/*
2 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9// Own
10#include "Unit.h"
11#include "formatter_export.h"
12
13// Qt
14#include <QString>
15#include <QVariant>
16
18
19namespace KSysGuard
20{
21/**
22 * This enum type is used to specify format options.
23 */
24enum FormatOption {
25 FormatOptionNone = 0,
26 FormatOptionAgo = 1 << 0,
27 FormatOptionShowNull = 1 << 1,
28};
29Q_DECLARE_FLAGS(FormatOptions, FormatOption)
30
31/**
32 * A class for formatting sensor values
33 * @see FormatterWrapper, for using it from Qml
34 */
35class FORMATTER_EXPORT Formatter
36{
37public:
38 /**
39 * Returns the scale factor suitable for display.
40 *
41 * @param value The maximum output value.
42 * @param unit The unit of the value.
43 * @param targetPrefix Preferred metric prefix.
44 */
45 static qreal scaleDownFactor(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust);
46
47 /**
48 * Returns localized string that is suitable for display.
49 *
50 * @param value The maximum output value.
51 * @param unit The unit of the value.
52 * @param targetPrefix Preferred metric prefix.
53 */
54 static KLocalizedString localizedString(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust);
55
56 /**
57 * Converts @p value to the appropriate displayable string.
58 *
59 * The returned string is localized.
60 *
61 * @param value The value to be converted.
62 * @param unit The unit of the value.
63 * @param targetPrefix Preferred metric prefix.
64 * @param options
65 * @param precision The precision to use. If < 0, use a default value.
66 */
67 static QString formatValue(const QVariant &value,
68 Unit unit,
69 MetricPrefix targetPrefix = MetricPrefixAutoAdjust,
70 FormatOptions options = FormatOptionNone,
71 int precision = -1);
72
73 /**
74 * Returns a symbol that corresponds to the given @p unit.
75 *
76 * The returned unit symbol is localized.
77 */
78 static QString symbol(Unit unit);
79
80 /**
81 * Return the maximum length of a formatted string for the specified unit and font.
82 *
83 * @param unit The unit to use.
84 * @param font The font to use.
85 */
86 static qreal maximumLength(Unit unit, const QFont &font);
87};
88
89} // namespace KSysGuard
90
91Q_DECLARE_OPERATORS_FOR_FLAGS(KSysGuard::FormatOptions)
A class for formatting sensor values.
Definition Formatter.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.