mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Make separate option type for GncOwner.
GncOwner is not a QofInstance subclass.
This commit is contained in:
parent
9d150b1ae7
commit
05ac056449
@ -326,6 +326,7 @@ template GncOptionValue<const char*>::GncOptionValue(const GncOptionValue<const
|
||||
template GncOptionValue<std::string>::GncOptionValue(const GncOptionValue<std::string>&);
|
||||
template GncOptionValue<const QofInstance*>::GncOptionValue(const GncOptionValue<const QofInstance*>&);
|
||||
template GncOptionValue<const QofQuery*>::GncOptionValue(const GncOptionValue<const QofQuery*>&);
|
||||
template GncOptionValue<const GncOwner*>::GncOptionValue(const GncOptionValue<const GncOwner*>&);
|
||||
template GncOptionValue<RelativeDatePeriod>::GncOptionValue(const GncOptionValue<RelativeDatePeriod>&);
|
||||
template GncOptionValue<size_t>::GncOptionValue(const GncOptionValue<size_t>&);
|
||||
template GncOptionValue<GncOptionAccountList>::GncOptionValue(const GncOptionValue<GncOptionAccountList>&);
|
||||
@ -340,6 +341,7 @@ template void GncOptionValue<const char*>::set_value(const char*);
|
||||
template void GncOptionValue<std::string>::set_value(std::string);
|
||||
template void GncOptionValue<const QofInstance*>::set_value(const QofInstance*);
|
||||
template void GncOptionValue<const QofQuery*>::set_value(const QofQuery*);
|
||||
template void GncOptionValue<const GncOwner*>::set_value(const GncOwner*);
|
||||
template void GncOptionValue<RelativeDatePeriod>::set_value(RelativeDatePeriod);
|
||||
template void GncOptionValue<size_t>::set_value(size_t);
|
||||
template void GncOptionValue<GncOptionAccountList>::set_value(GncOptionAccountList);
|
||||
@ -353,6 +355,7 @@ template void GncOptionValue<const char*>::set_default_value(const char*);
|
||||
template void GncOptionValue<std::string>::set_default_value(std::string);
|
||||
template void GncOptionValue<const QofInstance*>::set_default_value(const QofInstance*);
|
||||
template void GncOptionValue<const QofQuery*>::set_default_value(const QofQuery*);
|
||||
template void GncOptionValue<const GncOwner*>::set_default_value(const GncOwner*);
|
||||
template void GncOptionValue<RelativeDatePeriod>::set_default_value(RelativeDatePeriod);
|
||||
template void GncOptionValue<size_t>::set_default_value(size_t);
|
||||
template void GncOptionValue<GncOptionAccountList>::set_default_value(GncOptionAccountList);
|
||||
@ -366,6 +369,7 @@ template void GncOptionValue<const char*>::reset_default_value();
|
||||
template void GncOptionValue<std::string>::reset_default_value();
|
||||
template void GncOptionValue<const QofInstance*>::reset_default_value();
|
||||
template void GncOptionValue<const QofQuery*>::reset_default_value();
|
||||
template void GncOptionValue<const GncOwner*>::reset_default_value();
|
||||
template void GncOptionValue<RelativeDatePeriod>::reset_default_value();
|
||||
template void GncOptionValue<size_t>::reset_default_value();
|
||||
template void GncOptionValue<GncOptionAccountList>::reset_default_value();
|
||||
|
@ -309,6 +309,7 @@ std::istream& operator>>(std::istream& iss, OptType& opt)
|
||||
{
|
||||
std::decay_t<decltype(opt.get_value())> value;
|
||||
if constexpr (std::is_same_v<std::decay_t<decltype(opt.get_value())>, SCM> ||
|
||||
std::is_same_v<std::decay_t<decltype(opt.get_value())>, const _gncOwner*> ||
|
||||
std::is_same_v<std::decay_t<decltype(opt.get_value())>, const _QofQuery*>)
|
||||
return iss;
|
||||
else
|
||||
@ -1198,6 +1199,20 @@ operator>> <GncOptionDateValue>(std::istream& iss,
|
||||
/** QofQuery Options
|
||||
*/
|
||||
|
||||
inline std::istream&
|
||||
gnc_option_from_scheme(std::istream& iss, GncOptionValue<const GncOwner*>& opt)
|
||||
{
|
||||
//FIXME: Implement or maybe rethink.
|
||||
return iss;
|
||||
}
|
||||
|
||||
inline std::ostream&
|
||||
gnc_option_to_scheme(std::ostream& oss, GncOptionValue<const GncOwner*>& opt)
|
||||
{
|
||||
//FIXME: Implement or maybe rethink.
|
||||
return oss;
|
||||
}
|
||||
|
||||
inline std::istream&
|
||||
gnc_option_from_scheme(std::istream& iss, GncOptionValue<const QofQuery*>& opt)
|
||||
{
|
||||
|
@ -468,6 +468,8 @@ GncOption::from_scheme(std::istream& iss)
|
||||
(std::is_same_v<std::decay_t<decltype(option)>,
|
||||
GncOptionMultichoiceValue>) ||
|
||||
std::is_same_v<std::decay_t<decltype(option)>,
|
||||
GncOptionValue<const GncOwner*>> ||
|
||||
std::is_same_v<std::decay_t<decltype(option)>,
|
||||
GncOptionValue<const QofQuery*>> ||
|
||||
std::is_same_v<std::decay_t<decltype(option)>,
|
||||
GncOptionValue<const QofInstance*>> ||
|
||||
@ -564,6 +566,8 @@ 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 GncOption::GncOption(const char*, const char*, const char*,
|
||||
const char*, const GncOwner*, GncOptionUIType);
|
||||
|
||||
template bool GncOption::get_value<bool>() const;
|
||||
template int GncOption::get_value<int>() const;
|
||||
|
@ -40,6 +40,10 @@ extern "C"
|
||||
struct OptionClassifier;
|
||||
class GncOptionUIItem;
|
||||
using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
|
||||
#ifndef SWIG //SWIG pulls in GncOwner from swig-engine.
|
||||
struct _gncOwner;
|
||||
using GncOwner = _gncOwner;
|
||||
#endif
|
||||
struct _QofQuery;
|
||||
using QofQuery = _QofQuery;
|
||||
struct QofInstance_s;
|
||||
@ -56,6 +60,7 @@ using GncOptionVariant = std::variant<GncOptionValue<std::string>,
|
||||
GncOptionValue<int64_t>,
|
||||
GncOptionValue<const QofInstance*>,
|
||||
GncOptionValue<const QofQuery*>,
|
||||
GncOptionValue<const GncOwner*>,
|
||||
GncOptionValue<SCM>,
|
||||
GncOptionAccountValue,
|
||||
GncOptionMultichoiceValue,
|
||||
|
@ -1061,9 +1061,19 @@ gnc_register_number_plot_size_option(GncOptionDB* db,
|
||||
void
|
||||
gnc_register_query_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, QofQuery* value)
|
||||
const char* doc_string, const QofQuery* value)
|
||||
{
|
||||
GncOption option{section, name, key, doc_string, (const QofInstance*)value,
|
||||
GncOption option{section, name, key, doc_string, value,
|
||||
GncOptionUIType::INTERNAL};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
void
|
||||
gnc_register_owner_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, const GncOwner* value)
|
||||
{
|
||||
GncOption option{section, name, key, doc_string, value,
|
||||
GncOptionUIType::INTERNAL};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
@ -501,18 +501,43 @@ inline void gnc_register_number_plot_size_option(const GncOptionDBPtr& db,
|
||||
*/
|
||||
void gnc_register_query_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, QofQuery* value);
|
||||
const char* doc_string, const QofQuery* value);
|
||||
|
||||
/**
|
||||
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
|
||||
*/
|
||||
inline void gnc_register_query_option(GncOptionDBPtr& db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, QofQuery* value)
|
||||
const char* doc_string,
|
||||
const QofQuery* value)
|
||||
{
|
||||
gnc_register_query_option(db.get(), section, name, key, doc_string, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GncOwner option and register it in the options database.
|
||||
*
|
||||
* @param db A GncOptionDB* for calling from C. Caller retains ownership.
|
||||
* @param section The database section for the option.
|
||||
* @param name The option name.
|
||||
* @param doc_string A description of the option. This will be used in tooltips and should be marked for translation.
|
||||
* @param value The initial and default value for the option.
|
||||
*/
|
||||
void gnc_register_owner_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, const GncOwner* value);
|
||||
|
||||
/**
|
||||
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
|
||||
*/
|
||||
inline void gnc_register_owner_option(GncOptionDBPtr& db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string,
|
||||
const GncOwner* value)
|
||||
{
|
||||
gnc_register_owner_option(db.get(), section, name, key, doc_string, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new color option and register it in the options database.
|
||||
*
|
||||
|
@ -53,6 +53,7 @@ SCM scm_init_sw_gnc_optiondb_module(void);
|
||||
%include <std_string.i>
|
||||
%import <base-typemaps.i>
|
||||
%import (module="sw_engine") <gnc-budget.h>
|
||||
%import (module="sw_engine") <gncOwner.h>
|
||||
%import (module="sw_engine") <gncCustomer.h>
|
||||
%import (module="sw_engine") <gncEmployee.h>
|
||||
%import (module="sw_engine") <gncVendor.h>
|
||||
@ -195,13 +196,16 @@ scm_from_value<const QofInstance*>(const QofInstance* value)
|
||||
type = SWIGTYPE_p__gncJob;
|
||||
else if (GNC_IS_VENDOR(value))
|
||||
type = SWIGTYPE_p__gncVendor;
|
||||
/* There is no type macro for QofQuery, it's not a GObject.
|
||||
else if (GNC_IS_QOFQUERY(value))
|
||||
type = SWIGTYPE_p_Query;
|
||||
*/
|
||||
|
||||
return SWIG_NewPointerObj(ptr, type, FALSE);
|
||||
}
|
||||
|
||||
template <> inline SCM
|
||||
scm_from_value<QofInstance*>(QofInstance* value)
|
||||
{
|
||||
return scm_from_value<const QofInstance*>(value);
|
||||
}
|
||||
|
||||
template <> inline SCM
|
||||
scm_from_value<const QofQuery*>(const QofQuery* value)
|
||||
{
|
||||
@ -216,9 +220,16 @@ scm_from_value<QofQuery*>(QofQuery* value)
|
||||
}
|
||||
|
||||
template <> inline SCM
|
||||
scm_from_value<QofInstance*>(QofInstance* value)
|
||||
scm_from_value<const GncOwner*>(const GncOwner* value)
|
||||
{
|
||||
return scm_from_value<const QofInstance*>(value);
|
||||
auto ptr{static_cast<void*>(const_cast<GncOwner*>(value))};
|
||||
return SWIG_NewPointerObj(ptr, SWIGTYPE_p__gncOwner, FALSE);
|
||||
}
|
||||
|
||||
template <> inline SCM
|
||||
scm_from_value<GncOwner*>(GncOwner* value)
|
||||
{
|
||||
return scm_from_value<const GncOwner*>(value);
|
||||
}
|
||||
|
||||
template <typename ValueType> inline ValueType
|
||||
@ -267,16 +278,16 @@ scm_to_value<const QofInstance*>(SCM new_value)
|
||||
{
|
||||
if (new_value == SCM_BOOL_F)
|
||||
return nullptr;
|
||||
|
||||
|
||||
auto info = SWIG_PointerType(new_value);
|
||||
|
||||
static const std::array<swig_type_info*, 10> types{
|
||||
SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity,
|
||||
SWIGTYPE_p_budget_s, SWIGTYPE_p__gncInvoice,
|
||||
SWIGTYPE_p__gncTaxTable, SWIGTYPE_p_Account,
|
||||
SWIGTYPE_p__gncCustomer, SWIGTYPE_p__gncEmployee,
|
||||
SWIGTYPE_p__gncJob, SWIGTYPE_p__gncVendor
|
||||
};
|
||||
static const std::array<swig_type_info*, 11> types{
|
||||
SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity,
|
||||
SWIGTYPE_p_budget_s, SWIGTYPE_p__gncInvoice,
|
||||
SWIGTYPE_p__gncTaxTable, SWIGTYPE_p_Account,
|
||||
SWIGTYPE_p__gncCustomer, SWIGTYPE_p__gncEmployee,
|
||||
SWIGTYPE_p__gncJob, SWIGTYPE_p__gncVendor
|
||||
};
|
||||
void* ptr{};
|
||||
auto pos = std::find_if(types.begin(), types.end(),
|
||||
[&new_value, &ptr](auto type){
|
||||
@ -298,6 +309,16 @@ scm_to_value<const QofQuery*>(SCM new_value)
|
||||
return static_cast<const QofQuery*>(ptr);
|
||||
}
|
||||
|
||||
template <> inline const GncOwner*
|
||||
scm_to_value<const GncOwner*>(SCM new_value)
|
||||
{
|
||||
if (new_value == SCM_BOOL_F)
|
||||
return nullptr;
|
||||
void* ptr{};
|
||||
SWIG_ConvertPtr(new_value, &ptr, SWIGTYPE_p__gncOwner, 0);
|
||||
return static_cast<const GncOwner*>(ptr);
|
||||
}
|
||||
|
||||
template <>inline GncOptionAccountList
|
||||
scm_to_value<GncOptionAccountList>(SCM new_value)
|
||||
{
|
||||
@ -776,6 +797,7 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
|
||||
%template(gnc_make_int64_option) gnc_make_option<int64_t>;
|
||||
%template(gnc_make_qofinstance_option) gnc_make_option<const QofInstance*>;
|
||||
%template(gnc_make_query_option) gnc_make_option<const QofQuery*>;
|
||||
%template(gnc_make_owner_option) gnc_make_option<const GncOwner*>;
|
||||
|
||||
%extend GncOption {
|
||||
SCM get_scm_value()
|
||||
|
@ -232,15 +232,22 @@
|
||||
(gnc-make-SCM-option section name key desc default type)))
|
||||
(define-public (gnc:make-owner-option section name key docstring getter validator owner-type)
|
||||
(issue-deprecation-warning "gnc:make-owner-option is deprecated. Make and register the option in one command with gnc-register-owner-option.")
|
||||
(let ((ui-type (cond
|
||||
(let* ((ui-type (cond
|
||||
((eqv? owner-type GNC-OWNER-CUSTOMER) (GncOptionUIType-CUSTOMER))
|
||||
((eqv? owner-type GNC-OWNER-VENDOR) (GncOptionUIType-VENDOR))
|
||||
((eqv? owner-type GNC-OWNER-EMPLOYEE) (GncOptionUIType-EMPLOYEE))
|
||||
((eqv? owner-type GNC-OWNER-JOB) (GncOptionUIType-JOB))
|
||||
(else (GncOptionUIType-INTERNAL))))
|
||||
(defval (if getter (getter) #f)))
|
||||
(format #t "Making owner option ~a:~a ~a ~a~%" section name defval ui-type)(force-output)
|
||||
(gnc-make-qofinstance-option section name key docstring defval ui-type)))
|
||||
|
||||
(guid (gncOwnerReturnGUID (getter)))
|
||||
(book (gnc-get-current-book))
|
||||
(defval (cond
|
||||
((eqv? owner-type GNC-OWNER-CUSTOMER) (gncCustomerLookupFlip guid book))
|
||||
((eqv? owner-type GNC-OWNER-VENDOR) (gncVendorLookupFlip guid book))
|
||||
((eqv? owner-type GNC-OWNER-EMPLOYEE) (gncEmployeeLookupFlip guid book))
|
||||
((eqv? owner-type GNC-OWNER-JOB) (gncJobLookupFlip guid book)))))
|
||||
|
||||
(gnc-make-owner-option section name key docstring defval ui-type)))
|
||||
(define-public (gnc:make-invoice-option section name key docstring getter validator)
|
||||
(issue-deprecation-warning "gnc:make-invoice-option is deprecated. Make and register the option in one command with gnc-register-ionvoice-option.")
|
||||
(gnc-make-qofinstance-option section name key docstring #f (GncOptionUIType-INVOICE)))
|
||||
|
Loading…
Reference in New Issue
Block a user