Retire PARAM_OBSOLETE in favour of a schema migration.

This commit is contained in:
Jeff Young 2021-08-02 17:38:15 +01:00
parent 7d501e8a43
commit 78fd268b18
4 changed files with 28 additions and 35 deletions

View File

@ -21,6 +21,7 @@
#include <3d_enums.h>
#include <common_ogl/ogl_attr_list.h>
#include <settings/parameters.h>
#include <settings/json_settings_internals.h>
#include <wx/config.h>
#include "eda_3d_viewer_settings.h"
@ -28,7 +29,7 @@
using KIGFX::COLOR4D;
///! Update the schema version whenever a migration is required
const int viewer3dSchemaVersion = 0;
const int viewer3dSchemaVersion = 1;
EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS()
@ -169,7 +170,8 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS()
&m_Render.show_board_body, true ) );
m_params.emplace_back( new PARAM<bool>( "render.show_comments",
&m_Render.show_comments, true ) );
m_params.emplace_back( new PARAM<bool>( "render.show_eco", &m_Render.show_eco, true ) );
m_params.emplace_back( new PARAM<bool>( "render.show_eco",
&m_Render.show_eco, true ) );
m_params.emplace_back( new PARAM<bool>( "render.show_footprints_insert",
&m_Render.show_footprints_insert, true ) );
m_params.emplace_back( new PARAM<bool>( "render.show_footprints_normal",
@ -199,7 +201,27 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS()
m_params.emplace_back( new PARAM<int>( "camera.projection_mode",
&m_Camera.projection_mode, 1 ) );
m_params.emplace_back( new PARAM_OBSOLETE( "colors" ) );
registerMigration( 0, 1, std::bind( &EDA_3D_VIEWER_SETTINGS::migrateSchema0to1, this ) );
}
bool EDA_3D_VIEWER_SETTINGS::migrateSchema0to1()
{
/**
* Schema version 0 to 1:
*
* delete colors (they're now stored in the 'user' color theme.
*/
try
{
if( m_internals->contains( "colors" ) )
m_internals->erase( "colors" );
}
catch( ... )
{
}
return true;
}

View File

@ -106,8 +106,10 @@ public:
CAMERA_SETTINGS m_Camera;
protected:
virtual std::string getLegacyFrameName() const override { return "Viewer3DFrameName"; }
private:
bool migrateSchema0to1();
};

View File

@ -25,13 +25,6 @@
#include <gal/color4d.h>
#include <project/project_file.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>

View File

@ -156,30 +156,6 @@ protected:
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
*/