Audacity 3.2.0
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 351 of file Prefs.h.

Constructor & Destructor Documentation

◆ ChoiceSetting()

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

Definition at line 354 of file Prefs.h.

359 : mKey{ key.GetPath() }
360
361 , mSymbols{ std::move( symbols ) }
362
363 , mDefaultSymbol{ defaultSymbol }
364 {
365 wxASSERT( defaultSymbol < (long)mSymbols.size() );
366 }
static const AudacityProject::AttachedObjects::RegisteredFactory key
const wxString mKey
Definition: Prefs.h:387
const EnumValueSymbols mSymbols
Definition: Prefs.h:389
long mDefaultSymbol
Definition: Prefs.h:394

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 315 of file Prefs.cpp.

316{
317 if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
318 return mSymbols[ mDefaultSymbol ];
319 static EnumValueSymbol empty;
320 return empty;
321}
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...

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

347{
348 auto start = GetSymbols().begin();
349 return size_t(
350 std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
351 - start );
352}
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:370
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for, if Traits<Type>::iterated_type is defined.
Definition: PackedArray.h:126

References PackedArray::end(), and 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 370 of file Prefs.h.

370{ 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 368 of file Prefs.h.

368{ 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, SpectrogramSettings::ColorSchemeEnumSetting, and TracksViewModeEnumSetting.

Definition at line 354 of file Prefs.cpp.

355{
356 (void)value;// Compiler food
357}

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 323 of file Prefs.cpp.

324{
325 const auto &defaultValue = Default().Internal();
326 return ReadWithDefault( defaultValue );
327}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:329
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:315
const wxString & Internal() const

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

330{
331 wxString value;
332 if ( !gPrefs->Read(mKey, &value, defaultValue) )
333 if (!mMigrated) {
334 const_cast<ChoiceSetting*>(this)->Migrate( value );
335 mMigrated = true;
336 }
337
338 // Remap to default if the string is not known -- this avoids surprises
339 // in case we try to interpret config files from future versions
340 auto index = Find( value );
341 if ( index >= mSymbols.size() )
342 value = defaultValue;
343 return value;
344}
FileConfig * gPrefs
Definition: Prefs.cpp:71
size_t Find(const wxString &value) const
Definition: Prefs.cpp:346
bool mMigrated
Definition: Prefs.h:392
virtual void Migrate(wxString &)
Definition: Prefs.cpp:354

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

390{
391 if ( value < (long)mSymbols.size() )
392 mDefaultSymbol = value;
393 else
394 wxASSERT( false );
395}

References mDefaultSymbol, and mSymbols.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 359 of file Prefs.cpp.

360{
361 auto index = Find( value );
362 if (index >= mSymbols.size())
363 return false;
364
365 auto result = gPrefs->Write( mKey, value );
366 mMigrated = true;
367 return result;
368}

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

Referenced by EnumSettingBase::Migrate(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), TracksViewModeEnumSetting::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 394 of file Prefs.h.

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

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 387 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 392 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: