mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Adapt GncOptionMultiChoiceValue to support list options.
Main change adds a value field to the constructor to set the value and default value.
This commit is contained in:
@@ -311,11 +311,22 @@ class GncOptionMultichoiceValue :
|
||||
public:
|
||||
GncOptionMultichoiceValue(const char* section, const char* name,
|
||||
const char* key, const char* doc_string,
|
||||
const char* value,
|
||||
GncMultiChoiceOptionChoices&& choices,
|
||||
GncOptionUIType ui_type = GncOptionUIType::MULTICHOICE) :
|
||||
OptionClassifier{section, name, key, doc_string},
|
||||
OptionUIItem(ui_type),
|
||||
m_value{}, m_default_value{}, m_choices{std::move(choices)} {}
|
||||
m_value{}, m_default_value{}, m_choices{std::move(choices)} {
|
||||
if (value)
|
||||
{
|
||||
if (auto index = find_key(value);
|
||||
index != std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
m_value = index;
|
||||
m_default_value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GncOptionMultichoiceValue(const GncOptionMultichoiceValue&) = default;
|
||||
GncOptionMultichoiceValue(GncOptionMultichoiceValue&&) = default;
|
||||
|
||||
@@ -314,21 +314,21 @@ void
|
||||
gnc_register_multichoice_option(const GncOptionDBPtr& db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string,
|
||||
GncMultiChoiceOptionChoices&& value)
|
||||
GncMultiChoiceOptionChoices&& choices)
|
||||
{
|
||||
GncOption option{GncOptionMultichoiceValue{section, name, key, doc_string,
|
||||
std::move(value)}};
|
||||
std::get<0>(choices.at(0)).c_str(), std::move(choices)}};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
void
|
||||
gnc_register_list_option(const GncOptionDBPtr& db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string,
|
||||
GncMultiChoiceOptionChoices&& value)
|
||||
const char* doc_string, const char* value,
|
||||
GncMultiChoiceOptionChoices&& list)
|
||||
{
|
||||
GncOption option{GncOptionMultichoiceValue{section, name, key, doc_string,
|
||||
std::move(value), GncOptionUIType::LIST}};
|
||||
value, std::move(list), GncOptionUIType::LIST}};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ gnc_register_query_option(const GncOptionDBPtr& db, const char* section,
|
||||
const char* doc_string, QofQuery* value)
|
||||
{
|
||||
GncOption option{section, name, key, doc_string, value,
|
||||
GncOptionUIType::QUERY};
|
||||
GncOptionUIType::INTERNAL};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
|
||||
@@ -211,8 +211,8 @@ void gnc_register_multichoice_option(const GncOptionDBPtr& db,
|
||||
*/
|
||||
void gnc_register_list_option(const GncOptionDBPtr& db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string,
|
||||
GncMultiChoiceOptionChoices&& value);
|
||||
const char* doc_string, const char* value,
|
||||
GncMultiChoiceOptionChoices&& list);
|
||||
|
||||
/* Number range options use the option-data as a list whose elements are:
|
||||
* (lower-bound upper-bound step-size).
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
(test-begin "test-gnc-optiondb-scheme")
|
||||
(test-gnc-make-text-option)
|
||||
(test-gnc-make-multichoice-option)
|
||||
(test-gnc-make-list-option)
|
||||
(test-gnc-make-date-option)
|
||||
(test-gnc-make-number-range-option)
|
||||
(test-end "test-gnc-optiondb-scheme"))
|
||||
@@ -80,6 +81,20 @@
|
||||
(test-equal "corge" (gnc-option-value option-db "foo" "bar")))
|
||||
(test-end "test-gnc-test-multichoice-option"))
|
||||
|
||||
(define (test-gnc-make-list-option)
|
||||
(test-begin "test-gnc-test-list-option")
|
||||
(let* ((option-db (gnc-option-db-new))
|
||||
(value-list (list (vector "AvgBalPlot" "Average" "Average Balance")
|
||||
(vector "GainPlot" "Profit" "Profit (Gain minus Loss)")
|
||||
(vector "GLPlot" "Gain/Loss" "Gain and Loss")))
|
||||
(list-op (gnc-register-list-option option-db "foo" "bar" "baz"
|
||||
"Phony Option" "AvgBalPlot"
|
||||
value-list)))
|
||||
(test-equal "AvgBalPlot" (gnc-option-value option-db "foo" "bar"))
|
||||
(gnc-set-option option-db "foo" "bar" "GLPlot")
|
||||
(test-equal "GLPlot" (gnc-option-value option-db "foo" "bar"))
|
||||
(test-end "test-gnc-test-list-option"))
|
||||
|
||||
(define (test-gnc-make-date-option)
|
||||
(test-begin "test-gnc-test-date-option")
|
||||
(let* ((option-db (gnc-option-db-new))
|
||||
|
||||
Reference in New Issue
Block a user