KiCad PCB EDA Suite
Loading...
Searching...
No Matches
JSON_SETTINGS Class Reference

#include <json_settings.h>

Inheritance diagram for JSON_SETTINGS:
APP_SETTINGS_BASE COLOR_SETTINGS COMMON_SETTINGS DATABASE_LIB_SETTINGS NESTED_SETTINGS PROJECT_FILE PROJECT_LOCAL_SETTINGS BITMAP2CMP_SETTINGS EDA_3D_VIEWER_SETTINGS EESCHEMA_SETTINGS FOOTPRINT_EDITOR_SETTINGS GERBVIEW_SETTINGS KICAD_SETTINGS PCB_CALCULATOR_SETTINGS PCB_VIEWERS_SETTINGS_BASE PL_EDITOR_SETTINGS SYMBOL_EDITOR_SETTINGS BOARD_DESIGN_SETTINGS ERC_SETTINGS NET_SETTINGS PNS::ROUTING_SETTINGS SCHEMATIC_SETTINGS SPICE_SIMULATOR_SETTINGS

Public Member Functions

 JSON_SETTINGS (const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
 
 JSON_SETTINGS (const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion, bool aCreateIfMissing, bool aCreateIfDefault, bool aWriteFile)
 
virtual ~JSON_SETTINGS ()
 
wxString GetFilename () const
 
wxString GetFullFilename () const
 
void SetFilename (const wxString &aFilename)
 
void SetLocation (SETTINGS_LOC aLocation)
 
SETTINGS_LOC GetLocation () const
 
void SetLegacyFilename (const wxString &aFilename)
 
bool IsReadOnly () const
 
void SetReadOnly (bool aReadOnly)
 
nlohmann::json & At (const std::string &aPath)
 Wrappers for the underlying JSON API so that most consumers don't need json.hpp All of these functions take a string that is passed to PointerFromString internally. More...
 
bool Contains (const std::string &aPath) const
 
JSON_SETTINGS_INTERNALSInternals ()
 
virtual void Load ()
 Updates the parameters of this object based on the current JSON document contents. More...
 
virtual bool Store ()
 Stores the current parameters into the JSON document represented by this object Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER. More...
 
virtual bool LoadFromFile (const wxString &aDirectory="")
 Loads the backing file from disk and then calls Load() More...
 
virtual bool SaveToFile (const wxString &aDirectory="", bool aForce=false)
 
void ResetToDefaults ()
 Resets all parameters to default values. More...
 
std::optional< nlohmann::json > GetJson (const std::string &aPath) const
 Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1.key2.key3" to refer to nested objects. More...
 
template<typename ValueType >
std::optional< ValueType > Get (const std::string &aPath) const
 Fetches a value from within the JSON document. More...
 
template<typename ValueType >
void Set (const std::string &aPath, ValueType aVal)
 Stores a value into the JSON document Will throw an exception if ValueType isn't something that the library can handle. More...
 
bool Migrate ()
 Migrates the schema of this settings from the version in the file to the latest version. More...
 
virtual bool MigrateFromLegacy (wxConfigBase *aLegacyConfig)
 Migrates from wxConfig to JSON-based configuration. More...
 
void AddNestedSettings (NESTED_SETTINGS *aSettings)
 Transfers ownership of a given NESTED_SETTINGS to this object. More...
 
void ReleaseNestedSettings (NESTED_SETTINGS *aSettings)
 Saves and frees a nested settings object, if it exists within this one. More...
 
void SetManager (SETTINGS_MANAGER *aManager)
 
const std::string FormatAsString () const
 
bool LoadFromRawFile (const wxString &aPath)
 
template<>
std::optional< wxString > Get (const std::string &aPath) const
 
template<>
void Set (const std::string &aPath, wxString aVal)
 
template<>
void Set (const std::string &aPath, wxString aVal)
 

Static Public Member Functions

static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, wxString &aTarget)
 Sets the given string if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, bool &aTarget)
 Sets the given bool if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, int &aTarget)
 Sets the given int if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, unsigned int &aTarget)
 Sets the given unsigned int if the given key/path is present. More...
 

