From 102f36c3be237967842cb6df073fa5a7ffa98b61 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 18 Feb 2020 14:23:59 -0800 Subject: [PATCH] Provide more than one Date UI type to match options available in dialog-option.c Also differentiates begin-period and end-period controls. --- libgnucash/app-utils/gnc-option-impl.hpp | 23 +++++++++++-------- libgnucash/app-utils/gnc-option-uitype.hpp | 6 ++++- libgnucash/app-utils/gnc-optiondb.cpp | 5 +++- .../app-utils/test/gtest-gnc-option.cpp | 3 ++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libgnucash/app-utils/gnc-option-impl.hpp b/libgnucash/app-utils/gnc-option-impl.hpp index adc47a40fa..700efaa343 100644 --- a/libgnucash/app-utils/gnc-option-impl.hpp +++ b/libgnucash/app-utils/gnc-option-impl.hpp @@ -680,31 +680,34 @@ gnc_option_from_scheme(std::istream& iss, OptType& opt) gnc-date-option-show-time? -- option_data[1] gnc-date-option-get-subtype -- option_data[0] gnc-date-option-value-type m_value -gnc-date-option-absolute-time m_type == DateTyupe::Absolute -gnc-date-option-relative-time m_type != DateTyupe::Absolute +gnc-date-option-absolute-time m_type == RelativeDatePeriod::ABSOLUTE +gnc-date-option-relative-time m_type != RelativeDatePeriod::ABSOLUTE */ class GncOptionDateValue : public OptionClassifier { public: GncOptionDateValue(const char* section, const char* name, - const char* key, const char* doc_string) : + const char* key, const char* doc_string, + GncOptionUIType ui_type) : OptionClassifier{section, name, key, doc_string}, - m_period{RelativeDatePeriod::END_ACCOUNTING_PERIOD}, + m_ui_type{ui_type}, m_period{RelativeDatePeriod::END_ACCOUNTING_PERIOD}, m_date{INT64_MAX}, m_default_period{RelativeDatePeriod::END_ACCOUNTING_PERIOD}, m_default_date{INT64_MAX} {} GncOptionDateValue(const char* section, const char* name, const char* key, const char* doc_string, - time64 time) : + GncOptionUIType ui_type, time64 time) : OptionClassifier{section, name, key, doc_string}, - m_period{RelativeDatePeriod::ABSOLUTE}, m_date{time}, - m_default_period{RelativeDatePeriod::ABSOLUTE}, m_default_date{time} {} + m_ui_type{ui_type}, m_period{RelativeDatePeriod::ABSOLUTE}, + m_date{time}, m_default_period{RelativeDatePeriod::ABSOLUTE}, + m_default_date{time} {} GncOptionDateValue(const char* section, const char* name, const char* key, const char* doc_string, + GncOptionUIType ui_type, const RelativeDatePeriod period) : OptionClassifier{section, name, key, doc_string}, - m_period{period}, m_date{INT64_MAX}, + m_ui_type{ui_type}, m_period{period}, m_date{INT64_MAX}, m_default_period{period}, m_default_date{INT64_MAX} {} GncOptionDateValue(const GncOptionDateValue&) = default; GncOptionDateValue(GncOptionDateValue&&) = default; @@ -712,6 +715,8 @@ public: GncOptionDateValue& operator=(GncOptionDateValue&&) = default; time64 get_value() const; time64 get_default_value() const { return static_cast(GncDateTime()); } + RelativeDatePeriod get_period() const noexcept { return m_period; } + RelativeDatePeriod get_default_period() const noexcept { return m_default_period; } std::ostream& out_stream(std::ostream& oss) const noexcept; std::istream& in_stream(std::istream& iss); void set_value(RelativeDatePeriod value) { @@ -727,7 +732,7 @@ public: GncOptionUIType get_ui_type() const noexcept { return m_ui_type; } void make_internal() { m_ui_type = GncOptionUIType::INTERNAL; } private: - GncOptionUIType m_ui_type = GncOptionUIType::DATE; + GncOptionUIType m_ui_type; RelativeDatePeriod m_period; time64 m_date; RelativeDatePeriod m_default_period; diff --git a/libgnucash/app-utils/gnc-option-uitype.hpp b/libgnucash/app-utils/gnc-option-uitype.hpp index 48c75df1ea..9814d709f0 100644 --- a/libgnucash/app-utils/gnc-option-uitype.hpp +++ b/libgnucash/app-utils/gnc-option-uitype.hpp @@ -32,7 +32,11 @@ enum GncOptionUIType CURRENCY, COMMODITY, MULTICHOICE, - DATE, + DATE_ABSOLUTE, + DATE_RELATIVE_BEGIN, + DATE_BOTH_BEGIN, + DATE_RELATIVE_END, + DATE_BOTH_END, ACCOUNT_LIST, ACCOUNT_SEL, LIST, diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index 82735a6102..0b78e7be3f 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -971,6 +971,9 @@ gnc_register_date_interval_option(const GncOptionDBPtr& db, const char* section, const char* doc_string, RelativeDatePeriod period) { - GncOption option{GncOptionDateValue(section, name, key, doc_string, period)}; + auto ui_type = static_cast(period) % 2 ? + GncOptionUIType::DATE_BOTH_END : GncOptionUIType::DATE_BOTH_BEGIN; + GncOption option{GncOptionDateValue(section, name, key, doc_string, + ui_type, period)}; db->register_option(section, std::move(option)); } diff --git a/libgnucash/app-utils/test/gtest-gnc-option.cpp b/libgnucash/app-utils/test/gtest-gnc-option.cpp index 03c4f4dba8..992294af11 100644 --- a/libgnucash/app-utils/test/gtest-gnc-option.cpp +++ b/libgnucash/app-utils/test/gtest-gnc-option.cpp @@ -1012,7 +1012,8 @@ class GncOptionDateOptionTest : public ::testing::Test { protected: GncOptionDateOptionTest() : - m_option{GncOptionDateValue{"foo", "bar", "a", "Phony Date Option"}} {} + m_option{GncOptionDateValue{"foo", "bar", "a", "Phony Date Option", + GncOptionUIType::DATE_BOTH_END}} {} GncOption m_option; };