21#ifndef _JSON_SETTINGS_H
22#define _JSON_SETTINGS_H
31#include <nlohmann/json_fwd.hpp>
54#define traceSettings wxT( "KICAD_SETTINGS" )
75 JSON_SETTINGS( aFilename, aLocation, aSchemaVersion, true, true, true )
79 bool aCreateIfMissing,
bool aCreateIfDefault,
bool aWriteFile );
90 wxString GetFullFilename()
const;
113 nlohmann::json& At(
const std::string& aPath );
114 bool Contains(
const std::string& aPath )
const;
128 virtual bool Store();
135 virtual bool LoadFromFile(
const wxString& aDirectory =
"" );
142 virtual bool SaveToFile(
const wxString& aDirectory =
"",
bool aForce =
false );
153 void ResetToDefaults();
161 std::optional<nlohmann::json> GetJson(
const std::string& aPath )
const;
170 template<
typename ValueType>
171 std::optional<ValueType> Get(
const std::string& aPath )
const;
180 template<
typename ValueType>
181 void Set(
const std::string& aPath, ValueType aVal );
183 virtual std::map<std::string, nlohmann::json> GetFileHistories();
202 virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig );
231 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
240 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
bool& aTarget );
248 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath,
int& aTarget );
256 static bool SetIfPresent(
const nlohmann::json& aObj,
const std::string& aPath ,
257 unsigned int& aTarget );
259 const std::string FormatAsString();
261 bool LoadFromRawFile(
const wxString& aPath );
273 void registerMigration(
int aOldSchemaVersion,
int aNewSchemaVersion,
274 std::function<
bool(
void)> aMigrator );
283 template<
typename ValueType>
284 bool fromLegacy( wxConfigBase* aConfig,
const std::string& aKey,
const std::string& aDest );
292 bool fromLegacyString( wxConfigBase* aConfig,
const std::string& aKey,
293 const std::string& aDest );
301 bool fromLegacyColor( wxConfigBase* aConfig,
const std::string& aKey,
302 const std::string& aDest );
306 return wxT(
"json" );
311 return wxEmptyString;
321 template<
typename ResultType>
322 static ResultType fetchOrDefault(
const nlohmann::json& aJson,
const std::string& aKey,
323 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)
bool IsFileSynced() const
bool m_fileSynced
True once the store has been synchronized with an on-disk file (loaded or saved)
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.
virtual const PROJECT * GetOwningProject() const
Project-located settings override this to report the project they belong to so their save path is res...
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/)
@ PROJECT
The settings directory inside a project folder.
@ 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.