Optika GUI Toolik Version of the Day
Optika_ValidatorApplier.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #ifndef OPTIKA_VALIDATORAPPLIER_HPP_
00042 #define OPTIKA_VALIDATORAPPLIER_HPP_
00043 #include <QSpinBox>
00044 #include <QDoubleSpinBox>
00045 #include <QIntValidator>
00046 #include <QDoubleValidator>
00047 #include "Optika_ConfigDefs.hpp"
00048 #include <QLineEdit>
00049 
00056 namespace Optika{
00057 
00063 template<class S> class ValidatorApplier{
00064 public:
00066 
00067 
00076   static void applyToSpinBox(RCP<const EnhancedNumberValidator<S> > validator, QSpinBox *spinBox){
00077     if(!is_null(validator)){
00078       spinBox->setMinimum(validator->getMin());
00079       spinBox->setMaximum(validator->getMax());
00080       spinBox->setSingleStep(validator->getStep());
00081     }
00082     else{
00083       spinBox->setMinimum(EnhancedNumberTraits<S>::min());
00084       spinBox->setMaximum(EnhancedNumberTraits<S>::max());
00085       spinBox->setSingleStep(EnhancedNumberTraits<S>::defaultStep());
00086     }
00087   }
00088 
00089   static void applyToLineEdit(RCP<const EnhancedNumberValidator<S> > validator, QLineEdit *lineEdit){
00090     QIntValidator* qvalidator = new QIntValidator(lineEdit);
00091     if(!is_null(validator)){
00092       qvalidator->setRange(validator->getMin(), validator->getMax());
00093     }
00094     else{
00095       qvalidator->setRange(EnhancedNumberTraits<S>::min(), EnhancedNumberTraits<S>::max());
00096     }
00097     lineEdit->setValidator(qvalidator);
00098   }
00099 
00101 
00102 };
00103 
00108 template<>
00109 class ValidatorApplier<double>{
00110 public:
00111 
00113 
00114 
00121   static void applyToSpinBox(RCP<const EnhancedNumberValidator<double> > validator, QDoubleSpinBox *spinBox){
00122     if(!is_null(validator)){
00123       spinBox->setMinimum(validator->getMin());
00124       spinBox->setMaximum(validator->getMax());
00125       spinBox->setSingleStep(validator->getStep());
00126       spinBox->setDecimals(validator->getPrecision());
00127     }
00128     else{
00129       spinBox->setMinimum(EnhancedNumberTraits<double>::min());
00130       spinBox->setMaximum(EnhancedNumberTraits<double>::max());
00131       spinBox->setSingleStep(EnhancedNumberTraits<double>::defaultStep());
00132       spinBox->setDecimals(EnhancedNumberTraits<double>::defaultPrecision());
00133     }
00134   }
00135 
00136   static void applyToLineEdit(RCP<const EnhancedNumberValidator<double> > validator, QLineEdit *lineEdit){
00137     QDoubleValidator* qvalidator = new QDoubleValidator(lineEdit);
00138     if(!is_null(validator)){
00139       qvalidator->setRange(validator->getMin(), validator->getMax());
00140       qvalidator->setDecimals(validator->getPrecision());
00141     }
00142     else{
00143       qvalidator->setRange(EnhancedNumberTraits<double>::min(), EnhancedNumberTraits<double>::max());
00144       qvalidator->setDecimals(EnhancedNumberTraits<double>::defaultPrecision());
00145     }
00146     lineEdit->setValidator(qvalidator);
00147   }
00148 
00150 };
00151 
00156 template<>
00157 class ValidatorApplier<float>{
00158 public:
00159 
00161 
00162 
00169   static void applyToSpinBox(RCP<const EnhancedNumberValidator<float> > validator, QDoubleSpinBox *spinBox){
00170     if(!is_null(validator)){
00171       spinBox->setMinimum(validator->getMin());
00172       spinBox->setMaximum(validator->getMax());
00173       spinBox->setSingleStep(validator->getStep());
00174       spinBox->setDecimals(validator->getPrecision());
00175     }
00176     else{
00177       spinBox->setMinimum(EnhancedNumberTraits<float>::min());
00178       spinBox->setMaximum(EnhancedNumberTraits<float>::max());
00179       spinBox->setSingleStep(EnhancedNumberTraits<float>::defaultStep());
00180       spinBox->setDecimals(EnhancedNumberTraits<float>::defaultPrecision());
00181     }
00182   }
00183 
00184   static void applyToLineEdit(RCP<const EnhancedNumberValidator<float> > validator, QLineEdit *lineEdit){
00185     QDoubleValidator* qvalidator = new QDoubleValidator(lineEdit);
00186     if(!is_null(validator)){
00187       qvalidator->setRange(validator->getMin(), validator->getMax());
00188       qvalidator->setDecimals(validator->getPrecision());
00189     }
00190     else{
00191       qvalidator->setRange(EnhancedNumberTraits<float>::min(), EnhancedNumberTraits<float>::max());
00192       qvalidator->setDecimals(EnhancedNumberTraits<float>::defaultPrecision());
00193     }
00194     lineEdit->setValidator(qvalidator);
00195   }
00196 
00198 }; 
00199 
00200 }
00201 #endif // OPTIKA_VALIDATORAPPLIER_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines