src/TesterRulePage.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include <qlayout.h>
00023 #include <qvgroupbox.h>
00024 #include <qfile.h>
00025 #include <qtextstream.h>
00026 #include "TesterRulePage.h"
00027 
00028 
00029 TesterRulePage::TesterRulePage (QWidget *p) : QWidget (p)
00030 {
00031   QVBoxLayout *vbox = new QVBoxLayout(this);
00032   vbox->setMargin(5);
00033   vbox->setSpacing(5);
00034   
00035   QGridLayout *grid = new QGridLayout(vbox, 2, 2);
00036   
00037   QVGroupBox *gbox = new QVGroupBox(tr("Enter Long"), this);
00038   grid->addWidget(gbox, 0, 0);
00039 
00040   enterLongEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  
00041   
00042   gbox = new QVGroupBox(tr("Exit Long"), this);
00043   grid->addWidget(gbox, 0, 1);
00044 
00045   exitLongEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  
00046 
00047   gbox = new QVGroupBox(tr("Enter Short"), this);
00048   grid->addWidget(gbox, 1, 0);
00049 
00050   enterShortEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  
00051   
00052   gbox = new QVGroupBox(tr("Exit Short"), this);
00053   grid->addWidget(gbox, 1, 1);
00054 
00055   exitShortEdit = new FormulaEdit(gbox, FormulaEdit::Logic);  
00056 }
00057 
00058 TesterRulePage::~TesterRulePage ()
00059 {
00060 }
00061 
00062 void TesterRulePage::saveEditRule (EditRule type, QString &ruleName)
00063 {
00064   Config config;
00065   FormulaEdit *edit = 0;
00066   QString s;
00067   config.getData(Config::TestPath, s);
00068   s.append("/" + ruleName);
00069   
00070   switch(type)
00071   {
00072     case 0:
00073       edit = enterLongEdit;
00074       s.append("/el/rule");
00075       break;
00076     case 1:
00077       edit = exitLongEdit;
00078       s.append("/xl/rule");
00079       break;
00080     case 2:
00081       edit = enterShortEdit;
00082       s.append("/es/rule");
00083       break;
00084     case 3:
00085       edit = exitShortEdit;
00086       s.append("/xs/rule");
00087       break;
00088     default:
00089       break;
00090   }
00091 
00092   QFile f(s);
00093   if (! f.open(IO_WriteOnly))
00094     return;
00095   QTextStream stream(&f);
00096 
00097   edit->getText(s);
00098   stream << s << "\n";
00099   
00100   f.close();
00101 }
00102 
00103 void TesterRulePage::loadEditRule (EditRule type, QString &ruleName)
00104 {
00105   Config config;
00106   FormulaEdit *edit = 0;
00107   QString s;
00108   config.getData(Config::TestPath, s);
00109   s.append("/" + ruleName);
00110   
00111   switch(type)
00112   {
00113     case 0:
00114       edit = enterLongEdit;
00115       s.append("/el/rule");
00116       break;
00117     case 1:
00118       edit = exitLongEdit;
00119       s.append("/xl/rule");
00120       break;
00121     case 2:
00122       edit = enterShortEdit;
00123       s.append("/es/rule");
00124       break;
00125     case 3:
00126       edit = exitShortEdit;
00127       s.append("/xs/rule");
00128       break;
00129     default:
00130       break;
00131   }
00132 
00133   QFile f(s);
00134   if (! f.open(IO_ReadOnly))
00135     return;
00136   QTextStream stream(&f);
00137 
00138   while(stream.atEnd() == 0)
00139   {
00140     s = stream.readLine();
00141     s = s.stripWhiteSpace();
00142     if (! s.length())
00143       continue;
00144   
00145     edit->setLine(s);
00146   }  
00147   
00148   f.close();
00149 }
00150 
00151 QString TesterRulePage::getEditRule (EditRule type)
00152 {
00153   QString s;
00154   switch (type)
00155   {
00156     case EnterLong:
00157       enterLongEdit->getText(s);
00158       break;
00159     case ExitLong:
00160       exitLongEdit->getText(s);
00161       break;
00162     case EnterShort:
00163       enterShortEdit->getText(s);
00164       break;
00165     case ExitShort:
00166       exitShortEdit->getText(s);
00167       break;
00168     default:
00169       break;
00170   }
00171 
00172   return s;
00173 }
00174