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 SettingPath &, EnumValueSymbols, long=-1)=delete
 
 ChoiceSetting (TransactionalSettingBase &key, EnumValueSymbols symbols, long defaultSymbol=-1)
 
 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
 
TransactionalSettingBase *const mpOtherSettings {}
 
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 411 of file Prefs.h.

Constructor & Destructor Documentation

◆ ChoiceSetting() [1/3]

ChoiceSetting::ChoiceSetting ( const SettingPath ,
EnumValueSymbols  ,
long  = -1 
)
delete

Disallow construction from the GetPath() of another SettingBase object; instead require that object to be passed as reference to the next ctor

◆ ChoiceSetting() [2/3]

ChoiceSetting::ChoiceSetting ( TransactionalSettingBase key,
EnumValueSymbols  symbols,
long  defaultSymbol = -1 
)
inline
Precondition
defaultSymbol < static_cast<long>(mSymbols.size())

Definition at line 419 of file Prefs.h.

421 : mKey{ key.GetPath() }
422 , mSymbols{ move(symbols) }
423 , mpOtherSettings{ &key }
424 , mDefaultSymbol{ defaultSymbol }
425 {
426 assert(defaultSymbol < static_cast<long>(mSymbols.size()));
427 }
static const AudacityProject::AttachedObjects::RegisteredFactory key
const wxString mKey
Definition: Prefs.h:459
const EnumValueSymbols mSymbols
Definition: Prefs.h:460
TransactionalSettingBase *const mpOtherSettings
Definition: Prefs.h:461
long mDefaultSymbol
Definition: Prefs.h:466

◆ ChoiceSetting() [3/3]

ChoiceSetting::ChoiceSetting ( const SettingBase key,
EnumValueSymbols  symbols,
long  defaultSymbol = -1 
)
inline
Precondition
defaultSymbol < static_cast<long>(symbols.size())

Definition at line 430 of file Prefs.h.

432 : mKey{ key.GetPath() }
433 , mSymbols{ move(symbols) }
434 , mDefaultSymbol{ defaultSymbol }
435 {
436 assert(defaultSymbol < static_cast<long>(mSymbols.size()));
437 }

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 380 of file Prefs.cpp.

381{
382 if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
383 return mSymbols[ mDefaultSymbol ];
384 static EnumValueSymbol empty;
385 return empty;
386}
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 411 of file Prefs.cpp.

412{
413 auto start = GetSymbols().begin();
414 return size_t(
415 std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
416 - start );
417}
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:441
const char * end(const char *str) noexcept
Definition: StringUtils.h:106

References details::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 441 of file Prefs.h.

441{ return mSymbols; }

Referenced by Find(), AudioPasteDialog::PopulateOrExchange(), TracksBehaviorsPrefs::PopulateOrExchange(), 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 439 of file Prefs.h.

439{ 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 419 of file Prefs.cpp.

420{
421 (void)value;// Compiler food
422}

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 388 of file Prefs.cpp.

389{
390 const auto &defaultValue = Default().Internal();
391 return ReadWithDefault( defaultValue );
392}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:394
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:380
const wxString & Internal() const

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

Referenced by anonymous_namespace{PluginMenus.cpp}::AnalyzeMenu(), anonymous_namespace{PluginMenus.cpp}::EffectMenu(), ExportAudioDialog::ExportAudioDialog(), anonymous_namespace{EditMenus.cpp}::FindSourceTracks(), anonymous_namespace{PluginMenus.cpp}::GenerateMenu(), ThemeBase::LoadPreferredTheme(), AudioPasteDialog::OnContinue(), EnumSettingBase::ReadInt(), AudacityMirProject::ShouldBeReconfigured(), ThemeBase::SwitchTheme(), ShuttleGuiBase::TieChoice(), anonymous_namespace{PluginMenus.cpp}::ToolsMenu(), and anonymous_namespace{RealtimeEffectPanel.cpp}::EffectsMenuHelper::UpdateEffectMenuItems().

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

395{
396 wxString value;
397 if ( !gPrefs->Read(mKey, &value, defaultValue) )
398 if (!mMigrated) {
399 const_cast<ChoiceSetting*>(this)->Migrate( value );
400 mMigrated = true;
401 }
402
403 // Remap to default if the string is not known -- this avoids surprises
404 // in case we try to interpret config files from future versions
405 auto index = Find( value );
406 if ( index >= mSymbols.size() )
407 value = defaultValue;
408 return value;
409}
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
size_t Find(const wxString &value) const
Definition: Prefs.cpp:411
bool mMigrated
Definition: Prefs.h:464
virtual void Migrate(wxString &)
Definition: Prefs.cpp:419
virtual bool Read(const wxString &key, bool *value) const =0

References Find(), gPrefs, Migrate(), mKey, mMigrated, mSymbols, and audacity::BasicSettings::Read().

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)
Precondition
defaultSymbol < static_cast<long>(GetSymbols().size())

Definition at line 439 of file Prefs.cpp.

440{
441 mDefaultSymbol = value;
442}

References mDefaultSymbol.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 424 of file Prefs.cpp.

425{
426 auto index = Find( value );
427 if (index >= mSymbols.size())
428 return false;
429
430 auto result = gPrefs->Write( mKey, value );
431 mMigrated = true;
432
433 if (mpOtherSettings)
435
436 return result;
437}
virtual void Invalidate()=0
virtual bool Write(const wxString &key, bool value)=0

References Find(), gPrefs, TransactionalSettingBase::Invalidate(), mKey, mMigrated, mpOtherSettings, mSymbols, and audacity::BasicSettings::Write().

Referenced by EnumSettingBase::Migrate(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), TracksViewModeEnumSetting::Migrate(), AudioPasteDialog::OnContinue(), AudacityMirProject::ShouldBeReconfigured(), HelpSystem::ShowHelp(), ShuttleGuiBase::TieChoice(), 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 466 of file Prefs.h.

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

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 459 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 464 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mpOtherSettings

TransactionalSettingBase* const ChoiceSetting::mpOtherSettings {}
protected

Definition at line 461 of file Prefs.h.

Referenced by Write().

◆ mSymbols

const EnumValueSymbols ChoiceSetting::mSymbols
protected

The documentation for this class was generated from the following files: