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

Constructor & Destructor Documentation

◆ ChoiceSetting()

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

Definition at line 272 of file Prefs.h.

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

References key.

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 274 of file Prefs.cpp.

275 {
276  if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
277  return mSymbols[ mDefaultSymbol ];
278  static EnumValueSymbol empty;
279  return empty;
280 }

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

306 {
307  auto start = GetSymbols().begin();
308  return size_t(
309  std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
310  - start );
311 }

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

288 { 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 286 of file Prefs.h.

286 { 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 313 of file Prefs.cpp.

314 {
315  (void)value;// Compiler food
316 }

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 282 of file Prefs.cpp.

283 {
284  const auto &defaultValue = Default().Internal();
285  return ReadWithDefault( defaultValue );
286 }

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

Referenced by anonymous_namespace{PluginMenus.cpp}::AddEffectMenuItems(), ExportFLAC::Export(), ThemeBase::LoadPreferredTheme(), anonymous_namespace{PluginMenus.cpp}::PopulateEffectsMenu(), EnumSettingBase::ReadInt(), ThemeBase::SwitchTheme(), 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 288 of file Prefs.cpp.

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

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

349 {
350  if ( value < (long)mSymbols.size() )
351  mDefaultSymbol = value;
352  else
353  wxASSERT( false );
354 }

References mDefaultSymbol, and mSymbols.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 318 of file Prefs.cpp.

319 {
320  auto index = Find( value );
321  if (index >= mSymbols.size())
322  return false;
323 
324  auto result = gPrefs->Write( mKey, value );
325  mMigrated = true;
326  return result;
327 }

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

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

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 305 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 310 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:305
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ChoiceSetting
Definition: Prefs.h:270
ChoiceSetting::mDefaultSymbol
long mDefaultSymbol
Definition: Prefs.h:312
ChoiceSetting::ReadWithDefault
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:288
ChoiceSetting::GetSymbols
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:288
ChoiceSetting::mMigrated
bool mMigrated
Definition: Prefs.h:310
ChoiceSetting::mKey
const wxString mKey
Definition: Prefs.h:305
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
ChoiceSetting::Default
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:274
ChoiceSetting::Migrate
virtual void Migrate(wxString &)
Definition: Prefs.cpp:313
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterfaceSymbol.h:55
ChoiceSetting::mSymbols
const EnumValueSymbols mSymbols
Definition: Prefs.h:307