Add PARAM_OBSOLETE to clean out old JSON structures.
While not technically necessary, the old structures can be confusing to users looking at the files. Fixes https://gitlab.com/kicad/code/kicad/issues/8856
This commit is contained in:
parent
4943d2f0a3
commit
7d501e8a43
|
@ -198,6 +198,8 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS()
|
||||||
&m_Camera.rotation_increment, 10.0 ) );
|
&m_Camera.rotation_increment, 10.0 ) );
|
||||||
m_params.emplace_back( new PARAM<int>( "camera.projection_mode",
|
m_params.emplace_back( new PARAM<int>( "camera.projection_mode",
|
||||||
&m_Camera.projection_mode, 1 ) );
|
&m_Camera.projection_mode, 1 ) );
|
||||||
|
|
||||||
|
m_params.emplace_back( new PARAM_OBSOLETE( "colors" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -369,18 +369,6 @@ void JSON_SETTINGS::ResetToDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JSON_SETTINGS::IsDefault( const std::string& aParamName )
|
|
||||||
{
|
|
||||||
for( const PARAM_BASE* param : m_params )
|
|
||||||
{
|
|
||||||
if( param->GetJsonPath() == aParamName )
|
|
||||||
return param->IsDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
|
bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce )
|
||||||
{
|
{
|
||||||
if( !m_writeFile )
|
if( !m_writeFile )
|
||||||
|
|
|
@ -25,6 +25,13 @@
|
||||||
#include <gal/color4d.h>
|
#include <gal/color4d.h>
|
||||||
#include <project/project_file.h>
|
#include <project/project_file.h>
|
||||||
#include <settings/parameters.h>
|
#include <settings/parameters.h>
|
||||||
|
#include <settings/json_settings_internals.h>
|
||||||
|
|
||||||
|
|
||||||
|
void PARAM_OBSOLETE::Store( JSON_SETTINGS* aSettings ) const
|
||||||
|
{
|
||||||
|
aSettings->Internals()->erase( m_path );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
|
|
|
@ -151,11 +151,6 @@ public:
|
||||||
( *m_map )[ m_key ] = m_default;
|
( *m_map )[ m_key ] = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return ( *m_map )[ m_key ] == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||||
{
|
{
|
||||||
if( OPT<COLOR4D> optval = aSettings->Get<COLOR4D>( m_path ) )
|
if( OPT<COLOR4D> optval = aSettings->Get<COLOR4D>( m_path ) )
|
||||||
|
|
|
@ -61,7 +61,8 @@ public:
|
||||||
friend class NESTED_SETTINGS;
|
friend class NESTED_SETTINGS;
|
||||||
|
|
||||||
JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation, int aSchemaVersion ) :
|
JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation, int aSchemaVersion ) :
|
||||||
JSON_SETTINGS( aFilename, aLocation, aSchemaVersion, true, true, true ) {}
|
JSON_SETTINGS( aFilename, aLocation, aSchemaVersion, true, true, true )
|
||||||
|
{}
|
||||||
|
|
||||||
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 );
|
bool aCreateIfMissing, bool aCreateIfDefault, bool aWriteFile );
|
||||||
|
@ -123,13 +124,6 @@ c * @return true if the file was saved
|
||||||
*/
|
*/
|
||||||
void ResetToDefaults();
|
void ResetToDefaults();
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the current state of a parameter matches its default value
|
|
||||||
* @param aParamName is the JSON path to the parameter
|
|
||||||
* @return true if the given parameter is at its default value
|
|
||||||
*/
|
|
||||||
bool IsDefault( const std::string& aParamName );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the
|
* 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.
|
* form "key1.key2.key3" to refer to nested objects.
|
||||||
|
|
|
@ -54,12 +54,6 @@ public:
|
||||||
|
|
||||||
virtual void SetDefault() = 0;
|
virtual void SetDefault() = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether or not this param has been changed from its default value
|
|
||||||
* @return true if the parameter in memory matches its default value
|
|
||||||
*/
|
|
||||||
virtual bool IsDefault() const = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the parameter in memory matches the one in a given JSON file
|
* Checks whether the parameter in memory matches the one in a given JSON file
|
||||||
* @param aSettings is a JSON_SETTINGS to check the JSON file contents of
|
* @param aSettings is a JSON_SETTINGS to check the JSON file contents of
|
||||||
|
@ -144,11 +138,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||||
{
|
{
|
||||||
if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
if( OPT<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
||||||
|
@ -167,6 +156,30 @@ protected:
|
||||||
ValueType m_default;
|
ValueType m_default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles an obsolete parameter (ie: removes it on write).
|
||||||
|
*/
|
||||||
|
class PARAM_OBSOLETE : public PARAM_BASE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PARAM_OBSOLETE( const std::string& aJsonPath ) :
|
||||||
|
PARAM_BASE( aJsonPath, false )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Store( JSON_SETTINGS* aSettings ) const override;
|
||||||
|
|
||||||
|
void SetDefault() override
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||||
|
{
|
||||||
|
return !aSettings->Contains( m_path );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a path as a string with directory separators normalized to unix-style
|
* Stores a path as a string with directory separators normalized to unix-style
|
||||||
*/
|
*/
|
||||||
|
@ -268,11 +281,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||||
{
|
{
|
||||||
if( OPT<int> val = aSettings->Get<int>( m_path ) )
|
if( OPT<int> val = aSettings->Get<int>( m_path ) )
|
||||||
|
@ -328,11 +336,6 @@ public:
|
||||||
m_setter( m_default );
|
m_setter( m_default );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return m_getter() == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -414,11 +417,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||||
{
|
{
|
||||||
if( OPT<double> optval = aSettings->Get<double>( m_path ) )
|
if( OPT<double> optval = aSettings->Get<double>( m_path ) )
|
||||||
|
@ -463,11 +461,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -559,11 +552,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -596,11 +584,6 @@ public:
|
||||||
*m_ptr = m_default;
|
*m_ptr = m_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefault() const override
|
|
||||||
{
|
|
||||||
return *m_ptr == m_default;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue