33#ifndef GNC_OPTION_HPP_
34#define GNC_OPTION_HPP_
46#include "gnc-option-ui.hpp"
52using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
70using GncOptionDateFormat = std::tuple<QofDateFormat, GNCDateMonthFormat, bool, std::string>;
71using GncOptionReportPlacement = std::tuple<uint32_t, uint32_t, uint32_t>;
72using GncOptionReportPlacementVec = std::vector<GncOptionReportPlacement>;
76 static constexpr bool value =
77 std::is_base_of_v<OptionClassifier, std::decay_t<T>>;
80template <
typename T>
inline constexpr bool
83template <
typename T,
typename U>
86 static constexpr bool value = std::is_same_v<std::decay_t<T>,
90template <
typename T,
typename U>
inline constexpr bool
96 static constexpr bool value =
97 (is_same_decayed_v<T, GncOptionRangeValue<int>> ||
98 is_same_decayed_v<T, GncOptionRangeValue<double>>);
101template <
typename T>
inline constexpr bool
105using GncOptionVariant = std::variant<GncOptionValue<std::string>,
121using GncOptionVariantPtr = std::unique_ptr<GncOptionVariant>;
123enum class GncOptionMultichoiceKeyType
139 template <
typename OptionType,
140 typename std::enable_if_t<is_OptionClassifier_v<OptionType>,
144 m_option{std::make_unique<GncOptionVariant>(option)} {}
145 template <
typename ValueType,
146 typename std::enable_if_t<!is_OptionClassifier_v<ValueType>,
148 GncOption(
const char* section,
const char* name,
149 const char* key,
const char* doc_string,
152 template <
typename ValueType>
void set_value(ValueType value);
153 template <
typename ValueType>
void set_default_value(ValueType value);
154 template <
typename ValueType> ValueType get_default_value()
const;
155 template <
typename ValueType> ValueType get_value()
const;
156 void reset_default_value();
158 const std::string& get_section()
const;
159 const std::string& get_name()
const;
160 const std::string& get_key()
const;
161 const std::string& get_docstring()
const;
162 void set_ui_item(GncOptionUIItemPtr&& ui_elem);
164 void set_ui_item_selectable(
bool)
const noexcept;
166 void set_ui_item_from_option();
167 void set_option_from_ui_item();
168 void make_internal();
181 template <
typename ValueType>
void get_limits(ValueType&, ValueType&,
182 ValueType&)
const noexcept;
184 template <
typename ValueType>
bool validate(ValueType value)
const;
195 bool is_alternate()
const noexcept;
196 void set_alternate(
bool)
noexcept;
210 std::istream&
in_stream(std::istream& iss);
211 friend GncOptionVariant& swig_get_option(
GncOption*);
212 void set_widget_changed (std::any cb) { m_widget_changed = cb; }
213 std::any& get_widget_changed () {
return m_widget_changed; }
215 inline static const std::string c_empty_string{
""};
216 GncOptionVariantPtr m_option;
217 GncOptionUIItemPtr m_ui_item{
nullptr};
218 std::any m_widget_changed{};
224 return right.get_key() < left.get_key();
228operator<<(std::ostream& oss,
const GncOption& opt)
235operator>>(std::istream& iss,
GncOption& opt)
241output_color_value(std::ostream& oss,
const std::string& value)
244 oss << std::fixed << std::showpoint << std::setprecision(1);
245 auto len{value.length() > 8 ? 8 : value.length()};
246 for (
size_t i{}; i < len; i += 2)
248 oss << static_cast<float>(stoi(value.substr(i, 2),
nullptr, 16));
265 const char* key,
const char* doc_string,
268 return new GncOption(section, name, key, doc_string, value, ui_type);
Set one or more accounts on which to report, optionally restricted to certain account types.
class GncOptionCommodityValue Commodities are stored with their namespace and mnemonic instead of the...
A legal date value is a pair of either a RelativeDatePeriod, the absolute flag and a time64,...
Multichoice options have a vector of valid options (GncMultichoiceOptionChoices) and validate the sel...
Used for numeric ranges and plot sizes.
Holds a pointer to the UI item which will control the option and an enum representing the type of the...
The generic option-value class.
Represents the public interface for an option.
Relative date enumeration and manipulation functions.
bool validate(ValueType value) const
Not implemented for GncOptionValue.
void get_limits(ValueType &, ValueType &, ValueType &) const noexcept
Implemented only for GncOptionNumericRange.
GList * account_type_list() const noexcept
Implemented only for GncOptionAccountListValue.
void mark_saved() noexcept
Mark the option as needing to be saved.
bool is_dirty() const noexcept
const char * permissible_value(uint16_t index) const
Implemented only for GncOptionMultiselectValue.
const char * permissible_value_name(uint16_t index) const
Implemented only for GncOptionMultiselectValue.
std::istream & in_stream(std::istream &iss)
Set the option's value from an input stream.
bool deserialize(const std::string &str)
Set the option's value from a character sequence.
bool is_multiselect() const noexcept
uint16_t permissible_value_index(const char *value) const
Implemented only for GncOptionMultiselectValue.
bool is_changed() const noexcept
uint16_t num_permissible_values() const
Implemented only for GncOptionMultiselectValue.
std::string serialize() const
Get a string suitable for storage representing the option's value.
GncOptionUIType
Used by GncOptionClassifier to indicate to dialog-options what control should be displayed for the op...
GncOption * gnc_make_option(const char *section, const char *name, const char *key, const char *doc_string, ValueType value, GncOptionUIType ui_type)
Free function wrapping GncOption's constructor.
This class is the parent of all option implementations.