Protected Member Functions

void registerMigration (int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
 Registers a migration from one schema version to another. More...
 
template<typename ValueType >
bool fromLegacy (wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
 Translates a legacy wxConfig value to a given JSON pointer value. More...
 
bool fromLegacyString (wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
 Translates a legacy wxConfig string value to a given JSON pointer value. More...
 
bool fromLegacyColor (wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
 Translates a legacy COLOR4D stored in a wxConfig string to a given JSON pointer value. More...
 
virtual wxString getFileExt () const
 
virtual wxString getLegacyFileExt () const
 

Static Protected Member Functions

template<typename ResultType >
static ResultType fetchOrDefault (const nlohmann::json &aJson, const std::string &aKey, ResultType aDefault=ResultType())
 Helper to retrieve a value from a JSON object (dictionary) as a certain result type. More...
 

Protected Attributes

wxString m_filename
 The filename (not including path) of this settings file (inicode) More...
 
wxString m_legacy_filename
 The filename of the wxConfig legacy file (if different from m_filename) More...
 
SETTINGS_LOC m_location
 The location of this settings file (. More...
 
std::vector< PARAM_BASE * > m_params
 The list of parameters (owned by this object) More...
 
std::vector< NESTED_SETTINGS * > m_nested_settings
 Nested settings files that live inside this one, if any. More...
 
bool m_createIfMissing
 Whether or not the backing store file should be created it if doesn't exist. More...
 
bool m_createIfDefault
 Whether or not the backing store file should be created if all parameters are still at their default values. More...
 
bool m_writeFile
 Whether or not the backing store file should be written. More...
 
bool m_deleteLegacyAfterMigration
 Whether or not to delete legacy file after migration. More...
 
bool m_resetParamsIfMissing
 Whether or not to set parameters to their default value if missing from JSON on Load() More...
 
int m_schemaVersion
 Version of this settings schema. More...
 
SETTINGS_MANAGERm_manager
 A pointer to the settings manager managing this file (may be null) More...
 
std::map< int, std::pair< int, std::function< bool()> > > m_migrators
 A map of starting schema version to a pair of <ending version, migrator function> More...
 
std::unique_ptr< JSON_SETTINGS_INTERNALSm_internals
 

Friends

class NESTED_SETTINGS
 

Detailed Description

Definition at line 59 of file json_settings.h.

Constructor & Destructor Documentation

◆ JSON_SETTINGS() [1/2]

JSON_SETTINGS::JSON_SETTINGS ( const wxString &  aFilename,
SETTINGS_LOC  aLocation,
int  aSchemaVersion 
)
inline

Definition at line 64 of file json_settings.h.

◆ JSON_SETTINGS() [2/2]

JSON_SETTINGS::JSON_SETTINGS ( const wxString &  aFilename,
SETTINGS_LOC  aLocation,
int  aSchemaVersion,
bool  aCreateIfMissing,
bool  aCreateIfDefault,
bool  aWriteFile 
)

Definition at line 68 of file json_settings.cpp.

References GetFullFilename(), m_internals, m_params, m_schemaVersion, and traceSettings.

◆ ~JSON_SETTINGS()

JSON_SETTINGS::~JSON_SETTINGS ( )
virtual

Definition at line 100 of file json_settings.cpp.

References m_params.

Member Function Documentation

◆ AddNestedSettings()

void JSON_SETTINGS::AddNestedSettings ( NESTED_SETTINGS aSettings)

Transfers ownership of a given NESTED_SETTINGS to this object.

Can be used to construct a NESTED_SETTINGS without the parent object needing to know about the implementation of the nested object;

Parameters
aSettingsis the settings object to take ownership of
aTargetis a pointer to update to the passed in settings

Definition at line 807 of file json_settings.cpp.

References GetFilename(), m_nested_settings, and traceSettings.

Referenced by NESTED_SETTINGS::SetParent().

◆ At()

nlohmann::json & JSON_SETTINGS::At ( const std::string &  aPath)

Wrappers for the underlying JSON API so that most consumers don't need json.hpp All of these functions take a string that is passed to PointerFromString internally.

Definition at line 115 of file json_settings.cpp.

References m_internals.

Referenced by EESCHEMA_SETTINGS::migrateBomSettings(), GERBVIEW_SETTINGS::MigrateFromLegacy(), APP_SETTINGS_BASE::migrateLibTreeWidth(), BOARD_DESIGN_SETTINGS::migrateSchema0to1(), FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1(), COLOR_SETTINGS::migrateSchema0to1(), PCBNEW_SETTINGS::PCBNEW_SETTINGS(), and PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS().

◆ Contains()

◆ fetchOrDefault()

template<typename ResultType >
template bool JSON_SETTINGS::fetchOrDefault ( const nlohmann::json &  aJson,
const std::string &  aKey,
ResultType  aDefault = ResultType() 
)
staticprotected

Helper to retrieve a value from a JSON object (dictionary) as a certain result type.

Template Parameters
ResultTypeis the type of the retrieved value.
Parameters
aJsonis the object to act on .
aKeyis the object key to retrieve the value for.
Returns
the result, or aDefault if aKey is not found.

Definition at line 866 of file json_settings.cpp.

◆ FormatAsString()

const std::string JSON_SETTINGS::FormatAsString ( ) const

Definition at line 482 of file json_settings.cpp.

References dummy, and m_internals.

Referenced by ROUTER_TOOL::saveRouterDebugLog().

◆ fromLegacy()

template<typename ValueType >
template bool JSON_SETTINGS::fromLegacy< bool > ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protected

Translates a legacy wxConfig value to a given JSON pointer value.

Template Parameters
ValueTypeis the basic type of the value
Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 719 of file json_settings.cpp.

◆ fromLegacyColor()

bool JSON_SETTINGS::fromLegacyColor ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protected

Translates a legacy COLOR4D stored in a wxConfig string to a given JSON pointer value.

Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 779 of file json_settings.cpp.

References color.

Referenced by APP_SETTINGS_BASE::migrateWindowConfig().

◆ fromLegacyString()

bool JSON_SETTINGS::fromLegacyString ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protected

Translates a legacy wxConfig string value to a given JSON pointer value.

Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 755 of file json_settings.cpp.

Referenced by PROJECT_FILE::MigrateFromLegacy(), APP_SETTINGS_BASE::MigrateFromLegacy(), BITMAP2CMP_SETTINGS::MigrateFromLegacy(), EESCHEMA_SETTINGS::MigrateFromLegacy(), SYMBOL_EDITOR_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), COMMON_SETTINGS::MigrateFromLegacy(), PCB_CALCULATOR_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), and APP_SETTINGS_BASE::migrateWindowConfig().

◆ Get() [1/2]

template<>
std::optional< wxString > JSON_SETTINGS::Get ( const std::string &  aPath) const

Definition at line 837 of file json_settings.cpp.

References GetJson().

◆ Get() [2/2]

template<typename ValueType >
template std::optional< wxAuiPaneInfo > JSON_SETTINGS::Get< wxAuiPaneInfo > ( const std::string &  aPath) const

Fetches a value from within the JSON document.

Will return an empty optional if the value is not found or a mismatching type.

Template Parameters
ValueTypeis the type to cast to
Parameters
aPathis the path within the document to retrieve
Returns
a value from within this document

Definition at line 545 of file json_settings.cpp.

References GetJson().

Referenced by COLOR_MAP_PARAM::Load(), PARAM< ValueType >::Load(), PARAM_ENUM< EnumType >::Load(), PARAM_LAMBDA< ValueType >::Load(), PARAM_SCALED< ValueType >::Load(), COLOR_MAP_PARAM::MatchesFile(), PARAM< ValueType >::MatchesFile(), PARAM_PATH::MatchesFile(), PARAM_ENUM< EnumType >::MatchesFile(), PARAM_LAMBDA< ValueType >::MatchesFile(), and PARAM_SCALED< ValueType >::MatchesFile().

◆ getFileExt()

virtual wxString JSON_SETTINGS::getFileExt ( ) const
inlineprotectedvirtual

Reimplemented in DATABASE_LIB_SETTINGS, PROJECT_FILE, and PROJECT_LOCAL_SETTINGS.

Definition at line 275 of file json_settings.h.

Referenced by GetFullFilename(), LoadFromFile(), and SaveToFile().

◆ GetFilename()

◆ GetFullFilename()

wxString JSON_SETTINGS::GetFullFilename ( ) const

Definition at line 109 of file json_settings.cpp.

References getFileExt(), and m_filename.

Referenced by JSON_SETTINGS(), LoadFromFile(), NESTED_SETTINGS::LoadFromFile(), and SaveToFile().

◆ GetJson()

std::optional< nlohmann::json > JSON_SETTINGS::GetJson ( const std::string &  aPath) const

Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1.key2.key3" to refer to nested objects.

Parameters
aPathis a string containing one or more keys separated by '.'
Returns
a JSON object from within this one

Definition at line 525 of file json_settings.cpp.

References m_internals.

Referenced by Get(), PARAM_LAMBDA< ValueType >::Load(), PARAM_LIST< Type >::Load(), PARAM_SET< Type >::Load(), PARAM_MAP< Value >::Load(), PARAM_LAMBDA< ValueType >::MatchesFile(), PARAM_LIST< Type >::MatchesFile(), PARAM_SET< Type >::MatchesFile(), PARAM_PATH_LIST::MatchesFile(), PARAM_MAP< Value >::MatchesFile(), PARAM_WXSTRING_MAP::MatchesFile(), SETTINGS_MANAGER::SaveColorSettings(), and NESTED_SETTINGS::SaveToFile().

◆ getLegacyFileExt()

virtual wxString JSON_SETTINGS::getLegacyFileExt ( ) const
inlineprotectedvirtual

Reimplemented in PROJECT_FILE, and PROJECT_LOCAL_SETTINGS.

Definition at line 280 of file json_settings.h.

Referenced by LoadFromFile().

◆ GetLocation()

SETTINGS_LOC JSON_SETTINGS::GetLocation ( ) const
inline

Definition at line 80 of file json_settings.h.

References m_location.

Referenced by SETTINGS_MANAGER::GetPathForSettingsFile().

◆ Internals()

JSON_SETTINGS_INTERNALS * JSON_SETTINGS::Internals ( )

◆ IsReadOnly()

◆ Load()

◆ LoadFromFile()

bool JSON_SETTINGS::LoadFromFile ( const wxString &  aDirectory = "")
virtual

◆ LoadFromRawFile()

bool JSON_SETTINGS::LoadFromRawFile ( const wxString &  aPath)

Definition at line 493 of file json_settings.cpp.

References Load(), m_internals, and traceSettings.

◆ Migrate()

bool JSON_SETTINGS::Migrate ( )

Migrates the schema of this settings from the version in the file to the latest version.

Schema migration doesn't need to be used every time a setting is added! This is intended to be more of an "escape hatch" in the event that we decide to move settings around or make other changes to a settings file format that can't simply be handled by loading a new default

Returns
true if migration was successful

Definition at line 616 of file json_settings.cpp.

References m_internals, m_migrators, m_schemaVersion, and traceSettings.

Referenced by LoadFromFile(), and NESTED_SETTINGS::LoadFromFile().

◆ MigrateFromLegacy()

bool JSON_SETTINGS::MigrateFromLegacy ( wxConfigBase *  aLegacyConfig)
virtual

Migrates from wxConfig to JSON-based configuration.

Should be implemented by any subclasses of JSON_SETTINGS that map to a legacy (wxConfig-based) config file.

Parameters
aLegacyConfigis a wxConfigBase holding a loaded configuration to migrate
Returns
true if migration was successful

Reimplemented in PROJECT_FILE, APP_SETTINGS_BASE, COLOR_SETTINGS, EDA_3D_VIEWER_SETTINGS, BITMAP2CMP_SETTINGS, EESCHEMA_SETTINGS, SYMBOL_EDITOR_SETTINGS, GERBVIEW_SETTINGS, FOOTPRINT_EDITOR_SETTINGS, PROJECT_LOCAL_SETTINGS, COMMON_SETTINGS, CVPCB_SETTINGS, KICAD_SETTINGS, PL_EDITOR_SETTINGS, PCB_CALCULATOR_SETTINGS, and PCBNEW_SETTINGS.

Definition at line 650 of file json_settings.cpp.

References traceSettings.

Referenced by LoadFromFile().

◆ registerMigration()

void JSON_SETTINGS::registerMigration ( int  aOldSchemaVersion,
int  aNewSchemaVersion,
std::function< bool(void)>  aMigrator 
)
protected

Registers a migration from one schema version to another.

If the schema version in the file loaded from disk is less than the schema version of the JSON_SETTINGS class, migration functions will be called one after the other until the data is up-to-date.

Parameters
aOldSchemaVersionis the starting schema version for this migration
aNewSchemaVersionis the ending schema version for this migration
aMigratoris a function that performs the migration and returns true if successful

Definition at line 607 of file json_settings.cpp.

References m_migrators, and m_schemaVersion.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), COLOR_SETTINGS::COLOR_SETTINGS(), EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS(), EESCHEMA_SETTINGS::EESCHEMA_SETTINGS(), FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), NET_SETTINGS::NET_SETTINGS(), PCBNEW_SETTINGS::PCBNEW_SETTINGS(), PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS(), SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), and SYMBOL_EDITOR_SETTINGS::SYMBOL_EDITOR_SETTINGS().

