Provide more than one Date UI type to match options available in dialog-option.c

Also differentiates begin-period and end-period controls.
This commit is contained in:
John Ralls
2020-02-18 14:23:59 -08:00
parent 6c7f976a65
commit 102f36c3be
4 changed files with 25 additions and 12 deletions

View File

@@ -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<time64>(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;

View File

@@ -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,

View File

@@ -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<int>(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));
}

View File

@@ -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;
};