OptionsSearcher improvements: Fixed a key for option() and groups_and_categories.

It contains "preset_type;opt_key" now. This key helps to avoid a collisions by using a same options key from different type presets.
Example: Option "elefant_foot_compensation" is in Print presets and SLA_printer presets
This commit is contained in:
YuSanka 2021-03-24 10:45:37 +01:00
parent 10c3e82917
commit 991fa67fd1
7 changed files with 59 additions and 41 deletions

View file

@ -38,11 +38,11 @@ struct GroupAndCategory {
struct Option {
// bool operator<(const Option& other) const { return other.label > this->label; }
bool operator<(const Option& other) const { return other.opt_key > this->opt_key; }
bool operator<(const Option& other) const { return other.key > this->key; }
// Fuzzy matching works at a character level. Thus matching with wide characters is a safer bet than with short characters,
// though for some languages (Chinese?) it may not work correctly.
std::wstring opt_key;
std::wstring key;
Preset::Type type {Preset::TYPE_INVALID};
std::wstring label;
std::wstring label_local;
@ -50,6 +50,8 @@ struct Option {
std::wstring group_local;
std::wstring category;
std::wstring category_local;
std::string opt_key() const { return boost::nowide::narrow(key).substr(2); }
};
struct FoundOption {
@ -110,13 +112,13 @@ public:
bool search();
bool search(const std::string& search, bool force = false);
void add_key(const std::string& opt_key, const wxString& group, const wxString& category);
void add_key(const std::string& opt_key, Preset::Type type, const wxString& group, const wxString& category);
size_t size() const { return found_size(); }
const FoundOption& operator[](const size_t pos) const noexcept { return found[pos]; }
const Option& get_option(size_t pos_in_filter) const;
const Option& get_option(const std::string& opt_key) const;
const Option& get_option(const std::string& opt_key, Preset::Type type) const;
Option get_option(const std::string& opt_key, const wxString& label, Preset::Type type) const;
const std::vector<FoundOption>& found_options() { return found; }
@ -125,10 +127,11 @@ public:
void set_printer_technology(PrinterTechnology pt) { printer_technology = pt; }
void sort_options_by_opt_key() {
void sort_options_by_key() {
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
return o1.opt_key < o2.opt_key; });
return o1.key < o2.key; });
}
void sort_options_by_label() { sort_options(); }
};