Audacity  3.0.3
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ChoiceSetting Class Reference

#include <Prefs.h>

Inheritance diagram for ChoiceSetting:
[legend]
Collaboration diagram for ChoiceSetting:
[legend]

Public Member Functions

 ChoiceSetting (const wxString &key, EnumValueSymbols symbols, long defaultSymbol=-1)
 
const wxString & Key () const
 
const EnumValueSymbolDefault () const
 
const EnumValueSymbolsGetSymbols () const
 
wxString Read () const
 
wxString ReadWithDefault (const wxString &) const
 
bool Write (const wxString &value)
 
void SetDefault (long value)
 

Protected Member Functions

size_t Find (const wxString &value) const
 
virtual void Migrate (wxString &)
 

Protected Attributes

const wxString mKey
 
const EnumValueSymbols mSymbols
 
bool mMigrated { false }
 
long mDefaultSymbol
 

Detailed Description

Packages a table of user-visible choices each with an internal code string, a preference key path, and a default choice

Definition at line 89 of file Prefs.h.

Constructor & Destructor Documentation

◆ ChoiceSetting()

ChoiceSetting::ChoiceSetting ( const wxString &  key,
EnumValueSymbols  symbols,
long  defaultSymbol = -1 
)
inline

Definition at line 92 of file Prefs.h.

97  : mKey{ key }
98 
99  , mSymbols{ std::move( symbols ) }
100 
101  , mDefaultSymbol{ defaultSymbol }
102  {
103  wxASSERT( defaultSymbol < (long)mSymbols.size() );
104  }

References key.

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 227 of file Prefs.cpp.

228 {
229  if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
230  return mSymbols[ mDefaultSymbol ];
231  static EnumValueSymbol empty;
232  return empty;
233 }

References mDefaultSymbol, and mSymbols.

Referenced by Read(), HelpSystem::ShowHelp(), ShuttleGuiBase::StartRadioButtonGroup(), ShuttleGuiBase::TieChoice(), and anonymous_namespace{GetInfoCommand.cpp}::ShuttleGuiGetDefinition::TieChoice().

Here is the caller graph for this function:

◆ Find()

size_t ChoiceSetting::Find ( const wxString &  value) const
protected

Definition at line 258 of file Prefs.cpp.

259 {
260  auto start = GetSymbols().begin();
261  return size_t(
262  std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
263  - start );
264 }

References GetSymbols().

Referenced by EnumSettingBase::ReadInt(), EnumSettingBase::ReadIntWithDefault(), ReadWithDefault(), and Write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSymbols()

const EnumValueSymbols& ChoiceSetting::GetSymbols ( ) const
inline

Definition at line 108 of file Prefs.h.

108 { return mSymbols; }

References mSymbols.

Referenced by Find(), ShuttleGuiBase::StartRadioButtonGroup(), ShuttleGuiBase::TieChoice(), and anonymous_namespace{GetInfoCommand.cpp}::ShuttleGuiGetDefinition::TieChoice().

Here is the caller graph for this function:

◆ Key()

const wxString& ChoiceSetting::Key ( ) const
inline

Definition at line 106 of file Prefs.h.

106 { return mKey; }

References mKey.

Referenced by ShuttleGuiBase::StartRadioButtonGroup(), ShuttleGuiBase::TieChoice(), and anonymous_namespace{GetInfoCommand.cpp}::ShuttleGuiGetDefinition::TieChoice().

Here is the caller graph for this function:

◆ Migrate()

void ChoiceSetting::Migrate ( wxString &  value)
protectedvirtual

Reimplemented in EnumSettingBase.

Definition at line 266 of file Prefs.cpp.

267 {
268  (void)value;// Compiler food
269 }

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 235 of file Prefs.cpp.

236 {
237  const auto &defaultValue = Default().Internal();
238  return ReadWithDefault( defaultValue );
239 }

References Default(), ComponentInterfaceSymbol::Internal(), and ReadWithDefault().

Referenced by anonymous_namespace{PluginMenus.cpp}::AddEffectMenuItems(), ExportFLAC::Export(), ThemeBase::LoadPreferredTheme(), anonymous_namespace{PluginMenus.cpp}::PopulateEffectsMenu(), EnumSettingBase::ReadInt(), ShuttleGuiBase::TieChoice(), ProjectSettings::UpdatePrefs(), and Settings::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadWithDefault()

wxString ChoiceSetting::ReadWithDefault ( const wxString &  defaultValue) const

Definition at line 241 of file Prefs.cpp.

242 {
243  wxString value;
244  if ( !gPrefs->Read(mKey, &value, defaultValue) )
245  if (!mMigrated) {
246  const_cast<ChoiceSetting*>(this)->Migrate( value );
247  mMigrated = true;
248  }
249 
250  // Remap to default if the string is not known -- this avoids surprises
251  // in case we try to interpret config files from future versions
252  auto index = Find( value );
253  if ( index >= mSymbols.size() )
254  value = defaultValue;
255  return value;
256 }

References Find(), gPrefs, Migrate(), mKey, mMigrated, and mSymbols.

Referenced by Read(), and EnumSettingBase::ReadIntWithDefault().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDefault()

void ChoiceSetting::SetDefault ( long  value)

Definition at line 301 of file Prefs.cpp.

302 {
303  if ( value < (long)mSymbols.size() )
304  mDefaultSymbol = value;
305  else
306  wxASSERT( false );
307 }

References mDefaultSymbol, and mSymbols.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 271 of file Prefs.cpp.

272 {
273  auto index = Find( value );
274  if (index >= mSymbols.size())
275  return false;
276 
277  auto result = gPrefs->Write( mKey, value );
278  mMigrated = true;
279  return result;
280 }

References Find(), gPrefs, mKey, mMigrated, and mSymbols.

Referenced by EnumSettingBase::Migrate(), DependencyDialog::SaveFutureActionChoice(), HelpSystem::ShowHelp(), and EnumSettingBase::WriteInt().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mDefaultSymbol

long ChoiceSetting::mDefaultSymbol
protected

Definition at line 132 of file Prefs.h.

Referenced by Default(), EnumSettingBase::Migrate(), and SetDefault().

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 125 of file Prefs.h.

Referenced by Key(), ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 130 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mSymbols

const EnumValueSymbols ChoiceSetting::mSymbols
protected

The documentation for this class was generated from the following files:
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:67
ChoiceSetting::Find
size_t Find(const wxString &value) const
Definition: Prefs.cpp:258
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ChoiceSetting
Definition: Prefs.h:90
ChoiceSetting::mDefaultSymbol
long mDefaultSymbol
Definition: Prefs.h:132
ChoiceSetting::ReadWithDefault
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:241
ChoiceSetting::GetSymbols
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:108
ChoiceSetting::mMigrated
bool mMigrated
Definition: Prefs.h:130
ChoiceSetting::mKey
const wxString mKey
Definition: Prefs.h:125
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:196
ChoiceSetting::Default
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:227
ChoiceSetting::Migrate
virtual void Migrate(wxString &)
Definition: Prefs.cpp:266
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterface.h:88
ChoiceSetting::mSymbols
const EnumValueSymbols mSymbols
Definition: Prefs.h:127