◆ ReleaseNestedSettings()

void JSON_SETTINGS::ReleaseNestedSettings ( NESTED_SETTINGS aSettings)

Saves and frees a nested settings object, if it exists within this one.

Parameters
aSettingsis a pointer to a NESTED_SETTINGS that has already been added to this one

Definition at line 814 of file json_settings.cpp.

References m_manager, m_nested_settings, NESTED_SETTINGS::SetParent(), and traceSettings.

Referenced by BOARD_DESIGN_SETTINGS::~BOARD_DESIGN_SETTINGS(), ERC_SETTINGS::~ERC_SETTINGS(), NESTED_SETTINGS::~NESTED_SETTINGS(), NET_SETTINGS::~NET_SETTINGS(), and SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS().

◆ ResetToDefaults()

void JSON_SETTINGS::ResetToDefaults ( )

Resets all parameters to default values.

Does NOT write to file or update underlying JSON.

Definition at line 371 of file json_settings.cpp.

References m_params.

Referenced by EDA_3D_VIEWER_FRAME::Process_Special_Functions(), PANEL_COMMON_SETTINGS::ResetPanel(), and PANEL_MOUSE_SETTINGS::ResetPanel().

◆ SaveToFile()

bool JSON_SETTINGS::SaveToFile ( const wxString &  aDirectory = "",
bool  aForce = false 
)
virtual

