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 SettingBase &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 266 of file Prefs.h.

Constructor & Destructor Documentation

◆ ChoiceSetting()

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

Definition at line 269 of file Prefs.h.

274  : mKey{ key.GetPath() }
275 
276  , mSymbols{ std::move( symbols ) }
277 
278  , mDefaultSymbol{ defaultSymbol }
279  {
280  wxASSERT( defaultSymbol < (long)mSymbols.size() );
281  }

References key.

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 268 of file Prefs.cpp.

269 {
270  if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
271  return mSymbols[ mDefaultSymbol ];
272  static EnumValueSymbol empty;
273  return empty;
274 }

References mDefaultSymbol, and mSymbols.

Referenced by Read(), HelpSystem::ShowHelp(), 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 299 of file Prefs.cpp.

300 {
301  auto start = GetSymbols().begin();
302  return size_t(
303  std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
304  - start );
305 }

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 285 of file Prefs.h.

285 { return mSymbols; }

Referenced by Find(), 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 283 of file Prefs.h.

283 { return mKey; }

Referenced by 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 307 of file Prefs.cpp.

308 {
309  (void)value;// Compiler food
310 }

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 276 of file Prefs.cpp.

277 {
278  const auto &defaultValue = Default().Internal();
279  return ReadWithDefault( defaultValue );
280 }

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 282 of file Prefs.cpp.

283 {
284  wxString value;
285  if ( !gPrefs->Read(mKey, &value, defaultValue) )
286  if (!mMigrated) {
287  const_cast<ChoiceSetting*>(this)->Migrate( value );
288  mMigrated = true;
289  }
290 
291  // Remap to default if the string is not known -- this avoids surprises
292  // in case we try to interpret config files from future versions
293  auto index = Find( value );
294  if ( index >= mSymbols.size() )
295  value = defaultValue;
296  return value;
297 }

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 342 of file Prefs.cpp.

343 {
344  if ( value < (long)mSymbols.size() )
345  mDefaultSymbol = value;
346  else
347  wxASSERT( false );
348 }

References mDefaultSymbol, and mSymbols.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 312 of file Prefs.cpp.

313 {
314  auto index = Find( value );
315  if (index >= mSymbols.size())
316  return false;
317 
318  auto result = gPrefs->Write( mKey, value );
319  mMigrated = true;
320  return result;
321 }

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 309 of file Prefs.h.

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

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 302 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 307 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:70
ChoiceSetting::Find
size_t Find(const wxString &value) const
Definition: Prefs.cpp:299
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ChoiceSetting
Definition: Prefs.h:267
ChoiceSetting::mDefaultSymbol
long mDefaultSymbol
Definition: Prefs.h:309
ChoiceSetting::ReadWithDefault
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:282
ChoiceSetting::GetSymbols
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:285
ChoiceSetting::mMigrated
bool mMigrated
Definition: Prefs.h:307
ChoiceSetting::mKey
const wxString mKey
Definition: Prefs.h:302
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:197
ChoiceSetting::Default
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:268
ChoiceSetting::Migrate
virtual void Migrate(wxString &)
Definition: Prefs.cpp:307
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterfaceSymbol.h:55
ChoiceSetting::mSymbols
const EnumValueSymbols mSymbols
Definition: Prefs.h:304