Fold GncOptionGncOwnerValue into GncOptionValue<const QofQuery*>.

Reflecting the way Scheme options handles it.
This commit is contained in:
John Ralls 2021-03-11 17:56:53 -08:00
parent 418eb06620
commit 0a8f66ee90
7 changed files with 43 additions and 80 deletions

View File

@ -211,8 +211,8 @@ qof_instance_from_guid(GncGUID* guid, GncOptionUIType type)
case GncOptionUIType::BUDGET:
qof_type = "Budget";
break;
case GncOptionUIType::OWNER:
qof_type = "gncOwner";
case GncOptionUIType::JOB:
qof_type = "gncJob";
break;
case GncOptionUIType::CUSTOMER:
qof_type = "gncCustomer";

View File

@ -51,6 +51,7 @@ enum class GncOptionUIType : unsigned int
VENDOR,
EMPLOYEE,
INVOICE,
JOB,
TAX_TABLE,
QUERY,
REPORT_LIST,

View File

@ -36,7 +36,10 @@ extern "C"
#include <config.h>
#include <qof.h>
#include <gncInvoice.h>
#include <gncOwner.h>
#include <gncCustomer.h>
#include <gncEmployee.h>
#include <gncJob.h>
#include <gncVendor.h>
#include <gncTaxTable.h>
}

View File