◆ Set() [1/3]

template<typename ValueType >
template void JSON_SETTINGS::Set< wxAuiPaneInfo > ( const std::string &  aPath,
ValueType  aVal 
)

Stores a value into the JSON document Will throw an exception if ValueType isn't something that the library can handle.

Template Parameters
ValueTypeis the type to store
Parameters
aPathis a path to store in the form "key1.key2.key3"
aValis the value to store

Definition at line 581 of file json_settings.cpp.

References m_internals.

Referenced by COLOR_SETTINGS::COLOR_SETTINGS(), EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS(), EESCHEMA_SETTINGS::EESCHEMA_SETTINGS(), BOARD_DESIGN_SETTINGS::LoadFromFile(), APP_SETTINGS_BASE::migrateFindReplace(), PROJECT_FILE::MigrateFromLegacy(), APP_SETTINGS_BASE::MigrateFromLegacy(), EDA_3D_VIEWER_SETTINGS::MigrateFromLegacy(), EESCHEMA_SETTINGS::MigrateFromLegacy(), SYMBOL_EDITOR_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), COMMON_SETTINGS::MigrateFromLegacy(), KICAD_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), BOARD_DESIGN_SETTINGS::migrateSchema0to1(), FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1(), COLOR_SETTINGS::migrateSchema0to1(), PCBNEW_SETTINGS::PCBNEW_SETTINGS(), PROJECT_FILE::SaveAs(), PROJECT_LOCAL_SETTINGS::SaveAs(), PROJECT_FILE::SaveToFile(), PROJECT_LOCAL_SETTINGS::SaveToFile(), SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), COLOR_MAP_PARAM::Store(), PARAM< ValueType >::Store(), PARAM_PATH::Store(), PARAM_ENUM< EnumType >::Store(), PARAM_LAMBDA< ValueType >::Store(), PARAM_SCALED< ValueType >::Store(), PARAM_LIST< Type >::Store(), PARAM_SET< Type >::Store(), PARAM_PATH_LIST::Store(), and PARAM_MAP< Value >::Store().

