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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #ifndef OPTIKA_VALIDATORAPPLIER_HPP_
00029 #define OPTIKA_VALIDATORAPPLIER_HPP_
00030 #include <QSpinBox>
00031 #include <QDoubleSpinBox>
00032 #include <QIntValidator>
00033 #include <QDoubleValidator>
00034 #include "Optika_ConfigDefs.hpp"
00035 #include <QLineEdit>
00036 
00043 namespace Optika{
00044 
00050 template<class S> class ValidatorApplier{
00051 public:
00053 
00054 
00063   static void applyToSpinBox(RCP<const EnhancedNumberValidator<S> > validator, QSpinBox *spinBox){
00064     if(!is_null(validator)){
00065       spinBox->setMinimum(validator->getMin());
00066       spinBox->setMaximum(validator->getMax());
00067       spinBox->setSingleStep(validator->getStep());
00068     }
00069     else{
00070       spinBox->setMinimum(EnhancedNumberTraits<S>::min());
00071       spinBox->setMaximum(EnhancedNumberTraits<S>::max());
00072       spinBox->setSingleStep(EnhancedNumberTraits<S>::defaultStep());
00073     }
00074   }
00075 
00076   static void applyToLineEdit(RCP<const EnhancedNumberValidator<S> > validator, QLineEdit *lineEdit){
00077     QIntValidator* qvalidator = new QIntValidator(lineEdit);
00078     if(!is_null(validator)){
00079       qvalidator->setRange(validator->getMin(), validator->getMax());
00080     }
00081     else{
00082       qvalidator->setRange(EnhancedNumberTraits<S>::min(), EnhancedNumberTraits<S>::max());
00083     }
00084     lineEdit->setValidator(qvalidator);
00085   }
00086 
00088 
00089 };
00090 
00095 template<>
00096 class ValidatorApplier<double>{
00097 public:
00098 
00100 
00101 
00108   static void applyToSpinBox(RCP<const EnhancedNumberValidator<double> > validator, QDoubleSpinBox *spinBox){
00109     if(!is_null(validator)){
00110       spinBox->setMinimum(validator->getMin());
00111       spinBox->setMaximum(validator->getMax());
00112       spinBox->setSingleStep(validator->getStep());
00113       spinBox->setDecimals(validator->getPrecision());
00114     }
00115     else{
00116       spinBox->setMinimum(EnhancedNumberTraits<double>::min());
00117       spinBox->setMaximum(EnhancedNumberTraits<double>::max());
00118       spinBox->setSingleStep(EnhancedNumberTraits<double>::defaultStep());
00119       spinBox->setDecimals(EnhancedNumberTraits<double>::defaultPrecision());
00120     }
00121   }
00122 
00123   static void applyToLineEdit(RCP<const EnhancedNumberValidator<double> > validator, QLineEdit *lineEdit){
00124     QDoubleValidator* qvalidator = new QDoubleValidator(lineEdit);
00125     if(!is_null(validator)){
00126       qvalidator->setRange(validator->getMin(), validator->getMax());
00127       qvalidator->setDecimals(validator->getPrecision());
00128     }
00129     else{
00130       qvalidator->setRange(EnhancedNumberTraits<double>::min(), EnhancedNumberTraits<double>::max());
00131       qvalidator->setDecimals(EnhancedNumberTraits<double>::defaultPrecision());
00132     }
00133     lineEdit->setValidator(qvalidator);
00134   }
00135 
00137 };
00138 
00143 template<>
00144 class ValidatorApplier<float>{
00145 public:
00146 
00148 
00149 
00156   static void applyToSpinBox(RCP<const EnhancedNumberValidator<float> > validator, QDoubleSpinBox *spinBox){
00157     if(!is_null(validator)){
00158       spinBox->setMinimum(validator->getMin());
00159       spinBox->setMaximum(validator->getMax());
00160       spinBox->setSingleStep(validator->getStep());
00161       spinBox->setDecimals(validator->getPrecision());
00162     }
00163     else{
00164       spinBox->setMinimum(EnhancedNumberTraits<float>::min());
00165       spinBox->setMaximum(EnhancedNumberTraits<float>::max());
00166       spinBox->setSingleStep(EnhancedNumberTraits<float>::defaultStep());
00167       spinBox->setDecimals(EnhancedNumberTraits<float>::defaultPrecision());
00168     }
00169   }
00170 
00171   static void applyToLineEdit(RCP<const EnhancedNumberValidator<float> > validator, QLineEdit *lineEdit){
00172     QDoubleValidator* qvalidator = new QDoubleValidator(lineEdit);
00173     if(!is_null(validator)){
00174       qvalidator->setRange(validator->getMin(), validator->getMax());
00175       qvalidator->setDecimals(validator->getPrecision());
00176     }
00177     else{
00178       qvalidator->setRange(EnhancedNumberTraits<float>::min(), EnhancedNumberTraits<float>::max());
00179       qvalidator->setDecimals(EnhancedNumberTraits<float>::defaultPrecision());
00180     }
00181     lineEdit->setValidator(qvalidator);
00182   }
00183 
00185 }; 
00186 
00187 }
00188 #endif // OPTIKA_VALIDATORAPPLIER_HPP_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines