diff --git a/gnucash/gnome-utils/gnc-option-gtk-ui.cpp b/gnucash/gnome-utils/gnc-option-gtk-ui.cpp index e5dc0b0915..9c6c725984 100644 --- a/gnucash/gnome-utils/gnc-option-gtk-ui.cpp +++ b/gnucash/gnome-utils/gnc-option-gtk-ui.cpp @@ -1269,19 +1269,21 @@ public: 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()); + value = static_cast(option.get_value()); else - gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()), - option.get_value()); + value = option.get_value(); + + 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(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget()))); + option.set_value(static_cast(value)); else - option.set_value(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget()))); + option.set_value(value); } }; diff --git a/libgnucash/engine/gnc-optiondb.cpp b/libgnucash/engine/gnc-optiondb.cpp index b45b9823ab..39488eeff6 100644 --- a/libgnucash/engine/gnc-optiondb.cpp +++ b/libgnucash/engine/gnc-optiondb.cpp @@ -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()}; - auto value{static_cast(d_value)}; - kvp = new KvpValue(value); + if (option.is_alternate()) + { + kvp = new KvpValue(static_cast(option.template get_value())); + } + else + { + kvp = new KvpValue(option.template get_value()); + } } else { @@ -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()}; if (strcmp(static_cast(list_head.data), counters) == 0) - option.set_value(static_cast(value)); + option.set_value(static_cast(value)); else option.set_value(value); }; @@ -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{section, name, key, doc_string, - value, 0.0, 999999999.0, 1.0}}; + GncOption option{GncOptionRangeValue{section, name, key, doc_string, + value, 1, 999999999, 1}}; + option.set_alternate(true); db->register_option(section, std::move(option)); } @@ -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", @@ -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", @@ -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", @@ -1183,7 +1189,7 @@ 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."), @@ -1191,7 +1197,7 @@ gnc_option_db_book_options(GncOptionDB* odb) 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", @@ -1200,7 +1206,7 @@ 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."), @@ -1208,7 +1214,7 @@ gnc_option_db_book_options(GncOptionDB* odb) 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."), @@ -1216,7 +1222,7 @@ gnc_option_db_book_options(GncOptionDB* odb) 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."), diff --git a/libgnucash/engine/gnc-optiondb.hpp b/libgnucash/engine/gnc-optiondb.hpp index 6a587d41ee..7a9cd8ca61 100644 --- a/libgnucash/engine/gnc-optiondb.hpp +++ b/libgnucash/engine/gnc-optiondb.hpp @@ -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&) for calling from C++.