Audacity 3.2.0
NumericConverterFormatter.h
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.h
7
8 Dmitry Vedenko
9
10 **********************************************************************/
11#pragma once
12
13#include <optional>
14#include <vector>
15
16#include <wx/string.h>
17
18#include "Observer.h"
19
20class AudacityProject;
21
22struct NUMERIC_FORMATS_API NumericField final
23{
24private:
25 NumericField(size_t digits, bool zeropad);
26
27public:
28 static NumericField ForRange(size_t range, bool zeropad = true, size_t minDigits = 0);
29 static NumericField WithDigits(size_t digits, bool zeropad = true);
30
31 NumericField(const NumericField&) = default;
33 // NumericField( NumericField && ) = default;
34 // NumericField &operator = ( NumericField && ) = default;
35 size_t digits { 0 };
36
37 wxString label;
38 wxString formatStr;
39
40 size_t pos { wxString::npos }; // Index of this field in the ValueString
41};
42
43using NumericFields = std::vector<NumericField>;
44
45struct NUMERIC_FORMATS_API DigitInfo final
46{
47 size_t field; // Which field
48 size_t index; // Index of this digit within the field
49 size_t pos; // Position in the ValueString
50};
51
52using DigitInfos = std::vector<DigitInfo>;
53
55{
56 double value;
57 bool shrunk;
58};
59
60struct NUMERIC_FORMATS_API NumericConverterFormatter /* not final */ :
61 public Observer::Publisher<NumericConverterFormatChangedMessage>
62{
64
65 struct NUMERIC_FORMATS_API ConversionResult final
66 {
67 wxString valueString;
68 std::vector<wxString> fieldValueStrings;
69 };
70
72 virtual void UpdateFormatForValue(double value, bool canShrink);
74 virtual ConversionResult
75 ValueToString(double value, bool nearest) const = 0;
76
77 virtual std::optional<double>
78 StringToValue(const wxString& value) const = 0;
79
80 virtual double SingleStep(double value, int digitIndex, bool upwards) const = 0;
81
82 const wxString& GetPrefix() const;
83 const NumericFields& GetFields() const;
84 const DigitInfos& GetDigitInfos() const;
85
86protected:
87 wxString mPrefix;
88
91};
std::vector< NumericField > NumericFields
std::vector< DigitInfo > DigitInfos
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
constexpr size_t npos(-1)
virtual ConversionResult ValueToString(double value, bool nearest) const =0
virtual double SingleStep(double value, int digitIndex, bool upwards) const =0
virtual std::optional< double > StringToValue(const wxString &value) const =0
NumericField(const NumericField &)=default
NumericField & operator=(const NumericField &)=default