From f66a918be463bc36a3ecd6c5c8d28eac05837df8 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 11 Mar 2021 18:03:36 -0800 Subject: [PATCH] Implement GncOptionValue QofQuery isn't a QofInstance and doesn't have a GUID. --- libgnucash/app-utils/gnc-option-impl.hpp | 30 ++++++++++++++++++++++++ libgnucash/app-utils/gnc-option.cpp | 7 ++++++ libgnucash/app-utils/gnc-option.hpp | 4 ++++ libgnucash/app-utils/gnc-optiondb.i | 18 ++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/libgnucash/app-utils/gnc-option-impl.hpp b/libgnucash/app-utils/gnc-option-impl.hpp index 4b2f84de3a..09eb8d20df 100644 --- a/libgnucash/app-utils/gnc-option-impl.hpp +++ b/libgnucash/app-utils/gnc-option-impl.hpp @@ -1157,4 +1157,34 @@ operator>> (std::istream& iss, return opt.in_stream(iss); } +/** QofQuery Options + */ + +inline std::istream& +gnc_option_from_scheme(std::istream& iss, GncOptionValue& opt) +{ +//FIXME: Implement or maybe rethink. + return iss; +} + +inline std::ostream& +gnc_option_to_scheme(std::ostream& oss, GncOptionValue& opt) +{ +//FIXME: Implement or maybe rethink. + return oss; +} + +inline std::istream& +gnc_option_from_scheme(std::istream& iss, GncOptionValidatedValue& opt) +{ +//FIXME: Implement or maybe rethink. + return iss; +} + +inline std::ostream& +gnc_option_to_scheme(std::ostream& oss, GncOptionValidatedValue& opt) +{ +//FIXME: Implement or maybe rethink. + return oss; +} #endif //GNC_OPTION_IMPL_HPP_ diff --git a/libgnucash/app-utils/gnc-option.cpp b/libgnucash/app-utils/gnc-option.cpp index 4ef3af971d..6f708681bf 100644 --- a/libgnucash/app-utils/gnc-option.cpp +++ b/libgnucash/app-utils/gnc-option.cpp @@ -481,8 +481,12 @@ GncOption::from_scheme(std::istream& iss) (std::is_same_v, GncOptionMultichoiceValue>) || std::is_same_v, + GncOptionValue> || + std::is_same_v, GncOptionValue> || std::is_same_v, + GncOptionValidatedValue> || + std::is_same_v, GncOptionValidatedValue>) gnc_option_from_scheme(iss, option); else if constexpr @@ -571,6 +575,8 @@ template GncOption::GncOption(const char*, const char*, const char*, const char*, const QofInstance*, GncOptionUIType); template GncOption::GncOption(const char*, const char*, const char*, const char*, SCM, GncOptionUIType); +template GncOption::GncOption(const char*, const char*, const char*, + const char*, const QofQuery*, GncOptionUIType); template bool GncOption::get_value() const; template int GncOption::get_value() const; @@ -634,6 +640,7 @@ template bool GncOption::validate(double) const; template bool GncOption::validate(const char*) const; template bool GncOption::validate(std::string) const; template bool GncOption::validate(const QofInstance*) const; +template bool GncOption::validate(const QofQuery*) const; template bool GncOption::validate(RelativeDatePeriod) const; template bool GncOption::validate(GncMultichoiceOptionIndexVec) const; diff --git a/libgnucash/app-utils/gnc-option.hpp b/libgnucash/app-utils/gnc-option.hpp index 401c84f3a7..5edbc9404c 100644 --- a/libgnucash/app-utils/gnc-option.hpp +++ b/libgnucash/app-utils/gnc-option.hpp @@ -40,6 +40,8 @@ extern "C" struct OptionClassifier; class GncOptionUIItem; using GncOptionUIItemPtr = std::unique_ptr; +struct _QofQuery; +using QofQuery = _QofQuery; struct QofInstance_s; using QofInstance = QofInstance_s; template class GncOptionValue; @@ -53,12 +55,14 @@ using GncOptionVariant = std::variant, GncOptionValue, GncOptionValue, GncOptionValue, + GncOptionValue, GncOptionValue, GncOptionAccountValue, GncOptionMultichoiceValue, GncOptionRangeValue, GncOptionRangeValue, GncOptionValidatedValue, + GncOptionValidatedValue, GncOptionDateValue>; using GncOptionVariantPtr = std::unique_ptr; diff --git a/libgnucash/app-utils/gnc-optiondb.i b/libgnucash/app-utils/gnc-optiondb.i index 0541644b32..f46446c262 100644 --- a/libgnucash/app-utils/gnc-optiondb.i +++ b/libgnucash/app-utils/gnc-optiondb.i @@ -208,6 +208,13 @@ scm_from_value(const QofInstance* value) return SWIG_NewPointerObj(ptr, type, FALSE); } +template <> inline SCM +scm_from_value(const QofQuery* value) +{ + auto ptr{static_cast(const_cast(value))}; + return SWIG_NewPointerObj(ptr, SWIGTYPE_p__QofQuery, FALSE); +} + template inline ValueType scm_to_value(SCM new_value) { @@ -273,6 +280,16 @@ scm_to_value(SCM new_value) return static_cast(ptr); } +template <> inline const QofQuery* +scm_to_value(SCM new_value) +{ + if (new_value == SCM_BOOL_F) + return nullptr; + void* ptr{}; + SWIG_ConvertPtr(new_value, &ptr, SWIGTYPE_p__QofQuery, 0); + return static_cast(ptr); +} + template <>inline GncOptionAccountList scm_to_value(SCM new_value) { @@ -689,6 +706,7 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB); %template(gnc_make_bool_option) gnc_make_option; %template(gnc_make_int64_option) gnc_make_option; %template(gnc_make_qofinstance_option) gnc_make_option; +%template(gnc_make_query_option) gnc_make_option; %extend GncOption { SCM get_scm_value()