◆ Set() [2/3]

template<>
void JSON_SETTINGS::Set ( const std::string &  aPath,
wxString  aVal 
)

Definition at line 846 of file json_settings.cpp.

◆ Set() [3/3]

template<>
void JSON_SETTINGS::Set ( const std::string &  aPath,
wxString  aVal 
)

◆ SetFilename()

void JSON_SETTINGS::SetFilename ( const wxString &  aFilename)
inline

◆ SetIfPresent() [1/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json &  aObj,
const std::string &  aPath,
bool &  aTarget 
)
static

Sets the given bool if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 673 of file json_settings.cpp.

References JSON_SETTINGS_INTERNALS::PointerFromString().

◆ SetIfPresent() [2/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json &  aObj,
const std::string &  aPath,
int &  aTarget 
)
static

Sets the given int if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 688 of file json_settings.cpp.

References JSON_SETTINGS_INTERNALS::PointerFromString().

◆ SetIfPresent() [3/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json &  aObj,
const std::string &  aPath,
unsigned int &  aTarget 
)
static

Sets the given unsigned int if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 703 of file json_settings.cpp.

References JSON_SETTINGS_INTERNALS::PointerFromString().

◆ SetIfPresent() [4/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json &  aObj,
const std::string &  aPath,
wxString &  aTarget 
)
static

