Fix default values for color theme editor

At the time of creating a copy, the defaultColors map
is not initialized, so needs to be initialized from the
copy constructor.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/4841
This commit is contained in:
Jon Evans 2020-07-08 12:19:10 -04:00
parent 37ce9fb847
commit 3dd2dc89ad
2 changed files with 20 additions and 7 deletions

View File

@ -214,22 +214,33 @@ COLOR_SETTINGS::COLOR_SETTINGS( std::string aFilename ) :
COLOR_SETTINGS::COLOR_SETTINGS( const COLOR_SETTINGS& aOther ) :
JSON_SETTINGS( aOther.m_filename, SETTINGS_LOC::COLORS, colorsSchemaVersion )
{
m_displayName = aOther.m_displayName;
m_overrideSchItemColors = aOther.m_overrideSchItemColors;
m_colors = aOther.m_colors;
m_defaultColors = aOther.m_defaultColors;
initFromOther( aOther );
}
COLOR_SETTINGS& COLOR_SETTINGS::operator=( const COLOR_SETTINGS &aOther )
{
m_filename = aOther.m_filename;
m_filename = aOther.m_filename;
initFromOther( aOther );
return *this;
}
void COLOR_SETTINGS::initFromOther( const COLOR_SETTINGS& aOther )
{
m_displayName = aOther.m_displayName;
m_overrideSchItemColors = aOther.m_overrideSchItemColors;
m_colors = aOther.m_colors;
m_defaultColors = aOther.m_defaultColors;
return *this;
// Ensure default colors are present
for( PARAM_BASE* param : aOther.m_params )
{
if( COLOR_MAP_PARAM* cmp = dynamic_cast<COLOR_MAP_PARAM*>( param ) )
m_defaultColors[cmp->GetKey()] = cmp->GetDefault();
}
}
@ -335,7 +346,7 @@ COLOR4D COLOR_SETTINGS::GetDefaultColor( int aLayer )
m_defaultColors[aLayer] = COLOR4D::UNSPECIFIED;
}
return m_defaultColors.at( aLayer );;
return m_defaultColors.at( aLayer );
}

View File

@ -91,6 +91,8 @@ public:
private:
bool migrateSchema0to1();
void initFromOther( const COLOR_SETTINGS& aOther );
wxString m_displayName;
bool m_overrideSchItemColors;