Audacity
3.2.0
libraries
lib-numeric-formats
NumericConverterFormatter.cpp
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/**********************************************************************
3
4
Audacity: A Digital Audio Editor
5
6
@file NumericConverterFormatter.cpp
7
8
Dmitry Vedenko
9
10
**********************************************************************/
11
#include "
NumericConverterFormatter.h
"
12
13
#include <cmath>
14
15
namespace
16
{
17
size_t
CalculateDigits
(
size_t
rangeEnd)
18
{
19
if
(rangeEnd == 0)
20
return
0;
21
22
--rangeEnd;
23
24
size_t
digitsCount = 0;
25
26
while
(rangeEnd > 0)
27
{
28
rangeEnd /= 10;
29
++digitsCount;
30
}
31
32
return
digitsCount;
33
}
34
}
35
36
NumericField::NumericField
(
size_t
_digits,
bool
zeropad)
37
: digits { _digits }
38
{
39
if
(zeropad &&
digits
> 1)
40
formatStr
.Printf(
wxT
(
"%%0%zud"
),
digits
);
// ex. "%03d" if digits is 3
41
else
42
formatStr
=
"%d"
;
43
}
44
45
NumericField
NumericField::ForRange
(
size_t
range,
bool
zeropad,
size_t
minDigits)
46
{
47
// Previously, Audacity used 5 digits by default (why?)
48
return
NumericField
(
49
range > 1 ? std::max(minDigits,
CalculateDigits
(range)) : 5, zeropad);
50
}
51
52
NumericField
NumericField::WithDigits
(
size_t
digits,
bool
zeropad)
53
{
54
return
NumericField
(
digits
, zeropad);
55
}
56
57
NumericConverterFormatter::~NumericConverterFormatter
()
58
{
59
}
60
61
void
NumericConverterFormatter::UpdateFormatForValue
(
double
,
bool
)
62
{
63
}
64
65
const
wxString&
NumericConverterFormatter::GetPrefix
()
const
66
{
67
return
mPrefix
;
68
}
69
70
const
NumericFields
&
NumericConverterFormatter::GetFields
()
const
71
{
72
return
mFields
;
73
}
74
75
const
DigitInfos
&
NumericConverterFormatter::GetDigitInfos
()
const
76
{
77
return
mDigits
;
78
}
wxT
wxT("CloseDown"))
NumericConverterFormatter.h
NumericFields
std::vector< NumericField > NumericFields
Definition:
NumericConverterFormatter.h:43
DigitInfos
std::vector< DigitInfo > DigitInfos
Definition:
NumericConverterFormatter.h:52
anonymous_namespace{NumericConverterFormatter.cpp}::CalculateDigits
size_t CalculateDigits(size_t rangeEnd)
Definition:
NumericConverterFormatter.cpp:17
NumericConverterFormatter::GetFields
const NumericFields & GetFields() const
Definition:
NumericConverterFormatter.cpp:70
NumericConverterFormatter::mFields
NumericFields mFields
Definition:
NumericConverterFormatter.h:89
NumericConverterFormatter::GetPrefix
const wxString & GetPrefix() const
Definition:
NumericConverterFormatter.cpp:65
NumericConverterFormatter::mDigits
DigitInfos mDigits
Definition:
NumericConverterFormatter.h:90
NumericConverterFormatter::GetDigitInfos
const DigitInfos & GetDigitInfos() const
Definition:
NumericConverterFormatter.cpp:75
NumericConverterFormatter::~NumericConverterFormatter
virtual ~NumericConverterFormatter()
Definition:
NumericConverterFormatter.cpp:57
NumericConverterFormatter::UpdateFormatForValue
virtual void UpdateFormatForValue(double value, bool canShrink)
Potentially updates the format so it can fit the value. Default implementation is empty.
Definition:
NumericConverterFormatter.cpp:61
NumericConverterFormatter::mPrefix
wxString mPrefix
Definition:
NumericConverterFormatter.h:87
NumericField
Definition:
NumericConverterFormatter.h:23
NumericField::WithDigits
static NumericField WithDigits(size_t digits, bool zeropad=true)
Definition:
NumericConverterFormatter.cpp:52
NumericField::ForRange
static NumericField ForRange(size_t range, bool zeropad=true, size_t minDigits=0)
Definition:
NumericConverterFormatter.cpp:45
NumericField::NumericField
NumericField(size_t digits, bool zeropad)
Definition:
NumericConverterFormatter.cpp:36
NumericField::formatStr
wxString formatStr
Definition:
NumericConverterFormatter.h:38
NumericField::digits
size_t digits
Definition:
NumericConverterFormatter.h:35
Generated by
1.9.3