Skip to content

Commit

Permalink
Bug 798952 - Unable to set day threshold or counters in properties
Browse files Browse the repository at this point in the history
Make counters explicitly integer type and adjust the kvp load and save functions
to recognize that and behave accordingly so that other range options like day
threshold aren't affected.
  • Loading branch information
jralls committed Jun 17, 2023
1 parent 39ed069 commit 4dc8a7e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
14 changes: 8 additions & 6 deletions gnucash/gnome-utils/gnc-option-gtk-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1269,19 +1269,21 @@ class GncGtkNumberRangeUIItem : public GncOptionGtkUIItem
GncOptionGtkUIItem{widget, GncOptionUIType::NUMBER_RANGE} {}
void set_ui_item_from_option(GncOption& option) noexcept override
{
double value;
if (option.is_alternate())
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()),
option.get_value<int>());
value = static_cast<double>(option.get_value<int>());
else
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()),
option.get_value<double>());
value = option.get_value<double>();

gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()), value);
}
void set_option_from_ui_item(GncOption& option) noexcept override
{
auto value{gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget()))};
if (option.is_alternate())
option.set_value<int>(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget())));
option.set_value<int>(static_cast<int>(value));
else
option.set_value<double>(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget())));
option.set_value<double>(value);
}
};

Expand Down
38 changes: 22 additions & 16 deletions libgnucash/engine/gnc-optiondb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,14 @@ GncOptionDB::save_to_kvp(QofBook* book, bool clear_options) const noexcept
kvp = kvp_value_from_qof_instance_option(option);
else if (type == GncOptionUIType::NUMBER_RANGE)
{
auto d_value{option.template get_value<double>()};
auto value{static_cast<int64_t>(d_value)};
kvp = new KvpValue(value);
if (option.is_alternate())
{
kvp = new KvpValue(static_cast<int64_t>(option.template get_value<int>()));
}
else
{
kvp = new KvpValue(option.template get_value<double>());
}
}
else
{
Expand Down Expand Up @@ -518,12 +523,12 @@ GncOptionDB::load_from_kvp(QofBook* book) noexcept
/*counters might have been set as doubles
* because of
* https://bugs.gnucash.org/show_bug.cgi?id=798930. They
* should be int64_t.
* should be int.
*/
constexpr const char *counters{"counters"};
auto value{kvp->get<double>()};
if (strcmp(static_cast<char*>(list_head.data), counters) == 0)
option.set_value(static_cast<int64_t>(value));
option.set_value(static_cast<int>(value));
else
option.set_value(value);
};
Expand Down Expand Up @@ -873,10 +878,11 @@ gnc_register_invoice_print_report_option(GncOptionDB* db, const char* section,
void
gnc_register_counter_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, double value)
const char* doc_string, int value)
{
GncOption option{GncOptionRangeValue<double>{section, name, key, doc_string,
value, 0.0, 999999999.0, 1.0}};
GncOption option{GncOptionRangeValue<int>{section, name, key, doc_string,
value, 1, 999999999, 1}};
option.set_alternate(true);
db->register_option(section, std::move(option));
}

Expand Down Expand Up @@ -1156,7 +1162,7 @@ gnc_option_db_book_options(GncOptionDB* odb)
gnc_register_counter_option(odb, counter_section,
N_("Customer number"), "gncCustomera",
N_("The previous customer number generated. This number will be incremented to generate the next customer number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Customer number format"),
"gncCustomerb",
Expand All @@ -1165,7 +1171,7 @@ gnc_option_db_book_options(GncOptionDB* odb)
gnc_register_counter_option(odb, counter_section,
N_("Employee number"), "gncEmployeea",
N_("The previous employee number generated. This number will be incremented to generate the next employee number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Employee number format"),
"gncEmployeeb",
Expand All @@ -1174,7 +1180,7 @@ gnc_option_db_book_options(GncOptionDB* odb)
gnc_register_counter_option(odb, counter_section,
N_("Invoice number"), "gncInvoicea",
N_("The previous invoice number generated. This number will be incremented to generate the next invoice number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Invoice number format"),
"gncInvoiceb",
Expand All @@ -1183,15 +1189,15 @@ gnc_option_db_book_options(GncOptionDB* odb)
gnc_register_counter_option(odb, counter_section,
N_("Bill number"), "gncBilla",
N_("The previous bill number generated. This number will be incremented to generate the next bill number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Bill number format"), "gncBillb",
N_("The format string to use for generating bill numbers. This is a printf-style format string."),
empty_string);
gnc_register_counter_option(odb, counter_section,
N_("Expense voucher number"), "gncExpVouchera",
N_("The previous expense voucher number generated. This number will be incremented to generate the next voucher number."),
0.0);
0LL);
gnc_register_counter_format_option(odb, counter_section,
N_("Expense voucher number format"),
"gncExpVoucherb",
Expand All @@ -1200,23 +1206,23 @@ gnc_option_db_book_options(GncOptionDB* odb)
gnc_register_counter_option(odb, counter_section,
N_("Job number"), "gncJoba",
N_("The previous job number generated. This number will be incremented to generate the next job number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Job number format"), "gncJobb",
N_("The format string to use for generating job numbers. This is a printf-style format string."),
empty_string);
gnc_register_counter_option(odb, counter_section,
N_("Order number"), "gncOrdera",
N_("The previous order number generated. This number will be incremented to generate the next order number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Order number format"), "gncOrderb",
N_("The format string to use for generating order numbers. This is a printf-style format string."),
empty_string);
gnc_register_counter_option(odb, counter_section,
N_("Vendor number"), "gncVendora",
N_("The previous vendor number generated. This number will be incremented to generate the next vendor number."),
0.0);
0);
gnc_register_counter_format_option(odb, counter_section,
N_("Vendor number format"), "gncVendorb",
N_("The format string to use for generating vendor numbers. This is a printf-style format string."),
Expand Down
2 changes: 1 addition & 1 deletion libgnucash/engine/gnc-optiondb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ inline void gnc_register_invoice_print_report_option(const GncOptionDBPtr& db,
*/
void gnc_register_counter_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, double value);
const char* doc_string, int value);

/**
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
Expand Down

0 comments on commit 4dc8a7e

Please sign in to comment.