GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoAlgoParameter.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #ifndef __QGoAlgoParameter_h
35 #define __QGoAlgoParameter_h
36 
37 #include <string>
38 #include <stdlib.h>
39 #include <QStringList>
40 #include <QSpinBox>
41 #include <QDoubleSpinBox>
42 #include <QComboBox>
43 
48 template< class T >
50 {
51  public:
53  {};
55 
56  protected:
57  T m_Value;
59  std::string m_ParamName;
60 };
61 //-------------------------------------------------------------------------
62 
63 //-------------------------------------------------------------------------
64 template<>
65 class QGoAlgoParameter< int >
66 {
67  public:
69  QGoAlgoParameter<int>(std::string iParamName,
70  bool iAdvParam, int iMin, int iMax,
71  int iDefaultValue = 0, int iDefaultStep= 1)
72  {
73  m_ParamName = iParamName;
74  m_Box = new RepresentationType;
75  m_AdvParam = iAdvParam;
76  SetRangeValues(iMin, iMax, iDefaultValue, iDefaultStep);
77  };
78 
80  {
81  /*if (m_Box != NULL)
82  {
83  delete m_Box;
84  }*/
85  };
86 
87  std::string m_ParamName;
88  bool m_AdvParam;
90 
91  int GetValue()
92  {
93  return m_Box->value();
94  };
95 
96  protected:
97 
98  void SetRangeValues(int iMin, int iMax, int iDefaultValue, int iDefaultStep)
99  {
100  m_Box->setRange(iMin, iMax);
101  m_Box->setSingleStep(iDefaultStep);
102  if (iDefaultValue != 0)
103  {
104  m_Box->setValue(iDefaultValue);
105  }
106  };
107 
108 };
109 //-------------------------------------------------------------------------
110 
111 //-------------------------------------------------------------------------
112 template<>
113 class QGoAlgoParameter< double >
114 {
115  public:
117  QGoAlgoParameter<double>(std::string iParamName,
118  bool iAdvParam, double iMin, double iMax,
119  int iNbDecimal, double iDefaultValue = 0, double iDefaultStep = 0.1)
120  {
121  m_ParamName = iParamName;
122  m_Box = new RepresentationType;
123  m_AdvParam = iAdvParam;
124  SetRangeValues(iMin, iMax, iNbDecimal, iDefaultValue, iDefaultStep);
125  };
126 
128  {
129  /*if (m_Box != NULL)
130  {
131  delete m_Box;
132  }*/
133  };
134 
135  std::string m_ParamName;
138 
139  double GetValue()
140  {
141  return m_Box->value();
142  };
143 
144  protected:
145 
146  void SetRangeValues(double iMin, double iMax,
147  int iNbDecimal, double iDefaultValue, double iDefaultStep)
148  {
149  m_Box->setRange(iMin, iMax);
150  m_Box->setDecimals(iNbDecimal);
151  m_Box->setSingleStep(iDefaultStep);
152  if (iDefaultValue != 0)
153  {
154  m_Box->setValue(iDefaultValue);
155  }
156  };
157 };
158 //-------------------------------------------------------------------------
159 
160 //-------------------------------------------------------------------------
161 template<>
162 class QGoAlgoParameter< std::string >
163 {
164  public:
166  QGoAlgoParameter<std::string>(std::string iParamName,
167  bool iAdvParam,
168  QStringList iListValues, std::string iDefaultValue = "")
169  {
170  m_ParamName = iParamName;
171  m_Box = new RepresentationType;
172  m_AdvParam = iAdvParam;
173  SetListValues(iListValues, iDefaultValue);
174  }
175 
177  {
178  /*if (m_Box != NULL)
179  {
180  delete m_Box;
181  }*/
182  };
183 
184  std::string m_ParamName;
187 
188  std::string Getvalue()
189  {
190  return m_Box->currentText().toStdString();
191  }
192 
193  protected:
194 
195  void SetListValues(QStringList iListValues, std::string iDefaultValue)
196  {
197  m_Box->addItems(iListValues);
198  if (!iDefaultValue.empty())
199  {
200  m_Box->setCurrentIndex(m_Box->findText(iDefaultValue.c_str()));
201  }
202  };
203 };
204 
205 
206 #endif
RepresentationType * m_Box
void SetListValues(QStringList iListValues, std::string iDefaultValue)
void SetRangeValues(int iMin, int iMax, int iDefaultValue, int iDefaultStep)
std::string m_ParamName
RepresentationType * m_Box
specialized class for a parameter to be added in an algorithm widget
void SetRangeValues(double iMin, double iMax, int iNbDecimal, double iDefaultValue, double iDefaultStep)