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

414 : mKey{ key.GetPath() }
415 , mSymbols{ move(symbols) }
416 , mpOtherSettings{ &key }
417 , mDefaultSymbol{ defaultSymbol }
418 {
419 assert(defaultSymbol < static_cast<long>(mSymbols.size()));
420 }
static const AudacityProject::AttachedObjects::RegisteredFactory key
const wxString mKey
Definition: Prefs.h:452
const EnumValueSymbols mSymbols
Definition: Prefs.h:453
TransactionalSettingBase *const mpOtherSettings
Definition: Prefs.h:454
long mDefaultSymbol
Definition: Prefs.h:459

◆ ChoiceSetting() [3/3]

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

Definition at line 423 of file Prefs.h.

425 : mKey{ key.GetPath() }
426 , mSymbols{ move(symbols) }
427 , mDefaultSymbol{ defaultSymbol }
428 {
429 assert(defaultSymbol < static_cast<long>(mSymbols.size()));
430 }

Member Function Documentation

◆ Default()

const EnumValueSymbol & ChoiceSetting::Default ( ) const

Definition at line 346 of file Prefs.cpp.

347{
348 if ( mDefaultSymbol >= 0 && mDefaultSymbol < (long)mSymbols.size() )
349 return mSymbols[ mDefaultSymbol ];
350 static EnumValueSymbol empty;
351 return empty;
352}
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 377 of file Prefs.cpp.

378{
379 auto start = GetSymbols().begin();
380 return size_t(
381 std::find( start, GetSymbols().end(), EnumValueSymbol{ value, {} } )
382 - start );
383}
const EnumValueSymbols & GetSymbols() const
Definition: Prefs.h:434
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

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

434{ 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 432 of file Prefs.h.

432{ 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 385 of file Prefs.cpp.

386{
387 (void)value;// Compiler food
388}

Referenced by ReadWithDefault().

Here is the caller graph for this function:

◆ Read()

wxString ChoiceSetting::Read ( ) const

Definition at line 354 of file Prefs.cpp.

355{
356 const auto &defaultValue = Default().Internal();
357 return ReadWithDefault( defaultValue );
358}
wxString ReadWithDefault(const wxString &) const
Definition: Prefs.cpp:360
const EnumValueSymbol & Default() const
Definition: Prefs.cpp:346
const wxString & Internal() const

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

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

361{
362 wxString value;
363 if ( !gPrefs->Read(mKey, &value, defaultValue) )
364 if (!mMigrated) {
365 const_cast<ChoiceSetting*>(this)->Migrate( value );
366 mMigrated = true;
367 }
368
369 // Remap to default if the string is not known -- this avoids surprises
370 // in case we try to interpret config files from future versions
371 auto index = Find( value );
372 if ( index >= mSymbols.size() )
373 value = defaultValue;
374 return value;
375}
FileConfig * gPrefs
Definition: Prefs.cpp:71
size_t Find(const wxString &value) const
Definition: Prefs.cpp:377
bool mMigrated
Definition: Prefs.h:457
virtual void Migrate(wxString &)
Definition: Prefs.cpp:385

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

Definition at line 405 of file Prefs.cpp.

406{
407 mDefaultSymbol = value;
408}

References mDefaultSymbol.

◆ Write()

bool ChoiceSetting::Write ( const wxString &  value)

Definition at line 390 of file Prefs.cpp.

391{
392 auto index = Find( value );
393 if (index >= mSymbols.size())
394 return false;
395
396 auto result = gPrefs->Write( mKey, value );
397 mMigrated = true;
398
399 if (mpOtherSettings)
401
402 return result;
403}
virtual void Invalidate()=0

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

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

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

◆ mKey

const wxString ChoiceSetting::mKey
protected

Definition at line 452 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mMigrated

bool ChoiceSetting::mMigrated { false }
mutableprotected

Definition at line 457 of file Prefs.h.

Referenced by ReadWithDefault(), and Write().

◆ mpOtherSettings

TransactionalSettingBase* const ChoiceSetting::mpOtherSettings {}
protected

Definition at line 454 of file Prefs.h.

Referenced by Write().

◆ mSymbols

const EnumValueSymbols ChoiceSetting::mSymbols
protected

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