21#ifndef _JSON_SETTINGS_H
22#define _JSON_SETTINGS_H
53#define traceSettings wxT( "KICAD_SETTINGS" )
74 JSON_SETTINGS( aFilename, aLocation, aSchemaVersion, true, true, true )
78 bool aCreateIfMissing,
bool aCreateIfDefault,
bool aWriteFile );
89 wxString GetFullFilename()
const;
106 nlohmann::json& At(
const std::string& aPath );
107 bool Contains(
const std::string& aPath )
const;
121 virtual bool Store();
128 virtual bool LoadFromFile(
const wxString& aDirectory =
"" );
135 virtual bool SaveToFile(
const wxString& aDirectory =
"",
bool aForce =
false );
140 void ResetToDefaults();
148 std::optional<nlohmann::json> GetJson(
const std::string& aPath )
const;
157 template<
typename ValueType>
158 std::optional<ValueType> Get(
const std::string& aPath )
const;
167 template<
typename ValueType>
168 void Set(
const std::string& aPath, ValueType aVal );
170 virtual std::map<std::string, nlohmann::json> GetFileHistories();
189 virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig );
218 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
227 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
bool& aTarget );
235 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
int& aTarget );
243 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath ,
244 unsigned int& aTarget );
246 const std::string FormatAsString();
248 bool LoadFromRawFile(
const wxString& aPath );
260 void registerMigration(
int aOldSchemaVersion,
int aNewSchemaVersion,
261 std::function<
bool(
void)> aMigrator );
270 template<
typename ValueType>
271 bool fromLegacy( wxConfigBase* aConfig,
const std::string& aKey,
const std::string& aDest );
279 bool fromLegacyString( wxConfigBase* aConfig,
const std::string& aKey,
280 const std::string& aDest );
288 bool fromLegacyColor( wxConfigBase* aConfig,
const std::string& aKey,
289 const std::string& aDest );
293 return wxT(
"json" );
298 return wxEmptyString;
308 template<
typename ResultType>
309 static ResultType fetchOrDefault(
const nlohmann::json& aJson,
const std::string& aKey,
310 ResultType aDefault = ResultType() );
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
virtual wxString getFileExt() const
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 l...
JSON_SETTINGS & operator=(const JSON_SETTINGS &)=delete
wxString m_filename
The filename (not including path) of this settings file (inicode)
SETTINGS_MANAGER * m_manager
A pointer to the settings manager managing this file (may be null)
SETTINGS_LOC GetLocation() const
bool m_isFutureFormat
Set to true if this settings is loaded from a file with a newer schema version than is known.
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
bool m_modified
True if the JSON data store has been written to since the last file write.
bool m_createIfDefault
Whether or not the backing store file should be created if all parameters are still at their default ...
JSON_SETTINGS(const JSON_SETTINGS &)=delete
void SetLocation(SETTINGS_LOC aLocation)
bool m_writeFile
Whether or not the backing store file should be written.
void SetManager(SETTINGS_MANAGER *aManager)
void SetReadOnly(bool aReadOnly)
bool m_createIfMissing
Whether or not the backing store file should be created it if doesn't exist.
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
bool m_deleteLegacyAfterMigration
Whether or not to delete legacy file after migration.
std::unique_ptr< JSON_SETTINGS_INTERNALS > m_internals
friend class NESTED_SETTINGS
void SetFilename(const wxString &aFilename)
SETTINGS_LOC m_location
The location of this settings file (.
virtual wxString getLegacyFileExt() const
bool m_resetParamsIfMissing
Whether or not to set parameters to their default value if missing from JSON on Load()
void SetLegacyFilename(const wxString &aFilename)
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>
int m_schemaVersion
Version of this settings schema.
wxString m_legacy_filename
The filename of the wxConfig legacy file (if different from m_filename)
wxString GetFilename() const
A color representation with 4 components: red, green, blue, alpha.
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
Container for project specific data.
KICOMMON_API void to_json(nlohmann::json &aJson, const wxString &aString)
@ TOOLBARS
The toolbar directory (e.g. ~/.config/kicad/toolbars/)
@ USER
The main config directory (e.g. ~/.config/kicad/)
@ COLORS
The color scheme directory (e.g. ~/.config/kicad/colors/)
@ NESTED
Not stored in a file, but inside another JSON_SETTINGS.
KICOMMON_API void from_json(const nlohmann::json &aJson, wxString &aString)
The Cairo implementation of the graphics abstraction layer.
Common grid settings, available to every frame.