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 */
66 static QString formatValue(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust, FormatOptions options = FormatOptionNone);
67
68 /**
69 * Returns a symbol that corresponds to the given @p unit.
70 *
71 * The returned unit symbol is localized.
72 */
73 static QString symbol(Unit unit);
74
75 /**
76 * Return the maximum length of a formatted string for the specified unit and font.
77 *
78 * @param unit The unit to use.
79 * @param font The font to use.
80 */
81 static qreal maximumLength(Unit unit, const QFont &font);
82};
83
84} // namespace KSysGuard
85
86Q_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 Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.