Sets the given string if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 658 of file json_settings.cpp.

References JSON_SETTINGS_INTERNALS::PointerFromString().

Referenced by FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), and PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS().

◆ SetLegacyFilename()

void JSON_SETTINGS::SetLegacyFilename ( const wxString &  aFilename)
inline

Definition at line 82 of file json_settings.h.

References m_legacy_filename.

Referenced by SYMBOL_EDITOR_SETTINGS::SYMBOL_EDITOR_SETTINGS().

◆ SetLocation()

void JSON_SETTINGS::SetLocation ( SETTINGS_LOC  aLocation)
inline

Definition at line 79 of file json_settings.h.

References m_location.

Referenced by COLOR_SETTINGS::COLOR_SETTINGS().

◆ SetManager()

void JSON_SETTINGS::SetManager ( SETTINGS_MANAGER aManager)
inline

Definition at line 191 of file json_settings.h.

References m_manager.

◆ SetReadOnly()

◆ Store()

bool JSON_SETTINGS::Store ( )
virtual

Stores the current parameters into the JSON document represented by this object Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER.

Returns
true if any part of the JSON document was updated

Definition at line 357 of file json_settings.cpp.

References m_params.

Referenced by PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), SETTINGS_MANAGER::SaveColorSettings(), SaveToFile(), and NESTED_SETTINGS::SaveToFile().

