Commit Graph

24669 Commits

Author SHA1 Message Date
John Ralls
12f8df1eab Fix test failure: Clear the stream before reusing it. 2021-07-31 17:54:30 -07:00
John Ralls
be322a0d7c Group GncOptionMultChoiceValue::set_multiple with set_default_multiple.
Better readability.
2021-07-31 17:54:30 -07:00
John Ralls
27670a6e98 Make the 'pixel and 'percent SCM symbols C++ constants.
Improves efficiency and conciseness.
2021-07-31 17:54:30 -07:00
John Ralls
a94f69d6e0 Pretty up some SFINAE formatting for easier reading. 2021-07-31 17:54:30 -07:00
John Ralls
0f8446a1bb Remove some no longer needed diagnostics. 2021-07-31 17:54:30 -07:00
John Ralls
f66a918be4 Implement GncOptionValue<const QofQuery*>
QofQuery isn't a QofInstance and doesn't have a GUID.
2021-07-31 17:54:30 -07:00
John Ralls
0a8f66ee90 Fold GncOptionGncOwnerValue into GncOptionValue<const QofQuery*>.
Reflecting the way Scheme options handles it.
2021-07-31 17:54:30 -07:00
John Ralls
418eb06620 Remove GncOptionDateValue::set_default_value(size_t)
Because it's ambiguous with set_default_value(time64).
2021-07-31 17:54:30 -07:00
John Ralls
7d0cdf7c94 Handle #f input to option typemap(in)s. 2021-07-31 17:54:30 -07:00
John Ralls
86a2f1551f Implement gnc-make-date-option. 2021-07-31 17:54:30 -07:00
John Ralls
693e966bf9 Extract Scheme date handling functions and apply them.
Including in RelativeDatePeriodVec typemap, making it work correctly.
2021-07-31 17:54:30 -07:00
John Ralls
63502900f3 Permit GncOptionAccountValue to have a nil default value. 2021-07-31 17:54:30 -07:00
John Ralls
42185c0ec8 typemap for std::size_t
Unaccountably missing from swig_guile.
2021-07-31 17:54:30 -07:00
John Ralls
5c74337810 Add function GncOption::set_default_value.
Allows reports to derive from other reports and then change the option
default values to suit. If they change only the values and not the defaults
then it's possible to create saved report configs that don't include the
options whose values are changed to the base report's default value. See
https://bugs.gnucash.org/show_bug.cgi?id=642292.
2021-07-31 17:54:30 -07:00
John Ralls
c04f4a00e0 Replace gnc_make_option<SCM> with gnc_make_scm_option
To finesse SWIG_Guile's typedef unsigned long SCM, which causes SFINAE
issues when trying to resolve the template.
2021-07-31 17:54:30 -07:00
John Ralls
e7309f077b Replace gnc_make_option<gnc_commodity*> with gnc_make_commodity_option.
To handle cases where we try to create commodity options with a symbol as
the default instead of a gnc_commodity*.
2021-07-31 17:54:29 -07:00
John Ralls
3aa86ca992 QofInstance* needs a typemap to match the from/to SCM logic. 2021-07-31 17:54:29 -07:00
John Ralls
4a305998e4 GncOptionDateValue set_value_from_scm: 'else' required. 2021-07-31 17:54:29 -07:00
John Ralls
d9984f75ab Update test-gnc-optiondb.scm for not renaming the RelativeDatePeriod enums. 2021-07-31 17:54:29 -07:00
John Ralls
43cd81ba78 Fix a couple of RangeValue retrieval issues. 2021-07-31 17:54:29 -07:00
John Ralls
9bd3baff63 Change the reldate_values alist from a static to a singleton.
A static has to be initialized at library load and Guile
isn't necessarily running then. The singleton gets evaluated at
runtime only if the getter is called from Guile.
2021-07-31 17:54:29 -07:00
John Ralls
534a7c2893 GncOptionMultichoiceValue allow setting a default selection.
Instead of arbitrarily using the first allowed value.
Also update tests for the Scheme type addition to
GncMultichoiceOptionChoices, intercept more cases where the value
needs to be transformed, and go back to emitting a string instead of
throwing in GncOptionMultichoiceValue::get_value when m_values has more
than one value.
2021-07-31 17:54:29 -07:00
John Ralls
c62b526ba0 Implement scm_to_value<bool>. 2021-07-31 17:54:29 -07:00
John Ralls
efc7346490 Implement scm_to_value<GncOptionAccountList>. 2021-07-31 17:54:29 -07:00
John Ralls
f20c358ce1 Return a pair in scheme for GncOptionRangeValue<int>.
This is a bit of a hack to handle PlotSize options. They're the only
RangeValues that use ints; the rest use doubles because the control is a
GtkSpinButton and that uses doubles. The chart code expects a pair with
either 'pixel or 'percent saying what to put in front of the number. We
hack that too: if value <= 100 then it's percent because 100px is about
3cm on modern monitors and 15mm on HiDPI ones. Bigger numbers are pixels.
2021-07-31 17:54:29 -07:00
John Ralls
b5c0477143 Use the SWIGGED pointer for the SCM value of QofInstance* Values.
This effectively reverts b7dd7f.

