FIX: support config editing of type FloatsOrPercents

Change-Id: If0821dc357b14f1b72aa1c89b3b0378947e80a5c
Jira: none
(cherry picked from commit 115fb9ce072273acf8df558a33fe48cf71f8e35b)
This commit is contained in:
chunmao.guo 2024-07-19 09:59:23 +08:00 committed by Lane.Wei
parent 0b92ffee35
commit 0c03a6b361
5 changed files with 55 additions and 32 deletions

View File

@ -2686,6 +2686,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi
case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, config_other, config_this); break; case coFloats: add_correct_opts_to_diff<ConfigOptionFloats >(opt_key, diff, config_other, config_this); break;
case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, config_other, config_this); break; case coStrings: add_correct_opts_to_diff<ConfigOptionStrings >(opt_key, diff, config_other, config_this); break;
case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, config_other, config_this); break; case coPercents:add_correct_opts_to_diff<ConfigOptionPercents >(opt_key, diff, config_other, config_this); break;
case coFloatsOrPercents: add_correct_opts_to_diff<ConfigOptionFloatsOrPercents>(opt_key, diff, config_other, config_this); break;
case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, config_other, config_this); break; case coPoints: add_correct_opts_to_diff<ConfigOptionPoints >(opt_key, diff, config_other, config_this); break;
// BBS // BBS
case coEnums: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break; case coEnums: add_correct_opts_to_diff<ConfigOptionInts >(opt_key, diff, config_other, config_this); break;

View File

@ -338,7 +338,8 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
break; } break; }
case coString: case coString:
case coStrings: case coStrings:
case coFloatOrPercent: { case coFloatOrPercent:
case coFloatsOrPercents: {
if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%') if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%')
{ {
double val = 0.; double val = 0.;

View File

@ -108,8 +108,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
try{ try{
if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) {
ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) }; auto vec_new = std::make_unique<ConfigOptionBoolsNullable>(1, boost::any_cast<unsigned char>(value) );
config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new.get(), opt_index, 0);
return; return;
} }
@ -125,6 +125,17 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field) double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent)); config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent));
break;} break;}
case coFloatsOrPercents:{
std::string str = boost::any_cast<std::string>(value);
bool percent = false;
if (str.back() == '%') {
str.pop_back();
percent = true;
}
double val = std::stod(str); // locale-dependent (on purpose - the input is the actual content of the field)
auto vec_new = std::make_unique<ConfigOptionFloatOrPercent>(val, percent);
config.option<ConfigOptionFloatsOrPercents>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break;}
case coPercent: case coPercent:
config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value))); config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast<double>(value)));
break; break;
@ -134,13 +145,13 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break; break;
} }
case coPercents:{ case coPercents:{
ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) }; auto vec_new = std::make_unique <ConfigOptionPercent>(boost::any_cast<double>(value));
config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break; break;
} }
case coFloats:{ case coFloats:{
ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) }; auto vec_new = std::make_unique<ConfigOptionFloat>(boost::any_cast<double>(value));
config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index); config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new.get(), opt_index, opt_index);
break; break;
} }
case coString: case coString:
@ -165,8 +176,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.option<ConfigOptionStrings>(opt_key)->values = values; config.option<ConfigOptionStrings>(opt_key)->values = values;
} }
else{ else{
ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) }; auto vec_new = std::make_unique<ConfigOptionString>(boost::any_cast<std::string>(value));
config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
} }
break; break;
@ -174,15 +185,15 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value))); config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
break; break;
case coBools:{ case coBools:{
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 }; auto vec_new = std::make_unique<ConfigOptionBool>(boost::any_cast<unsigned char>(value) != 0);
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionBools>(opt_key)->set_at(vec_new.get(), opt_index, 0);
break;} break;}
case coInt: case coInt:
config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value))); config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value)));
break; break;
case coInts:{ case coInts:{
ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) }; auto vec_new = std::make_unique<ConfigOptionInt>(boost::any_cast<int>(value));
config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionInts>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coEnum:{ case coEnum:{
@ -193,9 +204,9 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
break; break;
// BBS // BBS
case coEnums:{ case coEnums:{
ConfigOptionEnumsGeneric* vec_new = new ConfigOptionEnumsGeneric{ boost::any_cast<int>(value) }; auto vec_new = std::make_unique<ConfigOptionEnumsGeneric>(std::vector<int>{boost::any_cast<int>(value)});
if (config.has(opt_key)) if (config.has(opt_key))
config.option<ConfigOptionEnumsGeneric>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionEnumsGeneric>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coPoint:{ case coPoint:{
@ -207,8 +218,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value); config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
break; break;
} }
ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast<Vec2d>(value) }; auto vec_new = std::make_unique<ConfigOptionPoint>(boost::any_cast<Vec2d>(value));
config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new, opt_index, 0); config.option<ConfigOptionPoints>(opt_key)->set_at(vec_new.get(), opt_index, 0);
} }
break; break;
case coNone: case coNone:

View File

@ -980,6 +980,15 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
if (value.percent) if (value.percent)
text_value += "%"; text_value += "%";
ret = text_value;
break;
}
case coFloatsOrPercents: {
const auto &value = config.option<ConfigOptionFloatsOrPercents>(opt_key)->get_at(idx);
text_value = double_to_string(value.value);
if (value.percent) text_value += "%";
ret = text_value; ret = text_value;
break; break;
} }

View File

@ -875,6 +875,7 @@ void TabPrinter::init_options_list()
case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break; case coFloats: add_correct_opts_to_options_list<ConfigOptionFloats >(opt_key, m_options_list, this, m_opt_status_value); break;
case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break; case coStrings: add_correct_opts_to_options_list<ConfigOptionStrings >(opt_key, m_options_list, this, m_opt_status_value); break;
case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break; case coPercents:add_correct_opts_to_options_list<ConfigOptionPercents >(opt_key, m_options_list, this, m_opt_status_value); break;
case coFloatsOrPercents: add_correct_opts_to_options_list<ConfigOptionFloatsOrPercents>(opt_key, m_options_list, this, m_opt_status_value); break;
case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break; case coPoints: add_correct_opts_to_options_list<ConfigOptionPoints >(opt_key, m_options_list, this, m_opt_status_value); break;
// BBS // BBS
case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break; case coEnums: add_correct_opts_to_options_list<ConfigOptionInts >(opt_key, m_options_list, this, m_opt_status_value); break;