]> https://gitweb.dealii.org/ - parameter_gui.git/commitdiff
Only allow values in range. Allow scientific notation for double.
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Tue, 4 Apr 2017 09:36:36 +0000 (03:36 -0600)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Tue, 4 Apr 2017 17:18:47 +0000 (11:18 -0600)
parameter_delegate.cpp
parameter_delegate.h

index a4b4d9397e6bbf4eabdb31bde16812b31e7881e3..80163ed0e09197c5527cca6f5ca88572b8b9e513 100644 (file)
@@ -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<int>::min();
-              const int max_int_value = std::numeric_limits<int>::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<double>::max();
-              const double max_double_value = std::numeric_limits<double>::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<double>::max()/2;
+              const double min_double = std::numeric_limits<double>::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
             {
index ddf401bda5e751d906c2ed9808b04032744f758a..e531111ae5510b919672e6886d2a0416a3e3058e 100644 (file)
@@ -95,24 +95,6 @@ namespace dealii
                                      * The column this delegate will be used on.
                                      */
         int value_column;
-                                    /**
-                                     * For parameters of type <tt>double</tt> a spin box
-                                     * will be shown as editor. Any click on the spin box
-                                     * will change the value about <tt>double_steps</tt>.
-                                     */
-        double  double_steps;
-                                    /**
-                                     * For parameters of type <tt>integer</tt> a spin box
-                                     * will be shown as editor. Any click on the spin box
-                                     * will change the value about <tt>int_steps</tt>.
-                                     */
-        unsigned int  int_steps;
-                                    /**
-                                     * For parameters of type <tt>double</tt> a spin box
-                                     * will be shown as editor. The spin box will show
-                                     * parameters with a precision of <tt>double_decimals</tt>.
-                                     */
-        unsigned int  double_decimals;
     };
   }
 /**@}*/

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.