Note that two cases aren't handled because the types aren't GObjects and
so don't have type macros to decipher them: GncOwner and QofQuery. Since
they're not GObjects they're obviously not QofInstances either and we
need to rethink this value type a bit.
2021-07-31 17:54:29 -07:00
John Ralls
f7f2d22909 Implement gnc-optiondb-foreach. 2021-07-31 17:54:29 -07:00
John Ralls
81d261897e scm_to_value<QofInstance*>() handle Swigged ptrs as well as GUIDs.
Some swigged engine functions used to set options return Swigged ptrs.
2021-07-31 17:54:29 -07:00
John Ralls
16a36d9104 Correctly set value of a GncOptionMultichoiceValue.
Accounting for the 3 types of SCM object that we might be handed.
2021-07-31 17:54:29 -07:00
John Ralls
7c1b4b794a Convert from Scheme date-period symbols to C++ RelativeDatePeriod enum.
Create an alist mapping the Scheme symbols to the corresponding Swig
functions that alias the enumerations. When a symbol is received look
up the corresponding function and evaluate it, retrieving the enumeration.
2021-07-31 17:54:29 -07:00
John Ralls
d41292fddd Make set_selectable a GncOptionsGtkUIItem member function.
Callable from the option object with set_ui_item_selectable and from
Scheme as gnc-option-db-set-option-selectable-by-name.
2021-07-31 17:54:29 -07:00
John Ralls
a21f329b1e Use 100% instead of 20000 px for default Pixmap size. 2021-07-31 17:54:29 -07:00
John Ralls
8c2a8edbed Implement gnc_option_db_set_string_value and gnc_optiondb_lookup_string_value. 2021-07-31 17:54:29 -07:00
John Ralls
86102e1be7 Return SCM_BOOL_F instead of nullptr to Scheme optiondb-lookup.
Because unlike C, Scheme thinks (if 0) should return true. Besides, Swig
hides pointers so a null check doesn't even work.
2021-07-31 17:54:29 -07:00
John Ralls
53ad0ba440 Prevent SWIG from trying to call delete on a std::unique_ptr. 2021-07-31 17:54:29 -07:00
John Ralls
08d1eebba2 Use GUID strings instead of QofInstance* for scheme value of QofInstance.
Because that's what gets used everywhere else.
2021-07-31 17:54:29 -07:00
John Ralls
fba0248548 Support different GncOptionMultichoiceValue key types.
Scheme can use strings, symbols, or ints as keys in multichoice options,
but C++ can handle only strings. Add conversion and tracking so that the
right key type gets sent back to Scheme.
2021-07-31 17:54:29 -07:00
John Ralls
55a2ed1df8 gnc-optiondb.i uses functions declared in gnc-optiondb.h.
So it needs it declared in the swig file.
2021-07-31 17:54:29 -07:00
John Ralls
18b83874fd Another bit of Remove test-option-utils 2021-07-31 17:54:29 -07:00
John Ralls
0b7ccfbd5b Create gnc-make-foo-option functions.
For compatibility with current Scheme code.
2021-07-31 17:54:29 -07:00
John Ralls
a602f64b17 SFINAE-constrain the GncOption constructor templates.
So that one can't instantiate an invalid constructor.

Unfortunately Swig doesn't understand SFINAE and will try to create the
invalid constructors anyway but at least this generates a compile-time
error when it tries to.
2021-07-31 17:54:29 -07:00
John Ralls
43f4bcb610 Make GncOptionUIType an enum class.
So that Swig will create properly constrained identifiers for its values.
2021-07-31 17:54:29 -07:00
John Ralls
7fa6778b4b Add a register_option overload to GncOptionDB
For compatibility with existing scheme code.
2021-07-31 17:54:29 -07:00
John Ralls
cb7270cafe Fix myriad gcc10 complaints. 2021-07-31 17:54:29 -07:00
John Ralls
76b0001cbe Remove option-util. 2021-07-31 17:54:29 -07:00
John Ralls
e2c87f23c3 Convert optiondb users in gnome and gnome-utils to C++.
To enable using std::unique_ptr<GncObjectDB> and avoid memory management
problems.
2021-07-31 17:54:29 -07:00
John Ralls
ea835b31b7 Provide GncOptionPtr& overloads for register-option functions.
Simplifies and makes safer calls from Scheme and C++ by not requiring
a raw pointer.
2021-07-31 17:54:29 -07:00
John Ralls
472814d315 Change the normal internal option ValueType to SCM.
Internal options are used as a Scheme hack and don't need to be interpreted
on the C side so there's no point in converting them to C types.
2021-07-31 17:54:29 -07:00
John Ralls
023db23353 Make URLType an alias for const char* instead of char*.
Because it uses macros declared as string constants as values and C++
objects if one tries to initialize a non-const char* with a string constant.
On the other hand one doesn't want to strdup into a const char* because
then you can't free it, so all of the instances where it's strduped for
inserting into a container must be changed from URLType to char*.
2021-07-31 17:54:29 -07:00
John Ralls
ae73b3855d Cast const char* args from guile to char*.
Swig's guile typemaps lack a const char* freearg typemap. When a function
argument is explicitly const char* Swig automatically discards the const
in the temporary's decl so freeing it isn't a problem, but if the function
arg is declared as something typedeffed to const char* the alias is used
in the temporary's decl causing an error about discarding the const
qualifier when it's time to free the temporary. Providing a const char*
freearg typemap works around the shortcoming.
2021-07-31 17:54:29 -07:00