diff --git a/libgnucash/app-utils/gnc-option-impl.cpp b/libgnucash/app-utils/gnc-option-impl.cpp index 5131aef8cc..92f60c29cd 100644 --- a/libgnucash/app-utils/gnc-option-impl.cpp +++ b/libgnucash/app-utils/gnc-option-impl.cpp @@ -334,9 +334,6 @@ qof_instance_from_guid(GncGUID* guid, GncOptionUIType type) case GncOptionUIType::TAX_TABLE: qof_type = "gncTaxtable"; break; - case GncOptionUIType::QUERY: - qof_type = "gncQuery"; - break; case GncOptionUIType::ACCOUNT_LIST: case GncOptionUIType::ACCOUNT_SEL: default: @@ -432,6 +429,11 @@ GncOptionValue::reset_default_value() m_value = m_default_value; } +/* Missing on purpose: QofQuery because for current usage it's serialized with + * gnc_query2scm. The future is to replace QofQuery with SQL queries so there's + * not much point to spending the time to create a std::string serialization for + * them. + */ template std::string GncOptionValue::serialize() const noexcept { diff --git a/libgnucash/app-utils/gnc-optiondb.i b/libgnucash/app-utils/gnc-optiondb.i index 3cb568f40a..334bb5d112 100644 --- a/libgnucash/app-utils/gnc-optiondb.i +++ b/libgnucash/app-utils/gnc-optiondb.i @@ -219,16 +219,15 @@ scm_from_value(const Account* value) } template <> inline SCM -scm_from_value(const QofQuery* value) +scm_from_value(QofQuery* value) { - auto ptr{static_cast(const_cast(value))}; - return SWIG_NewPointerObj(ptr, SWIGTYPE_p__QofQuery, FALSE); + return gnc_query2scm(value); } template <> inline SCM -scm_from_value(QofQuery* value) +scm_from_value(const QofQuery* value) { - return scm_from_value(value); + return scm_from_value(const_cast(value)); } template <> inline SCM @@ -1014,18 +1013,18 @@ inline SCM return_scm_value(ValueType value) static const auto no_value{scm_from_utf8_string("No Value")}; if constexpr (is_same_decayed_v) - { + { static const SCM list_format_str{scm_from_utf8_string("'~s")}; auto acct_list{option.get_value()}; if (acct_list.empty()) return no_value; SCM guid_list{scm_c_eval_string("'()")};//Empty list for(auto acct : acct_list) - { + { auto acct_str{qof_instance_to_string(QOF_INSTANCE(acct))}; auto acct_scm{scm_from_utf8_string(acct_str.c_str())}; guid_list = scm_cons(acct_scm, guid_list); - } + } return scm_simple_format(SCM_BOOL_F, list_format_str, scm_list_1(guid_list)); } @@ -1037,13 +1036,13 @@ inline SCM return_scm_value(ValueType value) return no_value; auto value{scm_list_1(scm_from_utf8_string(serial.c_str()))}; if (uitype == GncOptionUIType::CURRENCY) - { - const SCM quoted_format_str{scm_from_utf8_string("\"~a\"")}; - return scm_simple_format(SCM_BOOL_F, quoted_format_str, value); - } - else if (uitype == GncOptionUIType::COMMODITY) - { - const SCM commodity_fmt{scm_from_utf8_string("\"~a\" \"~a\"")}; + { + const SCM quoted_format_str{scm_from_utf8_string("\"~a\"")}; + return scm_simple_format(SCM_BOOL_F, quoted_format_str, value); + } + else if (uitype == GncOptionUIType::COMMODITY) + { + const SCM commodity_fmt{scm_from_utf8_string("\"~a\" \"~a\"")}; auto comm{GNC_COMMODITY(option.get_value())}; auto name_space{gnc_commodity_get_namespace(comm)}; auto mnemonic{gnc_commodity_get_mnemonic(comm)}; @@ -1052,20 +1051,20 @@ inline SCM return_scm_value(ValueType value) return scm_simple_format(SCM_BOOL_F, commodity_fmt, commodity_val); } else - { + { return scm_simple_format(SCM_BOOL_F, plain_format_str, value); - } - } + } + } if constexpr (is_same_decayed_v) - { + { auto serial{option.serialize()}; if (serial.empty()) return no_value; auto value{scm_list_1(scm_from_utf8_string(serial.c_str()))}; - const SCM date_fmt{scm_from_utf8_string("'~a")}; - return scm_simple_format(SCM_BOOL_F, date_fmt, value); - } + const SCM date_fmt{scm_from_utf8_string("'~a")}; + return scm_simple_format(SCM_BOOL_F, date_fmt, value); + } if constexpr (is_same_decayed_v>) @@ -1084,14 +1083,14 @@ inline SCM return_scm_value(ValueType value) GncOptionRangeValue> || is_same_decayed_v>) - { + { auto serial{option.serialize()}; if (serial.empty()) - { + { return no_value; - } - else - { + } + else + { auto scm_str{scm_list_1(scm_from_utf8_string(serial.c_str()))}; return scm_simple_format(SCM_BOOL_F, ticked_format_str, scm_str); } @@ -1100,7 +1099,7 @@ inline SCM return_scm_value(ValueType value) if (serial.empty()) { return no_value; - } + } else if ($self->get_ui_type() == GncOptionUIType::COLOR) { auto red{static_cast(std::stoi(serial.substr(0, 2), @@ -1124,7 +1123,7 @@ inline SCM return_scm_value(ValueType value) { auto scm_str{scm_list_1(scm_from_utf8_string(serial.c_str()))}; return scm_simple_format(SCM_BOOL_F, plain_format_str, scm_str); - } + } }, swig_get_option($self)); } @@ -1175,6 +1174,20 @@ inline SCM return_scm_value(ValueType value) } return; } + if constexpr (is_QofQueryValue_v) + { + if (scm_is_pair(new_value)) + { + auto val{gnc_scm2query(new_value)}; + option.set_value(val); + } + else + { + auto val{scm_to_value(new_value)}; + option.set_value(val); + } + return; + } if constexpr (is_same_decayed_v) { diff --git a/libgnucash/app-utils/options.scm b/libgnucash/app-utils/options.scm index 52e55c2e00..f0aaf2077b 100644 --- a/libgnucash/app-utils/options.scm +++ b/libgnucash/app-utils/options.scm @@ -274,7 +274,7 @@ (define-public (gnc:make-query-option section name default) (issue-deprecation-warning "gnc:make-query-option is deprecated. Make and register the option in one command with gnc-register-query-option.") (let ((defv (if (list? default) default (gnc-query2scm default)))) - (gnc-make-SCM-option section name "" "query" defv (GncOptionUIType-INTERNAL)))) + (gnc-make-query-option section name "" "query" defv (GncOptionUIType-INTERNAL)))) (define-public (gnc:make-internal-option section name default) (issue-deprecation-warning "gnc:make-internal-option is deprecated. Make and register the option in one command with gnc-register-internal-option.") (let ((type (GncOptionUIType-INTERNAL))