@ -1070,38 +1070,6 @@ gnc_register_internal_option(GncOptionDB* db, const char* section,
GncOptionUIType::INTERNAL};
db->register_option(section, std::move(option));
}
static inline GncOptionUIType
owner_type_to_ui_type(GncOwnerType type)
{
switch (type)
{
case GNC_OWNER_NONE:
case GNC_OWNER_UNDEFINED:
case GNC_OWNER_JOB:
return GncOptionUIType::INTERNAL;
case GNC_OWNER_CUSTOMER:
return GncOptionUIType::CUSTOMER;
case GNC_OWNER_VENDOR:
return GncOptionUIType::VENDOR;
case GNC_OWNER_EMPLOYEE:
return GncOptionUIType::EMPLOYEE;
}
return GncOptionUIType::INTERNAL;
}
void
gnc_register_owner_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, GncOwner* value,
GncOwnerType type)
{
GncOption option{section, name, key, doc_string,
(const QofInstance*)value->owner.undefined,
owner_type_to_ui_type(type)};
db->register_option(section, std::move(option));
}
void
gnc_register_invoice_option(GncOptionDB* db, const char* section,
const char* name, const char* key,

View File

@ -44,7 +44,6 @@ extern "C"
#include <gnc-budget.h>
#include <gnc-commodity.h>
#include <gncInvoice.h>
#include <gncOwner.h>
#include <gncTaxTable.h>
/**

View File

@ -37,7 +37,6 @@ extern "C"
#include <gnc-budget.h>
#include <gnc-commodity.h>
#include <gncInvoice.h>
#include <gncOwner.h>
#include <gncTaxTable.h>
}
#include "gnc-option.hpp"
@ -620,33 +619,6 @@ inline void gnc_register_invoice_option(const GncOptionDBPtr& db,
doc_string, value);
}
/**
* Create a new owner-type 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.
* @param type The Owner-type (Customer, Employee, or Vendor)
*/
void gnc_register_owner_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, GncOwner* value,
GncOwnerType type);
/**
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
*/
inline void gnc_register_owner_option(const GncOptionDBPtr& db,
const char* section, const char* name,
const char* key, const char* doc_string,
GncOwner* value, GncOwnerType type)
{
gnc_register_owner_option(db.get(), section, name, key,
doc_string, value, type);
}
/**
* Create a new taxtable option and register it in the options database.
*

View File

@ -64,25 +64,33 @@ SCM scm_init_sw_gnc_optiondb_module(void);
*/
%typemap (out) QofInstance_s* {
swig_type_info *type = $descriptor(QofInstance_s);
if ($1 == nullptr)
{
$result = SCM_BOOL_F;
$result = SWIG_NewPointerObj(nullptr, type, FALSE);
}
else
{
auto ptr{static_cast<void*>(const_cast<QofInstance*>($1))};
swig_type_info *type = SWIGTYPE_p_QofInstance_s;
if (GNC_IS_COMMODITY($1))
type = SWIGTYPE_p_gnc_commodity;
type = $descriptor(gnc_commodity*);
else if (GNC_IS_ACCOUNT($1))
type = SWIGTYPE_p_Account;
type = $descriptor(Account*);
else if (GNC_IS_BUDGET($1))
type = SWIGTYPE_p_GncBudget;
type = $descriptor(GncBudget*);
else if (GNC_IS_INVOICE($1))
type = SWIGTYPE_p_GncInvoice;
type = $descriptor(GncInvoice*);
else if (GNC_IS_TAXTABLE($1))
type = SWIGTYPE_p_GncTaxTable;
type = $descriptor(GncTaxTable*);
else if (GNC_IS_CUSTOMER($1))
type = $descriptor(_gncCustomer*);
else if (GNC_IS_EMPLOYEE($1))
type = $descriptor(_gncEmployee*);
else if (GNC_IS_JOB($1))
type = $descriptor(_gncJob*);
else if (GNC_IS_VENDOR($1))
type = $descriptor(_gncVendor*);
$result = SWIG_NewPointerObj(ptr, type, FALSE);
}
}
@ -90,10 +98,12 @@ SCM scm_init_sw_gnc_optiondb_module(void);
%typemap (in) QofInstance_s* {
if (scm_is_true($input))
{
static const std::array<swig_type_info*, 6> types {
SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity,
SWIGTYPE_p_GncBudget, SWIGTYPE_p_GncInvoice,
SWIGTYPE_p_GncTaxTable, SWIGTYPE_p_Account
static const std::array<swig_type_info*, 10> types {
$descriptor(QofInstance_s*), $descriptor(gnc_commodity*),
$descriptor(GncBudget*), $descriptor(GncInvoice*),
$descriptor(GncTaxTable*), $descriptor(Account*),
$descriptor(_gncCustomer*), $descriptor(_gncEmployee*),
$descriptor(_gncJob*), $descriptor(_gncVendor*)
};
void* ptr{};
auto pos = std::find_if(types.begin(), types.end(),
@ -168,10 +178,11 @@ scm_from_value<double>(double value)
template <> inline SCM
scm_from_value<const QofInstance*>(const QofInstance* value)
{
if (!value) return SCM_BOOL_F;
swig_type_info *type = SWIGTYPE_p_QofInstance_s;
if (!value)
return SWIG_NewPointerObj(nullptr, type, FALSE);
auto ptr{static_cast<void*>(const_cast<QofInstance*>(value))};
swig_type_info *type = SWIGTYPE_p_QofInstance_s;
if (GNC_IS_COMMODITY(value))
type = SWIGTYPE_p_gnc_commodity;
else if (GNC_IS_ACCOUNT(value))
@ -182,6 +193,14 @@ scm_from_value<const QofInstance*>(const QofInstance* value)
type = SWIGTYPE_p_GncInvoice;
else if (GNC_IS_TAXTABLE(value))
type = SWIGTYPE_p_GncTaxTable;
else if (GNC_IS_CUSTOMER(value))
type = SWIGTYPE_p__gncCustomer;
else if (GNC_IS_EMPLOYEE(value))
type = SWIGTYPE_p__gncEmployee;
else if (GNC_IS_JOB(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;
@ -236,10 +255,12 @@ scm_to_value<const QofInstance*>(SCM new_value)
if (new_value == SCM_BOOL_F)
return nullptr;
static const std::array<swig_type_info*, 6> types{
static const std::array<swig_type_info*, 10> types{
SWIGTYPE_p_QofInstance_s, SWIGTYPE_p_gnc_commodity,
SWIGTYPE_p_GncBudget, SWIGTYPE_p_GncInvoice,
SWIGTYPE_p_GncTaxTable, SWIGTYPE_p_Account
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(),
@ -502,7 +523,6 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
%ignore gnc_register_internal_option(GncOptionDB*, const char*, const char*, const char*, const char*, std::string);
%ignore gnc_register_currency_option(GncOptionDB*, const char*, const char*, const char*, const char*, gnc_commodity*);
%ignore gnc_register_invoice_option(GncOptionDB*, const char*, const char*, const char*, const char*, GncInvoice*);
%ignore gnc_register_owner_option(GncOptionDB*, const char*, const char*, const char*, const char*, GncOwner*, GncOwnerType);
%ignore gnc_register_taxtable_option(GncOptionDB*, const char*, const char*, const char*, const char*, GncTaxTable*);
%ignore gnc_register_counter_option(GncOptionDB*, const char*, const char*, const char*, const char*, double);
%ignore gnc_register_counter_format_option(GncOptionDB*, const char*, const char*, const char*, const char*, std::string);