Fix the option GncOptionRangeValue

The GncOptionRangeValue can be used with integers or doubles, the
default being doubles. When used for setting the plot width/height,
integers are used so all ValueTypes need to be integers other wise
the when create_range_spinner is used you end up with the upper_bound
value being G_MAXDOUBLE, a 309 character wide spin button. To
differentiate the two, use 'set_alternate(true)' for integers.
This commit is contained in:
Robert Fewell 2022-04-18 10:00:36 +01:00
parent 506eb38493
commit 0b67a91217
2 changed files with 27 additions and 10 deletions

View File

@ -2021,12 +2021,19 @@ public:
GncOptionGtkUIItem{widget, GncOptionUIType::NUMBER_RANGE} {}
void set_ui_item_from_option(GncOption& option) noexcept override
{
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()),
option.get_value<double>());
if (option.is_alternate())
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()),
option.get_value<int>());
else
gtk_spin_button_set_value(GTK_SPIN_BUTTON(get_widget()),
option.get_value<double>());
}
void set_option_from_ui_item(GncOption& option) noexcept override
{
option.set_value<double>(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())));
else
option.set_value<double>(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget())));
}
};
@ -2042,7 +2049,19 @@ create_range_spinner(GncOption& option)
gdouble upper_bound = G_MAXDOUBLE;
gdouble step_size = 1.0;
option.get_limits(upper_bound, lower_bound, step_size);
if (option.is_alternate())
{
int tmp_lower_bound = G_MININT;
int tmp_upper_bound = G_MAXINT;
int tmp_step_size = 1.0;
option.get_limits<int>(tmp_upper_bound, tmp_lower_bound, tmp_step_size);
lower_bound =(double)tmp_lower_bound;
upper_bound = (double)tmp_upper_bound;
step_size = (double)tmp_step_size;
}
else
option.get_limits<double>(upper_bound, lower_bound, step_size);
auto adj = GTK_ADJUSTMENT(gtk_adjustment_new(lower_bound, lower_bound,
upper_bound, step_size,
step_size * 5.0,

View File

@ -335,8 +335,9 @@ public:
OptionClassifier{section, name, key, doc_string},
m_value{value >= min && value <= max ? value : min},
m_default_value{value >= min && value <= max ? value : min},
m_min{min}, m_max{max}, m_step{step} {}
m_min{min}, m_max{max}, m_step{step} {
if constexpr(is_same_decayed_v<ValueType, int>)
set_alternate(true);}
GncOptionRangeValue<ValueType>(const GncOptionRangeValue<ValueType>&) = default;
GncOptionRangeValue<ValueType>(GncOptionRangeValue<ValueType>&&) = default;
GncOptionRangeValue<ValueType>& operator=(const GncOptionRangeValue<ValueType>&) = default;
@ -369,10 +370,7 @@ public:
GncOptionUIType get_ui_type() const noexcept { return m_ui_type; }
void make_internal() { m_ui_type = GncOptionUIType::INTERNAL; }
bool is_alternate() const noexcept { return m_alternate; }
void set_alternate(bool value) noexcept {
if (m_ui_type == GncOptionUIType::PLOT_SIZE)
m_alternate = value;
}
void set_alternate(bool value) noexcept { m_alternate = value; }
std::string serialize() const noexcept;
bool deserialize(const std::string& str) noexcept;
private: