From: Rene Gassmoeller Date: Tue, 4 Apr 2017 09:36:36 +0000 (-0600) Subject: Only allow values in range. Allow scientific notation for double. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=567136540eb96a106e57f8d3dc7af66fd6cc0c09;p=parameter_gui.git Only allow values in range. Allow scientific notation for double. --- diff --git a/parameter_delegate.cpp b/parameter_delegate.cpp index a4b4d93..80163ed 100644 --- a/parameter_delegate.cpp +++ b/parameter_delegate.cpp @@ -29,11 +29,6 @@ namespace dealii : QItemDelegate(parent) { this->value_column = value_column; - - double_steps = 0.1; // any click in the editor will increase or decrease the value about double_steps - double_decimals = 14; // number of decimals shown in the editor - - int_steps = 1; // step value for increasing or decreasing integers } @@ -161,38 +156,48 @@ namespace dealii return dirname_editor; } - else if (rx_integer.indexIn (pattern_description) != -1) // if the tpye is "Integer" + else if (rx_integer.indexIn (pattern_description) != -1) // if the type is "Integer" { - QSpinBox * spin_box = new QSpinBox(parent); // choose a spin box - - const int min_int_value = std::numeric_limits::min(); - const int max_int_value = std::numeric_limits::max(); + const QStringList default_pattern = pattern_description.split(" ").filter("..."); + const QStringList default_values = default_pattern[0].split("..."); - spin_box->setMaximum(max_int_value); // set max and min from the limits.h class - spin_box->setMinimum(min_int_value); - spin_box->setSingleStep(int_steps); // and every klick is a SingleStep + QLineEdit * line_edit = new QLineEdit(parent); + line_edit->setValidator(new QIntValidator(default_values[0].toInt(), default_values[1].toInt(), line_edit)); - connect(spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function + connect(line_edit, SIGNAL(editingFinished()), // connect editors signal to the closer function this, SLOT(commit_and_close_editor())); - return spin_box; + return line_edit; } else if (rx_double.indexIn (pattern_description) != -1) // the same with "Double" { - QDoubleSpinBox * double_spin_box = new QDoubleSpinBox(parent); // choose a spin box - - const double min_double_value = -std::numeric_limits::max(); - const double max_double_value = std::numeric_limits::max(); - - double_spin_box->setMaximum(max_double_value); // set max and min from the limits.h class - double_spin_box->setMinimum(min_double_value); - double_spin_box->setDecimals(double_decimals); // show "double_decimals" decimals - double_spin_box->setSingleStep(double_steps); // and every klick is a SingleStep - - connect(double_spin_box, SIGNAL(editingFinished()), // connect editors signal to the closer function + const QStringList default_pattern = pattern_description.split(" ").filter("..."); + QStringList default_values = default_pattern[0].split("..."); + + // Unfortunately conversion of MAX_DOUBLE to string and back fails + // sometimes, therefore use MAX_DOUBLE/2 to make sure we are below. + // In practice MAX_DOUBLE just means VERY large, it is normally not + // important how large. + const double max_double = std::numeric_limits::max()/2; + const double min_double = std::numeric_limits::min(); + + default_values = default_values.replaceInStrings("MAX_DOUBLE", + QVariant(max_double).toString()); + default_values = default_values.replaceInStrings("MIN_DOUBLE", + QVariant(min_double).toString()); + + const unsigned int number_of_decimals = 14; + + QLineEdit * line_edit = new QLineEdit(parent); + line_edit->setValidator(new QDoubleValidator(default_values[0].toDouble(), + default_values[1].toDouble(), + number_of_decimals, + line_edit)); + + connect(line_edit, SIGNAL(editingFinished()), // connect editors signal to the closer function this, SLOT(commit_and_close_editor())); - return double_spin_box; + return line_edit; } else if (rx_selection.indexIn (pattern_description) != -1) // and selections { diff --git a/parameter_delegate.h b/parameter_delegate.h index ddf401b..e531111 100644 --- a/parameter_delegate.h +++ b/parameter_delegate.h @@ -95,24 +95,6 @@ namespace dealii * The column this delegate will be used on. */ int value_column; - /** - * For parameters of type double a spin box - * will be shown as editor. Any click on the spin box - * will change the value about double_steps. - */ - double double_steps; - /** - * For parameters of type integer a spin box - * will be shown as editor. Any click on the spin box - * will change the value about int_steps. - */ - unsigned int int_steps; - /** - * For parameters of type double a spin box - * will be shown as editor. The spin box will show - * parameters with a precision of double_decimals. - */ - unsigned int double_decimals; }; } /**@}*/