uTrade Frontend Algo API  Version 1.0.0.0
μTrade HFT
sharedParams.h
1 #ifndef SHAREDPARAMS_H
2 #define SHAREDPARAMS_H
3 
4 #include "sharedEnums.h"
5 #if IS_QT4_VERSION
6 #include <QtGui>
7 #else
8 #include <QtWidgets>
9 #endif
10 namespace API2
11 {
12 
14 {
15 
16 private :
17  QLabel *_uiLabel;
18  QWidget *_uiWidget;
19 
20  short _uiElementType;
21  short _uiElementState;
22  short _elementDataType;
23  short _updatable;
24  short _isDbField;
25 
26  QString _uiLabelName;
27  QVariant _tempValue;
28  QVariant _uiValue;
29 
30  int _columnIndex;
31  short _filterType;
32  short _isShowInTable;
33  short _isColumnHidden;
34  bool _isDefaultPrecision;
35  QString _columnName;
36  bool _isColumnEditable;
37  short _sortingType;
38  bool _isShowInPortfolio;
39  short _portfolioIndex;
40 
41 public:
42 
55  StrategyParameters(const QString &paramNameArg,
56  const QString &colName,
57  QWidget *uiWidget,
58  short elementType,
59  short dataType=API2::DATA_TYPE_UNSIGNED_LONG,
60  short state=API2::UI_STATE_DISABLED,
61  short showTableStatus =API2::TABLE_STATE_HIDE,
62  short isDbColumn = API2::DB_FEILD_HIDE,
63  short isUpdatable = API2::UPDATE_STATE_DISABLE,
64  short portfolioState = API2::SHOW_IN_PORTFOLIO_DISABLE)
65  : _uiWidget(uiWidget),
66  _uiElementState(state),
67  _isShowInTable(showTableStatus),
68  _uiElementType(elementType),
69  _elementDataType(dataType),
70  _uiLabelName(paramNameArg),
71  _columnName(colName),
72  _isDbField(isDbColumn),
73  _updatable(isUpdatable),
74  _isColumnEditable(false),
75  _isColumnHidden(false),
76  _isDefaultPrecision(true)
77  {
78  _isShowInPortfolio = (portfolioState == API2::SHOW_IN_PORTFOLIO_ENABLE) && _isDbField ;
79  _uiLabel = new QLabel(paramNameArg);
80  _filterType = WidgetType_MAX;
81  _sortingType = SortingType_MAX;
82  _uiElementState = elementType==UI_ELEMENT_NO_UI ? false : _uiElementState;
83  if(_uiWidget)
84  {
85  _uiWidget->setEnabled(_uiElementState);
86  _tempValue=getParamUIValue();
87  }
88  else
89  _tempValue = 0;
90  }
91 
92 
94  {
95 
96  }
97 
98  void setVisible(bool isVisible)
99  {
100  _uiWidget->setVisible(isVisible);
101  _uiLabel->setVisible(isVisible);
102  }
103 
104 
105  QVariant getParamValue()
106  {
107  if(( _elementDataType==DATA_TYPE_INTEGER || _elementDataType==DATA_TYPE_SHORT)
108  && (_uiElementType!=UI_ELEMENT_DOUBLE_SPIN_BOX))
109  {
110  if(_uiElementType == UI_ELEMENT_COMBO_BOX)
111  _tempValue=_tempValue.toInt();
112  }
113  return _tempValue;
114  }
115 
116  QVariant getParamUIValue()
117  {
118  double value=0.00f;
119  if(!_uiWidget) return _tempValue;
120  switch(_uiElementType)
121  {
122  case UI_ELEMENT_LABEL :
123  break;
124  case UI_ELEMENT_COMBO_BOX:
125  _uiValue =((QComboBox *)getElement())->currentText();
126  break;
127  case UI_ELEMENT_LINE_EDIT:
128  _uiValue =((QLineEdit *)getElement())->text();
129  break;
130  case UI_ELEMENT_CHECK_BOX:
131  _uiValue = ((QCheckBox *)_uiWidget)->isChecked();
132  break;
133  case UI_ELEMENT_PUSH_BUTTON:
134  break;
135  case UI_ELEMENT_SPIN_BOX:
136  _uiValue =((QSpinBox *)getElement())->value();
137  break;
138  case UI_ELEMENT_DOUBLE_SPIN_BOX:
139  value =((QDoubleSpinBox *)_uiWidget)->value();
140  _uiValue = QString::number(value,'f',((QDoubleSpinBox *)_uiWidget)->decimals()).remove(".").toLongLong();
141  break;
142  case UI_ELEMENT_RADIO_BUTTON:
143  break;
144  case UI_ELEMENT_NO_UI:
145  _uiValue = 0;
146  break;
147  case UI_ELEMENT_SLIDER:
148  return ((QSlider *)_uiWidget)->value();
149  break;
150  default:
151  break;
152  }
153 
154  if(( _elementDataType==DATA_TYPE_INTEGER || _elementDataType==DATA_TYPE_SHORT)
155  && (_uiElementType!=UI_ELEMENT_DOUBLE_SPIN_BOX))
156  {
157  if(_uiElementType == UI_ELEMENT_COMBO_BOX)
158  _uiValue.setValue(((QComboBox *)_uiWidget)->currentIndex());
159  }
160 
161  return _uiValue;
162  }
163 
164  QString getDoubleText()
165  {
166  if(_uiElementType == UI_ELEMENT_DOUBLE_SPIN_BOX)
167  {
168  double value =((QDoubleSpinBox *)_uiWidget)->value();
169  return QString::number(value,'f',((QDoubleSpinBox *)_uiWidget)->decimals());
170  }
171  return " ";
172  }
173 
174 
175  QVariant getValueFromDouble()
176  {
177  if(_uiElementType == UI_ELEMENT_DOUBLE_SPIN_BOX)
178  {
179  double value = _tempValue.toLongLong()/pow(10.0, ((QDoubleSpinBox *)_uiWidget)->decimals());
180  return QString::number(value,'f',((QDoubleSpinBox *)_uiWidget)->decimals());
181  }
182  return " ";
183  }
184 
185 
186 
187  void setValue(QVariant value)
188  {
189  _tempValue=value;
190  }
191 
192 
193  void setUIValue(QVariant value)
194  {
195  _uiValue=value;
196  if(_uiWidget)
197  {
198  switch(_uiElementType)
199  {
200  case UI_ELEMENT_LABEL :
201  break;
202  case UI_ELEMENT_COMBO_BOX:
203 
204  if(!QString(value.typeName()).compare("QString") && _elementDataType!=DATA_TYPE_INTEGER)
205  {
206  setCurrentIndex(findText(value.toString()));
207  }
208  if(!QString(value.typeName()).compare("int") || _elementDataType==DATA_TYPE_INTEGER)
209  {
210  ((QComboBox *)_uiWidget)->setCurrentIndex(value.toInt());
211  }
212  break;
213  case UI_ELEMENT_LINE_EDIT:
214  ((QLineEdit *)_uiWidget)->setText(_uiValue.toString());
215  break;
216  case UI_ELEMENT_CHECK_BOX:
217  ((QCheckBox *)_uiWidget)->setChecked(value.toBool());
218  break;
219  case UI_ELEMENT_PUSH_BUTTON:
220  break;
221  case UI_ELEMENT_SPIN_BOX:
222  ((QSpinBox *)_uiWidget)->setValue(_uiValue.toInt());
223  break;
224  case UI_ELEMENT_DOUBLE_SPIN_BOX:
225  ((QDoubleSpinBox *)_uiWidget)->setValue(_uiValue.toDouble());
226  break;
227  case UI_ELEMENT_RADIO_BUTTON:
228  break;
229  case UI_ELEMENT_NO_UI:
230  _uiValue=value;
231  break;
232  case UI_ELEMENT_SLIDER:
233  ((QSlider *)_uiWidget)->setValue(_uiValue.toInt());
234  default:
235  break;
236  }
237  if(_elementDataType==DATA_TYPE_DOUBLE){_uiValue=value.toDouble();}
238  }
239  }
240 
241  void setEnabled(bool value)
242  {
243  if(_uiElementType!=UI_ELEMENT_NO_UI || _uiElementType!=UI_ELEMENT_CHECK_BOX)
244  {
245  if(_uiWidget)
246  _uiWidget->setEnabled(value);
247  }
248  }
249 
250  void addItem(const QString str)
251  {
252  if(_uiElementType!=UI_ELEMENT_COMBO_BOX){return;}
253  ((QComboBox *)_uiWidget)->addItem(str);
254  }
255 
256  void setCurrentIndex(short index)
257  {
258  if(_uiElementType!=UI_ELEMENT_COMBO_BOX){return;}
259  ((QComboBox *)_uiWidget)->setCurrentIndex(index);
260  }
261 
262  short getCurrenIndexComboBox()
263  {
264  if(_uiElementType!=UI_ELEMENT_COMBO_BOX){return 0;}
265  return(((QComboBox *)_uiWidget)->currentIndex());
266  }
267 
268  int findText(const QString &str)
269  {
270  return(((QComboBox*)_uiWidget)->findText(str));
271  }
272 
273  void clear()
274  {
275  QString str ="";
276  switch(_uiElementType)
277  {
278  case UI_ELEMENT_LABEL :
279  _uiValue.setValue(str);
280  ((QLabel *)getElement())->clear();
281  break;
282  case UI_ELEMENT_COMBO_BOX:
283  _uiValue.setValue(str);
284  ((QComboBox *)getElement())->clear();
285  break;
286  case UI_ELEMENT_LINE_EDIT:
287  _uiValue.setValue(str);
288  ((QLineEdit *)getElement())->clear();
289  break;
290  case UI_ELEMENT_CHECK_BOX:
291  _uiValue.setValue(false);
292  ((QCheckBox *)_uiWidget)->setChecked(false);
293  break;
294  case UI_ELEMENT_PUSH_BUTTON:
295  break;
296  case UI_ELEMENT_SPIN_BOX:
297  _uiValue.setValue(0);
298  ((QSpinBox *)getElement())->setValue(0);
299  break;
300  case UI_ELEMENT_DOUBLE_SPIN_BOX:
301  _uiValue.setValue(0.00);
302  ((QDoubleSpinBox *)getElement())->setValue(0.00);
303  break;
304  case UI_ELEMENT_RADIO_BUTTON:
305  break;
306  case UI_ELEMENT_NO_UI:
307  break;
308  case UI_ELEMENT_SLIDER:
309  _uiValue.setValue(0);
310  ((QSlider *)_uiWidget)->setValue(0);
311  default:
312  break;
313  }
314  }
315 
316 
317  bool compareValue(QVariant toCompare)
318  {
319  switch(_elementDataType)
320  {
321  case DATA_TYPE_SHORT:
322  return(getParamValue().toInt()==toCompare.toInt());
323  case DATA_TYPE_INTEGER:
324  return(getParamValue().toInt()==toCompare.toInt());
325  case DATA_TYPE_FLOAT:
326  return(getParamValue().toFloat()==toCompare.toFloat());
327  case DATA_TYPE_DOUBLE:
328  return(getParamValue().toDouble()==toCompare.toDouble());
329  case DATA_TYPE_STRING:
330  return(getParamValue().toString()==toCompare.toString());
331  case DATA_TYPE_SIGNED_LONG:
332  return(getParamValue().toLongLong()==toCompare.toLongLong());
333  case DATA_TYPE_UNSIGNED_LONG:
334  return(getParamValue().toLongLong()==toCompare.toLongLong());
335  case DATA_TYPE_CHARACTER:
336  return(getParamValue().toChar()==toCompare.toChar());
337  case DATA_TYPE_BOOLEAN:
338  return(getParamValue().toBool()==toCompare.toBool());
339  }
340  return false;
341  }
342 
343  void setcolumnProperties(QString colName,int colIndex,bool show)
344  {
345  _columnName=colName;
346  _columnIndex=colIndex;
347  _isShowInTable=show;
348  }
349  void setColumnEditable(bool type){_isColumnEditable = type;}
350  bool isColumnEditable(){return _isColumnEditable;}
351  bool isDbField(){return _isDbField;}
352  bool isUpdatable(){return _updatable;}
353  int getDecimals(){ return ((QDoubleSpinBox *)_uiWidget)->decimals();}
354  QString ItemAt(int index){return ((QComboBox *)_uiWidget)->itemText(index);}
355  void setColumnName(QString colName){_columnName=colName;}
356  void setColumnIndex(int colIndex){_columnIndex=colIndex;}
357  void showLabel(bool value){ _uiLabel->setVisible(value);}
358  void setFilterType(short type){_filterType = type;}
359  short getFilterType(){return _filterType;}
360  void setWidget(QWidget *wid){_uiWidget = wid;}
361  void setDefaultPrecision(bool isDefaultPrecision){_isDefaultPrecision =isDefaultPrecision;}
362  bool isDefaultPrecision(){return _isDefaultPrecision;}
363  void setChecked(bool value){((QCheckBox *)_uiWidget)->setChecked(value);}
364  void removeItem(int index) {((QComboBox *)_uiWidget)->removeItem(index);}
365  QWidget* getElement() {return _uiWidget;}
366  QString getWidgetName() {return _uiLabel->text();}
367  short getElementType(){return _uiElementType;}
368  short isShowInStrategyTable(){return _isShowInTable;}
369  short getElementDataType(){return _elementDataType;}
370  bool isChecked(){return(((QCheckBox *)_uiWidget)->isChecked());}
371  short getParamState(){return _uiElementState;}
372  int Count(){ return ((QComboBox *)_uiWidget)->count();}
373  bool isGui(){ return _uiElementType!=UI_ELEMENT_NO_UI;}
374  Qt::CheckState checkedState(){return ((QCheckBox *)_uiWidget)->checkState();}
375  qlonglong getLongLongValue(){ return getParamValue().toLongLong();}
376  QString currentText(){return getParamValue().toString();}
377  int currentIndex(){return(((QComboBox *)_uiWidget)->currentIndex());}
378  int spinBoxValue(){ return getParamValue().toInt();}
379  double dspinBoxValue() {return getParamValue().toDouble();}
380  QString getParamName(){ return _uiLabelName;}
381  QString getColumnName(){ return _columnName;}
382  int getColumnIndex(){return _columnIndex;}
383  void setColumnHidden(bool isHidden){_isColumnHidden =isHidden;}
384  bool isColumnHidden(){return _isColumnHidden;}
385  void setSortingType(short type){_sortingType = type;}
386  short getSortingType(){return _sortingType;}
387  void setPortfolioIndex(short index){_portfolioIndex = index;}
388  short getPortfolioIndex(){return _portfolioIndex;}
389  bool isShowInPortfolio() {return _isShowInPortfolio; }
390 };
391 typedef StrategyParameters PARAM;
392 typedef QMap<QString,PARAM *> StrategyParamMap;
393 typedef QMap<QString,QVariant> StgValueMap;
394 typedef QVector<StrategyParamMap *> ParamMapGroup;
395 }
396 #endif // SHAREDPARAMS_H
397 
398 
Definition: sharedParams.h:13
StrategyParameters(const QString &paramNameArg, const QString &colName, QWidget *uiWidget, short elementType, short dataType=API2::DATA_TYPE_UNSIGNED_LONG, short state=API2::UI_STATE_DISABLED, short showTableStatus=API2::TABLE_STATE_HIDE, short isDbColumn=API2::DB_FEILD_HIDE, short isUpdatable=API2::UPDATE_STATE_DISABLE, short portfolioState=API2::SHOW_IN_PORTFOLIO_DISABLE)
Constructor structure name - DbName colName widget widgetype datatype string state enable tablestatus...
Definition: sharedParams.h:55