Config layer: Refactored handling of open enums

This commit is contained in:
Vojtech Bubnik 2023-09-05 09:42:36 +02:00
parent 8dad25efc4
commit 827fb8356e
2 changed files with 6 additions and 6 deletions

View File

@ -335,12 +335,9 @@ void ConfigDef::finalize()
if (def.type == coEnum) {
assert(def.enum_def);
assert(def.enum_def->is_valid_closed_enum());
assert(def.gui_type != ConfigOptionDef::GUIType::i_enum_open &&
def.gui_type != ConfigOptionDef::GUIType::f_enum_open &&
def.gui_type != ConfigOptionDef::GUIType::select_open);
assert(! def.is_gui_type_enum_open());
def.enum_def->finalize_closed_enum();
} else if (def.gui_type == ConfigOptionDef::GUIType::i_enum_open || def.gui_type == ConfigOptionDef::GUIType::f_enum_open ||
def.gui_type == ConfigOptionDef::GUIType::select_open) {
} else if (def.is_gui_type_enum_open()) {
assert(def.enum_def);
assert(def.enum_def->is_valid_open_enum());
assert(def.gui_type != ConfigOptionDef::GUIType::i_enum_open || def.type == coInt || def.type == coInts);
@ -427,7 +424,7 @@ std::ostream& ConfigDef::print_cli_help(std::ostream& out, bool show_defaults, s
descr += " (";
if (!def.sidetext.empty()) {
descr += def.sidetext + ", ";
} else if (def.enum_def->has_values()) {
} else if (def.enum_def && def.enum_def->has_values()) {
descr += boost::algorithm::join(def.enum_def->values(), ", ") + "; ";
}
descr += "default: " + def.default_value->serialize() + ")";

View File

@ -1836,6 +1836,8 @@ public:
// Close parameter, string value could be one of the list values.
select_close,
};
static bool is_gui_type_enum_open(const GUIType gui_type)
{ return gui_type == ConfigOptionDef::GUIType::i_enum_open || gui_type == ConfigOptionDef::GUIType::f_enum_open || gui_type == ConfigOptionDef::GUIType::select_open; }
// Identifier of this option. It is stored here so that it is accessible through the by_serialization_key_ordinal map.
t_config_option_key opt_key;
@ -1923,6 +1925,7 @@ public:
// Special values - "i_enum_open", "f_enum_open" to provide combo box for int or float selection,
// "select_open" - to open a selection dialog (currently only a serial port selection).
GUIType gui_type { GUIType::undefined };
bool is_gui_type_enum_open() const { return is_gui_type_enum_open(this->gui_type); }
// Usually empty. Otherwise "serialized" or "show_value"
// The flags may be combined.
// "serialized" - vector valued option is entered in a single edit field. Values are separated by a semicolon.