Friends And Related Function Documentation

◆ NESTED_SETTINGS

friend class NESTED_SETTINGS
friend

Definition at line 62 of file json_settings.h.

Member Data Documentation

◆ m_createIfDefault

bool JSON_SETTINGS::m_createIfDefault
protected

Whether or not the backing store file should be created if all parameters are still at their default values.

Ignored if m_createIfMissing is false or m_writeFile is false.

Definition at line 318 of file json_settings.h.

Referenced by SaveToFile().

◆ m_createIfMissing

bool JSON_SETTINGS::m_createIfMissing
protected

Whether or not the backing store file should be created it if doesn't exist.

Definition at line 312 of file json_settings.h.

Referenced by SaveToFile().

◆ m_deleteLegacyAfterMigration

bool JSON_SETTINGS::m_deleteLegacyAfterMigration
protected

Whether or not to delete legacy file after migration.

Definition at line 324 of file json_settings.h.

Referenced by LoadFromFile(), PROJECT_FILE::PROJECT_FILE(), and PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS().

◆ m_filename

◆ m_internals

◆ m_legacy_filename

wxString JSON_SETTINGS::m_legacy_filename
protected

The filename of the wxConfig legacy file (if different from m_filename)

Definition at line 300 of file json_settings.h.

Referenced by LoadFromFile(), and SetLegacyFilename().

◆ m_location

SETTINGS_LOC JSON_SETTINGS::m_location
protected

The location of this settings file (.

See also
SETTINGS_LOC)

Definition at line 303 of file json_settings.h.

Referenced by GetLocation(), and SetLocation().

◆ m_manager

SETTINGS_MANAGER* JSON_SETTINGS::m_manager
protected

A pointer to the settings manager managing this file (may be null)

Definition at line 333 of file json_settings.h.

Referenced by FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1(), COLOR_SETTINGS::migrateSchema0to1(), ReleaseNestedSettings(), and SetManager().

◆ m_migrators

std::map<int, std::pair<int, std::function<bool()> > > JSON_SETTINGS::m_migrators
protected

A map of starting schema version to a pair of <ending version, migrator function>

Definition at line 336 of file json_settings.h.

Referenced by Migrate(), and registerMigration().

◆ m_nested_settings

std::vector<NESTED_SETTINGS*> JSON_SETTINGS::m_nested_settings
protected

Nested settings files that live inside this one, if any.

Definition at line 309 of file json_settings.h.

Referenced by AddNestedSettings(), LoadFromFile(), ReleaseNestedSettings(), and SaveToFile().

◆ m_params

◆ m_resetParamsIfMissing

bool JSON_SETTINGS::m_resetParamsIfMissing
protected

Whether or not to set parameters to their default value if missing from JSON on Load()

Definition at line 327 of file json_settings.h.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), and Load().

◆ m_schemaVersion

int JSON_SETTINGS::m_schemaVersion
protected

Version of this settings schema.

Definition at line 330 of file json_settings.h.

Referenced by JSON_SETTINGS(), LoadFromFile(), NESTED_SETTINGS::LoadFromFile(), Migrate(), registerMigration(), and NESTED_SETTINGS::SaveToFile().

◆ m_writeFile

bool JSON_SETTINGS::m_writeFile
protected

Whether or not the backing store file should be written.

Definition at line 321 of file json_settings.h.

Referenced by COLOR_SETTINGS::CreateBuiltinColorSettings(), COLOR_SETTINGS::initFromOther(), IsReadOnly(), LoadFromFile(), SaveToFile(), and SetReadOnly().


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