gnucash stable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sat Jun 17 19:59:03 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/aae568ec (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4dc8a7ee (commit)
	from  https://github.com/Gnucash/gnucash/commit/39ed069f (commit)



commit aae568eca6a9de86dadd4156aa898f16bef6e76b
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Jun 17 16:58:03 2023 -0700

    Add comment explaining "option.template get_value<int>()".

diff --git a/libgnucash/engine/gnc-optiondb.cpp b/libgnucash/engine/gnc-optiondb.cpp
index 39488eeff6..97a5286fe1 100644
--- a/libgnucash/engine/gnc-optiondb.cpp
+++ b/libgnucash/engine/gnc-optiondb.cpp
@@ -392,6 +392,14 @@ option_path(const GncOption& option, GSList* list)
     list->data = (void*)option.get_section().c_str();
 }
 
+/* The usage "option.template get_value<bool>()" looks weird, but it's required
+ * by the C++ standard: "When the name of a member template specialization
+ * appears after . or -> in a postfix-expression, or after nested-name-specifier
+ * in a qualified-id, and the postfix-expression or qualified-id explicitly
+ * depends on a template-parameter (14.6.2), the member template name must be
+ * prefixed by the keyword template. Otherwise the name is assumed to name a
+ * non-template."
+ */
 static inline KvpValue*
 kvp_value_from_bool_option(const GncOption& option)
 {

commit 4dc8a7ee0d2da8a96914db0c79f8b4919595cbf4
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Jun 17 16:49:52 2023 -0700

    Bug 798952 - Unable to set day threshold or counters in properties
    
    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.

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<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);
     }
 };
 
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<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
                         {
@@ -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);
                     };
@@ -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));
 }
 
@@ -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<GncOptionDB>&) for calling from C++.



Summary of changes:
 gnucash/gnome-utils/gnc-option-gtk-ui.cpp | 14 ++++++----
 libgnucash/engine/gnc-optiondb.cpp        | 46 ++++++++++++++++++++-----------
 libgnucash/engine/gnc-optiondb.hpp        |  2 +-
 3 files changed, 39 insertions(+), 23 deletions(-)



More information about the gnucash-changes mailing list