Audacity 3.2.0
NumericConverter.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 NumericConverter.h
6
7 Dominic Mazzoni
8
9 See NumericConverter.cpp for documentation on how to use the
10 format string to specify how a NumericTextCtrl's fields are
11 laid out.
12
13 Paul Licameli split from NumericTextCtrl.h
14
15**********************************************************************/
16#ifndef __AUDACITY_NUMERIC_CONVERTER__
17#define __AUDACITY_NUMERIC_CONVERTER__
18
19#include <memory>
20
24
26#include "TranslatableString.h"
27
28
29class NUMERIC_FORMATS_API NumericConverter /* not final */
30{
31public:
33 const NumericFormatSymbol & formatName = {},
34 double value = 0.0f);
35
36 virtual ~NumericConverter();
37
38 // ValueToControls() formats a raw value (either provided as
39 // argument, or mValue, depending on the version of the function
40 // called). The result is stored to mValueString.
41 virtual void ValueToControls();
42 virtual void ValueToControls(double rawValue, bool nearest = true);
43
44 // Converts the stored formatted string (mValueString) back to a
45 // raw value (mValue).
46 virtual void ControlsToValue();
47
48private:
49 bool ParseFormatString(const TranslatableString & untranslatedFormat);
50
51public:
52 // returns true if the format type really changed:
53 bool SetTypeAndFormatName(const NumericConverterType& type, const NumericFormatSymbol& formatName);
54 // returns true if the format name really changed:
55 bool SetFormatName(const NumericFormatSymbol & formatName);
56 // Could be empty if custom format is used
57 NumericFormatSymbol GetFormatName() const;
58
59 bool SetCustomFormat(const TranslatableString& customFormat);
60
61 void SetValue(double newValue);
62 void SetMinValue(double minValue);
63 void ResetMinValue();
64 void SetMaxValue(double maxValue);
65 void ResetMaxValue();
66
67 double GetValue();
68 wxString GetString();
69
70 // Adjust the value by the number "steps" in the active format.
71 // Increment if "dir" is 1, decrement if "dir" is -1.
72 void Adjust(int steps, int dir, int focusedDigit);
73
74 void Increment(int focusedDigit = -1);
75 void Decrement(int focusedDigit = -1);
76
77protected:
78 bool UpdateFormatter();
79 virtual void OnFormatUpdated();
80
82
84
85 double mValue;
86
87 double mMinValue;
88 double mMaxValue;
89 double mInvalidValue { -1 };
90
91 std::unique_ptr<NumericConverterFormatter>
93
96
97 // Formatted mValue, by ValueToControls().
98 wxString mValueString;
99 std::vector<wxString> mFieldValueStrings;
100
102
103private:
104 int GetSafeFocusedDigit(int focusedDigit) const noexcept;
105};
106#endif // __AUDACITY_NUMERIC_CONVERTER__
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A context in which formatter operates.
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
NumericConverterType mType
NumericFormatSymbol mFormatSymbol
std::vector< wxString > mFieldValueStrings
FormatterContext mContext
std::unique_ptr< NumericConverterFormatter > mFormatter
TranslatableString mCustomFormat
Observer::Subscription mFormatUpdatedSubscription
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Holds a msgid for the translation catalog; may also bind format arguments.