SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
numberformat.h
Go to the documentation of this file.
1
18#ifndef OPENSWMMVIS_PLOT_NUMBERFORMAT_H
19#define OPENSWMMVIS_PLOT_NUMBERFORMAT_H
20
21#include <QString>
22
23namespace openswmmvis::plot {
24
32enum class NumberFormatMode {
33 Decimals = 0,
35 Scientific = 2,
36 Engineering = 3,
37 Thousands = 4
38};
39
43 int count = 2;
44
49 QString custom;
50
52 int effectiveCount() const noexcept;
53
56 char fmtChar() const noexcept;
57
61 bool hasValidCustom() const;
62
65 QString printfSpec() const;
66
68 QString format(double v) const;
69};
70
107
109inline constexpr int axisNumberFormatPresetCount = 17;
110
113[[nodiscard]] NumberFormat numberFormatForPreset(int preset);
114
121[[nodiscard]] int presetForNumberFormat(NumberFormatMode mode, int count);
122
123} // namespace openswmmvis::plot
124
125#endif // OPENSWMMVIS_PLOT_NUMBERFORMAT_H
Definition chartproperties.h:34
NumberFormat numberFormatForPreset(int preset)
The mode + count a preset stands for. Out-of-range input falls back to two decimals,...
Definition numberformat.cpp:126
NumberFormatMode
Interpretation of NumberFormat::count.
Definition numberformat.h:32
@ Scientific
1.23e+04: count mantissa decimals ('e').
@ Decimals
Fixed-point: count digits after the point ('f').
@ SignificantFigures
General: count significant figures ('g').
@ Engineering
12.3e+03: exponent a multiple of 3, count mantissa decimals.
@ Thousands
12,345.68: locale group separators, count decimals.
constexpr int axisNumberFormatPresetCount
Number of presets; the valid range is [0, axisNumberFormatPresetCount).
Definition numberformat.h:109
AxisNumberFormatPreset
The axis-format choices offered to the user, as one combined list.
Definition numberformat.h:88
@ Decimals6
12.345679
Definition numberformat.h:94
@ SigFigs3
12.3
Definition numberformat.h:95
@ SigFigs4
12.35
Definition numberformat.h:96
@ Scientific2
1.23e+01
Definition numberformat.h:98
@ Decimals4
12.3457
Definition numberformat.h:93
@ Scientific4
1.2346e+01
Definition numberformat.h:100
@ Scientific3
1.235e+01
Definition numberformat.h:99
@ Integer
12
Definition numberformat.h:89
@ Thousands2
12,345.68
Definition numberformat.h:105
@ SigFigs6
12.3457
Definition numberformat.h:97
@ ThousandsInteger
12,346
Definition numberformat.h:103
@ Engineering3
12.346e+00
Definition numberformat.h:102
@ Decimals1
12.3
Definition numberformat.h:90
@ Thousands1
12,345.7
Definition numberformat.h:104
@ Engineering2
12.35e+00 / 1.23e+03
Definition numberformat.h:101
@ Decimals3
12.346
Definition numberformat.h:92
@ Decimals2
12.35
Definition numberformat.h:91
int presetForNumberFormat(NumberFormatMode mode, int count)
The preset that best represents mode + count.
Definition numberformat.cpp:139
QVector< int > v
pool vertex indices
Definition pslgminsize.cpp:159
A mode + count describing how to render a double.
Definition numberformat.h:41
QString custom
Optional user-supplied printf spec (e.g. "%.2f", "%.1f m"). When it holds a single valid floating-poi...
Definition numberformat.h:49
int effectiveCount() const noexcept
Effective, clamped digit count for the current mode.
Definition numberformat.cpp:18
NumberFormatMode mode
Definition numberformat.h:42
bool hasValidCustom() const
True when custom is a single, safe floating-point printf conversion (specifier in eEfFgGaA,...
Definition numberformat.cpp:62
QString format(double v) const
Format v for hand-drawn ticks, labels, tooltips, stats.
Definition numberformat.cpp:80
int count
Decimals (>=0) or sig figs (>=1).
Definition numberformat.h:43
char fmtChar() const noexcept
printf conversion the mode maps onto: 'f' (Decimals, Thousands), 'g' (SignificantFigures),...
Definition numberformat.cpp:27
QString printfSpec() const
printf spec for QValueAxis::setLabelFormat — custom when valid, else e.g. "%.2f" / "%....
Definition numberformat.cpp:73