diff --git a/libgnucash/app-utils/gnc-option.hpp b/libgnucash/app-utils/gnc-option.hpp index 1677e7b5d2..414d7e39f9 100644 --- a/libgnucash/app-utils/gnc-option.hpp +++ b/libgnucash/app-utils/gnc-option.hpp @@ -138,6 +138,12 @@ private: GncOptionUIItemPtr m_ui_item{nullptr}; }; +inline bool +operator<(const GncOption& right, const GncOption& left) +{ + return right.get_key() < left.get_key(); +} + inline std::ostream& operator<<(std::ostream& oss, const GncOption& opt) { diff --git a/libgnucash/app-utils/gnc-optiondb-impl.hpp b/libgnucash/app-utils/gnc-optiondb-impl.hpp index d06f4a4520..97885c0fec 100644 --- a/libgnucash/app-utils/gnc-optiondb-impl.hpp +++ b/libgnucash/app-utils/gnc-optiondb-impl.hpp @@ -63,6 +63,13 @@ public: }; using GncOptionSectionPtr = std::shared_ptr; + +inline bool +operator<(const GncOptionSectionPtr& right, const GncOptionSectionPtr& left) +{ + return right->get_name() < left->get_name(); +} + using GncOptionDBChangeCallback = void (*)(void* user_data); struct GncOptionDBCallback diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index 763e7ec78a..be005b1c10 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -132,7 +132,9 @@ GncOptionSection::foreach_option(std::function func) con void GncOptionSection::add_option(GncOption&& option) { - m_options.emplace_back(std::move(option)); + m_options.push_back(std::move(option)); + if (!std::is_sorted(m_options.begin(), m_options.end())) + std::sort(m_options.begin(), m_options.end()); } void @@ -176,8 +178,10 @@ GncOptionDB::register_option(const char* sectname, GncOption&& option) return; } - m_sections.emplace_back(std::make_shared(sectname)); + m_sections.push_back(std::make_shared(sectname)); m_sections.back()->add_option(std::move(option)); + if (!std::is_sorted(m_sections.begin(), m_sections.end())) + std::sort(m_sections.begin(), m_sections.end()); } void